jcubic
jcubic

Reputation: 66480

How to automatically kill buffer on terminal process exit in Emacs

How can I automatically kill the terminal buffer when the process associated with it ends.

Upvotes: 6

Views: 1076

Answers (2)

Łukasz Gruner
Łukasz Gruner

Reputation: 3179

I found much simpler method, define an advice on term-handle-exit

(defadvice term-handle-exit
  (after term-kill-buffer-on-exit activate)
(kill-buffer))

Upvotes: 6

jcubic
jcubic

Reputation: 66480

I found that I can use process sentinels for that and set it using term-exec-hook

(add-hook 'term-exec-hook (lambda ()
            (let* ((buff (current-buffer))
                 (proc (get-buffer-process buff)))
            (lexical-let ((buff buff))
               (set-process-sentinel proc (lambda (process event)
                            (if (string= event "finished\n")
                                       (kill-buffer buff))))))))

Upvotes: 1

Related Questions