]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/eshell/em-term.el (eshell-term-sentinel):
authorSamer Masterson <samer@samertm.com>
Sun, 17 May 2015 21:55:16 +0000 (14:55 -0700)
committerSamer Masterson <samer@samertm.com>
Sun, 17 May 2015 21:57:13 +0000 (14:57 -0700)
No-op by default, only kills term buffer if
`eshell-destroy-buffer-when-process-dies' is non-nil.  (Bug#18108)
(eshell-destroy-buffer-when-process-dies): New custom to preserve
previous behavior.

etc/NEWS
lisp/eshell/em-term.el

index cf26ded7656f45560c57f39e209e25d6139738b7..c0401863382a457193d5c6f0ce57d463f40b6b03 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -681,6 +681,14 @@ buffers from eshell more convenient.  Custom variable
 `eshell-buffer-shorthand', which has been broken for a while, has been
 removed.
 
+*** By default, eshell "visual" program buffers (created by
+`eshell-visual-commands' and similar custom vars) are no longer killed
+when their processes die.  This fixes issues with short-lived commands
+and makes visual programs more useful in general.  For example, if
+"git log" is a visual command, it will always show the visual command
+buffer, even if the "git log" process dies.  For the old behavior,
+make the new option `eshell-destroy-buffer-when-process-dies' non-nil.
+
 ** Browse-url
 
 *** Support for the Conkeror web browser.
index 4a6ac23544951c2f4f4a173846b5459097660522..9ac281372cfe3d1cad5f298054b126867e19c131 100644 (file)
@@ -132,6 +132,13 @@ character to the invoked process."
   :type 'boolean
   :group 'eshell-term)
 
+(defcustom eshell-destroy-buffer-when-process-dies nil
+  "If non-nil, term buffers are destroyed after their processes die.
+WARNING: Setting this to non-nil may result in unexpected
+behavior for short-lived processes, see bug#18108."
+  :type 'boolean
+  :group 'eshell-term)
+
 ;;; Internal Variables:
 
 (defvar eshell-parent-buffer)
@@ -190,20 +197,24 @@ allowed."
   nil)
 
 ;; Process sentinels receive two arguments.
-(defun eshell-term-sentinel (proc _string)
-  "Destroy the buffer visiting PROC."
-  (let ((proc-buf (process-buffer proc)))
-    (when (and proc-buf (buffer-live-p proc-buf)
-              (not (eq 'run (process-status proc)))
-              (= (process-exit-status proc) 0))
-      (if (eq (current-buffer) proc-buf)
-         (let ((buf (and (boundp 'eshell-parent-buffer)
-                         eshell-parent-buffer
-                         (buffer-live-p eshell-parent-buffer)
-                         eshell-parent-buffer)))
-           (if buf
-               (switch-to-buffer buf))))
-      (kill-buffer proc-buf))))
+(defun eshell-term-sentinel (proc msg)
+  "Clean up the buffer visiting PROC.
+If `eshell-destroy-buffer-when-process-dies' is non-nil, destroy
+the buffer."
+  (term-sentinel proc msg) ;; First call the normal term sentinel.
+  (when eshell-destroy-buffer-when-process-dies
+    (let ((proc-buf (process-buffer proc)))
+      (when (and proc-buf (buffer-live-p proc-buf)
+                 (not (eq 'run (process-status proc)))
+                 (= (process-exit-status proc) 0))
+        (if (eq (current-buffer) proc-buf)
+            (let ((buf (and (boundp 'eshell-parent-buffer)
+                            eshell-parent-buffer
+                            (buffer-live-p eshell-parent-buffer)
+                            eshell-parent-buffer)))
+              (if buf
+                  (switch-to-buffer buf))))
+        (kill-buffer proc-buf)))))
 
 ;; jww (1999-09-17): The code below will allow Eshell to send input
 ;; characters directly to the currently running interactive process.