我编写了一个函数,它接受所选区域的内容,然后通过两个外部进程运行它。有效地,我想要复制的行为是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)))
答案 0 :(得分:1)
只需在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*
以查看输出。