Synchronize scroll on all windows showing terminal

* eat.el (eat--synchronize-scroll-windows): New function.
* eat.el (eat--synchronize-scroll)
(eat--eshell-synchronize-scroll): Take a single argument,
WINDOWS, list of windows to synchronize.  The special value
'buffer' can also be included, to synchronize the point in
buffer.
* eat.el (eat-self-input, eat-yank, eat-yank-from-kill-ring):
Pass the return value of 'eat--synchronize-scroll-windows' to
the function in 'eat--synchronize-scroll-function'.
* eat.el (eat--process-output-queue)
(eat--adjust-process-window-size, eat--eshell-output-filter)
Call 'eat--synchronize-scroll-windows' before doing anything,
save the result, and pass it as the first argument to the
function in 'eat--synchronize-scroll-function'.
* eat.el (eat--trace-replay-eval): Pass the return value of
'get-buffer-window-list' to 'eat--synchronize-scroll'.
This commit is contained in:
Akib Azmain Turja 2022-12-12 14:00:57 +06:00
parent f76c27cd93
commit f2d57e2086
No known key found for this signature in database
GPG key ID: 5535FCF54D88616B

119
eat.el
View file

@ -4476,7 +4476,8 @@ event."
(select-window (posn-window (event-start e)))) (select-window (posn-window (event-start e))))
(when eat--terminal (when eat--terminal
(unless (mouse-movement-p e) (unless (mouse-movement-p e)
(funcall eat--synchronize-scroll-function)) (funcall eat--synchronize-scroll-function
(eat--synchronize-scroll-windows 'force-selected)))
(if (memq (event-basic-type e) (if (memq (event-basic-type e)
'( mouse-1 mouse-2 mouse-3 mouse-4 mouse-5 mouse-6 '( mouse-1 mouse-2 mouse-3 mouse-4 mouse-5 mouse-6
mouse-7 mouse-8 mouse-9 mouse-10 mouse-11 mouse-7 mouse-8 mouse-9 mouse-10 mouse-11
@ -4579,7 +4580,8 @@ argument COUNT specifies how many times to insert CHARACTER."
ARG is passed to `yank', which see." ARG is passed to `yank', which see."
(interactive "*P") (interactive "*P")
(when eat--terminal (when eat--terminal
(funcall eat--synchronize-scroll-function) (funcall eat--synchronize-scroll-function
(eat--synchronize-scroll-windows 'force-selected))
(eat-send-string-as-yank (eat-send-string-as-yank
eat--terminal eat--terminal
(let ((yank-hook (bound-and-true-p yank-transform-functions))) (let ((yank-hook (bound-and-true-p yank-transform-functions)))
@ -4595,7 +4597,8 @@ STRING and ARG are passed to `yank-pop', which see."
(interactive (list (read-from-kill-ring "Yank from kill-ring: ") (interactive (list (read-from-kill-ring "Yank from kill-ring: ")
current-prefix-arg)) current-prefix-arg))
(when eat--terminal (when eat--terminal
(funcall eat--synchronize-scroll-function) (funcall eat--synchronize-scroll-function
(eat--synchronize-scroll-windows 'force-selected))
(eat-send-string-as-yank (eat-send-string-as-yank
eat--terminal eat--terminal
(let ((yank-hook (bound-and-true-p yank-transform-functions))) (let ((yank-hook (bound-and-true-p yank-transform-functions)))
@ -4754,14 +4757,35 @@ MODE should one of:
;;;;; Major Mode. ;;;;; Major Mode.
(defun eat--synchronize-scroll () (defun eat--synchronize-scroll-windows (&optional force-selected)
"Synchronize scrolling and point between terminal and window." "Return the list of windows whose scrolling should be synchronized.
(when-let* ((window (get-buffer-window (current-buffer))))
(set-window-start When FORCE-SELECTED is non-nil, always include `buffer' and the
window (eat-term-display-beginning eat--terminal)) selected window in the list if the window is showing the current
(set-window-point buffer."
window (eat-term-display-cursor eat--terminal))) `(,@(and (or force-selected
(goto-char (eat-term-display-cursor eat--terminal))) eat--char-mode
(= (eat-term-display-cursor eat--terminal) (point)))
'(buffer))
,@(seq-filter
(lambda (window)
(or (and force-selected (eq window (selected-window)))
(= (eat-term-display-cursor eat--terminal)
(window-point window))))
(get-buffer-window-list))))
(defun eat--synchronize-scroll (windows)
"Synchronize scrolling and point between terminal and WINDOWS.
WINDOWS is a list of windows. WINDOWS may also contain the special
symbol `buffer', in which case the point of current buffer is set."
(dolist (window windows)
(if (eq window 'buffer)
(goto-char (eat-term-display-cursor eat--terminal))
(set-window-start
window (eat-term-display-beginning eat--terminal))
(set-window-point
window (eat-term-display-cursor eat--terminal)))))
(defun eat--setup-glyphless-chars () (defun eat--setup-glyphless-chars ()
"Setup the display of glyphless characters." "Setup the display of glyphless characters."
@ -4956,9 +4980,7 @@ OS's."
(let ((inhibit-quit t) ; Don't disturb! (let ((inhibit-quit t) ; Don't disturb!
(inhibit-read-only t) (inhibit-read-only t)
(inhibit-modification-hooks t) (inhibit-modification-hooks t)
(synchronize-scroll (sync-windows (eat--synchronize-scroll-windows)))
(or (= (eat-term-display-cursor eat--terminal) (point))
eat--char-mode)))
(when eat--process-output-queue-timer (when eat--process-output-queue-timer
(cancel-timer eat--process-output-queue-timer)) (cancel-timer eat--process-output-queue-timer))
(setq eat--output-queue-first-chunk-time nil) (setq eat--output-queue-first-chunk-time nil)
@ -4981,8 +5003,7 @@ OS's."
eat-shell-prompt-annotation-correction-delay eat-shell-prompt-annotation-correction-delay
nil #'eat--correct-shell-prompt-mark-overlays nil #'eat--correct-shell-prompt-mark-overlays
buffer)) buffer))
(when synchronize-scroll (funcall eat--synchronize-scroll-function sync-windows)))))
(funcall eat--synchronize-scroll-function))))))
(defun eat--filter (process output) (defun eat--filter (process output)
"Handle OUTPUT from PROCESS." "Handle OUTPUT from PROCESS."
@ -5058,13 +5079,10 @@ of window displaying PROCESS's buffer."
(let ((width (max (car size) 1)) (let ((width (max (car size) 1))
(height (max (cdr size) 1)) (height (max (cdr size) 1))
(inhibit-read-only t) (inhibit-read-only t)
(synchronize-scroll (sync-windows (eat--synchronize-scroll-windows)))
(or (= (eat-term-display-cursor eat--terminal) (point))
eat--char-mode)))
(eat-term-resize eat--terminal width height) (eat-term-resize eat--terminal width height)
(eat-term-redisplay eat--terminal) (eat-term-redisplay eat--terminal)
(when synchronize-scroll (funcall eat--synchronize-scroll-function sync-windows)))
(funcall eat--synchronize-scroll-function))))
size)) size))
;; Adapted from Term. ;; Adapted from Term.
@ -5351,13 +5369,10 @@ PROGRAM can be a shell command."
eshell-last-output-start eshell-last-output-start
eshell-last-output-end))) eshell-last-output-end)))
(delete-region eshell-last-output-start eshell-last-output-end) (delete-region eshell-last-output-start eshell-last-output-end)
(let ((synchronize-scroll (let ((sync-windows (eat--synchronize-scroll-windows)))
(or (= (eat-term-display-cursor eat--terminal) (point))
eat--eshell-char-mode)))
(eat-term-process-output eat--terminal str) (eat-term-process-output eat--terminal str)
(eat-term-redisplay eat--terminal) (eat-term-redisplay eat--terminal)
(when synchronize-scroll (funcall eat--synchronize-scroll-function sync-windows))
(funcall eat--synchronize-scroll-function)))
(let ((end (eat-term-end eat--terminal))) (let ((end (eat-term-end eat--terminal)))
(set-marker eshell-last-output-start end) (set-marker eshell-last-output-start end)
(set-marker eshell-last-output-end end) (set-marker eshell-last-output-end end)
@ -5536,29 +5551,33 @@ sane 2>%s ; if [ $1 = .. ]; then shift; fi; exec \"$@\""
;;;;; Minor Modes. ;;;;; Minor Modes.
(defun eat--eshell-synchronize-scroll () (defun eat--eshell-synchronize-scroll (windows)
"Synchronize scrolling and point between terminal and window." "Synchronize scrolling and point between terminal and WINDOWS.
(when-let* ((window (get-buffer-window (current-buffer))))
(set-window-start WINDOWS is a list of windows. WINDOWS may also contain the special
window symbol `buffer', in which case the point of current buffer is set."
(if (or (eat-term-in-alternative-display-p eat--terminal) (dolist (window windows)
eat--eshell-char-mode) (if (eq window 'buffer)
(eat-term-display-beginning eat--terminal) (goto-char (eat-term-display-cursor eat--terminal))
(save-restriction (set-window-start
(narrow-to-region window
(eat-term-beginning eat--terminal) (if (or (eat-term-in-alternative-display-p eat--terminal)
(eat-term-end eat--terminal)) eat--eshell-char-mode)
(let ((start-line (- (floor (window-screen-lines)) (eat-term-display-beginning eat--terminal)
(line-number-at-pos (point-max))))) (save-restriction
(goto-char (point-min)) (narrow-to-region
(widen) (eat-term-beginning eat--terminal)
(if (<= start-line 0) (eat-term-end eat--terminal))
(eat-term-display-beginning eat--terminal) (let ((start-line (- (floor (window-screen-lines))
(vertical-motion (- start-line)) (line-number-at-pos (point-max)))))
(point)))))) (goto-char (point-min))
(set-window-point (widen)
window (eat-term-display-cursor eat--terminal))) (if (<= start-line 0)
(goto-char (eat-term-display-cursor eat--terminal))) (eat-term-display-beginning eat--terminal)
(vertical-motion (- start-line))
(point))))))
(set-window-point
window (eat-term-display-cursor eat--terminal)))))
(defun eat--eshell-update-cwd () (defun eat--eshell-update-cwd ()
"Update the current working directory." "Update the current working directory."
@ -6141,7 +6160,7 @@ FN is the original definition of `eat--eshell-cleanup', which see."
(eat-term-reset eat--terminal)) (eat-term-reset eat--terminal))
(`(,_time finish) (`(,_time finish)
(eat-term-delete eat--terminal))) (eat-term-delete eat--terminal)))
(eat--synchronize-scroll))) (eat--synchronize-scroll (get-buffer-window-list))))
(defun eat--trace-replay-eval-next () (defun eat--trace-replay-eval-next ()
"Evaluate next sexp in trace output." "Evaluate next sexp in trace output."