How to automatically kill a buffer on terminal output in Emacs

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

+4
source share
2 answers

I found that I can use process breakpoints for this 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)))))))) 
+1
source

I found a much simpler method by defining term-handle-exit advice

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

Source: https://habr.com/ru/post/1436642/


All Articles