开发者

Multiple asynchronous shell-commands in Emacs-Dired?

开发者 https://www.devze.com 2023-03-25 12:28 出处:网络
Emacs obviously can handle multiple asynchronous sub-processes, otherwise a multi-language programming environment like org-babel, to 开发者_高级运维give an example, wouldn\'t be possible.

Emacs obviously can handle multiple asynchronous sub-processes, otherwise a multi-language programming environment like org-babel, to 开发者_高级运维give an example, wouldn't be possible.

However, when I'm in Dired and start an asynchronous shell command to view a pdf file (& evince), and then try to do the same on a second pdf file, I get the following message:

"A command is running - kill it? Yes or No?"

Is there a way to run several asynchronous shell commands in parallel, when in Dired?


When you use dired-do-async-shell-command Emacs create a *Async Shell Command* buffer. If you want another async command you need to rename this buffer, for example using M-x rename-uniquely

you could try to change the comportment of dired-do-async-shell-command by advising it:

 (defadvice shell-command (after shell-in-new-buffer (command &optional output-buffer error-buffer))
    (when (get-buffer "*Async Shell Command*")
      (with-current-buffer "*Async Shell Command*"
         (rename-uniquely))))
 (ad-activate 'shell-command)

note that I really advice the shell-command Emacs command because it's called by dired.


I don't think it's possible with dired-do-async-shell-command, but if you just want to open some file is certain external application I suggest using OpenWith, which allows any number of external processes running.


I've just setup the following which erases the current definition of dired-run-shell-command to pass a dedicated buffer name to shell-command:

(defun dired-run-shell-command (command)
       (let ((handler
          (find-file-name-handler (directory-file-name default-directory)
                      'shell-command)))
     (if handler (apply handler 'shell-command (list command))
       (shell-command command
              (generate-new-buffer-name
               (concat "*Shell Command Output: '" command "'*")))))
       ;; Return nil for sake of nconc in dired-bunch-files.
       nil)
0

精彩评论

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

关注公众号