diff --git a/users/crumb/programs/emacs/modules/syd-ui.el b/users/crumb/programs/emacs/modules/syd-ui.el index eaa9108..d288f7c 100755 --- a/users/crumb/programs/emacs/modules/syd-ui.el +++ b/users/crumb/programs/emacs/modules/syd-ui.el @@ -94,20 +94,27 @@ (scroll-bar-mode -1) (tool-bar-mode -1)) -(defun syd-init-kill-comint-on-exit () - (defun syd-comint--kill-buffer-sentinel (process output) +(defun syd-init-kill-process-buffer-on-exit () + (defun syd-comint--kill-buffer-sentinel (process _output) "Process sentinel to auto kill associated buffer once PROCESS dies." - (unless (process-live-p process) - (kill-buffer (process-buffer process)))) + ;; Note that `process-exit-status' returns zero when the process has not yet + ;; died. + (unless (and process (zerop (process-exit-status process))) + (let ((buffer (process-buffer process))) + (with-current-buffer buffer + (goto-char (point-max)) + (insert (format "\n[Process exited with exit status %d]" + (process-exit-status process)))) + (kill-buffer (process-buffer process))))) (defun syd-comint--add-kill-on-exit-sentinel () "Replace current process sentinel with a new sentinel composed of the current one and `syd-comint--kill-buffer-sentinel'." (let* ((process (get-buffer-process (current-buffer))) - (og-sentinel (process-sentinel process)) + (original-sentinel (process-sentinel process)) (sentinel-list (-remove #'null - (list og-sentinel #'syd-comint--kill-buffer-sentinel))) + (list original-sentinel #'syd-comint--kill-buffer-sentinel))) (combined-sentinel (lambda (process line) (--each sentinel-list @@ -127,11 +134,11 @@ for example when calling `shell'.") (syd-add-hook 'comint-mode-hook (defun syd-comint--kill-on-exit-h () - (unless syd-comint--kill-on-exit-h-has-run - (setq-local syd-comint--kill-on-exit-h-has-run t) - (syd-comint--async-funcall - #'syd-comint--add-kill-on-exit-sentinel - (current-buffer)))))) + (unless syd-comint--kill-on-exit-h-has-run + (setq-local syd-comint--kill-on-exit-h-has-run t) + (syd-comint--async-funcall + #'syd-comint--add-kill-on-exit-sentinel + (current-buffer)))))) (with-eval-after-load 'comint (require 'syd-kanagawa) @@ -143,8 +150,6 @@ for example when calling `shell'.") :background unspecified :weight bold)))) - (syd-init-kill-comint-on-exit) - (general-def :keymaps 'comint-mode-map :states '(normal insert) @@ -163,6 +168,7 @@ for example when calling `shell'.") (set-popup-rule! "*Messages*" :ttl nil :quit t) + (syd-init-kill-process-buffer-on-exit) ;; Required for :quit t to do anything. (evil-set-initial-state 'messages-buffer-mode 'motion) (evil-set-initial-state 'debugger-mode 'normal)