使用emacs将文本作为参数传递给外部程序

Sen*_*ess 4 emacs

假设我在文件中包含此文本:

/home is where the heart is.
Run Code Online (Sandbox Code Playgroud)

例如,如果我选择/home文本,使用C-spc,有没有办法将它发送到ls,那么最终是否会执行ls /homeM-|不起作用.

Vic*_*gin 5

据我所知,没有办法直接在Emacs中这样做.但是在elisp的帮助下,一切皆有可能:

(defun region-as-argument-to-command (cmd)
  (interactive "sCommand: ")
  (shell-command
   (format
    "%s %s"
    cmd
    (shell-quote-argument
     (buffer-substring (region-beginning)
                       (region-end))))))
Run Code Online (Sandbox Code Playgroud)


hua*_*uan 5

试试 M-| xargs ls.也就是说,xargs ls在所选区域上传递" "作为shell命令.

xargs.