开发者

function to call same shell command in dired

开发者 https://www.devze.com 2022-12-13 09:48 出处:网络
i\'d like to be abl开发者_JAVA技巧e to call the same shell command on the marked files in dired without the need for emacs to prompt the command input as the command will always be the same.in particu

i'd like to be abl开发者_JAVA技巧e to call the same shell command on the marked files in dired without the need for emacs to prompt the command input as the command will always be the same. in particular, the command is "open" (for mac os x).

i tried to hack the function dired-do-shell-command in dired-aux.el but i don't understand the interactive line.

at the end of the day, i'd like to be able to bind this function to C-o for dired-mode so that i don't have to use mac os x's Finder to navigate files and open them. this will allow me to move to emacs entirely.

thanks.


(defun dired-open ()
  (interactive)
  (dired-do-async-shell-command
   "open" current-prefix-arg
   (dired-get-marked-files t current-prefix-arg)))

(define-key dired-mode-map (kbd "C-o") 'dired-open)

Edit:

We may use save-window-excursion to protect the existing window configuration from being messed up by the output buffer:

(defun dired-open ()
  (interactive)
  (save-window-excursion
    (dired-do-async-shell-command
     "open" current-prefix-arg
     (dired-get-marked-files t current-prefix-arg))))
0

精彩评论

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