i have this function you guys helped me write

 (defun z/dired-shell-other-window-beets ()
   (let ((command (concat "beet import " (format "%S" (dired-get-filename)))))
     (switch-to-buffer (shell)
       (insert command)

is there a way to 1. rename the buffer to beets when created and 2.auto close (kill) the beets buffer when the command i run beet import finishes running?

  • Do you actually want the buffer at all (e.g. to see the output of the beet command)? If not there are better ways of running commands than starting a shell window, To directly answer the first part of your question, use (shell "beets").
    – icarus
    Dec 23 '16 at 12:55
  • 1
    thx @icarus. for various reasons yes i would like to get the buffer output and see it. sometimes beets will ask questions interactively and thus its needed. thx.
    – zeltak
    Dec 23 '16 at 14:46
  • 2
    How about using start-process and a process-sentinel instead of a shell; or, start-process-shell-command? gnu.org/software/emacs/manual/html_node/elisp/… And, here is the link for sentinels: gnu.org/software/emacs/manual/html_node/elisp/Sentinels.html With the process sentinel, you can monitor the output for things like a finished signal. With a process filter, you can monitor additional output.
    – lawlist
    Dec 23 '16 at 15:30

CAVEAT: The two snippets below are examples using the function ls that is available on most *nix systems. Copy and paste snippets to the *scratch* buffer, place the cursor immediately following the last parentheses of either snippet, and press: C-x C-e (aka eval-last-sexp).

The following snippet is an example using the function shell to process a string with comint-simple-send:

(let ((kill-buffer-query-functions nil)
      (buf (shell "*OUTPUT-BUFFER*")))
   (comint-simple-send buf "ls -la")
   (sit-for 2)
   (kill-process (get-buffer-process buf))
   (when (and (not (one-window-p)) (get-buffer-window buf))
      (delete-window (get-buffer-window buf)))
   (kill-buffer buf))

The following snippet is with start-process and set-process-sentinel:

  (lambda (p e)
    (when (= 0 (process-exit-status p))
      (let ((buf (process-buffer p)))
        (when (get-buffer buf)
          (display-buffer buf t)
          (sit-for 2)
          (delete-window (get-buffer-window buf))
          (kill-buffer buf))))))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.