]> git.eshelyaron.com Git - emacs.git/commitdiff
(term-exec): Set up sentinel.
authorRichard M. Stallman <rms@gnu.org>
Mon, 29 Dec 2003 19:58:11 +0000 (19:58 +0000)
committerRichard M. Stallman <rms@gnu.org>
Mon, 29 Dec 2003 19:58:11 +0000 (19:58 +0000)
(term-sentinel): New function.
(term-handle-exit): New function.

lisp/term.el

index d2088a29785cac142d82b5130d94d07d68e3726e..b329004c0836c488f645078ffb3be196db20e4e6 100644 (file)
@@ -1290,6 +1290,7 @@ buffer.  The hook term-exec-hook is run after each exec."
       (goto-char (point-max))
       (set-marker (process-mark proc) (point))
       (set-process-filter proc 'term-emulate-terminal)
+      (set-process-sentinel proc 'term-sentinel)
       ;; Feed it the startfile.
       (cond (startfile
             ;;This is guaranteed to wait long enough
@@ -1306,6 +1307,49 @@ buffer.  The hook term-exec-hook is run after each exec."
     (run-hooks 'term-exec-hook)
     buffer)))
 
+(defun term-sentinel  (proc msg)
+  "Sentinel for term buffers.
+The main purpose is to get rid of the local keymap."
+  (let ((buffer (process-buffer proc)))
+    (if (memq (process-status proc) '(signal exit))
+       (progn
+         (if (null (buffer-name buffer))
+             ;; buffer killed
+             (set-process-buffer proc nil)
+           (let ((obuf (current-buffer)))
+             ;; save-excursion isn't the right thing if
+             ;; process-buffer is current-buffer
+             (unwind-protect
+                 (progn
+                   ;; Write something in the compilation buffer
+                   ;; and hack its mode line.
+                   (set-buffer buffer)
+                   ;; Get rid of local keymap.
+                   (use-local-map nil)
+                   (term-handle-exit (process-name proc)
+                                     msg)
+                   ;; Since the buffer and mode line will show that the
+                   ;; process is dead, we can delete it now.  Otherwise it
+                   ;; will stay around until M-x list-processes.
+                   (delete-process proc))
+               (set-buffer obuf))))
+         ))))
+
+(defun term-handle-exit (process-name msg)
+  "Write process exit (or other change) message MSG in the current buffer."
+  (let ((buffer-read-only nil)
+       (omax (point-max))
+       (opoint (point)))
+    ;; Record where we put the message, so we can ignore it
+    ;; later on.
+    (goto-char omax)
+    (insert ?\n "Process " process-name " " msg)
+    ;; Force mode line redisplay soon.
+    (force-mode-line-update)
+    (if (and opoint (< opoint omax))
+       (goto-char opoint))))
+
+
 ;;; Name to use for TERM.
 ;;; Using "emacs" loses, because bash disables editing if TERM == emacs.
 (defvar term-term-name "eterm")