]> code.delx.au - gnu-emacs/blobdiff - lisp/eshell/em-term.el
No longer set dired-directory in eshell. (Bug#16477)
[gnu-emacs] / lisp / eshell / em-term.el
index 2932f443e4fcac577dc0fb9c370d832bd7a85159..9ac281372cfe3d1cad5f298054b126867e19c131 100644 (file)
@@ -1,6 +1,6 @@
-;;; em-term.el --- running visual commands
+;;; em-term.el --- running visual commands  -*- lexical-binding:t -*-
 
-;; Copyright (C) 1999-2013 Free Software Foundation, Inc.
+;; Copyright (C) 1999-2015 Free Software Foundation, Inc.
 
 ;; Author: John Wiegley <johnw@gnu.org>
 
@@ -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)
@@ -189,20 +196,25 @@ allowed."
          (term-set-escape-char ?\C-x))))
   nil)
 
-(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))))
+;; Process sentinels receive two arguments.
+(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.