diff options
| author | Chong Yidong | 2012-05-01 21:37:56 +0800 |
|---|---|---|
| committer | Chong Yidong | 2012-05-01 21:37:56 +0800 |
| commit | 782fbf2a338e61231655e76b1727790374e02ca1 (patch) | |
| tree | be8c7198432f61f26e0c571f5866dc9620a1d96f | |
| parent | eb0ae1d14375a40eeda911da4812191d4f8d4baf (diff) | |
| download | emacs-782fbf2a338e61231655e76b1727790374e02ca1.tar.gz emacs-782fbf2a338e61231655e76b1727790374e02ca1.zip | |
* 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.
| -rw-r--r-- | etc/NEWS | 7 | ||||
| -rw-r--r-- | lisp/ChangeLog | 34 | ||||
| -rw-r--r-- | lisp/comint.el | 64 | ||||
| -rw-r--r-- | lisp/follow.el | 1410 |
4 files changed, 477 insertions, 1038 deletions
| @@ -100,6 +100,13 @@ these commands now). | |||
| 100 | ** erc will look up server/channel names via auth-source and use the | 100 | ** erc will look up server/channel names via auth-source and use the |
| 101 | channel keys found, if any. | 101 | channel keys found, if any. |
| 102 | 102 | ||
| 103 | ** Follow mode | ||
| 104 | |||
| 105 | *** The obsolete variable `follow-mode-off-hook' has been removed. | ||
| 106 | |||
| 107 | *** Follow mode no longer works by using advice. | ||
| 108 | The option `follow-intercept-processes' has been removed. | ||
| 109 | |||
| 103 | ** The `server-auth-key' variable can be used to set a permanent | 110 | ** The `server-auth-key' variable can be used to set a permanent |
| 104 | shared key for Emacs Server. | 111 | shared key for Emacs Server. |
| 105 | 112 | ||
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index e3f91f562bc..31fda48df48 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,37 @@ | |||
| 1 | 2012-05-01 Chong Yidong <cyd@gnu.org> | ||
| 2 | |||
| 3 | * follow.el: Eliminate advice. | ||
| 4 | (set-process-filter, process-filter, sit-for): Advice deleted. | ||
| 5 | (follow-mode-off-hook): Obsolete hook removed. | ||
| 6 | (follow-avoid-tail-recenter-p, follow-process-filter-alist): Vars | ||
| 7 | deleted. | ||
| 8 | (follow-auto): Use a :set function. | ||
| 9 | (follow-mode): Rewritten. Don't advise process filters. | ||
| 10 | (follow-switch-to-current-buffer-all, follow-scroll-up) | ||
| 11 | (follow-scroll-down): Assume follow-mode is bound. | ||
| 12 | (follow-comint-scroll-to-bottom) | ||
| 13 | (follow-align-compilation-windows): New functions. | ||
| 14 | (follow--window-sorter): New function. | ||
| 15 | (follow-all-followers): Use it to explicitly sort windows by their | ||
| 16 | positions; don't make assumptions about next-window order. | ||
| 17 | (follow-windows-start-end, follow-delete-other-windows-and-split) | ||
| 18 | (follow-calc-win-start): Doc fix. | ||
| 19 | (follow-windows-aligned-p, follow-select-if-visible): Don't call | ||
| 20 | vertical-motion unnecessarily. | ||
| 21 | (follow-adjust-window): New function. | ||
| 22 | (follow-post-command-hook): Use it. | ||
| 23 | (follow-call-set-process-filter, follow-call-process-filter) | ||
| 24 | (follow-intercept-process-output, follow-tidy-process-filter-alist) | ||
| 25 | (follow-stop-intercept-process-output, follow-generic-filter): | ||
| 26 | Functions deleted. | ||
| 27 | (follow-scroll-bar-toolkit-scroll, follow-scroll-bar-drag) | ||
| 28 | (follow-scroll-bar-scroll-up, follow-scroll-bar-scroll-down): New | ||
| 29 | functions, replacing advice on scroll-bar-* commands. | ||
| 30 | |||
| 31 | * comint.el (comint-adjust-point): New function. | ||
| 32 | (comint-postoutput-scroll-to-bottom): Use it. Call | ||
| 33 | follow-comint-scroll-to-bottom for Follow mode buffers. | ||
| 34 | |||
| 1 | 2012-05-01 Glenn Morris <rgm@gnu.org> | 35 | 2012-05-01 Glenn Morris <rgm@gnu.org> |
| 2 | 36 | ||
| 3 | * term/AT386.el, term/apollo.el, term/bobcat.el, term/cygwin.el: | 37 | * term/AT386.el, term/apollo.el, term/bobcat.el, term/cygwin.el: |
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." | |||
| 2101 | (select-window selected)))) | 2101 | (select-window selected)))) |
| 2102 | nil t)))))) | 2102 | nil t)))))) |
| 2103 | 2103 | ||
| 2104 | (defvar follow-mode) | ||
| 2105 | (declare-function follow-comint-scroll-to-bottom "follow" ()) | ||
| 2106 | |||
| 2104 | (defun comint-postoutput-scroll-to-bottom (_string) | 2107 | (defun comint-postoutput-scroll-to-bottom (_string) |
| 2105 | "Go to the end of buffer in some or all windows showing it. | 2108 | "Go to the end of buffer in some or all windows showing it. |
| 2106 | Does not scroll if the current line is the last line in the buffer. | 2109 | Do not scroll if the current line is the last line in the buffer. |
| 2107 | Depends on the value of `comint-move-point-for-output' and | 2110 | Depends on the value of `comint-move-point-for-output' and |
| 2108 | `comint-scroll-show-maximum-output'. | 2111 | `comint-scroll-show-maximum-output'. |
| 2109 | 2112 | ||
| 2110 | This function should be in the list `comint-output-filter-functions'." | 2113 | This function should be in the list `comint-output-filter-functions'." |
| 2111 | (let* ((selected (selected-window)) | 2114 | (let* ((current (current-buffer)) |
| 2112 | (current (current-buffer)) | 2115 | (process (get-buffer-process current))) |
| 2113 | (process (get-buffer-process current)) | ||
| 2114 | (scroll comint-move-point-for-output)) | ||
| 2115 | (unwind-protect | 2116 | (unwind-protect |
| 2116 | (if process | 2117 | (cond |
| 2117 | (walk-windows | 2118 | ((null process)) |
| 2118 | (lambda (window) | 2119 | ((bound-and-true-p follow-mode) |
| 2119 | (when (eq (window-buffer window) current) | 2120 | (follow-comint-scroll-to-bottom)) |
| 2120 | (select-window window) | 2121 | (t |
| 2121 | (if (and (< (point) (process-mark process)) | 2122 | (let ((selected (selected-window))) |
| 2122 | (or (eq scroll t) (eq scroll 'all) | 2123 | (dolist (w (get-buffer-window-list current nil t)) |
| 2123 | ;; Maybe user wants point to jump to end. | 2124 | (select-window w) |
| 2124 | (and (eq scroll 'this) (eq selected window)) | 2125 | (unwind-protect |
| 2125 | (and (eq scroll 'others) (not (eq selected window))) | 2126 | (progn |
| 2126 | ;; If point was at the end, keep it at end. | 2127 | (comint-adjust-point selected) |
| 2127 | (and (marker-position comint-last-output-start) | 2128 | ;; Optionally scroll to the bottom of the window. |
| 2128 | (>= (point) comint-last-output-start)))) | 2129 | (and comint-scroll-show-maximum-output |
| 2129 | (goto-char (process-mark process))) | 2130 | (eobp) |
| 2130 | ;; Optionally scroll so that the text | 2131 | (recenter (- -1 scroll-margin)))) |
| 2131 | ;; ends at the bottom of the window. | 2132 | (select-window selected)))))) |
| 2132 | (if (and comint-scroll-show-maximum-output | ||
| 2133 | (= (point) (point-max))) | ||
| 2134 | (save-excursion | ||
| 2135 | (goto-char (point-max)) | ||
| 2136 | (recenter (- -1 scroll-margin)))) | ||
| 2137 | (select-window selected))) | ||
| 2138 | nil t)) | ||
| 2139 | (set-buffer current)))) | 2133 | (set-buffer current)))) |
| 2140 | 2134 | ||
| 2135 | (defun comint-adjust-point (selected) | ||
| 2136 | "Move point in the selected window based on Comint settings. | ||
| 2137 | SELECTED is the window that was originally selected." | ||
| 2138 | (let ((process (get-buffer-process (current-buffer)))) | ||
| 2139 | (and (< (point) (process-mark process)) | ||
| 2140 | (or (memq comint-move-point-for-output '(t all)) | ||
| 2141 | ;; Maybe user wants point to jump to end. | ||
| 2142 | (eq comint-move-point-for-output | ||
| 2143 | (if (eq (selected-window) selected) 'this 'others)) | ||
| 2144 | ;; If point was at the end, keep it at end. | ||
| 2145 | (and (marker-position comint-last-output-start) | ||
| 2146 | (>= (point) comint-last-output-start))) | ||
| 2147 | (goto-char (process-mark process))))) | ||
| 2148 | |||
| 2141 | (defun comint-truncate-buffer (&optional _string) | 2149 | (defun comint-truncate-buffer (&optional _string) |
| 2142 | "Truncate the buffer to `comint-buffer-maximum-size'. | 2150 | "Truncate the buffer to `comint-buffer-maximum-size'. |
| 2143 | This function could be on `comint-output-filter-functions' or bound to a key." | 2151 | This function could be on `comint-output-filter-functions' or bound to a key." |
diff --git a/lisp/follow.el b/lisp/follow.el index e033c76b4e3..53dd4c2c354 100644 --- a/lisp/follow.el +++ b/lisp/follow.el | |||
| @@ -1,5 +1,4 @@ | |||
| 1 | ;;; follow.el --- synchronize windows showing the same buffer | 1 | ;;; follow.el --- synchronize windows showing the same buffer |
| 2 | |||
| 3 | ;; Copyright (C) 1995-1997, 1999, 2001-2012 Free Software Foundation, Inc. | 2 | ;; Copyright (C) 1995-1997, 1999, 2001-2012 Free Software Foundation, Inc. |
| 4 | 3 | ||
| 5 | ;; Author: Anders Lindgren <andersl@andersl.com> | 4 | ;; Author: Anders Lindgren <andersl@andersl.com> |
| @@ -107,24 +106,11 @@ | |||
| 107 | ;; (setq truncate-partial-width-windows nil) | 106 | ;; (setq truncate-partial-width-windows nil) |
| 108 | 107 | ||
| 109 | 108 | ||
| 110 | ;; Since the display of XEmacs is pixel-oriented, a line could be | ||
| 111 | ;; clipped in half at the bottom of the window. | ||
| 112 | ;; | ||
| 113 | ;; To make XEmacs avoid clipping (normal) lines, please place the | ||
| 114 | ;; following line in your init-file: | ||
| 115 | ;; | ||
| 116 | ;; (setq pixel-vertical-clip-threshold 30) | ||
| 117 | |||
| 118 | |||
| 119 | ;; The correct way to configure Follow mode, or any other mode for | 109 | ;; The correct way to configure Follow mode, or any other mode for |
| 120 | ;; that matter, is to create one or more functions that do | 110 | ;; that matter, is to create one or more functions that do |
| 121 | ;; whatever you would like to do. These functions are then added to | 111 | ;; whatever you would like to do. These functions are then added to |
| 122 | ;; a hook. | 112 | ;; a hook. |
| 123 | ;; | 113 | ;; |
| 124 | ;; When `Follow' mode is activated, functions stored in the hook | ||
| 125 | ;; `follow-mode-hook' are called. When it is deactivated | ||
| 126 | ;; `follow-mode-off-hook' is run. | ||
| 127 | ;; | ||
| 128 | ;; The keymap `follow-key-map' contains key bindings activated by | 114 | ;; The keymap `follow-key-map' contains key bindings activated by |
| 129 | ;; `follow-mode'. | 115 | ;; `follow-mode'. |
| 130 | ;; | 116 | ;; |
| @@ -196,77 +182,29 @@ | |||
| 196 | ;; Example from my ~/.emacs: | 182 | ;; Example from my ~/.emacs: |
| 197 | ;; (global-set-key [f8] 'follow-mode) | 183 | ;; (global-set-key [f8] 'follow-mode) |
| 198 | 184 | ||
| 199 | |||
| 200 | ;; Implementation: | 185 | ;; Implementation: |
| 201 | ;; | 186 | ;; |
| 202 | ;; In an ideal world, follow mode would have been implemented in the | 187 | ;; The main method by which Follow mode aligns windows is via the |
| 203 | ;; kernel of the display routines, making sure that the windows (using | 188 | ;; function `follow-post-command-hook', which is run after each |
| 204 | ;; follow mode) ALWAYS are aligned. On planet Earth, however, we must | 189 | ;; command. This "fixes up" the alignment of other windows which are |
| 205 | ;; accept a solution where we ALMOST ALWAYS can make sure that the | 190 | ;; showing the same Follow mode buffer, on the same frame as the |
| 206 | ;; windows are aligned. | 191 | ;; selected window. It does not try to deal with buffers other than |
| 192 | ;; the buffer of the selected frame, or windows on other frames. | ||
| 207 | ;; | 193 | ;; |
| 208 | ;; Follow mode does this in three places: | 194 | ;; Comint mode specially calls `follow-comint-scroll-to-bottom' on |
| 209 | ;; 1) After each user command. | 195 | ;; Follow mode buffers. This function scrolls the bottom-most window |
| 210 | ;; 2) After a process output has been performed. | 196 | ;; in a window chain and aligns the other windows accordingly. Follow |
| 211 | ;; 3) When a scrollbar has been moved. | 197 | ;; mode adds a function to `compilation-filter-hook' to align |
| 212 | ;; | 198 | ;; compilation buffers. |
| 213 | ;; This will cover most situations. (Let me know if there are other | ||
| 214 | ;; situations that should be covered.) | ||
| 215 | ;; | ||
| 216 | ;; Note that only the selected window is checked, for the reason of | ||
| 217 | ;; efficiency and code complexity. (I.e. it is possible to make a | ||
| 218 | ;; non-selected window unaligned. It will, however, pop right back | ||
| 219 | ;; when it is selected.) | ||
| 220 | 199 | ||
| 221 | ;;; Code: | 200 | ;;; Code: |
| 222 | 201 | ||
| 223 | ;; Preliminaries | ||
| 224 | |||
| 225 | ;; Make the compiler shut up! | ||
| 226 | ;; There are two strategies: | ||
| 227 | ;; 1) Shut warnings off completely. | ||
| 228 | ;; 2) Handle each warning separately. | ||
| 229 | ;; | ||
| 230 | ;; Since I would like to see real errors, I've selected the latter | ||
| 231 | ;; method. | ||
| 232 | ;; | ||
| 233 | ;; The problem with undefined variables and functions has been solved | ||
| 234 | ;; by using `set', `symbol-value' and `symbol-function' rather than | ||
| 235 | ;; `setq' and direct references to variables and functions. | ||
| 236 | ;; | ||
| 237 | ;; For example: | ||
| 238 | ;; (if (boundp 'foo) ... (symbol-value 'foo) ) | ||
| 239 | ;; (set 'foo ...) <-- XEmacs doesn't fall for this one. | ||
| 240 | ;; (funcall (symbol-function 'set) 'bar ...) | ||
| 241 | ;; | ||
| 242 | ;; Note: When this file is interpreted, `eval-when-compile' is | ||
| 243 | ;; evaluated. Since it doesn't hurt to evaluate it, but it is a bit | ||
| 244 | ;; annoying, we test if the byte-compiler has been loaded. This can, | ||
| 245 | ;; of course, lead to some occasional unintended evaluation... | ||
| 246 | ;; | ||
| 247 | ;; Should someone come up with a better solution, please let me | ||
| 248 | ;; know. | ||
| 249 | |||
| 250 | (require 'easymenu) | 202 | (require 'easymenu) |
| 251 | 203 | ||
| 252 | (eval-when-compile | ||
| 253 | (if (or (featurep 'bytecomp) | ||
| 254 | (featurep 'byte-compile)) | ||
| 255 | (cond ((featurep 'xemacs) | ||
| 256 | ;; Make XEmacs shut up! I'm using standard Emacs | ||
| 257 | ;; functions, they are NOT obsolete! | ||
| 258 | (if (eq (get 'force-mode-line-update 'byte-compile) | ||
| 259 | 'byte-compile-obsolete) | ||
| 260 | (put 'force-mode-line-update 'byte-compile 'nil)) | ||
| 261 | (if (eq (get 'frame-first-window 'byte-compile) | ||
| 262 | 'byte-compile-obsolete) | ||
| 263 | (put 'frame-first-window 'byte-compile 'nil)))))) | ||
| 264 | |||
| 265 | ;;; Variables | 204 | ;;; Variables |
| 266 | 205 | ||
| 267 | (defgroup follow nil | 206 | (defgroup follow nil |
| 268 | "Synchronize windows showing the same buffer." | 207 | "Synchronize windows showing the same buffer." |
| 269 | :prefix "follow-" | ||
| 270 | :group 'windows | 208 | :group 'windows |
| 271 | :group 'convenience) | 209 | :group 'convenience) |
| 272 | 210 | ||
| @@ -275,28 +213,15 @@ | |||
| 275 | :type 'hook | 213 | :type 'hook |
| 276 | :group 'follow) | 214 | :group 'follow) |
| 277 | 215 | ||
| 278 | (defcustom follow-mode-off-hook nil | ||
| 279 | "Hooks to run when Follow mode is turned off." | ||
| 280 | :type 'hook | ||
| 281 | :group 'follow) | ||
| 282 | (make-obsolete-variable 'follow-mode-off-hook 'follow-mode-hook "22.2") | ||
| 283 | |||
| 284 | ;;; Keymap/Menu | 216 | ;;; Keymap/Menu |
| 285 | 217 | ||
| 286 | ;; Define keys for the follow-mode minor mode map and replace some | 218 | ;; Define keys for the follow-mode minor mode map and replace some |
| 287 | ;; functions in the global map. All `follow' mode special functions | 219 | ;; functions in the global map. All Follow mode special functions can |
| 288 | ;; can be found on (the somewhat cumbersome) "C-c . <key>" | 220 | ;; be found on the `C-c .' prefix key. |
| 289 | ;; (Control-C dot <key>). (As of Emacs 19.29 the keys | ||
| 290 | ;; C-c <punctuation character> are reserved for minor modes.) | ||
| 291 | ;; | ||
| 292 | ;; To change the prefix, redefine `follow-mode-prefix' before | ||
| 293 | ;; `follow' is loaded, or see the section on `follow-mode-hook' | ||
| 294 | ;; above for an example of how to bind the keys the way you like. | ||
| 295 | ;; | 221 | ;; |
| 296 | ;; Please note that the keymap is defined the first time this file is | 222 | ;; To change the prefix, redefine `follow-mode-prefix' before `follow' |
| 297 | ;; loaded. Also note that the only valid way to manipulate the | 223 | ;; is loaded, or see the section on `follow-mode-hook' above for an |
| 298 | ;; keymap is to use `define-key'. Don't change it using `setq' or | 224 | ;; example of how to bind the keys the way you like. |
| 299 | ;; similar! | ||
| 300 | 225 | ||
| 301 | (defcustom follow-mode-prefix "\C-c." | 226 | (defcustom follow-mode-prefix "\C-c." |
| 302 | "Prefix key to use for follow commands in Follow mode. | 227 | "Prefix key to use for follow commands in Follow mode. |
| @@ -329,6 +254,11 @@ After that, changing the prefix key requires manipulating keymaps." | |||
| 329 | ;; the look and feel of Follow mode.) | 254 | ;; the look and feel of Follow mode.) |
| 330 | (define-key mainmap [remap end-of-buffer] 'follow-end-of-buffer) | 255 | (define-key mainmap [remap end-of-buffer] 'follow-end-of-buffer) |
| 331 | 256 | ||
| 257 | (define-key mainmap [remap scroll-bar-toolkit-scroll] 'follow-scroll-bar-toolkit-scroll) | ||
| 258 | (define-key mainmap [remap scroll-bar-drag] 'follow-scroll-bar-drag) | ||
| 259 | (define-key mainmap [remap scroll-bar-scroll-up] 'follow-scroll-bar-scroll-up) | ||
| 260 | (define-key mainmap [remap scroll-bar-scroll-down] 'follow-scroll-bar-scroll-down) | ||
| 261 | |||
| 332 | mainmap) | 262 | mainmap) |
| 333 | "Minor mode keymap for Follow mode.") | 263 | "Minor mode keymap for Follow mode.") |
| 334 | 264 | ||
| @@ -340,16 +270,8 @@ After that, changing the prefix key requires manipulating keymaps." | |||
| 340 | '(["Follow mode" follow-mode | 270 | '(["Follow mode" follow-mode |
| 341 | :style toggle :selected follow-mode]))) | 271 | :style toggle :selected follow-mode]))) |
| 342 | 272 | ||
| 343 | ;; If there is a `tools' menu, we use it. However, we can't add a | ||
| 344 | ;; minor-mode specific item to it (it's broken), so we make the | ||
| 345 | ;; contents ghosted when not in use, and add ourselves to the | ||
| 346 | ;; global map. | ||
| 347 | (easy-menu-add-item nil '("Tools") | 273 | (easy-menu-add-item nil '("Tools") |
| 348 | '("Follow" | 274 | '("Follow" |
| 349 | ;; The Emacs code used to just gray out operations when follow-mode was | ||
| 350 | ;; not enabled, whereas the XEmacs code used to remove it altogether. | ||
| 351 | ;; Not sure which is preferable, but clearly the preference should not | ||
| 352 | ;; depend on the flavor. | ||
| 353 | :filter follow-menu-filter | 275 | :filter follow-menu-filter |
| 354 | ["Scroll Up" follow-scroll-up follow-mode] | 276 | ["Scroll Up" follow-scroll-up follow-mode] |
| 355 | ["Scroll Down" follow-scroll-down follow-mode] | 277 | ["Scroll Down" follow-scroll-down follow-mode] |
| @@ -378,30 +300,12 @@ are \" Fw\", or simply \"\"." | |||
| 378 | (defcustom follow-auto nil | 300 | (defcustom follow-auto nil |
| 379 | "Non-nil activates Follow mode whenever a file is loaded." | 301 | "Non-nil activates Follow mode whenever a file is loaded." |
| 380 | :type 'boolean | 302 | :type 'boolean |
| 381 | :group 'follow) | 303 | :group 'follow |
| 382 | 304 | :set (lambda (symbol value) | |
| 383 | (defcustom follow-intercept-processes (fboundp 'start-process) | 305 | (if value |
| 384 | "When non-nil, Follow mode will monitor process output." | 306 | (add-hook 'find-file-hook 'follow-find-file-hook t) |
| 385 | :type 'boolean | 307 | (remove-hook 'find-file-hook 'follow-find-file-hook)) |
| 386 | :group 'follow) | 308 | (set-default symbol value))) |
| 387 | |||
| 388 | (defvar follow-avoid-tail-recenter-p (not (featurep 'xemacs)) | ||
| 389 | "When non-nil, patch Emacs so that tail windows won't be recentered. | ||
| 390 | |||
| 391 | A \"tail window\" is a window that displays only the end of | ||
| 392 | the buffer. Normally it is practical for the user that empty | ||
| 393 | windows are recentered automatically. However, when using | ||
| 394 | Follow mode it breaks the display when the end is displayed | ||
| 395 | in a window \"above\" the last window. This is for | ||
| 396 | example the case when displaying a short page in info. | ||
| 397 | |||
| 398 | Must be set before Follow mode is loaded. | ||
| 399 | |||
| 400 | Please note that it is not possible to fully prevent Emacs from | ||
| 401 | recentering empty windows. Please report if you find a repeatable | ||
| 402 | situation in which Emacs recenters empty windows. | ||
| 403 | |||
| 404 | XEmacs, as of 19.12, does not recenter windows, good!") | ||
| 405 | 309 | ||
| 406 | (defvar follow-cache-command-list | 310 | (defvar follow-cache-command-list |
| 407 | '(next-line previous-line forward-char backward-char) | 311 | '(next-line previous-line forward-char backward-char) |
| @@ -425,9 +329,6 @@ property `follow-mode-use-cache' to non-nil.") | |||
| 425 | (defvar follow-internal-force-redisplay nil | 329 | (defvar follow-internal-force-redisplay nil |
| 426 | "True when Follow mode should redisplay the windows.") | 330 | "True when Follow mode should redisplay the windows.") |
| 427 | 331 | ||
| 428 | (defvar follow-process-filter-alist '() | ||
| 429 | "The original filters for processes intercepted by Follow mode.") | ||
| 430 | |||
| 431 | (defvar follow-active-menu nil | 332 | (defvar follow-active-menu nil |
| 432 | "The menu visible when Follow mode is active.") | 333 | "The menu visible when Follow mode is active.") |
| 433 | 334 | ||
| @@ -503,38 +404,31 @@ To split one large window into two side-by-side windows, the commands | |||
| 503 | 404 | ||
| 504 | Only windows displayed in the same frame follow each other. | 405 | Only windows displayed in the same frame follow each other. |
| 505 | 406 | ||
| 506 | If the variable `follow-intercept-processes' is non-nil, Follow mode | ||
| 507 | will listen to the output of processes and redisplay accordingly. | ||
| 508 | \(This is the default.) | ||
| 509 | |||
| 510 | This command runs the normal hook `follow-mode-hook'. | 407 | This command runs the normal hook `follow-mode-hook'. |
| 511 | 408 | ||
| 512 | Keys specific to Follow mode: | 409 | Keys specific to Follow mode: |
| 513 | \\{follow-mode-map}" | 410 | \\{follow-mode-map}" |
| 514 | :keymap follow-mode-map | 411 | :keymap follow-mode-map |
| 515 | (when (and follow-mode follow-intercept-processes) | 412 | (if follow-mode |
| 516 | (follow-intercept-process-output)) | 413 | (progn |
| 517 | (cond (follow-mode ; On | 414 | (add-hook 'compilation-filter-hook 'follow-align-compilation-windows t t) |
| 518 | ;; XEmacs: If this is non-nil, the window will scroll before | 415 | (add-hook 'post-command-hook 'follow-post-command-hook t) |
| 519 | ;; the point will have a chance to get into the next window. | 416 | (add-hook 'window-size-change-functions 'follow-window-size-change t)) |
| 520 | (when (boundp 'scroll-on-clipped-lines) | 417 | ;; Remove globally-installed hook functions only if there is no |
| 521 | (setq scroll-on-clipped-lines nil)) | 418 | ;; other Follow mode buffer. |
| 522 | (force-mode-line-update) | 419 | (let ((buffers (buffer-list)) |
| 523 | (add-hook 'post-command-hook 'follow-post-command-hook t)) | 420 | following) |
| 524 | 421 | (while (and (not following) buffers) | |
| 525 | ((not follow-mode) ; Off | 422 | (setq following (buffer-local-value 'follow-mode (car buffers)) |
| 526 | (force-mode-line-update)))) | 423 | buffers (cdr buffers))) |
| 527 | 424 | (unless following | |
| 528 | ;;; Find file hook | 425 | (remove-hook 'post-command-hook 'follow-post-command-hook) |
| 529 | 426 | (remove-hook 'window-size-change-functions 'follow-window-size-change))) | |
| 530 | ;; This will start follow-mode whenever a new file is loaded, if | 427 | (remove-hook 'compilation-filter-hook 'follow-align-compilation-windows t))) |
| 531 | ;; the variable `follow-auto' is non-nil. | ||
| 532 | |||
| 533 | (add-hook 'find-file-hook 'follow-find-file-hook t) | ||
| 534 | 428 | ||
| 535 | (defun follow-find-file-hook () | 429 | (defun follow-find-file-hook () |
| 536 | "Find-file hook for Follow mode. See the variable `follow-auto'." | 430 | "Find-file hook for Follow mode. See the variable `follow-auto'." |
| 537 | (if follow-auto (follow-mode t))) | 431 | (if follow-auto (follow-mode 1))) |
| 538 | 432 | ||
| 539 | ;;; User functions | 433 | ;;; User functions |
| 540 | 434 | ||
| @@ -566,7 +460,7 @@ Negative ARG means scroll downward. | |||
| 566 | 460 | ||
| 567 | Works like `scroll-up' when not in Follow mode." | 461 | Works like `scroll-up' when not in Follow mode." |
| 568 | (interactive "P") | 462 | (interactive "P") |
| 569 | (cond ((not (and (boundp 'follow-mode) follow-mode)) | 463 | (cond ((not follow-mode) |
| 570 | (scroll-up arg)) | 464 | (scroll-up arg)) |
| 571 | (arg | 465 | (arg |
| 572 | (save-excursion (scroll-up arg)) | 466 | (save-excursion (scroll-up arg)) |
| @@ -595,7 +489,7 @@ Negative ARG means scroll upward. | |||
| 595 | 489 | ||
| 596 | Works like `scroll-up' when not in Follow mode." | 490 | Works like `scroll-up' when not in Follow mode." |
| 597 | (interactive "P") | 491 | (interactive "P") |
| 598 | (cond ((not (and (boundp 'follow-mode) follow-mode)) | 492 | (cond ((not follow-mode) |
| 599 | (scroll-up arg)) | 493 | (scroll-up arg)) |
| 600 | (arg | 494 | (arg |
| 601 | (save-excursion (scroll-down arg))) | 495 | (save-excursion (scroll-down arg))) |
| @@ -615,6 +509,47 @@ Works like `scroll-up' when not in Follow mode." | |||
| 615 | (vertical-motion (- next-screen-context-lines 1)) | 509 | (vertical-motion (- next-screen-context-lines 1)) |
| 616 | (setq follow-internal-force-redisplay t)))))) | 510 | (setq follow-internal-force-redisplay t)))))) |
| 617 | 511 | ||
| 512 | (declare-function comint-adjust-point "comint" (window)) | ||
| 513 | (defvar comint-scroll-show-maximum-output) | ||
| 514 | |||
| 515 | (defun follow-comint-scroll-to-bottom (&optional window) | ||
| 516 | "Scroll the bottom-most window in the current Follow chain. | ||
| 517 | This is to be called by `comint-postoutput-scroll-to-bottom'." | ||
| 518 | (let* ((buffer (current-buffer)) | ||
| 519 | (selected (selected-window)) | ||
| 520 | (is-selected (eq (window-buffer) buffer)) | ||
| 521 | some-window) | ||
| 522 | (when (or is-selected | ||
| 523 | (setq some-window (get-buffer-window))) | ||
| 524 | (let* ((pos (progn (comint-adjust-point nil) (point))) | ||
| 525 | (win (if is-selected | ||
| 526 | selected | ||
| 527 | (car (last (follow-all-followers some-window)))))) | ||
| 528 | (select-window win) | ||
| 529 | (goto-char pos) | ||
| 530 | (setq follow-windows-start-end-cache nil) | ||
| 531 | (follow-adjust-window win pos) | ||
| 532 | (unless is-selected | ||
| 533 | (select-window selected) | ||
| 534 | (set-buffer buffer)))))) | ||
| 535 | |||
| 536 | (defun follow-align-compilation-windows () | ||
| 537 | "Align the windows of the current Follow mode buffer. | ||
| 538 | This is to be called from `compilation-filter-hook'." | ||
| 539 | (let ((buffer (current-buffer)) | ||
| 540 | (win (get-buffer-window)) | ||
| 541 | (selected (selected-window))) | ||
| 542 | (when (and follow-mode (waiting-for-user-input-p) win) | ||
| 543 | (let ((windows (follow-all-followers win))) | ||
| 544 | (unless (eq (window-buffer selected) buffer) | ||
| 545 | (setq win (car windows)) | ||
| 546 | (select-window win)) | ||
| 547 | (follow-redisplay windows win t) | ||
| 548 | (setq follow-windows-start-end-cache nil) | ||
| 549 | (unless (eq selected win) | ||
| 550 | (select-window selected) | ||
| 551 | (set-buffer buffer)))))) | ||
| 552 | |||
| 618 | ;;; Buffer | 553 | ;;; Buffer |
| 619 | 554 | ||
| 620 | ;;;###autoload | 555 | ;;;###autoload |
| @@ -630,11 +565,7 @@ two windows always will display two successive pages. | |||
| 630 | 565 | ||
| 631 | If ARG is positive, the leftmost window is selected. If negative, | 566 | If ARG is positive, the leftmost window is selected. If negative, |
| 632 | the rightmost is selected. If ARG is nil, the leftmost window is | 567 | the rightmost is selected. If ARG is nil, the leftmost window is |
| 633 | selected if the original window is the first one in the frame. | 568 | selected if the original window is the first one in the frame." |
| 634 | |||
| 635 | To bind this command to a hotkey, place the following line | ||
| 636 | in your `~/.emacs' file, replacing [f7] by your favorite key: | ||
| 637 | (global-set-key [f7] 'follow-delete-other-windows-and-split)" | ||
| 638 | (interactive "P") | 569 | (interactive "P") |
| 639 | (let ((other (or (and (null arg) | 570 | (let ((other (or (and (null arg) |
| 640 | (not (eq (selected-window) | 571 | (not (eq (selected-window) |
| @@ -670,24 +601,19 @@ Defaults to current buffer." | |||
| 670 | (current-buffer)))) | 601 | (current-buffer)))) |
| 671 | (or buffer (setq buffer (current-buffer))) | 602 | (or buffer (setq buffer (current-buffer))) |
| 672 | (let ((orig-window (selected-window))) | 603 | (let ((orig-window (selected-window))) |
| 673 | (walk-windows | 604 | (walk-windows (lambda (win) |
| 674 | (function | 605 | (select-window win) |
| 675 | (lambda (win) | 606 | (switch-to-buffer buffer)) |
| 676 | (select-window win) | 607 | 'no-minibuf) |
| 677 | (switch-to-buffer buffer)))) | ||
| 678 | (select-window orig-window) | 608 | (select-window orig-window) |
| 679 | (follow-redisplay))) | 609 | (follow-redisplay))) |
| 680 | 610 | ||
| 681 | 611 | ||
| 682 | (defun follow-switch-to-current-buffer-all () | 612 | (defun follow-switch-to-current-buffer-all () |
| 683 | "Show current buffer in all windows on this frame, and enter Follow mode. | 613 | "Show current buffer in all windows on this frame, and enter Follow mode." |
| 684 | |||
| 685 | To bind this command to a hotkey place the following line | ||
| 686 | in your `~/.emacs' file: | ||
| 687 | (global-set-key [f7] 'follow-switch-to-current-buffer-all)" | ||
| 688 | (interactive) | 614 | (interactive) |
| 689 | (or (and (boundp 'follow-mode) follow-mode) | 615 | (unless follow-mode |
| 690 | (follow-mode 1)) | 616 | (follow-mode 1)) |
| 691 | (follow-switch-to-buffer-all)) | 617 | (follow-switch-to-buffer-all)) |
| 692 | 618 | ||
| 693 | ;;; Movement | 619 | ;;; Movement |
| @@ -756,9 +682,7 @@ from the bottom." | |||
| 756 | (win (nth (/ (- (length windows) 1) 2) windows))) | 682 | (win (nth (/ (- (length windows) 1) 2) windows))) |
| 757 | (select-window win) | 683 | (select-window win) |
| 758 | (goto-char dest) | 684 | (goto-char dest) |
| 759 | (recenter) | 685 | (recenter)))) |
| 760 | ;;(setq follow-internal-force-redisplay t) | ||
| 761 | ))) | ||
| 762 | 686 | ||
| 763 | 687 | ||
| 764 | (defun follow-redraw () | 688 | (defun follow-redraw () |
| @@ -796,28 +720,35 @@ of the way from the true end." | |||
| 796 | 720 | ||
| 797 | ;;; Display | 721 | ;;; Display |
| 798 | 722 | ||
| 799 | (defun follow-all-followers (&optional testwin) | 723 | (defun follow--window-sorter (w1 w2) |
| 800 | "Return all windows displaying the same buffer as the TESTWIN. | 724 | "Sorting function for W1 and W2 based on their positions. |
| 801 | The list contains only windows displayed in the same frame as TESTWIN. | 725 | Return non-nil if W1 is above W2; if their top-lines |
| 802 | If TESTWIN is nil the selected window is used." | 726 | are at the same position, return non-nil if W1 is to the |
| 803 | (or (window-live-p testwin) | 727 | left of W2." |
| 804 | (setq testwin (selected-window))) | 728 | (let* ((edge-1 (window-pixel-edges w1)) |
| 805 | (let* ((top (frame-first-window (window-frame testwin))) | 729 | (edge-2 (window-pixel-edges w2)) |
| 806 | (win top) | 730 | (y1 (nth 1 edge-1)) |
| 807 | (done nil) | 731 | (y2 (nth 1 edge-2))) |
| 808 | (windows '()) | 732 | (if (= y1 y2) |
| 809 | (buffer (window-buffer testwin))) | 733 | (< (car edge-1) (car edge-2)) |
| 810 | (while (and (not done) win) | 734 | (< y1 y2)))) |
| 811 | (if (eq (window-buffer win) buffer) | 735 | |
| 812 | (setq windows (cons win windows))) | 736 | (defun follow-all-followers (&optional win) |
| 813 | (setq win (next-window win 'not)) | 737 | "Return all windows displaying the same buffer as the WIN. |
| 814 | (if (eq win top) | 738 | The list is sorted with topmost and leftmost windows first, and |
| 815 | (setq done t))) | 739 | contains only windows in the same frame as WIN. If WIN is nil, |
| 816 | (nreverse windows))) | 740 | it defaults to the selected window." |
| 817 | 741 | (unless (window-live-p win) | |
| 742 | (setq win (selected-window))) | ||
| 743 | (let ((buffer (window-buffer win)) | ||
| 744 | windows) | ||
| 745 | (dolist (w (window-list (window-frame win) 'no-minibuf win)) | ||
| 746 | (if (eq (window-buffer w) buffer) | ||
| 747 | (push w windows))) | ||
| 748 | (sort windows 'follow--window-sorter))) | ||
| 818 | 749 | ||
| 819 | (defun follow-split-followers (windows &optional win) | 750 | (defun follow-split-followers (windows &optional win) |
| 820 | "Split the WINDOWS into the sets: predecessors and successors. | 751 | "Split WINDOWS into two sets: predecessors and successors. |
| 821 | Return `(PRED . SUCC)' where `PRED' and `SUCC' are ordered starting | 752 | Return `(PRED . SUCC)' where `PRED' and `SUCC' are ordered starting |
| 822 | from the selected window." | 753 | from the selected window." |
| 823 | (or win | 754 | (or win |
| @@ -828,7 +759,6 @@ from the selected window." | |||
| 828 | (setq windows (cdr windows))) | 759 | (setq windows (cdr windows))) |
| 829 | (cons pred (cdr windows)))) | 760 | (cons pred (cdr windows)))) |
| 830 | 761 | ||
| 831 | |||
| 832 | (defun follow-calc-win-end (&optional win) | 762 | (defun follow-calc-win-end (&optional win) |
| 833 | "Calculate the end position for window WIN. | 763 | "Calculate the end position for window WIN. |
| 834 | Return (END-POS END-OF-BUFFER). | 764 | Return (END-POS END-OF-BUFFER). |
| @@ -845,20 +775,19 @@ window is used." | |||
| 845 | (list end (= end (point-max)))) | 775 | (list end (= end (point-max)))) |
| 846 | (list last-line-pos nil)))) | 776 | (list last-line-pos nil)))) |
| 847 | 777 | ||
| 848 | ;; Can't use `save-window-excursion' since it triggers a redraw. | ||
| 849 | (defun follow-calc-win-start (windows pos win) | 778 | (defun follow-calc-win-start (windows pos win) |
| 850 | "Calculate where WIN will start if the first in WINDOWS start at POS. | 779 | "Determine the start of window WIN in a Follow mode window chain. |
| 851 | 780 | WINDOWS is a list of chained windows, and POS is the starting | |
| 852 | If WIN is nil the point below all windows is returned." | 781 | position for the first window in the list. If WIN is nil, return |
| 853 | (let (start) | 782 | the point below all windows." |
| 854 | (while (and windows (not (eq (car windows) win))) | 783 | (while (and windows (not (eq (car windows) win))) |
| 855 | (setq start (window-start (car windows))) | 784 | (let ((old-start (window-start (car windows)))) |
| 785 | ;; Can't use `save-window-excursion' since it triggers a redraw. | ||
| 856 | (set-window-start (car windows) pos 'noforce) | 786 | (set-window-start (car windows) pos 'noforce) |
| 857 | (setq pos (car (follow-calc-win-end (car windows)))) | 787 | (setq pos (car (follow-calc-win-end (car windows)))) |
| 858 | (set-window-start (car windows) start 'noforce) | 788 | (set-window-start (car windows) old-start 'noforce) |
| 859 | (setq windows (cdr windows))) | 789 | (setq windows (cdr windows)))) |
| 860 | pos)) | 790 | pos) |
| 861 | |||
| 862 | 791 | ||
| 863 | ;; The result from `follow-windows-start-end' is cached when using | 792 | ;; The result from `follow-windows-start-end' is cached when using |
| 864 | ;; a handful simple commands, like cursor movement commands. | 793 | ;; a handful simple commands, like cursor movement commands. |
| @@ -877,23 +806,8 @@ Note that this handles the case when the cache has been set to nil." | |||
| 877 | (setq cache (cdr cache))) | 806 | (setq cache (cdr cache))) |
| 878 | (and res (null windows) (null cache)))) | 807 | (and res (null windows) (null cache)))) |
| 879 | 808 | ||
| 880 | |||
| 881 | (defsubst follow-invalidate-cache () | ||
| 882 | "Force `follow-windows-start-end' to recalculate the end of the window." | ||
| 883 | (setq follow-windows-start-end-cache nil)) | ||
| 884 | |||
| 885 | |||
| 886 | ;; Build a list of windows and their start and end positions. | ||
| 887 | ;; Useful to avoid calculating start/end position whenever they are needed. | ||
| 888 | ;; The list has the format: | ||
| 889 | ;; ((Win Start End End-of-buffer-visible-p) ...) | ||
| 890 | |||
| 891 | ;; Used to have a `save-window-excursion', but it obviously triggered | ||
| 892 | ;; redraws of the display. Check if I used it for anything. | ||
| 893 | |||
| 894 | |||
| 895 | (defun follow-windows-start-end (windows) | 809 | (defun follow-windows-start-end (windows) |
| 896 | "Builds a list of (WIN START END BUFFER-END-P) for every window in WINDOWS." | 810 | "Return a list of (WIN START END BUFFER-END-P) for window list WINDOWS." |
| 897 | (if (follow-cache-valid-p windows) | 811 | (if (follow-cache-valid-p windows) |
| 898 | follow-windows-start-end-cache | 812 | follow-windows-start-end-cache |
| 899 | (let ((orig-win (selected-window)) | 813 | (let ((orig-win (selected-window)) |
| @@ -905,7 +819,6 @@ Note that this handles the case when the cache has been set to nil." | |||
| 905 | (select-window orig-win) | 819 | (select-window orig-win) |
| 906 | (setq follow-windows-start-end-cache (nreverse win-start-end))))) | 820 | (setq follow-windows-start-end-cache (nreverse win-start-end))))) |
| 907 | 821 | ||
| 908 | |||
| 909 | (defsubst follow-pos-visible (pos win win-start-end) | 822 | (defsubst follow-pos-visible (pos win win-start-end) |
| 910 | "Non-nil when POS is visible in WIN." | 823 | "Non-nil when POS is visible in WIN." |
| 911 | (let ((wstart-wend-bend (cdr (assq win win-start-end)))) | 824 | (let ((wstart-wend-bend (cdr (assq win win-start-end)))) |
| @@ -919,20 +832,16 @@ Note that this handles the case when the cache has been set to nil." | |||
| 919 | ;; should start at a full screen line. | 832 | ;; should start at a full screen line. |
| 920 | 833 | ||
| 921 | (defsubst follow-windows-aligned-p (win-start-end) | 834 | (defsubst follow-windows-aligned-p (win-start-end) |
| 922 | "Non-nil if the follower windows are aligned." | 835 | "Non-nil if the follower windows are aligned. |
| 923 | (let ((res t)) | 836 | The argument, WIN-START-END, should be a list of the form |
| 924 | (save-excursion | 837 | returned by `follow-windows-start-end'." |
| 925 | (goto-char (window-start (caar win-start-end))) | 838 | (let ((result t)) |
| 926 | (unless (bolp) | 839 | (while (and win-start-end result) |
| 927 | (vertical-motion 0 (caar win-start-end)) | 840 | (if (cdr win-start-end) |
| 928 | (setq res (eq (point) (window-start (caar win-start-end)))))) | 841 | (setq result (eq (nth 2 (car win-start-end)) |
| 929 | (while (and res (cdr win-start-end)) | 842 | (nth 1 (cadr win-start-end))))) |
| 930 | ;; At least two followers left | ||
| 931 | (setq res (eq (car (cdr (cdr (car win-start-end)))) | ||
| 932 | (car (cdr (car (cdr win-start-end)))))) | ||
| 933 | (setq win-start-end (cdr win-start-end))) | 843 | (setq win-start-end (cdr win-start-end))) |
| 934 | res)) | 844 | result)) |
| 935 | |||
| 936 | 845 | ||
| 937 | ;; Check if the point is visible in all windows. (So that | 846 | ;; Check if the point is visible in all windows. (So that |
| 938 | ;; no one will be recentered.) | 847 | ;; no one will be recentered.) |
| @@ -968,42 +877,22 @@ Note that this handles the case when the cache has been set to nil." | |||
| 968 | (vertical-motion 1 win) | 877 | (vertical-motion 1 win) |
| 969 | (set-window-start win (point) 'noforce))))) | 878 | (set-window-start win (point) 'noforce))))) |
| 970 | 879 | ||
| 971 | ;;; Selection functions | ||
| 972 | |||
| 973 | ;; Make a window in WINDOWS selected if it currently | ||
| 974 | ;; is displaying the position DEST. | ||
| 975 | ;; | ||
| 976 | ;; We don't select a window if it just has been moved. | ||
| 977 | |||
| 978 | (defun follow-select-if-visible (dest win-start-end) | 880 | (defun follow-select-if-visible (dest win-start-end) |
| 979 | "Select and return a window, if DEST is visible in it. | 881 | "Select and return a window, if DEST is visible in it. |
| 980 | Return the selected window." | 882 | Return the selected window." |
| 981 | (let (win win-end) | 883 | (let (win win-end wse) |
| 982 | (while (and (not win) win-start-end) | 884 | (while (and (not win) win-start-end) |
| 983 | ;; Don't select a window that was just moved. This makes it | 885 | ;; Don't select a window that was just moved. This makes it |
| 984 | ;; possible to later select the last window after a `end-of-buffer' | 886 | ;; possible to later select the last window after a |
| 985 | ;; command. | 887 | ;; `end-of-buffer' command. |
| 986 | (when (follow-pos-visible dest (caar win-start-end) win-start-end) | 888 | (setq wse (car win-start-end)) |
| 987 | (setq win (caar win-start-end) | 889 | (when (follow-pos-visible dest (car wse) win-start-end) |
| 988 | win-end (car (cddr (car win-start-end)))) | 890 | (setq win (car wse) |
| 891 | win-end (nth 2 wse)) | ||
| 989 | (select-window win)) | 892 | (select-window win)) |
| 990 | (setq win-start-end (cdr win-start-end))) | 893 | (setq win-start-end (cdr win-start-end))) |
| 991 | ;; The last line of the window may be partially visible; if so, | ||
| 992 | ;; and if point is visible in the next window, select the next | ||
| 993 | ;; window instead. | ||
| 994 | (and win | ||
| 995 | (/= dest (point-max)) | ||
| 996 | win-start-end | ||
| 997 | (follow-pos-visible dest (caar win-start-end) win-start-end) | ||
| 998 | (save-excursion | ||
| 999 | (goto-char dest) | ||
| 1000 | (vertical-motion 1 win) | ||
| 1001 | (>= (point) win-end)) | ||
| 1002 | (setq win (caar win-start-end)) | ||
| 1003 | (select-window win)) | ||
| 1004 | win)) | 894 | win)) |
| 1005 | 895 | ||
| 1006 | |||
| 1007 | ;; Lets select a window showing the end. Make sure we only select it if | 896 | ;; Lets select a window showing the end. Make sure we only select it if |
| 1008 | ;; it wasn't just moved here. (I.e. M-> shall not unconditionally place | 897 | ;; it wasn't just moved here. (I.e. M-> shall not unconditionally place |
| 1009 | ;; the point in the selected window.) | 898 | ;; the point in the selected window.) |
| @@ -1109,7 +998,6 @@ repositioning the other windows." | |||
| 1109 | (set-window-start w start)) | 998 | (set-window-start w start)) |
| 1110 | (setq start (car (follow-calc-win-end w)))))) | 999 | (setq start (car (follow-calc-win-end w)))))) |
| 1111 | 1000 | ||
| 1112 | |||
| 1113 | (defun follow-estimate-first-window-start (windows win start) | 1001 | (defun follow-estimate-first-window-start (windows win start) |
| 1114 | "Estimate the position of the first window. | 1002 | "Estimate the position of the first window. |
| 1115 | The estimate is computed by assuming that the window WIN, which | 1003 | The estimate is computed by assuming that the window WIN, which |
| @@ -1148,9 +1036,6 @@ should be a member of WINDOWS, starts at position START." | |||
| 1148 | 1036 | ||
| 1149 | ;; Find the starting point, start at GUESS and search upward. Return | 1037 | ;; Find the starting point, start at GUESS and search upward. Return |
| 1150 | ;; a point on the same line as GUESS, or above. | 1038 | ;; a point on the same line as GUESS, or above. |
| 1151 | ;; | ||
| 1152 | ;; (Is this ever used? I must make sure it works just in case it is | ||
| 1153 | ;; ever called.) | ||
| 1154 | 1039 | ||
| 1155 | (defun follow-calculate-first-window-start-from-below | 1040 | (defun follow-calculate-first-window-start-from-below |
| 1156 | (windows guess &optional win start) | 1041 | (windows guess &optional win start) |
| @@ -1184,46 +1069,36 @@ should be a member of WINDOWS, starts at position START." | |||
| 1184 | 1069 | ||
| 1185 | ;;; Avoid tail recenter | 1070 | ;;; Avoid tail recenter |
| 1186 | 1071 | ||
| 1187 | ;; This sets the window internal flag `force_start'. The effect is that | 1072 | ;; This sets the window internal flag `force_start'. The effect is |
| 1188 | ;; windows only displaying the tail aren't recentered. | 1073 | ;; that windows only displaying the tail aren't recentered. |
| 1189 | ;; Has to be called before every redisplay... (Great isn't it?) | ||
| 1190 | ;; | 1074 | ;; |
| 1191 | ;; XEmacs doesn't recenter the tail, GOOD! | 1075 | ;; A window displaying only the tail, is a window whose window-start |
| 1192 | ;; | 1076 | ;; position is equal to (point-max) of the buffer it displays. |
| 1193 | ;; A window displaying only the tail, is a window whose | ||
| 1194 | ;; window-start position is equal to (point-max) of the buffer it | ||
| 1195 | ;; displays. | ||
| 1196 | ;; | ||
| 1197 | ;; Sometimes, calling this function could actually cause a redisplay, | ||
| 1198 | ;; especially if it is placed in the debug filter section. I must | ||
| 1199 | ;; investigate this further... | ||
| 1200 | 1077 | ||
| 1201 | (defun follow-avoid-tail-recenter (&rest _rest) | 1078 | (defun follow-avoid-tail-recenter (&rest _rest) |
| 1202 | "Make sure windows displaying the end of a buffer aren't recentered. | 1079 | "Make sure windows displaying the end of a buffer aren't recentered. |
| 1203 | |||
| 1204 | This is done by reading and rewriting the start position of | 1080 | This is done by reading and rewriting the start position of |
| 1205 | non-first windows in Follow mode." | 1081 | non-first windows in Follow mode." |
| 1206 | (if follow-avoid-tail-recenter-p | 1082 | (let* ((orig-buffer (current-buffer)) |
| 1207 | (let* ((orig-buffer (current-buffer)) | 1083 | (top (frame-first-window (selected-frame))) |
| 1208 | (top (frame-first-window (selected-frame))) | 1084 | (win top) |
| 1209 | (win top) | 1085 | who) ; list of (buffer . frame) |
| 1210 | who) ; list of (buffer . frame) | 1086 | ;; If the only window in the frame is a minibuffer |
| 1211 | ;; If the only window in the frame is a minibuffer | 1087 | ;; window, `next-window' will never find it again... |
| 1212 | ;; window, `next-window' will never find it again... | 1088 | (unless (window-minibuffer-p top) |
| 1213 | (unless (window-minibuffer-p top) | 1089 | (while ;; look, no body! |
| 1214 | (while ;; look, no body! | 1090 | (let ((start (window-start win)) |
| 1215 | (let ((start (window-start win)) | 1091 | (pair (cons (window-buffer win) (window-frame win)))) |
| 1216 | (pair (cons (window-buffer win) (window-frame win)))) | 1092 | (set-buffer (window-buffer win)) |
| 1217 | (set-buffer (window-buffer win)) | 1093 | (cond ((null (member pair who)) |
| 1218 | (cond ((null (member pair who)) | 1094 | (setq who (cons pair who))) |
| 1219 | (setq who (cons pair who))) | 1095 | ((and follow-mode (eq (point-max) start)) |
| 1220 | ((and follow-mode (eq (point-max) start)) | 1096 | ;; Write the same window start back, but don't |
| 1221 | ;; Write the same window start back, but don't | 1097 | ;; set the NOFORCE flag. |
| 1222 | ;; set the NOFORCE flag. | 1098 | (set-window-start win start))) |
| 1223 | (set-window-start win start))) | 1099 | (setq win (next-window win 'not t)) |
| 1224 | (setq win (next-window win 'not t)) | 1100 | (not (eq win top)))) ;; Loop while this is true. |
| 1225 | (not (eq win top)))) ;; Loop while this is true. | 1101 | (set-buffer orig-buffer)))) |
| 1226 | (set-buffer orig-buffer))))) | ||
| 1227 | 1102 | ||
| 1228 | ;;; Post Command Hook | 1103 | ;;; Post Command Hook |
| 1229 | 1104 | ||
| @@ -1246,146 +1121,149 @@ non-first windows in Follow mode." | |||
| 1246 | (with-current-buffer (window-buffer win) | 1121 | (with-current-buffer (window-buffer win) |
| 1247 | (unless (and (symbolp this-command) | 1122 | (unless (and (symbolp this-command) |
| 1248 | (get this-command 'follow-mode-use-cache)) | 1123 | (get this-command 'follow-mode-use-cache)) |
| 1249 | (follow-invalidate-cache)) | 1124 | (setq follow-windows-start-end-cache nil))) |
| 1250 | (when (and follow-mode | 1125 | (follow-adjust-window win (point))))) |
| 1251 | (not (window-minibuffer-p win))) | 1126 | |
| 1252 | ;; The buffer shown in the selected window is in follow | 1127 | (defun follow-adjust-window (win dest) |
| 1253 | ;; mode. Find the current state of the display. | 1128 | ;; Adjust the window WIN and its followers. |
| 1254 | (let* ((windows (follow-all-followers win)) | 1129 | (with-current-buffer (window-buffer win) |
| 1255 | (dest (point)) | 1130 | (when (and follow-mode |
| 1256 | (win-start-end (progn | 1131 | (not (window-minibuffer-p win))) |
| 1257 | (follow-update-window-start (car windows)) | 1132 | (let* ((windows (follow-all-followers win)) |
| 1258 | (follow-windows-start-end windows))) | 1133 | (win-start-end (progn |
| 1259 | (aligned (follow-windows-aligned-p win-start-end)) | 1134 | (follow-update-window-start (car windows)) |
| 1260 | (visible (follow-pos-visible dest win win-start-end)) | 1135 | (follow-windows-start-end windows))) |
| 1261 | selected-window-up-to-date) | 1136 | (aligned (follow-windows-aligned-p win-start-end)) |
| 1262 | (unless (and aligned visible) | 1137 | (visible (follow-pos-visible dest win win-start-end)) |
| 1263 | (follow-invalidate-cache)) | 1138 | selected-window-up-to-date) |
| 1264 | (follow-avoid-tail-recenter) | 1139 | (unless (and aligned visible) |
| 1265 | ;; Select a window to display point. | 1140 | (setq follow-windows-start-end-cache nil)) |
| 1266 | (unless follow-internal-force-redisplay | 1141 | |
| 1267 | (if (eq dest (point-max)) | 1142 | ;; Select a window to display point. |
| 1268 | ;; At point-max, we have to be careful since the | 1143 | (unless follow-internal-force-redisplay |
| 1269 | ;; display can be aligned while `dest' can be | 1144 | (if (eq dest (point-max)) |
| 1270 | ;; visible in several windows. | 1145 | ;; Be careful at point-max: the display can be aligned |
| 1271 | (cond | 1146 | ;; while DEST can be visible in several windows. |
| 1272 | ;; Select the current window, but only when the | 1147 | (cond |
| 1273 | ;; display is correct. (When inserting characters | 1148 | ;; Select the current window, but only when the display |
| 1274 | ;; in a tail window, the display is not correct, as | 1149 | ;; is correct. (When inserting characters in a tail |
| 1275 | ;; they are shown twice.) | 1150 | ;; window, the display is not correct, as they are |
| 1276 | ;; | 1151 | ;; shown twice.) |
| 1277 | ;; Never stick to the current window after a | 1152 | ;; |
| 1278 | ;; deletion. The reason is cosmetic: when typing | 1153 | ;; Never stick to the current window after a deletion. |
| 1279 | ;; `DEL' in a window showing only the end of the | 1154 | ;; Otherwise, when typing `DEL' in a window showing |
| 1280 | ;; file, a character would be removed from the | 1155 | ;; only the end of the file, a character would be |
| 1281 | ;; window above, which is very unintuitive. | 1156 | ;; removed from the window above, which is very |
| 1282 | ((and visible | 1157 | ;; unintuitive. |
| 1283 | aligned | 1158 | ((and visible |
| 1284 | (not (memq this-command | 1159 | aligned |
| 1285 | '(backward-delete-char | 1160 | (not (memq this-command |
| 1286 | delete-backward-char | 1161 | '(backward-delete-char |
| 1287 | backward-delete-char-untabify | 1162 | delete-backward-char |
| 1288 | kill-region)))) | 1163 | backward-delete-char-untabify |
| 1289 | (follow-debug-message "Max: same")) | 1164 | kill-region)))) |
| 1290 | ;; If the end is visible, and the window doesn't | 1165 | (follow-debug-message "Max: same")) |
| 1291 | ;; seems like it just has been moved, select it. | 1166 | ;; If the end is visible, and the window doesn't |
| 1292 | ((follow-select-if-end-visible win-start-end) | 1167 | ;; seems like it just has been moved, select it. |
| 1293 | (follow-debug-message "Max: end visible") | 1168 | ((follow-select-if-end-visible win-start-end) |
| 1294 | (setq visible t aligned nil) | 1169 | (follow-debug-message "Max: end visible") |
| 1295 | (goto-char dest)) | 1170 | (setq visible t aligned nil) |
| 1296 | ;; Just show the end... | 1171 | (goto-char dest)) |
| 1297 | (t | 1172 | ;; Just show the end... |
| 1298 | (follow-debug-message "Max: default") | 1173 | (t |
| 1299 | (select-window (car (reverse windows))) | 1174 | (follow-debug-message "Max: default") |
| 1300 | (goto-char dest) | 1175 | (select-window (car (last windows))) |
| 1301 | (setq visible nil aligned nil))) | 1176 | (goto-char dest) |
| 1302 | 1177 | (setq visible nil aligned nil))) | |
| 1303 | ;; We're not at the end, here life is much simpler. | 1178 | |
| 1304 | (cond | 1179 | ;; We're not at the end, here life is much simpler. |
| 1305 | ;; This is the normal case! | 1180 | (cond |
| 1306 | ;; It should be optimized for speed. | 1181 | ;; This is the normal case! |
| 1307 | ((and visible aligned) | 1182 | ;; It should be optimized for speed. |
| 1308 | (follow-debug-message "same")) | 1183 | ((and visible aligned) |
| 1309 | ;; Pick a position in any window. If the display is | 1184 | (follow-debug-message "same")) |
| 1310 | ;; ok, this will pick the `correct' window. | 1185 | ;; Pick a position in any window. If the display is ok, |
| 1311 | ((follow-select-if-visible dest win-start-end) | 1186 | ;; this picks the `correct' window. |
| 1312 | (follow-debug-message "visible") | 1187 | ((follow-select-if-visible dest win-start-end) |
| 1313 | (goto-char dest) | 1188 | (follow-debug-message "visible") |
| 1314 | ;; We have to perform redisplay, since scrolling is | 1189 | (goto-char dest) |
| 1315 | ;; needed in case the line is partially visible. | 1190 | ;; Perform redisplay, in case line is partially visible. |
| 1316 | (setq visible nil)) | 1191 | (setq visible nil)) |
| 1317 | ;; Not visible anywhere else, lets pick this one. | 1192 | ;; Not visible anywhere else, lets pick this one. |
| 1318 | ;; (Is this case used?) | 1193 | (visible |
| 1319 | (visible | 1194 | (follow-debug-message "visible in selected.")) |
| 1320 | (follow-debug-message "visible in selected.")) | 1195 | ;; If DEST is before the first window start, select the |
| 1321 | ;; Far out! | 1196 | ;; first window. |
| 1322 | ((eq dest (point-min)) | 1197 | ((< dest (nth 1 (car win-start-end))) |
| 1323 | (follow-debug-message "min") | 1198 | (follow-debug-message "before first") |
| 1324 | (select-window (car windows)) | 1199 | (select-window (car windows)) |
| 1325 | (goto-char dest) | 1200 | (goto-char dest) |
| 1326 | (set-window-start (selected-window) (point-min)) | 1201 | (setq visible nil aligned nil)) |
| 1327 | (setq win-start-end (follow-windows-start-end windows)) | 1202 | ;; If we can position the cursor without moving the first |
| 1328 | (follow-invalidate-cache) | 1203 | ;; window, do it. This is the case that catches `RET' at |
| 1329 | (setq visible t aligned nil)) | 1204 | ;; the bottom of a window. |
| 1330 | ;; If we can position the cursor without moving the first | 1205 | ((follow-select-if-visible-from-first dest windows) |
| 1331 | ;; window, do it. This is the case that catches `RET' | 1206 | (follow-debug-message "Below first") |
| 1332 | ;; at the bottom of a window. | 1207 | (setq visible t aligned t)) |
| 1333 | ((follow-select-if-visible-from-first dest windows) | 1208 | ;; None of the above. Stick to the selected window. |
| 1334 | (follow-debug-message "Below first") | 1209 | (t |
| 1335 | (setq visible t aligned t)) | 1210 | (follow-debug-message "None") |
| 1336 | ;; None of the above. For simplicity, we stick to the | 1211 | (setq visible nil aligned nil)))) |
| 1337 | ;; selected window. | 1212 | |
| 1338 | (t | 1213 | ;; If a new window was selected, make sure that the old is |
| 1339 | (follow-debug-message "None") | 1214 | ;; not scrolled when the point is outside the window. |
| 1340 | (setq visible nil aligned nil)))) | 1215 | (unless (eq win (selected-window)) |
| 1341 | ;; If a new window has been selected, make sure that the | 1216 | (let ((p (window-point win))) |
| 1342 | ;; old is not scrolled when the point is outside the | 1217 | (set-window-start win (window-start win) nil) |
| 1343 | ;; window. | 1218 | (set-window-point win p)))) |
| 1344 | (unless (eq win (selected-window)) | 1219 | |
| 1345 | (let ((p (window-point win))) | 1220 | (unless visible |
| 1346 | (set-window-start win (window-start win) nil) | 1221 | ;; If point may not be visible in the selected window, |
| 1347 | (set-window-point win p)))) | 1222 | ;; perform a redisplay; this ensures scrolling. |
| 1348 | (unless visible | 1223 | (let ((opoint (point))) |
| 1349 | ;; If point may not be visible in the selected window, | 1224 | (redisplay) |
| 1350 | ;; perform a redisplay; this ensures scrolling. | 1225 | ;; If this `redisplay' moved point, we got clobbered by a |
| 1351 | (redisplay) | 1226 | ;; previous call to `set-window-start'. Try again. |
| 1352 | (setq selected-window-up-to-date t) | 1227 | (when (/= (point) opoint) |
| 1353 | (follow-avoid-tail-recenter) | 1228 | (goto-char opoint) |
| 1354 | (setq win-start-end (follow-windows-start-end windows)) | 1229 | (redisplay))) |
| 1355 | (follow-invalidate-cache) | 1230 | |
| 1356 | (setq aligned nil)) | 1231 | (setq selected-window-up-to-date t) |
| 1357 | ;; Now redraw the windows around the selected window. | 1232 | (follow-avoid-tail-recenter) |
| 1358 | (unless (and (not follow-internal-force-redisplay) | 1233 | (setq win-start-end (follow-windows-start-end windows) |
| 1359 | (or aligned | 1234 | follow-windows-start-end-cache nil |
| 1360 | (follow-windows-aligned-p win-start-end)) | 1235 | aligned nil)) |
| 1361 | (follow-point-visible-all-windows-p | 1236 | |
| 1362 | win-start-end)) | 1237 | ;; Now redraw the windows around the selected window. |
| 1363 | (setq follow-internal-force-redisplay nil) | 1238 | (unless (and (not follow-internal-force-redisplay) |
| 1364 | (follow-redisplay windows (selected-window) | 1239 | (or aligned |
| 1365 | selected-window-up-to-date) | 1240 | (follow-windows-aligned-p win-start-end)) |
| 1366 | (setq win-start-end (follow-windows-start-end windows)) | 1241 | (follow-point-visible-all-windows-p win-start-end)) |
| 1367 | (follow-invalidate-cache) | 1242 | (setq follow-internal-force-redisplay nil) |
| 1368 | ;; When the point ends up in another window. This | 1243 | (follow-redisplay windows (selected-window) |
| 1369 | ;; happens when dest is in the beginning of the file and | 1244 | selected-window-up-to-date) |
| 1370 | ;; the selected window is not the first. It can also, | 1245 | (setq win-start-end (follow-windows-start-end windows) |
| 1371 | ;; in rare situations happen when long lines are used | 1246 | follow-windows-start-end-cache nil) |
| 1372 | ;; and there is a big difference between the width of | 1247 | ;; The point can ends up in another window when DEST is at |
| 1373 | ;; the windows. (When scrolling one line in a wide | 1248 | ;; the beginning of the buffer and the selected window is |
| 1374 | ;; window which will cause a move larger that an entire | 1249 | ;; not the first. It can also happen when long lines are |
| 1375 | ;; small window.) | 1250 | ;; used and there is a big difference between the width of |
| 1376 | (unless (follow-pos-visible dest win win-start-end) | 1251 | ;; the windows. (When scrolling one line in a wide window |
| 1377 | (follow-select-if-visible dest win-start-end) | 1252 | ;; which will cause a move larger that an entire small |
| 1378 | (goto-char dest))) | 1253 | ;; window.) |
| 1379 | 1254 | (unless (follow-pos-visible dest win win-start-end) | |
| 1380 | ;; If the region is visible, make it look good when spanning | 1255 | (follow-select-if-visible dest win-start-end) |
| 1381 | ;; multiple windows. | 1256 | (goto-char dest))) |
| 1382 | (when (region-active-p) | 1257 | |
| 1383 | (follow-maximize-region | 1258 | ;; If the region is visible, make it look good when spanning |
| 1384 | (selected-window) windows win-start-end)))) | 1259 | ;; multiple windows. |
| 1385 | ;; Whether or not the buffer was in follow mode, we must | 1260 | (when (region-active-p) |
| 1386 | ;; update the windows displaying the tail so that Emacs won't | 1261 | (follow-maximize-region |
| 1387 | ;; recenter them. | 1262 | (selected-window) windows win-start-end))) |
| 1388 | (follow-avoid-tail-recenter))))) | 1263 | |
| 1264 | ;; Whether or not the buffer was in follow mode, update windows | ||
| 1265 | ;; displaying the tail so that Emacs won't recenter them. | ||
| 1266 | (follow-avoid-tail-recenter)))) | ||
| 1389 | 1267 | ||
| 1390 | ;;; The region | 1268 | ;;; The region |
| 1391 | 1269 | ||
| @@ -1414,429 +1292,59 @@ non-first windows in Follow mode." | |||
| 1414 | 1292 | ||
| 1415 | ;;;; Scroll-bar support code. | 1293 | ;;;; Scroll-bar support code. |
| 1416 | 1294 | ||
| 1417 | ;; Why is it needed? Well, if the selected window is in follow mode, | 1295 | ;; This handles the case where the user drags the scroll bar of a |
| 1418 | ;; all its followers stick to it blindly. If one of them is scrolled, | 1296 | ;; non-selected window whose buffer is in Follow mode. |
| 1419 | ;; it immediately returns to the original position when the mouse is | 1297 | |
| 1420 | ;; released. If the selected window is not a follower of the dragged | 1298 | (defun follow-scroll-bar-toolkit-scroll (event) |
| 1421 | ;; window the windows will be unaligned. | 1299 | (interactive "e") |
| 1422 | 1300 | (scroll-bar-toolkit-scroll event) | |
| 1423 | ;; The advices don't get compiled. Aesthetically, this might be a | 1301 | (follow-redraw-after-event event)) |
| 1424 | ;; problem but in practical life it isn't. | 1302 | |
| 1425 | 1303 | (defun follow-scroll-bar-drag (event) | |
| 1426 | ;; Discussion: Now when the other windows in the chain follow the | 1304 | (interactive "e") |
| 1427 | ;; dragged, should we really select it? | 1305 | (scroll-bar-drag event) |
| 1428 | 1306 | (follow-redraw-after-event event)) | |
| 1429 | (cond ((fboundp 'scroll-bar-drag) | 1307 | |
| 1430 | ;;; | 1308 | (defun follow-scroll-bar-scroll-up (event) |
| 1431 | ;;; Emacs style scrollbars. | 1309 | (interactive "e") |
| 1432 | ;;; | 1310 | (scroll-bar-scroll-up event) |
| 1433 | 1311 | (follow-redraw-after-event event)) | |
| 1434 | ;; Select the dragged window if it is a follower of the | 1312 | |
| 1435 | ;; selected window. | 1313 | (defun follow-scroll-bar-scroll-down (event) |
| 1436 | ;; | 1314 | (interactive "e") |
| 1437 | ;; Generate advices of the form: | 1315 | (scroll-bar-scroll-down event) |
| 1438 | ;; (defadvice scroll-bar-drag (after follow-scroll-bar-drag activate) | 1316 | (follow-redraw-after-event event)) |
| 1439 | ;; "Adviced by `follow-mode'." | 1317 | |
| 1440 | ;; (follow-redraw-after-event (ad-get-arg 0))) | 1318 | (defun follow-redraw-after-event (event) |
| 1441 | (let ((cmds '(scroll-bar-drag | 1319 | "Re-align the Follow mode windows acted on by EVENT." |
| 1442 | scroll-bar-drag-1 ; Executed at every move. | 1320 | (let ((window (nth 0 (event-end event))) |
| 1443 | scroll-bar-scroll-down | 1321 | (orig-win (selected-window))) |
| 1444 | scroll-bar-scroll-up | 1322 | (when (and (buffer-local-value 'follow-mode (window-buffer window)) |
| 1445 | scroll-bar-set-window-start))) | 1323 | ;; Ignore the case where we scroll the selected window; |
| 1446 | (while cmds | 1324 | ;; that is handled by the post-command hook function. |
| 1447 | (eval | 1325 | (not (eq window (selected-window)))) |
| 1448 | `(defadvice ,(intern (symbol-name (car cmds))) | 1326 | (select-window window) |
| 1449 | (after | 1327 | (follow-redisplay) |
| 1450 | ,(intern (concat "follow-" (symbol-name (car cmds)))) | 1328 | (select-window orig-win)))) |
| 1451 | activate) | ||
| 1452 | "Adviced by Follow mode." | ||
| 1453 | (follow-redraw-after-event (ad-get-arg 0)))) | ||
| 1454 | (setq cmds (cdr cmds)))) | ||
| 1455 | |||
| 1456 | |||
| 1457 | (defun follow-redraw-after-event (event) | ||
| 1458 | "Adviced by Follow mode." | ||
| 1459 | (condition-case nil | ||
| 1460 | (let* ((orig-win (selected-window)) | ||
| 1461 | (win (nth 0 (funcall | ||
| 1462 | (symbol-function 'event-start) event))) | ||
| 1463 | (fmode (assq 'follow-mode | ||
| 1464 | (buffer-local-variables | ||
| 1465 | (window-buffer win))))) | ||
| 1466 | (if (and fmode (cdr fmode)) | ||
| 1467 | ;; The selected window is in follow-mode | ||
| 1468 | (progn | ||
| 1469 | ;; Recenter around the dragged window. | ||
| 1470 | (select-window win) | ||
| 1471 | (follow-redisplay) | ||
| 1472 | (select-window orig-win)))) | ||
| 1473 | (error nil)))) | ||
| 1474 | |||
| 1475 | |||
| 1476 | ((fboundp 'scrollbar-vertical-drag) | ||
| 1477 | ;;; | ||
| 1478 | ;;; XEmacs style scrollbars. | ||
| 1479 | ;;; | ||
| 1480 | |||
| 1481 | ;; Advice all scrollbar functions on the form: | ||
| 1482 | ;; | ||
| 1483 | ;; (defadvice scrollbar-line-down | ||
| 1484 | ;; (after follow-scrollbar-line-down activate) | ||
| 1485 | ;; (follow-xemacs-scrollbar-support (ad-get-arg 0))) | ||
| 1486 | |||
| 1487 | (let ((cmds '(scrollbar-line-down ; Window | ||
| 1488 | scrollbar-line-up | ||
| 1489 | scrollbar-page-down ; Object | ||
| 1490 | scrollbar-page-up | ||
| 1491 | scrollbar-to-bottom ; Window | ||
| 1492 | scrollbar-to-top | ||
| 1493 | scrollbar-vertical-drag ; Object | ||
| 1494 | ))) | ||
| 1495 | |||
| 1496 | (while cmds | ||
| 1497 | (eval | ||
| 1498 | `(defadvice ,(intern (symbol-name (car cmds))) | ||
| 1499 | (after | ||
| 1500 | ,(intern (concat "follow-" (symbol-name (car cmds)))) | ||
| 1501 | activate) | ||
| 1502 | "Adviced by `follow-mode'." | ||
| 1503 | (follow-xemacs-scrollbar-support (ad-get-arg 0)))) | ||
| 1504 | (setq cmds (cdr cmds)))) | ||
| 1505 | |||
| 1506 | |||
| 1507 | (defun follow-xemacs-scrollbar-support (window) | ||
| 1508 | "Redraw windows showing the same buffer as shown in WINDOW. | ||
| 1509 | WINDOW is either the dragged window, or a cons containing the | ||
| 1510 | window as its first element. This is called while the user drags | ||
| 1511 | the scrollbar. | ||
| 1512 | |||
| 1513 | WINDOW can be an object or a window." | ||
| 1514 | (condition-case nil | ||
| 1515 | (progn | ||
| 1516 | (if (consp window) | ||
| 1517 | (setq window (car window))) | ||
| 1518 | (let ((fmode (assq 'follow-mode | ||
| 1519 | (buffer-local-variables | ||
| 1520 | (window-buffer window)))) | ||
| 1521 | (orig-win (selected-window))) | ||
| 1522 | (if (and fmode (cdr fmode)) | ||
| 1523 | (progn | ||
| 1524 | ;; Recenter around the dragged window. | ||
| 1525 | (select-window window) | ||
| 1526 | (follow-redisplay) | ||
| 1527 | (select-window orig-win))))) | ||
| 1528 | (error nil))))) | ||
| 1529 | |||
| 1530 | ;;; Process output | ||
| 1531 | |||
| 1532 | ;; The following sections installs a spy that listens to process | ||
| 1533 | ;; output and tries to reposition the windows whose buffers are in | ||
| 1534 | ;; Follow mode. We play safe as much as possible... | ||
| 1535 | ;; | ||
| 1536 | ;; When follow-mode is activated all active processes are | ||
| 1537 | ;; intercepted. All new processes that change their filter function | ||
| 1538 | ;; using `set-process-filter' are also intercepted. The reason is | ||
| 1539 | ;; that a process can cause a redisplay recentering "tail" windows. | ||
| 1540 | ;; Note that it doesn't hurt to spy on more processes than needed. | ||
| 1541 | ;; | ||
| 1542 | ;; Technically, we set the process filter to `follow-generic-filter'. | ||
| 1543 | ;; The original filter is stored in `follow-process-filter-alist'. | ||
| 1544 | ;; Our generic filter calls the original filter, or inserts the | ||
| 1545 | ;; output into the buffer, if the buffer originally didn't have an | ||
| 1546 | ;; output filter. It also makes sure that the windows connected to | ||
| 1547 | ;; the buffer are aligned. | ||
| 1548 | ;; | ||
| 1549 | ;; Discussion: How do we find processes that don't call | ||
| 1550 | ;; `set-process-filter'? (How often are processes created in a | ||
| 1551 | ;; buffer after Follow mode are activated?) | ||
| 1552 | ;; | ||
| 1553 | ;; Discussion: Should we also advice `process-filter' to make our | ||
| 1554 | ;; filter invisible to others? | ||
| 1555 | |||
| 1556 | ;;; Advice for `set-process-filter' | ||
| 1557 | |||
| 1558 | ;; Do not call this with 'follow-generic-filter as the name of the | ||
| 1559 | ;; filter... | ||
| 1560 | |||
| 1561 | (defadvice set-process-filter (before follow-set-process-filter activate) | ||
| 1562 | "Ensure process output will be displayed correctly in Follow mode buffers. | ||
| 1563 | |||
| 1564 | Follow mode inserts its own process filter to do its | ||
| 1565 | magic stuff before the real process filter is called." | ||
| 1566 | (if follow-intercept-processes | ||
| 1567 | (progn | ||
| 1568 | (setq follow-process-filter-alist | ||
| 1569 | (delq (assq (ad-get-arg 0) follow-process-filter-alist) | ||
| 1570 | follow-process-filter-alist)) | ||
| 1571 | (follow-tidy-process-filter-alist) | ||
| 1572 | (cond ((eq (ad-get-arg 1) t)) | ||
| 1573 | ((eq (ad-get-arg 1) nil) | ||
| 1574 | (ad-set-arg 1 'follow-generic-filter)) | ||
| 1575 | (t | ||
| 1576 | (setq follow-process-filter-alist | ||
| 1577 | (cons (cons (ad-get-arg 0) (ad-get-arg 1)) | ||
| 1578 | follow-process-filter-alist)) | ||
| 1579 | (ad-set-arg 1 'follow-generic-filter)))))) | ||
| 1580 | |||
| 1581 | |||
| 1582 | (defun follow-call-set-process-filter (proc filter) | ||
| 1583 | "Call original `set-process-filter' without the Follow mode advice." | ||
| 1584 | (ad-disable-advice 'set-process-filter 'before | ||
| 1585 | 'follow-set-process-filter) | ||
| 1586 | (ad-activate 'set-process-filter) | ||
| 1587 | (prog1 | ||
| 1588 | (set-process-filter proc filter) | ||
| 1589 | (ad-enable-advice 'set-process-filter 'before | ||
| 1590 | 'follow-set-process-filter) | ||
| 1591 | (ad-activate 'set-process-filter))) | ||
| 1592 | |||
| 1593 | |||
| 1594 | (defadvice process-filter (after follow-process-filter activate) | ||
| 1595 | "Return the original process filter, not `follow-generic-filter'." | ||
| 1596 | (cond ((eq ad-return-value 'follow-generic-filter) | ||
| 1597 | (setq ad-return-value | ||
| 1598 | (cdr-safe (assq (ad-get-arg 0) | ||
| 1599 | follow-process-filter-alist)))))) | ||
| 1600 | |||
| 1601 | |||
| 1602 | (defun follow-call-process-filter (proc) | ||
| 1603 | "Call original `process-filter' without the Follow mode advice." | ||
| 1604 | (ad-disable-advice 'process-filter 'after | ||
| 1605 | 'follow-process-filter) | ||
| 1606 | (ad-activate 'process-filter) | ||
| 1607 | (prog1 | ||
| 1608 | (process-filter proc) | ||
| 1609 | (ad-enable-advice 'process-filter 'after | ||
| 1610 | 'follow-process-filter) | ||
| 1611 | (ad-activate 'process-filter))) | ||
| 1612 | |||
| 1613 | |||
| 1614 | (defun follow-tidy-process-filter-alist () | ||
| 1615 | "Remove old processes from `follow-process-filter-alist'." | ||
| 1616 | (let ((alist follow-process-filter-alist) | ||
| 1617 | (ps (process-list)) | ||
| 1618 | (new ())) | ||
| 1619 | (while alist | ||
| 1620 | (if (and (not (memq (process-status (car (car alist))) | ||
| 1621 | '(exit signal closed nil))) | ||
| 1622 | (memq (car (car alist)) ps)) | ||
| 1623 | (setq new (cons (car alist) new))) | ||
| 1624 | (setq alist (cdr alist))) | ||
| 1625 | (setq follow-process-filter-alist new))) | ||
| 1626 | |||
| 1627 | ;;; Start/stop interception of processes. | ||
| 1628 | |||
| 1629 | ;; Normally, all new processes are intercepted by our `set-process-filter'. | ||
| 1630 | ;; This is needed to intercept old processes that were started before we were | ||
| 1631 | ;; loaded, and processes we have forgotten by calling | ||
| 1632 | ;; `follow-stop-intercept-process-output'. | ||
| 1633 | |||
| 1634 | (defun follow-intercept-process-output () | ||
| 1635 | "Intercept all active processes. | ||
| 1636 | |||
| 1637 | This is needed so that Follow mode can track all display events in the | ||
| 1638 | system. (See `follow-mode'.)" | ||
| 1639 | (interactive) | ||
| 1640 | (let ((list (process-list))) | ||
| 1641 | (while list | ||
| 1642 | (if (eq (process-filter (car list)) 'follow-generic-filter) | ||
| 1643 | nil | ||
| 1644 | ;; The custom `set-process-filter' defined above. | ||
| 1645 | (set-process-filter (car list) (process-filter (car list)))) | ||
| 1646 | (setq list (cdr list)))) | ||
| 1647 | (setq follow-intercept-processes t)) | ||
| 1648 | |||
| 1649 | |||
| 1650 | (defun follow-stop-intercept-process-output () | ||
| 1651 | "Stop Follow mode from spying on processes. | ||
| 1652 | |||
| 1653 | All current spypoints are removed and no new will be added. | ||
| 1654 | |||
| 1655 | The effect is that Follow mode won't be able to handle buffers | ||
| 1656 | connected to processes. | ||
| 1657 | |||
| 1658 | The only reason to call this function is if the Follow mode spy filter | ||
| 1659 | would interfere with some other package. If this happens, please | ||
| 1660 | report this using the `report-emacs-bug' function." | ||
| 1661 | (interactive) | ||
| 1662 | (follow-tidy-process-filter-alist) | ||
| 1663 | (dolist (process (process-list)) | ||
| 1664 | (when (eq (follow-call-process-filter process) 'follow-generic-filter) | ||
| 1665 | (follow-call-set-process-filter | ||
| 1666 | process | ||
| 1667 | (cdr-safe (assq process follow-process-filter-alist))) | ||
| 1668 | (setq follow-process-filter-alist | ||
| 1669 | (delq (assq process follow-process-filter-alist) | ||
| 1670 | follow-process-filter-alist)))) | ||
| 1671 | (setq follow-intercept-processes nil)) | ||
| 1672 | |||
| 1673 | ;;; The filter | ||
| 1674 | |||
| 1675 | ;; The following section is a naive method to make buffers with | ||
| 1676 | ;; process output to work with Follow mode. Whenever the start of the | ||
| 1677 | ;; window displaying the buffer is moved, we move it back to its | ||
| 1678 | ;; original position and try to select a new window. (If we fail, | ||
| 1679 | ;; the normal redisplay functions of Emacs will scroll it right | ||
| 1680 | ;; back!) | ||
| 1681 | |||
| 1682 | (defun follow-generic-filter (proc output) | ||
| 1683 | "Process output filter for process connected to buffers in Follow mode." | ||
| 1684 | (let* ((old-buffer (current-buffer)) | ||
| 1685 | (orig-win (selected-window)) | ||
| 1686 | (buf (process-buffer proc)) | ||
| 1687 | (win (and buf (if (eq buf (window-buffer orig-win)) | ||
| 1688 | orig-win | ||
| 1689 | (get-buffer-window buf t)))) | ||
| 1690 | (return-to-orig-win (and win (not (eq win orig-win)))) | ||
| 1691 | (orig-window-start (and win (window-start win)))) | ||
| 1692 | |||
| 1693 | ;; If input is pending, the `sit-for' below won't redraw the | ||
| 1694 | ;; display. In that case, calling `follow-avoid-tail-recenter' may | ||
| 1695 | ;; provoke the process handling code to schedule a redisplay. | ||
| 1696 | ;(or (input-pending-p) | ||
| 1697 | ; (follow-avoid-tail-recenter)) | ||
| 1698 | |||
| 1699 | ;; Output the `output'. | ||
| 1700 | (let ((filter (cdr-safe (assq proc follow-process-filter-alist)))) | ||
| 1701 | (cond | ||
| 1702 | ;; Call the original filter function | ||
| 1703 | (filter | ||
| 1704 | (funcall filter proc output)) | ||
| 1705 | |||
| 1706 | ;; No filter, but we've got a buffer. Just output into it. | ||
| 1707 | (buf | ||
| 1708 | (set-buffer buf) | ||
| 1709 | (if (not (marker-buffer (process-mark proc))) | ||
| 1710 | (set-marker (process-mark proc) (point-max))) | ||
| 1711 | (let ((moving (= (point) (process-mark proc))) | ||
| 1712 | deactivate-mark | ||
| 1713 | (inhibit-read-only t)) | ||
| 1714 | (save-excursion | ||
| 1715 | (goto-char (process-mark proc)) | ||
| 1716 | ;; `insert-before-markers' just in case the user's next | ||
| 1717 | ;; command is M-y. | ||
| 1718 | (insert-before-markers output) | ||
| 1719 | (set-marker (process-mark proc) (point))) | ||
| 1720 | (if moving (goto-char (process-mark proc))))))) | ||
| 1721 | |||
| 1722 | ;; If we're in follow mode, do our stuff. Select a new window and | ||
| 1723 | ;; redisplay. (Actually, it is redundant to check `buf', but I | ||
| 1724 | ;; feel it's more correct.) | ||
| 1725 | (if (and buf (window-live-p win)) | ||
| 1726 | (progn | ||
| 1727 | (set-buffer buf) | ||
| 1728 | (if (and (boundp 'follow-mode) follow-mode) | ||
| 1729 | (progn | ||
| 1730 | (select-window win) | ||
| 1731 | (let* ((windows (follow-all-followers win)) | ||
| 1732 | (win-start-end (follow-windows-start-end windows)) | ||
| 1733 | (new-window-start (window-start win)) | ||
| 1734 | (new-window-point (window-point win))) | ||
| 1735 | (cond | ||
| 1736 | ;; The start of the selected window was repositioned. | ||
| 1737 | ;; Try to use the original start position and continue | ||
| 1738 | ;; working with a window to the "right" in the window | ||
| 1739 | ;; chain. This will create the effect that the output | ||
| 1740 | ;; starts in one window and continues into the next. | ||
| 1741 | |||
| 1742 | ;; If the display has changed so much that it is not | ||
| 1743 | ;; possible to keep the original window fixed and still | ||
| 1744 | ;; display the point then we give up and use the new | ||
| 1745 | ;; window start. | ||
| 1746 | |||
| 1747 | ;; This case is typically used when the process filter | ||
| 1748 | ;; tries to reposition the start of the window in order | ||
| 1749 | ;; to view the tail of the output. | ||
| 1750 | ((not (eq orig-window-start new-window-start)) | ||
| 1751 | (follow-debug-message "filter: Moved") | ||
| 1752 | (set-window-start win orig-window-start) | ||
| 1753 | (follow-redisplay windows win) | ||
| 1754 | (setq win-start-end (follow-windows-start-end windows)) | ||
| 1755 | (follow-select-if-visible new-window-point | ||
| 1756 | win-start-end) | ||
| 1757 | (goto-char new-window-point) | ||
| 1758 | (if (eq win (selected-window)) | ||
| 1759 | (set-window-start win new-window-start)) | ||
| 1760 | (setq win-start-end (follow-windows-start-end windows))) | ||
| 1761 | ;; Stick to this window, if point is visible in it. | ||
| 1762 | ((pos-visible-in-window-p new-window-point) | ||
| 1763 | (follow-debug-message "filter: Visible in window")) | ||
| 1764 | ;; Avoid redisplaying the first window. If the | ||
| 1765 | ;; point is visible at a window below, | ||
| 1766 | ;; redisplay and select it. | ||
| 1767 | ((follow-select-if-visible-from-first | ||
| 1768 | new-window-point windows) | ||
| 1769 | (follow-debug-message "filter: Seen from first") | ||
| 1770 | (setq win-start-end | ||
| 1771 | (follow-windows-start-end windows))) | ||
| 1772 | ;; None of the above. We stick to the current window. | ||
| 1773 | (t | ||
| 1774 | (follow-debug-message "filter: nothing"))) | ||
| 1775 | |||
| 1776 | ;; Here we have selected a window. Make sure the | ||
| 1777 | ;; windows are aligned and the point is visible | ||
| 1778 | ;; in the selected window. | ||
| 1779 | (if (and (not (follow-pos-visible | ||
| 1780 | (point) (selected-window) win-start-end)) | ||
| 1781 | (not return-to-orig-win)) | ||
| 1782 | (progn | ||
| 1783 | (sit-for 0) | ||
| 1784 | (setq win-start-end | ||
| 1785 | (follow-windows-start-end windows)))) | ||
| 1786 | |||
| 1787 | (if (or follow-internal-force-redisplay | ||
| 1788 | (not (follow-windows-aligned-p win-start-end))) | ||
| 1789 | (follow-redisplay windows))))))) | ||
| 1790 | |||
| 1791 | ;; return to the original window. | ||
| 1792 | (if return-to-orig-win | ||
| 1793 | (select-window orig-win)) | ||
| 1794 | ;; Restore the original buffer, unless the filter explicitly | ||
| 1795 | ;; changed buffer or killed the old buffer. | ||
| 1796 | (if (and (eq buf (current-buffer)) | ||
| 1797 | (buffer-name old-buffer)) | ||
| 1798 | (set-buffer old-buffer))) | ||
| 1799 | |||
| 1800 | (follow-invalidate-cache) | ||
| 1801 | |||
| 1802 | ;; Normally, if the display has been changed, it is redrawn. All | ||
| 1803 | ;; windows showing only the end of a buffer are unconditionally | ||
| 1804 | ;; recentered; we can't prevent that by calling | ||
| 1805 | ;; `follow-avoid-tail-recenter'. | ||
| 1806 | ;; | ||
| 1807 | ;; We force a redisplay here on our own, so Emacs does need to. | ||
| 1808 | ;; (However, redisplaying when there's input available just seems | ||
| 1809 | ;; to make things worse, so we exclude that case.) | ||
| 1810 | (if (and follow-avoid-tail-recenter-p | ||
| 1811 | (not (input-pending-p))) | ||
| 1812 | (sit-for 0))) | ||
| 1813 | 1329 | ||
| 1814 | ;;; Window size change | 1330 | ;;; Window size change |
| 1815 | 1331 | ||
| 1816 | ;; In Emacs 19.29, the functions in `window-size-change-functions' are | 1332 | ;; The functions in `window-size-change-functions' are called every |
| 1817 | ;; called every time a window in a frame changes size. Most notably, it | 1333 | ;; time a window in a frame changes size, most notably after the frame |
| 1818 | ;; is called after the frame has been resized. | 1334 | ;; has been resized. We call `follow-post-command-hook' for every |
| 1819 | ;; | 1335 | ;; Follow mode buffer visible in any window in the resized frame. |
| 1820 | ;; We basically call our post-command-hook for every buffer that is | ||
| 1821 | ;; visible in any window in the resized frame, which is in follow-mode. | ||
| 1822 | ;; | 1336 | ;; |
| 1823 | ;; Since this function can be called indirectly from | 1337 | ;; Since `follow-window-size-change' can be called indirectly from |
| 1824 | ;; `follow-post-command-hook' we have a potential infinite loop. We | 1338 | ;; `follow-post-command-hook' we have a potential infinite loop. To |
| 1825 | ;; handle this problem by simply not doing anything at all in this | 1339 | ;; avoid this, we simply do not do anything in this situation. The |
| 1826 | ;; situation. The variable `follow-inside-post-command-hook' contains | 1340 | ;; variable `follow-inside-post-command-hook' contains information |
| 1827 | ;; information about whether the execution actually is inside the | 1341 | ;; about whether the execution actually is inside the |
| 1828 | ;; post-command-hook or not. | 1342 | ;; post-command-hook or not. |
| 1829 | 1343 | ||
| 1830 | (if (boundp 'window-size-change-functions) | ||
| 1831 | (add-hook 'window-size-change-functions 'follow-window-size-change)) | ||
| 1832 | |||
| 1833 | |||
| 1834 | (defun follow-window-size-change (frame) | 1344 | (defun follow-window-size-change (frame) |
| 1835 | "Redraw all windows in FRAME, when in Follow mode." | 1345 | "Redraw all windows in FRAME, when in Follow mode." |
| 1836 | ;; Below, we call `post-command-hook'. This makes sure that we | 1346 | ;; Below, we call `post-command-hook'. Avoid an infloop. |
| 1837 | ;; don't start a mutually recursive endless loop. | 1347 | (unless follow-inside-post-command-hook |
| 1838 | (if follow-inside-post-command-hook | ||
| 1839 | nil | ||
| 1840 | (let ((buffers '()) | 1348 | (let ((buffers '()) |
| 1841 | (orig-window (selected-window)) | 1349 | (orig-window (selected-window)) |
| 1842 | (orig-buffer (current-buffer)) | 1350 | (orig-buffer (current-buffer)) |
| @@ -1846,108 +1354,26 @@ report this using the `report-emacs-bug' function." | |||
| 1846 | (select-frame frame) | 1354 | (select-frame frame) |
| 1847 | (unwind-protect | 1355 | (unwind-protect |
| 1848 | (walk-windows | 1356 | (walk-windows |
| 1849 | (function | 1357 | (lambda (win) |
| 1850 | (lambda (win) | 1358 | (setq buf (window-buffer win)) |
| 1851 | (setq buf (window-buffer win)) | 1359 | (unless (memq buf buffers) |
| 1852 | (if (memq buf buffers) | 1360 | (set-buffer buf) |
| 1853 | nil | 1361 | (when follow-mode |
| 1854 | (set-buffer buf) | 1362 | (setq windows (follow-all-followers win)) |
| 1855 | (if (and (boundp 'follow-mode) | 1363 | (if (not (memq orig-window windows)) |
| 1856 | follow-mode) | 1364 | (follow-redisplay windows win) |
| 1857 | (progn | 1365 | ;; Make sure we're redrawing around the selected |
| 1858 | (setq windows (follow-all-followers win)) | 1366 | ;; window. |
| 1859 | (if (memq orig-window windows) | 1367 | (select-window orig-window) |
| 1860 | (progn | 1368 | (follow-post-command-hook) |
| 1861 | ;; Make sure we're redrawing around the | 1369 | (setq orig-window (selected-window))) |
| 1862 | ;; selected window. | 1370 | (setq buffers (cons buf buffers))))) |
| 1863 | ;; | 1371 | 'no-minibuf) |
| 1864 | ;; We must be really careful not to do this | ||
| 1865 | ;; when we are (indirectly) called by | ||
| 1866 | ;; `post-command-hook'. | ||
| 1867 | (select-window orig-window) | ||
| 1868 | (follow-post-command-hook) | ||
| 1869 | (setq orig-window (selected-window))) | ||
| 1870 | (follow-redisplay windows win)) | ||
| 1871 | (setq buffers (cons buf buffers)))))))) | ||
| 1872 | (select-frame orig-frame) | 1372 | (select-frame orig-frame) |
| 1873 | (set-buffer orig-buffer) | 1373 | (set-buffer orig-buffer) |
| 1874 | (select-window orig-window))))) | 1374 | (select-window orig-window))))) |
| 1875 | 1375 | ||
| 1876 | ;;; XEmacs isearch | 1376 | (add-hook 'window-scroll-functions 'follow-avoid-tail-recenter t) |
| 1877 | |||
| 1878 | ;; In XEmacs, isearch often finds matches in other windows than the | ||
| 1879 | ;; currently selected. However, when exiting the old window | ||
| 1880 | ;; configuration is restored, with the exception of the beginning of | ||
| 1881 | ;; the start of the window for the selected window. This is not much | ||
| 1882 | ;; help for us. | ||
| 1883 | ;; | ||
| 1884 | ;; We overwrite the stored window configuration with the current, | ||
| 1885 | ;; unless we are in `slow-search-mode', i.e. only a few lines | ||
| 1886 | ;; of text is visible. | ||
| 1887 | |||
| 1888 | (if (featurep 'xemacs) | ||
| 1889 | (defadvice isearch-done (before follow-isearch-done activate) | ||
| 1890 | (if (and (boundp 'follow-mode) | ||
| 1891 | follow-mode | ||
| 1892 | (boundp 'isearch-window-configuration) | ||
| 1893 | isearch-window-configuration | ||
| 1894 | (boundp 'isearch-slow-terminal-mode) | ||
| 1895 | (not isearch-slow-terminal-mode)) | ||
| 1896 | (let ((buf (current-buffer))) | ||
| 1897 | (setq isearch-window-configuration | ||
| 1898 | (current-window-configuration)) | ||
| 1899 | (set-buffer buf))))) | ||
| 1900 | |||
| 1901 | ;;; Tail window handling | ||
| 1902 | |||
| 1903 | ;; In Emacs (not XEmacs) windows showing nothing are sometimes | ||
| 1904 | ;; recentered. When in Follow mode, this is not desirable for | ||
| 1905 | ;; non-first windows in the window chain. This section tries to | ||
| 1906 | ;; make the windows stay where they should be. | ||
| 1907 | ;; | ||
| 1908 | ;; If the display is updated, all windows starting at (point-max) are | ||
| 1909 | ;; going to be recentered at the next redisplay, unless we do a | ||
| 1910 | ;; read-and-write cycle to update the `force' flag inside the windows. | ||
| 1911 | ;; | ||
| 1912 | ;; In 19.30, a new variable `window-scroll-functions' is called every | ||
| 1913 | ;; time a window is recentered. It is not perfect for our situation, | ||
| 1914 | ;; since when it is called for a tail window, it is to late. However, | ||
| 1915 | ;; if it is called for another window, we can try to update our | ||
| 1916 | ;; windows. | ||
| 1917 | ;; | ||
| 1918 | ;; By patching `sit-for' we can make sure that to catch all explicit | ||
| 1919 | ;; updates initiated by lisp programs. Internal calls, on the other | ||
| 1920 | ;; hand, are not handled. | ||
| 1921 | |||
| 1922 | ;; If this function is called it is too late for this window, but | ||
| 1923 | ;; we might save other windows from being recentered. | ||
| 1924 | |||
| 1925 | (if (and follow-avoid-tail-recenter-p (boundp 'window-scroll-functions)) | ||
| 1926 | (add-hook 'window-scroll-functions 'follow-avoid-tail-recenter t)) | ||
| 1927 | |||
| 1928 | |||
| 1929 | ;; This prevents all packages that calls `sit-for' directly | ||
| 1930 | ;; to recenter tail windows. | ||
| 1931 | |||
| 1932 | (if follow-avoid-tail-recenter-p | ||
| 1933 | (defadvice sit-for (before follow-sit-for activate) | ||
| 1934 | "Adviced by Follow mode. | ||
| 1935 | |||
| 1936 | Avoid to recenter windows displaying only the end of a file as when | ||
| 1937 | displaying a short file in two windows, using Follow mode." | ||
| 1938 | (follow-avoid-tail-recenter))) | ||
| 1939 | |||
| 1940 | |||
| 1941 | ;; Without this advice, `mouse-drag-region' would start to recenter | ||
| 1942 | ;; tail windows. | ||
| 1943 | |||
| 1944 | (if (and follow-avoid-tail-recenter-p | ||
| 1945 | (fboundp 'move-overlay)) | ||
| 1946 | (defadvice move-overlay (before follow-move-overlay activate) | ||
| 1947 | "Adviced by Follow mode. | ||
| 1948 | Don't recenter windows showing only the end of a buffer. | ||
| 1949 | This prevents `mouse-drag-region' from messing things up." | ||
| 1950 | (follow-avoid-tail-recenter))) | ||
| 1951 | 1377 | ||
| 1952 | ;;; Profile support | 1378 | ;;; Profile support |
| 1953 | 1379 | ||
| @@ -1956,64 +1382,28 @@ This prevents `mouse-drag-region' from messing things up." | |||
| 1956 | ;; | 1382 | ;; |
| 1957 | ;; Invalid indentation on purpose! | 1383 | ;; Invalid indentation on purpose! |
| 1958 | 1384 | ||
| 1959 | (cond (nil | 1385 | ;; (setq elp-function-list |
| 1960 | (setq elp-function-list | 1386 | ;; '(window-end |
| 1961 | '(window-end | 1387 | ;; vertical-motion |
| 1962 | vertical-motion | 1388 | ;; follow-mode |
| 1963 | ; sit-for ;; elp can't handle advices... | 1389 | ;; follow-all-followers |
| 1964 | follow-mode | 1390 | ;; follow-split-followers |
| 1965 | follow-all-followers | 1391 | ;; follow-redisplay |
| 1966 | follow-split-followers | 1392 | ;; follow-estimate-first-window-start |
| 1967 | follow-redisplay | 1393 | ;; follow-calculate-first-window-start-from-above |
| 1968 | follow-estimate-first-window-start | 1394 | ;; follow-calculate-first-window-start-from-below |
| 1969 | follow-calculate-first-window-start-from-above | 1395 | ;; follow-calc-win-end |
| 1970 | follow-calculate-first-window-start-from-below | 1396 | ;; follow-calc-win-start |
| 1971 | follow-calc-win-end | 1397 | ;; follow-pos-visible |
| 1972 | follow-calc-win-start | 1398 | ;; follow-windows-start-end |
| 1973 | follow-pos-visible | 1399 | ;; follow-cache-valid-p |
| 1974 | follow-windows-start-end | 1400 | ;; follow-select-if-visible |
| 1975 | follow-cache-valid-p | 1401 | ;; follow-select-if-visible-from-first |
| 1976 | follow-select-if-visible | 1402 | ;; follow-windows-aligned-p |
| 1977 | follow-select-if-visible-from-first | 1403 | ;; follow-point-visible-all-windows-p |
| 1978 | follow-windows-aligned-p | 1404 | ;; follow-avoid-tail-recenter |
| 1979 | follow-point-visible-all-windows-p | 1405 | ;; follow-update-window-start |
| 1980 | follow-avoid-tail-recenter | 1406 | ;; follow-post-command-hook)) |
| 1981 | follow-update-window-start | ||
| 1982 | follow-post-command-hook | ||
| 1983 | )))) | ||
| 1984 | |||
| 1985 | ;;; The end | ||
| 1986 | |||
| 1987 | (defun follow-unload-function () | ||
| 1988 | "Unload Follow mode library." | ||
| 1989 | (easy-menu-remove-item nil '("Tools") "Follow") | ||
| 1990 | (follow-stop-intercept-process-output) | ||
| 1991 | (dolist (group '((before | ||
| 1992 | ;; XEmacs | ||
| 1993 | isearch-done | ||
| 1994 | ;; both | ||
| 1995 | set-process-filter sit-for move-overlay) | ||
| 1996 | (after | ||
| 1997 | ;; Emacs | ||
| 1998 | scroll-bar-drag scroll-bar-drag-1 scroll-bar-scroll-down | ||
| 1999 | scroll-bar-scroll-up scroll-bar-set-window-start | ||
| 2000 | ;; XEmacs | ||
| 2001 | scrollbar-line-down scrollbar-line-up scrollbar-page-down | ||
| 2002 | scrollbar-page-up scrollbar-to-bottom scrollbar-to-top | ||
| 2003 | scrollbar-vertical-drag | ||
| 2004 | ;; both | ||
| 2005 | process-filter))) | ||
| 2006 | (let ((class (car group))) | ||
| 2007 | (dolist (fun (cdr group)) | ||
| 2008 | (when (functionp fun) | ||
| 2009 | (condition-case nil | ||
| 2010 | (progn | ||
| 2011 | (ad-remove-advice fun class | ||
| 2012 | (intern (concat "follow-" (symbol-name fun)))) | ||
| 2013 | (ad-update fun)) | ||
| 2014 | (error nil)))))) | ||
| 2015 | ;; continue standard processing | ||
| 2016 | nil) | ||
| 2017 | 1407 | ||
| 2018 | (provide 'follow) | 1408 | (provide 'follow) |
| 2019 | 1409 | ||