summaryrefslogtreecommitdiff
path: root/lisp/comint.el
diff options
context:
space:
mode:
authorChong Yidong <cyd@gnu.org>2012-05-01 21:37:56 +0800
committerChong Yidong <cyd@gnu.org>2012-05-01 21:37:56 +0800
commit782fbf2a338e61231655e76b1727790374e02ca1 (patch)
treebe8c7198432f61f26e0c571f5866dc9620a1d96f /lisp/comint.el
parenteb0ae1d14375a40eeda911da4812191d4f8d4baf (diff)
downloademacs-782fbf2a338e61231655e76b1727790374e02ca1.tar.gz
* lisp/follow.el: Rework, eliminating reliance on advice.
(set-process-filter, process-filter, sit-for): Advice deleted. (follow-mode-off-hook): Obsolete hook removed. (follow-avoid-tail-recenter-p, follow-process-filter-alist): Vars deleted. (follow-auto): Use a :set function. (follow-mode): Rewritten. Don't advise process filters. (follow-switch-to-current-buffer-all, follow-scroll-up) (follow-scroll-down): Assume follow-mode is bound. (follow-comint-scroll-to-bottom) (follow-align-compilation-windows): New functions. (follow--window-sorter): New function. (follow-all-followers): Use it to explicitly sort windows by their positions; don't make assumptions about next-window order. (follow-windows-start-end, follow-delete-other-windows-and-split) (follow-calc-win-start): Doc fix. (follow-windows-aligned-p, follow-select-if-visible): Don't call vertical-motion unnecessarily. (follow-adjust-window): New function. (follow-post-command-hook): Use it. (follow-call-set-process-filter, follow-call-process-filter) (follow-intercept-process-output, follow-tidy-process-filter-alist) (follow-stop-intercept-process-output, follow-generic-filter): Functions deleted. (follow-scroll-bar-toolkit-scroll, follow-scroll-bar-drag) (follow-scroll-bar-scroll-up, follow-scroll-bar-scroll-down): New functions, replacing advice on scroll-bar-* commands. * lisp/comint.el (comint-adjust-point): New function. (comint-postoutput-scroll-to-bottom): Use it. Call follow-comint-scroll-to-bottom for Follow mode buffers.
Diffstat (limited to 'lisp/comint.el')
-rw-r--r--lisp/comint.el64
1 files changed, 36 insertions, 28 deletions
diff --git a/lisp/comint.el b/lisp/comint.el
index 2f8d7bd850c..8103db0e9bb 100644
--- a/lisp/comint.el
+++ b/lisp/comint.el
@@ -2101,43 +2101,51 @@ This function should be a pre-command hook."
(select-window selected))))
nil t))))))
+(defvar follow-mode)
+(declare-function follow-comint-scroll-to-bottom "follow" ())
+
(defun comint-postoutput-scroll-to-bottom (_string)
"Go to the end of buffer in some or all windows showing it.
-Does not scroll if the current line is the last line in the buffer.
+Do not scroll if the current line is the last line in the buffer.
Depends on the value of `comint-move-point-for-output' and
`comint-scroll-show-maximum-output'.
This function should be in the list `comint-output-filter-functions'."
- (let* ((selected (selected-window))
- (current (current-buffer))
- (process (get-buffer-process current))
- (scroll comint-move-point-for-output))
+ (let* ((current (current-buffer))
+ (process (get-buffer-process current)))
(unwind-protect
- (if process
- (walk-windows
- (lambda (window)
- (when (eq (window-buffer window) current)
- (select-window window)
- (if (and (< (point) (process-mark process))
- (or (eq scroll t) (eq scroll 'all)
- ;; Maybe user wants point to jump to 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 end.
- (and (marker-position comint-last-output-start)
- (>= (point) comint-last-output-start))))
- (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
- (= (point) (point-max)))
- (save-excursion
- (goto-char (point-max))
- (recenter (- -1 scroll-margin))))
- (select-window selected)))
- nil t))
+ (cond
+ ((null process))
+ ((bound-and-true-p follow-mode)
+ (follow-comint-scroll-to-bottom))
+ (t
+ (let ((selected (selected-window)))
+ (dolist (w (get-buffer-window-list current nil t))
+ (select-window w)
+ (unwind-protect
+ (progn
+ (comint-adjust-point selected)
+ ;; Optionally scroll to the bottom of the window.
+ (and comint-scroll-show-maximum-output
+ (eobp)
+ (recenter (- -1 scroll-margin))))
+ (select-window selected))))))
(set-buffer current))))
+(defun comint-adjust-point (selected)
+ "Move point in the selected window based on Comint settings.
+SELECTED is the window that was originally selected."
+ (let ((process (get-buffer-process (current-buffer))))
+ (and (< (point) (process-mark process))
+ (or (memq comint-move-point-for-output '(t all))
+ ;; Maybe user wants point to jump to end.
+ (eq comint-move-point-for-output
+ (if (eq (selected-window) selected) 'this 'others))
+ ;; If point was at the end, keep it at end.
+ (and (marker-position comint-last-output-start)
+ (>= (point) comint-last-output-start)))
+ (goto-char (process-mark process)))))
+
(defun comint-truncate-buffer (&optional _string)
"Truncate the buffer to `comint-buffer-maximum-size'.
This function could be on `comint-output-filter-functions' or bound to a key."