9

I frequently launch external programs from emacs using M-!, such as Firefox or Evince, etc. Whenever I do, a buffer pops up full of results for the process, which clobbers whatever else I've got going on in terms of windows arrangement.

Is there a way to bury such buffers by default, so that I don't have to see them unless I decide to go looking for them?

Chillar Anand
  • 4,042
  • 1
  • 23
  • 52
Steven Arntson
  • 1,313
  • 9
  • 27
  • 3
    Possible duplicate of [How can I run an async process in the background without popping up a buffer?](https://emacs.stackexchange.com/questions/299/how-can-i-run-an-async-process-in-the-background-without-popping-up-a-buffer) – Basil May 10 '18 at 15:09

4 Answers4

12

Since mention that the command is running asynchronously I am assuming you mean the command async-shell-command bound to M-&. You can follow the advice in documentation of async-shell-command (you can read it by doing C-hfasync-shell-commandRET) customize display-buffer-alist as follows

(add-to-list 'display-buffer-alist (cons "\\*Async Shell Command\\*.*" (cons #'display-buffer-no-window nil)))

Now the buffer used by the command to display output will never be shown.

Iqbal Ansari
  • 7,468
  • 1
  • 28
  • 31
  • This works beautifully, thank you. Additionally, I didn't know about `M-&` either. I was using `M-!` and then manually adding the `&` to the command I passed to the shell. – Steven Arntson Dec 19 '14 at 18:12
4

Emacs has a general-purpose facility to prevent any unintentional (or indeed intentional) window configuration changes from causing problems.

Add (winner-mode 1) to your init file. Then when something messes up your windows, use C-c<left> (winner-undo) to restore them. You can use it repeatedly to undo multiple window configuration changes. C-c<right> (winner-redo) returns you to the most recent configuration.

phils
  • 48,657
  • 3
  • 76
  • 115
4

Here's my configuration. It should work great if you're on Linux.

(require 'dired-aux)

(defvar dired-filelist-cmd
  '(("vlc" "-L")))

(defun dired-start-process (cmd &optional file-list)
  (interactive
   (let ((files (dired-get-marked-files t current-prefix-arg)))
     (list
      (dired-read-shell-command "& on %s: " current-prefix-arg files)
      files)))
  (start-process
   cmd nil shell-file-name
   shell-command-switch
   (format "nohup 1>/dev/null 2>/dev/null %s \"%s\""
           (if (> (length file-list) 1)
               (format "%s %s" cmd
                       (cadr (assoc cmd dired-filelist-cmd)))
             cmd)
           (mapconcat #'expand-file-name file-list "\" \""))))

(define-key dired-mode-map "r" 'dired-start-process)

Not only will it hide those pesky buffers when you e.g. open a pdf file from dired, Evince will persist even if you close Emacs. There's also a small customization for queuing up marked video files for a vlc playlist.

abo-abo
  • 13,943
  • 1
  • 29
  • 43
2

You can suppress that window for a single command instead of globally using let

(let ((display-buffer-alist
       (cons (cons "\\*Async Shell Command\\*.*"
                   (cons #'display-buffer-no-window nil))
             display-buffer-alist))) ;; suppress async shell command window
  (async-shell-command command))
killdash9
  • 179
  • 8