开发者

Pass text as argument to external program using emacs

Let's say I have this text in a file:

开发者_如何学编程
/home is where the heart is.

If for example, I select the /home text, using C-spc, is there a way of sending it to ls, so that in the end if will execute ls /home? M-| does not work.


As far as I know, there is no way to do that in Emacs directly. But everyting is possible with help of 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))))))


Try M-| xargs ls. That is, pass "xargs ls" as the shell command on the region selected.

See xargs.


Victor's answer is a good one for the question you asked, but in your specific case you might consider using M-x ffap (find-file-at-point). This will give you a dired buffer for the /home directory.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜