我编写了一个函数,它接受所选区域的内容,然后通过两个外部进程运行它。实际上,我想复制的行为是M-| smartypants -2 | ascii2uni -a D -q。
下面的函数可以工作,但需要对call-process-region进行两次调用,并将第一个进程的输出暂时存储在缓冲区中。有更好的方法吗?
(defun convert-ascii-to-unicode (&optional b e)
"Converts ascii punctuation marks (quotes, dashes, and ellipses) into their unicode equivilents."
(interactive "r")
(let ((output-buffer (generate-new-buffer "*ASCII to Unicode Output*")))
(call-process-region b e "smartypants" nil output-buffer nil "-2")
(set-buffer output-buffer)
(call-process-region (point-min) (point-max) "ascii2uni" t output-buffer nil "-a" "D" "-q")
(switch-to-buffer-other-window output-buffer)))发布于 2015-05-27 15:38:22
只需在shell命令中使用管道,下面的命令就可以执行您想要的操作:
(defun convert-ascii-to-unicode (beg end)
(interactive "r")
(shell-command
(format "smartypants -2 %s | ascii2uni -a D -q"
(shell-quote-argument (buffer-substring beg end)))))切换到*Shell Command Output*以查看输出。
https://stackoverflow.com/questions/30477567
复制相似问题