]> code.delx.au - gnu-emacs/blobdiff - lisp/comint.el
(comint-preinput-scroll-to-bottom): Added
[gnu-emacs] / lisp / comint.el
index 7bea60b54097b08c1007cb484e6b0e057b4ac6d7..771be5e5838d6c612eca7506f7c9cb81c0e4e279 100644 (file)
 ;;;     comint-input-send      - function         ...
 ;;;     comint-eol-on-send     - boolean          ...
 ;;;     comint-process-echoes   - boolean          ...
-;;;     comint-scroll-to-bottom-on-input - symbol For scroll behaviour
+;;;     comint-scroll-to-bottom-on-input - symbol For scroll behavior
 ;;;     comint-scroll-to-bottom-on-output - symbol    ...
 ;;;     comint-scroll-show-maximum-output - boolean   ...
 ;;;
 ;;; Comint mode non-buffer local variables:
 ;;;     comint-completion-addsuffix - boolean   For file name completion
-;;;     comint-completion-autolist  - boolean       behaviour
+;;;     comint-completion-autolist  - boolean       behavior
 ;;;     comint-completion-recexact  - boolean       ...
 
 (defvar comint-prompt-regexp "^"
@@ -161,7 +161,7 @@ This is a good thing to set in mode hooks.")
 
 (defvar comint-input-autoexpand 'history
   "*If non-nil, expand input command history references on completion.
-This mirrors the optional behaviour of the tcsh (its autoexpand and histlit).
+This mirrors the optional behavior of tcsh (its autoexpand and histlit).
 
 If the value is `input', then the expansion is seen on input.
 If the value is `history', then the expansion is only when inserting
@@ -172,7 +172,7 @@ This variable is buffer-local.")
 
 (defvar comint-input-ignoredups nil
   "*If non-nil, don't add input matching the last on the input ring.
-This mirrors the optional behaviour of the bash.
+This mirrors the optional behavior of bash.
 
 This variable is buffer-local.")
 
@@ -182,35 +182,33 @@ See also `comint-read-input-ring' and `comint-write-input-ring'.
 
 This variable is buffer-local, and is a good thing to set in mode hooks.")
 
-(defvar comint-scroll-to-bottom-on-input
-  nil
+(defvar comint-scroll-to-bottom-on-input nil
   "*Controls whether input to interpreter causes window to scroll.
 If nil, then do not scroll.  If t or `all', scroll all windows showing buffer.
 If `this', scroll only the selected window.
 
-The default nil.
+The default is nil.
 
 See `comint-preinput-scroll-to-bottom'.  This variable is buffer-local.")
 
-(defvar comint-scroll-to-bottom-on-output 
-  (if (> baud-rate 9600) 'this)
+(defvar comint-scroll-to-bottom-on-output nil
   "*Controls whether interpreter output causes window to scroll.
 If nil, then do not scroll.  If t or `all', scroll all windows showing buffer.
 If `this', scroll only the selected window.
 If `others', scroll only those that are not the selected window.
-The default is `this' for fast terminals, nil for slower ones.
+
+The default is nil.
 
 See variable `comint-scroll-show-maximum-output' and function
 `comint-postoutput-scroll-to-bottom'.  This variable is buffer-local.")
+
 (defvar comint-scroll-show-maximum-output t
   "*Controls how interpreter output causes window to scroll.
 If non-nil, then show the maximum output when the window is scrolled.
+
 See variable `comint-scroll-to-bottom-on-output' and function
 `comint-postoutput-scroll-to-bottom'.  This variable is buffer-local.")
+
 (defvar comint-input-ring-size 32
   "Size of input history ring.")
 
@@ -1112,60 +1110,59 @@ Similarly for Soar, Scheme, etc."
 ;; when output is inserted.
 (defun comint-output-filter (process string)
   ;; First check for killed buffer
-  (if (not (comint-check-proc (process-buffer process)))
-      (message
-       "comint-output-filter: buffer %s received output with no process"
-       (process-buffer process))
-    (let ((obuf (current-buffer))
-         (opoint nil) (obeg nil) (oend nil))
-      (set-buffer (process-buffer process))
-      (setq opoint (point))
-      (setq obeg (point-min))
-      (setq oend (point-max))
-      (let ((buffer-read-only nil)
-           (nchars (length string))
-           (ostart nil))
-       (widen)
-       (goto-char (process-mark process))
-       (setq ostart (point))
-       (if (<= (point) opoint)
-           (setq opoint (+ opoint nchars)))
-       ;; Insert after old_begv, but before old_zv.
-       (if (< (point) obeg)
-           (setq obeg (+ obeg nchars)))
-       (if (<= (point) oend)
-           (setq oend (+ oend nchars)))
-       (insert-before-markers string)
-       ;; Don't insert initial prompt outside the top of the window.
-       (if (= (window-start (selected-window)) (point))
-           (set-window-start (selected-window) (- (point) (length string))))
-       (if (and comint-last-input-end
-                (marker-buffer comint-last-input-end)
-                (= (point) comint-last-input-end))
-           (set-marker comint-last-input-end (- comint-last-input-end nchars)))
-       (set-marker comint-last-output-start ostart)
-       (set-marker (process-mark process) (point))
-       (force-mode-line-update))
-
-      (narrow-to-region obeg oend)
-      (goto-char opoint)
-      (let ((functions comint-output-filter-functions))
-       (while functions
-         (funcall (car functions) string)
-         (setq functions (cdr functions))))
-      (set-buffer obuf))))
+  (let ((oprocbuf (process-buffer process)))
+    (if (and oprocbuf (buffer-name oprocbuf))
+       (let ((obuf (current-buffer))
+             (opoint nil) (obeg nil) (oend nil))
+         (set-buffer oprocbuf)
+         (setq opoint (point))
+         (setq obeg (point-min))
+         (setq oend (point-max))
+         (let ((buffer-read-only nil)
+               (nchars (length string))
+               (ostart nil))
+           (widen)
+           (goto-char (process-mark process))
+           (setq ostart (point))
+           (if (<= (point) opoint)
+               (setq opoint (+ opoint nchars)))
+           ;; Insert after old_begv, but before old_zv.
+           (if (< (point) obeg)
+               (setq obeg (+ obeg nchars)))
+           (if (<= (point) oend)
+               (setq oend (+ oend nchars)))
+           (insert-before-markers string)
+           ;; Don't insert initial prompt outside the top of the window.
+           (if (= (window-start (selected-window)) (point))
+               (set-window-start (selected-window) (- (point) (length string))))
+           (if (and comint-last-input-end
+                    (marker-buffer comint-last-input-end)
+                    (= (point) comint-last-input-end))
+               (set-marker comint-last-input-end (- comint-last-input-end nchars)))
+           (set-marker comint-last-output-start ostart)
+           (set-marker (process-mark process) (point))
+           (force-mode-line-update))
+
+         (narrow-to-region obeg oend)
+         (goto-char opoint)
+         (let ((functions comint-output-filter-functions))
+           (while functions
+             (funcall (car functions) string)
+             (setq functions (cdr functions))))
+         (set-buffer obuf)))))
 
 (defun comint-preinput-scroll-to-bottom ()
   "Go to the end of buffer in all windows showing it.
 Movement occurs if point in the selected window is not after the process mark,
 and `this-command' is an insertion command.  Insertion commands recognised
-are `self-insert-command', `yank', `mouse-yank-at-click', and `hilit-yank'.
+are `self-insert-command', `comint-magic-space', `yank', `mouse-yank-at-click',
+and `hilit-yank'.
 Depends on the value of `comint-scroll-to-bottom-on-input'.
 
 This function should be a pre-command hook."
   (if (and comint-scroll-to-bottom-on-input
-          (memq this-command '(self-insert-command yank mouse-yank-at-click
-                               hilit-yank)))
+          (memq this-command '(self-insert-command comint-magic-space yank
+                               mouse-yank-at-click hilit-yank)))
       (let* ((selected (selected-window))
             (current (current-buffer))
             (process (get-buffer-process current))
@@ -1194,20 +1191,21 @@ This function should be in the list `comint-output-filter-functions'."
         (current (current-buffer))
         (process (get-buffer-process current))
         (scroll comint-scroll-to-bottom-on-output))
-    (if (and process scroll (not (window-minibuffer-p selected)))
+    (if (and process (not (window-minibuffer-p selected)))
        (walk-windows
         (function (lambda (window)
-          (if (and (eq (window-buffer window) current)
-                   (or (eq scroll t) (eq scroll 'all)
-                       (and (eq scroll 'this) (eq selected window))
-                       (and (eq scroll 'others) (not (eq selected window)))))
+          (if (eq (window-buffer window) current)
               (progn
                 (select-window window)
-                ;; If point WAS at process mark in this window,
-                ;; keep it at process mark.
-                (and (>= (point) (- (process-mark process) (length string)))
-                     (< (point) (process-mark process))
-                     (goto-char (process-mark process)))
+                (if (or (eq scroll t) (eq scroll 'all)
+                        ;; Maybe user wants point to jump to the end.
+                        (and (eq scroll 'this) (eq selected window))
+                        (and (eq scroll 'others) (not (eq selected window)))
+                        ;; If point was at the end, keep it at the end.
+                        (and (>= (point)
+                                 (- (process-mark process) (length string)))
+                             (< (point) (process-mark process))))
+                    (goto-char (process-mark process)))
                 ;; Optionally scroll so that the text
                 ;; ends at the bottom of the window.
                 (if (and comint-scroll-show-maximum-output
@@ -1714,15 +1712,15 @@ See `comint-prompt-regexp'."
 
 (defvar comint-completion-autolist nil
   "*If non-nil, automatically list possiblities on partial completion.
-This mirrors the optional behaviour of the tcsh.")
+This mirrors the optional behavior of tcsh.")
 
 (defvar comint-completion-addsuffix t
   "*If non-nil, add a `/' to completed directories, ` ' to file names.
-This mirrors the optional behaviour of the tcsh.")
+This mirrors the optional behavior of tcsh.")
 
 (defvar comint-completion-recexact nil
   "*If non-nil, use shortest completion if characters cannot be added.
-This mirrors the optional behaviour of the tcsh.
+This mirrors the optional behavior of tcsh.
 
 A non-nil value is useful if `comint-completion-autolist' is non-nil too.")