Take the 2-minute tour ×

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

share|improve this question

2 Answers 2

up vote 1 down vote accepted

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))))))))
share|improve this answer

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

(defadvice term-handle-exit
  (after term-kill-buffer-on-exit activate)
share|improve this answer

Your Answer


