Mercurial > emacs
annotate lisp/follow.el @ 21608:d191a8737145
(w32_msg_pump): Handle WM_EMACS_SETLOCALE.
(w32_wnd_proc): Handle WM_EMACS_SETFOREGROUND.
author | Geoff Voelker <voelker@cs.washington.edu> |
---|---|
date | Fri, 17 Apr 1998 05:08:23 +0000 |
parents | a6119c0748e9 |
children | ca6bab63bffd |
rev | line source |
---|---|
14578 | 1 ;;; follow.el --- Minor mode, Synchronize windows showing the same buffer. |
2 | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
3 ;; Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. |
14578 | 4 |
5 ;; Author: Anders Lindgren <andersl@csd.uu.se> | |
6 ;; Maintainer: Anders Lindgren <andersl@csd.uu.se> | |
7 ;; Created: 25 May 1995 | |
18028
89f6e1e17d2d
(follow-submit-feedback, follow-mode): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
16425
diff
changeset
|
8 ;; Version: 1.7 |
14578 | 9 ;; Keywords: display, window, minor-mode |
18144
f8860990bdf7
(set-process-filter): Advice doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18133
diff
changeset
|
10 ;; Date: 4 Jun 1997 |
14578 | 11 |
14992 | 12 ;; This file is part of GNU Emacs. |
13 | |
14 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
14578 | 15 ;; it under the terms of the GNU General Public License as published by |
16 ;; the Free Software Foundation; either version 2, or (at your option) | |
17 ;; any later version. | |
18 | |
14992 | 19 ;; GNU Emacs is distributed in the hope that it will be useful, |
14578 | 20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
22 ;; GNU General Public License for more details. | |
23 | |
24 ;; You should have received a copy of the GNU General Public License | |
14992 | 25 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
26 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
27 ;; Boston, MA 02111-1307, USA. | |
14578 | 28 |
29 ;;; Commentary: | |
30 | |
31 ;;{{{ Documentation | |
32 | |
21333
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
33 ;; `Follow mode' is a minor mode for Emacs and XEmacs that |
14578 | 34 ;; combines windows into one tall virtual window. |
35 ;; | |
36 ;; The feeling of a "virtual window" has been accomplished by the use | |
37 ;; of two major techniques: | |
38 ;; | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
39 ;; * The windows always displays adjacent sections of the buffer. |
14578 | 40 ;; This means that whenever one window is moved, all the |
41 ;; others will follow. (Hence the name Follow Mode.) | |
42 ;; | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
43 ;; * Should the point (cursor) end up outside a window, another |
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
44 ;; window displaying that point is selected, if possible. This |
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
45 ;; makes it possible to walk between windows using normal cursor |
14578 | 46 ;; movement commands. |
47 ;; | |
21333
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
48 ;; Follow mode comes to its prime when a large screen and two |
14578 | 49 ;; side-by-side window are used. The user can, with the help of Follow |
50 ;; mode, use two full-height windows as though they would have been | |
51 ;; one. Imagine yourself editing a large function, or section of text, | |
18028
89f6e1e17d2d
(follow-submit-feedback, follow-mode): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
16425
diff
changeset
|
52 ;; and being able to use 144 lines instead of the normal 72... (your |
14578 | 53 ;; mileage may vary). |
54 | |
21333
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
55 |
14578 | 56 ;; The latest version, and a demonstration, are avaiable at: |
57 ;; | |
21333
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
58 ;; http://www.csd.uu.se/~andersl/emacs.shtml |
14578 | 59 |
60 | |
61 ;; To test this package, make sure `follow' is loaded, or will be | |
62 ;; autoloaded when activated (see below). Then do the following: | |
63 ;; | |
21333
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
64 ;; * Find your favorite file (preferably a long one). |
14578 | 65 ;; |
21333
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
66 ;; * Resize Emacs so that it will be wide enough for two full size |
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
67 ;; columns. Delete the other windows and split the window with |
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
68 ;; the commands `C-x 1 C-x 3'. |
14578 | 69 ;; |
70 ;; * Give the command: | |
71 ;; M-x follow-mode <RETURN> | |
72 ;; | |
73 ;; * Now the display should look something like (assuming the text "71" | |
74 ;; is on line 71): | |
75 ;; | |
76 ;; +----------+----------+ | |
77 ;; |1 |73 | | |
78 ;; |2 |74 | | |
79 ;; |3 |75 | | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
80 ;; ... ... |
14578 | 81 ;; |71 |143 | |
82 ;; |72 |144 | | |
83 ;; +----------+----------+ | |
84 ;; | |
85 ;; As you can see, the right-hand window starts at line 73, the line | |
86 ;; immediately below the end of the left-hand window. As long as | |
87 ;; `follow-mode' is active, the two windows will follow eachother! | |
88 ;; | |
89 ;; * Play around and enjoy! Scroll one window and watch the other. | |
90 ;; Jump to the beginning or end. Press `Cursor down' at the last | |
91 ;; line of the left-hand window. Enter new lines into the | |
92 ;; text. Enter long lines spanning several lines, or several | |
93 ;; windows. | |
94 ;; | |
95 ;; * Should you find `Follow' mode annoying, just type | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
96 ;; M-x follow-mode <RETURN> |
14578 | 97 ;; to turn it off. |
98 | |
99 | |
100 ;; The command `follow-delete-other-windows-and-split' maximises the | |
101 ;; visible area of the current buffer. | |
102 ;; | |
103 ;; I recommend adding it, and `follow-mode', to hotkeys in the global | |
104 ;; key map. To do so, add the following lines (replacing `[f7]' and | |
105 ;; `[f8]' with your favorite keys) to the init file: | |
106 ;; | |
107 ;; (global-set-key [f8] 'follow-mode) | |
108 ;; (global-set-key [f7] 'follow-delete-other-windows-and-split) | |
109 | |
110 | |
21333
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
111 ;; There exists two system variables that controls the appearence of |
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
112 ;; lines that are wider than the window containing them. The default |
14609
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
113 ;; is to truncate long lines whenever a window isn't as wide as the |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
114 ;; frame. |
14578 | 115 ;; |
116 ;; To make sure lines are never truncated, please place the following | |
117 ;; lines in your init file: | |
118 ;; | |
119 ;; (setq truncate-lines nil) | |
120 ;; (setq truncate-partial-width-windows nil) | |
121 | |
122 | |
14609
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
123 ;; Since the display of XEmacs is pixel-oriented, a line could be |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
124 ;; clipped in half at the bottom of the window. |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
125 ;; |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
126 ;; To make XEmacs avoid clipping (normal) lines, please place the |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
127 ;; following line in your init-file: |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
128 ;; |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
129 ;; (setq pixel-vertical-clip-threshold 30) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
130 |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
131 |
14578 | 132 ;; The correct way to cofigurate Follow mode, or any other mode for |
21333
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
133 ;; that matter, is to create one (or more) function that does |
14578 | 134 ;; whatever you would like to do. The function is then added to |
135 ;; a hook. | |
136 ;; | |
137 ;; When `Follow' mode is activated, functions stored in the hook | |
138 ;; `follow-mode-hook' are called. When it is deactivated | |
139 ;; `follow-mode-off-hook' is runed. | |
140 ;; | |
141 ;; The keymap `follow-key-map' contains key bindings activated by | |
142 ;; `follow-mode'. | |
143 ;; | |
144 ;; Example: | |
145 ;; (add-hook 'follow-mode-hook 'my-follow-mode-hook) | |
146 ;; | |
147 ;; (defun my-follow-mode-hook () | |
148 ;; (define-key follow-mode-map "\C-ca" 'your-favorite-function) | |
149 ;; (define-key follow-mode-map "\C-cb" 'another-function)) | |
150 | |
151 | |
152 ;; Usage: | |
153 ;; | |
21333
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
154 ;; To activate issue the command "M-x follow-mode" |
14578 | 155 ;; and press return. To deactivate, do it again. |
156 ;; | |
21333
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
157 ;; The following is a list of commands useful when follow-mode is active. |
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
158 ;; |
14578 | 159 ;; follow-scroll-up C-c . C-v |
160 ;; Scroll text in a Follow Mode window chain up. | |
161 ;; | |
162 ;; follow-scroll-down C-c . v | |
163 ;; Like `follow-scroll-up', but in the other direction. | |
164 ;; | |
165 ;; follow-delete-other-windows-and-split C-c . 1 | |
166 ;; Maximise the visible area of the current buffer, | |
167 ;; and enter Follow Mode. This is a very convenient | |
168 ;; way to start Follow Mode, hence it is recomended | |
169 ;; that this command is added to the global keymap. | |
170 ;; | |
171 ;; follow-recenter C-c . C-l | |
172 ;; Place the point in the center of the middle window, | |
173 ;; or a specified number of lines from either top or bottom. | |
174 ;; | |
175 ;; follow-switch-to-buffer C-c . b | |
176 ;; Switch buffer in all windows displaying the current buffer | |
177 ;; in this frame. | |
178 ;; | |
179 ;; follow-switch-to-buffer-all C-c . C-b | |
180 ;; Switch buffer in all windows in the active frame. | |
181 ;; | |
182 ;; follow-switch-to-current-buffer-all | |
183 ;; Show the current buffer in all windows on the current | |
184 ;; frame and turn on `follow-mode'. | |
185 ;; | |
186 ;; follow-first-window C-c . < | |
187 ;; Select the first window in the frame showing the same buffer. | |
188 ;; | |
189 ;; follow-last-window C-c . > | |
190 ;; Select the last window in the frame showing the same buffer. | |
191 ;; | |
192 ;; follow-next-window C-c . n | |
193 ;; Select the next window in the frame showing the same buffer. | |
194 ;; | |
195 ;; follow-previous-window C-c . p | |
196 ;; Select the previous window showing the same buffer. | |
197 | |
198 | |
199 ;; Well, it seems ok, but what if I really want to look at two different | |
200 ;; positions in the text? Here are two simple methods to use: | |
201 ;; | |
202 ;; 1) Use multiple frames; `follow' mode only affects windows displayed | |
203 ;; in the same frame. (My apoligies to you who can't use frames.) | |
204 ;; | |
205 ;; 2) Bind `follow-mode' to key so you can turn it off whenever | |
206 ;; you want to view two locations. Of course, `follow' mode can | |
207 ;; be reactivated by hitting the same key again. | |
208 ;; | |
209 ;; Example from my ~/.emacs: | |
210 ;; (global-set-key [f8] 'follow-mode) | |
211 | |
212 | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
213 ;; Implementation: |
14578 | 214 ;; |
215 ;; In an ideal world, follow mode would have been implemented in the | |
21333
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
216 ;; kernel of the display routines, making sure that the windows (using |
14578 | 217 ;; follow mode) ALWAYS are aligned. On planet earth, however, we must |
218 ;; accept a solution where we ALMOST ALWAYS can make sure that the | |
219 ;; windows are aligned. | |
220 ;; | |
221 ;; Follow mode does this in three places: | |
222 ;; 1) After each user command. | |
223 ;; 2) After a process output has been perfomed. | |
224 ;; 3) When a scrollbar has been moved. | |
225 ;; | |
226 ;; This will cover most situations. (Let me know if there are other | |
21333
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
227 ;; situations that should be covered.) |
14578 | 228 ;; |
21333
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
229 ;; Note that only the selected window is checked, for the reason of |
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
230 ;; efficiency and code complexity. (I.e. it is possible to make a |
14578 | 231 ;; non-selected windows unaligned. It will, however, pop right back |
232 ;; when it is selected.) | |
233 | |
234 ;;}}} | |
235 | |
236 ;;; Code: | |
237 | |
238 ;;{{{ Preliminaries | |
239 | |
240 ;; Make the compiler shut up! | |
241 ;; There are two strategies: | |
242 ;; 1) Shut warnings off completely. | |
243 ;; 2) Handle each warning separately. | |
244 ;; | |
245 ;; Since I would like to see real errors, I've selected the latter | |
246 ;; method. | |
247 ;; | |
248 ;; The problem with undefined variables and functions has been solved | |
249 ;; by using `set', `symbol-value' and `symbol-function' rather than | |
250 ;; `setq' and direct references to variables and functions. | |
251 ;; | |
252 ;; For example: | |
253 ;; (if (boundp 'foo) ... (symbol-value 'foo) ) | |
254 ;; (set 'foo ...) <-- XEmacs doesn't fall for this one. | |
255 ;; (funcall (symbol-function 'set) 'bar ...) | |
256 ;; | |
257 ;; Note: When this file is interpreted, `eval-when-compile' is | |
21333
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
258 ;; evaluted. Since it doesn't hurt to evaluate it, but it is a bit |
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
259 ;; annoying, we test if the byte-compiler has been loaded. This can, |
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
260 ;; of course, lead to some occasional unintended evaluation... |
14578 | 261 ;; |
262 ;; Should someone come up with a better solution, please let me | |
263 ;; know. | |
264 | |
265 (eval-when-compile | |
266 (if (or (featurep 'bytecomp) | |
267 (featurep 'byte-compile)) | |
268 (cond ((string-match "XEmacs" emacs-version) | |
269 ;; Make XEmacs shut up! I'm using standard Emacs | |
270 ;; functions, they are NOT obsolete! | |
271 (if (eq (get 'force-mode-line-update 'byte-compile) | |
272 'byte-compile-obsolete) | |
273 (put 'force-mode-line-update 'byte-compile 'nil)) | |
274 (if (eq (get 'frame-first-window 'byte-compile) | |
275 'byte-compile-obsolete) | |
276 (put 'frame-first-window 'byte-compile 'nil)))))) | |
277 | |
278 ;;}}} | |
279 ;;{{{ Variables | |
280 | |
21088 | 281 (defgroup follow nil |
282 "Synchronize windows showing the same buffer." | |
283 :prefix "follow-" | |
284 :group 'windows) | |
285 | |
14578 | 286 (defvar follow-mode nil |
287 "Variable indicating if Follow mode is active.") | |
288 | |
21088 | 289 (defcustom follow-mode-hook nil |
290 "*Hooks to run when follow-mode is turned on." | |
291 :type 'hook | |
292 :group 'follow) | |
14578 | 293 |
21088 | 294 (defcustom follow-mode-off-hook nil |
295 "*Hooks to run when follow-mode is turned off." | |
296 :type 'hook | |
297 :group 'follow) | |
14578 | 298 |
299 (defvar follow-mode-map nil | |
14609
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
300 "*Minor mode keymap for Follow mode.") |
14578 | 301 |
21088 | 302 (defcustom follow-mode-line-text " Follow" |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
303 "*Text shown in the mode line when Follow mode is active. |
14578 | 304 Defaults to \" Follow\". Examples of other values |
21088 | 305 are \" Fw\", or simply \"\"." |
306 :type 'string | |
307 :group 'follow) | |
14578 | 308 |
21088 | 309 (defcustom follow-auto nil |
310 "*Non-nil activates Follow mode whenever a file is loaded." | |
311 :type 'boolean | |
312 :group 'follow) | |
14578 | 313 |
21088 | 314 (defcustom follow-mode-prefix "\C-c." |
14578 | 315 "*Prefix key to use for follow commands in Follow mode. |
316 The value of this variable is checked as part of loading Follow mode. | |
21088 | 317 After that, changing the prefix key requires manipulating keymaps." |
318 :type 'string | |
319 :group 'follow) | |
14578 | 320 |
21088 | 321 (defcustom follow-intercept-processes t |
322 "*When non-nil, Follow Mode will monitor process output." | |
323 :type 'boolean | |
324 :group 'follow) | |
14578 | 325 |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
326 (defvar follow-emacs-version-xemacs-p |
14578 | 327 (string-match "XEmacs" emacs-version) |
328 "Non-nil when running under XEmacs.") | |
329 | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
330 (defvar follow-avoid-tail-recenter-p |
14578 | 331 (not follow-emacs-version-xemacs-p) |
332 "*When non-nil, patch emacs so that tail windows won't be recentered. | |
333 | |
21333
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
334 A \"tail window\" is a window that displays only the end of |
14578 | 335 the buffer. Normally it is practical for the user that empty |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
336 windows are recentered automatically. However, when using |
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
337 Follow Mode it breaks the display when the end is displayed |
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
338 in a window \"above\" the last window. This is for |
14609
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
339 example the case when displaying a short page in info. |
14578 | 340 |
341 Must be set before Follow Mode is loaded. | |
342 | |
343 Please note that it is not possible to fully prevent Emacs from | |
344 recentering empty windows. Please report if you find a repeatable | |
345 situation in which Emacs recenters empty windows. | |
346 | |
347 XEmacs, as of 19.12, does not recenter windows, good!") | |
348 | |
14609
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
349 (defvar follow-cache-command-list |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
350 '(next-line previous-line forward-char backward-char) |
21333
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
351 "List of commands that don't require recalculation. |
14609
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
352 |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
353 In order to be able to use the cache, a command should not change the |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
354 contents of the buffer, nor should it change selected window or current |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
355 buffer. |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
356 |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
357 The commands in this list are checked at load time. |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
358 |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
359 To mark other commands as suitable for caching, set the symbol |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
360 property `follow-mode-use-cache' to non-nil.") |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
361 |
14578 | 362 (defvar follow-debug nil |
363 "*Non-nil when debugging Follow mode.") | |
364 | |
365 | |
14609
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
366 ;; Internal variables: |
14578 | 367 |
368 (defvar follow-internal-force-redisplay nil | |
369 "True when Follow mode should redisplay the windows.") | |
370 | |
371 (defvar follow-process-filter-alist '() | |
372 "The original filters for processes intercepted by Follow mode.") | |
373 | |
374 (defvar follow-active-menu nil | |
375 "The menu visible when Follow mode is active.") | |
376 | |
377 (defvar follow-deactive-menu nil | |
378 "The menu visible when Follow mode is deactivated.") | |
379 | |
380 (defvar follow-inside-post-command-hook nil | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
381 "Non-nil when inside Follow modes `post-command-hook'. |
14578 | 382 Used by `follow-window-size-change'.") |
383 | |
14609
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
384 (defvar follow-windows-start-end-cache nil |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
385 "Cache used by `follow-window-start-end'.") |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
386 |
14578 | 387 ;;}}} |
388 ;;{{{ Bug report | |
389 | |
390 (eval-when-compile (require 'reporter)) | |
391 | |
392 (defun follow-submit-feedback () | |
18028
89f6e1e17d2d
(follow-submit-feedback, follow-mode): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
16425
diff
changeset
|
393 "Submit feedback on Follow mode to the author: andersl@csd.uu.se" |
14578 | 394 (interactive) |
395 (require 'reporter) | |
396 (and (y-or-n-p "Do you really want to submit a report on Follow mode? ") | |
397 (reporter-submit-bug-report | |
398 "Anders Lindgren <andersl@csd.uu.se>" | |
21333
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
399 "follow.el" |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
400 '(post-command-hook |
14578 | 401 post-command-idle-hook |
402 pre-command-hook | |
403 window-size-change-functions | |
404 window-scroll-functions | |
405 follow-mode-hook | |
406 follow-mode-off-hook | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
407 follow-auto |
14578 | 408 follow-intercept-processes |
409 follow-avoid-tail-recenter-p | |
410 follow-process-filter-alist) | |
411 nil | |
412 nil | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
413 (concat |
14578 | 414 "Hi Anders!\n\n" |
415 "(I have read the section on how to report bugs in the " | |
416 "Emacs manual.)\n\n" | |
417 "Even though I know you are busy, I thought you might " | |
418 "want to know...\n\n")))) | |
419 | |
420 ;;}}} | |
421 ;;{{{ Debug messages | |
422 | |
423 ;; This inline function must be as small as possible! | |
21333
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
424 ;; Maybe we should define a macro that expands to nil if |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
425 ;; the variable is not set. |
14578 | 426 |
427 (defsubst follow-debug-message (&rest args) | |
428 "Like message, but only active when `follow-debug' is non-nil." | |
429 (if (and (boundp 'follow-debug) follow-debug) | |
430 (apply 'message args))) | |
431 | |
432 ;;}}} | |
433 | |
434 ;;{{{ Keymap/Menu | |
435 | |
436 ;;; Define keys for the follow-mode minor mode map and replace some | |
437 ;;; functions in the global map. All `follow' mode special functions | |
438 ;;; can be found on (the somewhat cumbersome) "C-c . <key>" | |
439 ;;; (Control-C dot <key>). (As of Emacs 19.29 the keys | |
440 ;;; C-c <punctuation character> are reserved for minor modes.) | |
441 ;;; | |
442 ;;; To change the prefix, redefine `follow-mode-prefix' before | |
443 ;;; `follow' is loaded, or see the section on `follow-mode-hook' | |
444 ;;; above for an example of how to bind the keys the way you like. | |
445 ;;; | |
446 ;;; Please note that the keymap is defined the first time this file is | |
447 ;;; loaded. Also note that the only legal way to manipulate the | |
448 ;;; keymap is to use `define-key'. Don't change it using `setq' or | |
449 ;;; similar! | |
450 | |
451 | |
452 (if follow-mode-map | |
453 nil | |
454 (setq follow-mode-map (make-sparse-keymap)) | |
455 (let ((map (make-sparse-keymap))) | |
456 (define-key map "\C-v" 'follow-scroll-up) | |
457 (define-key map "\M-v" 'follow-scroll-down) | |
458 (define-key map "v" 'follow-scroll-down) | |
459 (define-key map "1" 'follow-delete-other-windows-and-split) | |
460 (define-key map "b" 'follow-switch-to-buffer) | |
461 (define-key map "\C-b" 'follow-switch-to-buffer-all) | |
462 (define-key map "\C-l" 'follow-recenter) | |
463 (define-key map "<" 'follow-first-window) | |
464 (define-key map ">" 'follow-last-window) | |
465 (define-key map "n" 'follow-next-window) | |
466 (define-key map "p" 'follow-previous-window) | |
467 | |
468 (define-key follow-mode-map follow-mode-prefix map) | |
469 | |
470 ;; Replace the standard `end-of-buffer', when in Follow Mode. (I | |
21333
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
471 ;; don't see the point in trying to replace every function that |
14578 | 472 ;; could be enhanced in Follow mode. End-of-buffer is a special |
473 ;; case since it is very simple to define and it greatly enhances | |
474 ;; the look and feel of Follow mode.) | |
475 ;; | |
476 ;; (The function `substitute-key-definition' does not work | |
477 ;; in all versions of Emacs.) | |
478 (mapcar | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
479 (function |
14578 | 480 (lambda (pair) |
481 (let ((old (car pair)) | |
482 (new (cdr pair))) | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
483 (mapcar (function (lambda (key) |
14578 | 484 (define-key follow-mode-map key new))) |
485 (where-is-internal old global-map))))) | |
486 '((end-of-buffer . follow-end-of-buffer) | |
487 (fkey-end-of-buffer . follow-end-of-buffer))) | |
488 | |
489 ;;; | |
490 ;;; The menu. | |
491 ;;; | |
492 | |
493 (if (not follow-emacs-version-xemacs-p) | |
494 | |
495 ;; | |
21333
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
496 ;; Emacs |
14578 | 497 ;; |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
498 (let ((menumap (funcall (symbol-function 'make-sparse-keymap) |
14578 | 499 "Follow")) |
500 (count 0) | |
501 id) | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
502 (mapcar |
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
503 (function |
14578 | 504 (lambda (item) |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
505 (setq id |
14578 | 506 (or (cdr item) |
507 (progn | |
508 (setq count (+ count 1)) | |
509 (intern (format "separator-%d" count))))) | |
510 (define-key menumap (vector id) item) | |
511 (or (eq id 'follow-mode) | |
512 (put id 'menu-enable 'follow-mode)))) | |
513 ;; In reverse order: | |
514 '(("Toggle Follow mode" . follow-mode) | |
515 ("--") | |
516 ("Recenter" . follow-recenter) | |
517 ("--") | |
518 ("Previous Window" . follow-previous-window) | |
519 ("Next Windows" . follow-next-window) | |
520 ("Last Window" . follow-last-window) | |
521 ("First Window" . follow-first-window) | |
522 ("--") | |
523 ("Switch To Buffer (all windows)" | |
524 . follow-switch-to-buffer-all) | |
525 ("Switch To Buffer" . follow-switch-to-buffer) | |
526 ("--") | |
527 ("Delete Other Windows and Split" | |
528 . follow-delete-other-windows-and-split) | |
529 ("--") | |
530 ("Scroll Down" . follow-scroll-down) | |
531 ("Scroll Up" . follow-scroll-up))) | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
532 |
14578 | 533 ;; If there is a `tools' meny, we use it. However, we can't add a |
534 ;; minor-mode specific item to it (it's broken), so we make the | |
535 ;; contents ghosted when not in use, and add ourselves to the | |
536 ;; global map. If no `tools' menu is present, just make a | |
537 ;; top-level menu visible when the mode is activated. | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
538 |
14578 | 539 (let ((tools-map (lookup-key (current-global-map) [menu-bar tools])) |
540 (last nil)) | |
541 (if (sequencep tools-map) | |
542 (progn | |
543 ;; Find the last entry in the menu and store it in `last'. | |
544 (mapcar (function | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
545 (lambda (x) |
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
546 (setq last (or (cdr-safe |
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
547 (cdr-safe |
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
548 (cdr-safe x))) |
14578 | 549 last)))) |
550 tools-map) | |
551 (if last | |
552 (progn | |
553 (funcall (symbol-function 'define-key-after) | |
554 tools-map [separator-follow] '("--") last) | |
555 (funcall (symbol-function 'define-key-after) | |
556 tools-map [follow] (cons "Follow" menumap) | |
557 'separator-follow)) | |
558 ;; Didn't find the last item, Adding to the top of | |
559 ;; tools. (This will probably never happend...) | |
560 (define-key (current-global-map) [menu-bar tools follow] | |
561 (cons "Follow" menumap)))) | |
562 ;; No tools menu, add "Follow" to the menubar. | |
563 (define-key follow-mode-map [menu-bar follow] | |
564 (cons "Follow" menumap))))) | |
565 | |
566 ;; | |
567 ;; XEmacs. | |
568 ;; | |
569 | |
570 ;; place the menu in the `Tools' menu. | |
571 (let ((menu '("Follow" | |
572 :filter follow-menu-filter | |
573 ["Scroll Up" follow-scroll-up t] | |
574 ["Scroll Down" follow-scroll-down t] | |
575 ["Delete Other Windows and Split" | |
576 follow-delete-other-windows-and-split t] | |
577 ["Switch To Buffer" follow-switch-to-buffer t] | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
578 ["Switch To Buffer (all windows)" |
14578 | 579 follow-switch-to-buffer-all t] |
580 ["First Window" follow-first-window t] | |
581 ["Last Window" follow-last-window t] | |
582 ["Next Windows" follow-next-window t] | |
583 ["Previous Window" follow-previous-window t] | |
584 ["Recenter" follow-recenter t] | |
585 ["Deactivate" follow-mode t]))) | |
586 | |
587 ;; Why not just `(set-buffer-menubar current-menubar)'? The | |
588 ;; question is a very good question. The reason is that under | |
21333
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
589 ;; Emacs, neither `set-buffer-menubar' nor |
14578 | 590 ;; `current-menubar' is defined, hence the byte-compiler will |
591 ;; warn. | |
592 (funcall (symbol-function 'set-buffer-menubar) | |
593 (symbol-value 'current-menubar)) | |
594 (funcall (symbol-function 'add-submenu) '("Tools") menu)) | |
595 | |
596 ;; When the mode is not activated, only one item is visible: | |
597 ;; "Activate". | |
598 (defun follow-menu-filter (menu) | |
599 (if follow-mode | |
600 menu | |
601 '(["Activate " follow-mode t])))))) | |
602 | |
603 | |
604 ;;; Register the follow mode keymap. | |
605 (or (assq 'follow-mode minor-mode-map-alist) | |
606 (setq minor-mode-map-alist | |
607 (cons (cons 'follow-mode follow-mode-map) minor-mode-map-alist))) | |
608 | |
609 ;;}}} | |
14609
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
610 ;;{{{ Cache |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
611 |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
612 (let ((cmds follow-cache-command-list)) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
613 (while cmds |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
614 (put (car cmds) 'follow-mode-use-cache t) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
615 (setq cmds (cdr cmds)))) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
616 |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
617 ;;}}} |
14578 | 618 |
619 ;;{{{ The mode | |
620 | |
621 ;;;###autoload | |
622 (defun turn-on-follow-mode () | |
623 "Turn on Follow mode. Please see the function `follow-mode'." | |
624 (interactive) | |
625 (follow-mode 1)) | |
626 | |
627 | |
628 ;;;###autoload | |
629 (defun turn-off-follow-mode () | |
630 "Turn off Follow mode. Please see the function `follow-mode'." | |
631 (interactive) | |
632 (follow-mode -1)) | |
633 | |
634 | |
635 ;;;###autoload | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
636 (defun follow-mode (arg) |
21333
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
637 "Minor mode that combines windows into one tall virtual window. |
14578 | 638 |
639 The feeling of a \"virtual window\" has been accomplished by the use | |
640 of two major techniques: | |
641 | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
642 * The windows always displays adjacent sections of the buffer. |
14578 | 643 This means that whenever one window is moved, all the |
644 others will follow. (Hence the name Follow Mode.) | |
645 | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
646 * Should the point (cursor) end up outside a window, another |
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
647 window displaying that point is selected, if possible. This |
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
648 makes it possible to walk between windows using normal cursor |
14578 | 649 movement commands. |
650 | |
651 Follow mode comes to its prime when used on a large screen and two | |
652 side-by-side window are used. The user can, with the help of Follow | |
653 mode, use two full-height windows as though they would have been | |
654 one. Imagine yourself editing a large function, or section of text, | |
18028
89f6e1e17d2d
(follow-submit-feedback, follow-mode): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
16425
diff
changeset
|
655 and being able to use 144 lines instead of the normal 72... (your |
14578 | 656 mileage may vary). |
657 | |
658 To split one large window into two side-by-side windows, the commands | |
659 `\\[split-window-horizontally]' or \ | |
660 `M-x follow-delete-other-windows-and-split' can be used. | |
661 | |
662 Only windows displayed in the same frame follow each-other. | |
663 | |
664 If the variable `follow-intercept-processes' is non-nil, Follow mode | |
665 will listen to the output of processes and redisplay accordingly. | |
666 \(This is the default.) | |
667 | |
668 When Follow mode is switched on, the hook `follow-mode-hook' | |
669 is called. When turned off, `follow-mode-off-hook' is called. | |
670 | |
671 Keys specific to Follow mode: | |
672 \\{follow-mode-map}" | |
673 (interactive "P") | |
674 (make-local-variable 'follow-mode) | |
675 (put 'follow-mode 'permanent-local t) | |
676 (let ((follow-mode-orig follow-mode)) | |
677 (setq follow-mode | |
678 (if (null arg) | |
679 (not follow-mode) | |
680 (> (prefix-numeric-value arg) 0))) | |
681 (if (and follow-mode follow-intercept-processes) | |
682 (follow-intercept-process-output)) | |
683 (cond ((and follow-mode (not follow-mode-orig)) ; On | |
684 ;; XEmacs: If this is non-nil, the window will scroll before | |
685 ;; the point will have a chance to get into the next window. | |
686 (if (boundp 'scroll-on-clipped-lines) | |
687 (set 'scroll-on-clipped-lines nil)) | |
688 (force-mode-line-update) | |
689 (add-hook 'post-command-hook 'follow-post-command-hook t) | |
690 (if (boundp 'post-command-idle-hook) | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
691 (add-hook 'post-command-idle-hook |
14578 | 692 'follow-avoid-tail-recenter t)) |
693 (run-hooks 'follow-mode-hook)) | |
694 | |
695 ((and (not follow-mode) follow-mode-orig) ; Off | |
696 (force-mode-line-update) | |
697 (run-hooks 'follow-mode-off-hook))))) | |
698 | |
699 | |
700 ;; Register follow-mode as a minor mode. | |
701 | |
14609
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
702 (if (fboundp 'add-minor-mode) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
703 ;; XEmacs |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
704 (funcall (symbol-function 'add-minor-mode) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
705 'follow-mode 'follow-mode-line-text) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
706 (or (assq 'follow-mode minor-mode-alist) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
707 (setq minor-mode-alist |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
708 (cons '(follow-mode follow-mode-line-text) minor-mode-alist)))) |
14578 | 709 |
710 ;;}}} | |
711 ;;{{{ Find file hook | |
712 | |
713 ;; This will start follow-mode whenever a new file is loaded, if | |
714 ;; the variable `follow-auto' is non-nil. | |
715 | |
716 (add-hook 'find-file-hooks 'follow-find-file-hook t) | |
717 | |
718 (defun follow-find-file-hook () | |
719 "Find-file hook for Follow Mode. See the variable `follow-auto'." | |
720 (if follow-auto (follow-mode t))) | |
721 | |
722 ;;}}} | |
723 | |
724 ;;{{{ User functions | |
725 | |
726 ;;; | |
727 ;;; User functions usable when in Follow mode. | |
728 ;;; | |
729 | |
730 ;;{{{ Scroll | |
731 | |
732 ;; `scroll-up' and `-down', but for windows in Follow Mode. | |
733 ;; | |
734 ;; Almost like the real thing, excpet when the cursor ends up outside | |
735 ;; the top or bottom... In our case however, we end up outside the | |
736 ;; window and hence we are recenterd. Should we let `recenter' handle | |
737 ;; the point position we would never leave the selected window. To do | |
738 ;; it ourselves we would need to do our own redisplay, which is easier | |
739 ;; said than done. (Why didn't I do a real display abstraction from | |
740 ;; the beginning?) | |
741 ;; | |
742 ;; We must sometimes set `follow-internal-force-redisplay', otherwise | |
743 ;; our post-command-hook will move our windows back into the old | |
744 ;; position... (This would also be corrected if we would have had a | |
745 ;; good redisplay abstraction.) | |
746 | |
747 (defun follow-scroll-up (&optional arg) | |
748 "Scroll text in a Follow Mode window chain up. | |
749 | |
750 If called with no ARG, the `next-screen-context-lines' last lines of | |
751 the bottom window in the chain will be visible in the top window. | |
752 | |
753 If called with an argument, scroll ARG lines up. | |
754 Negative ARG means scroll downward. | |
755 | |
756 Works like `scroll-up' when not in Follow Mode." | |
757 (interactive "P") | |
758 (cond ((not (and (boundp 'follow-mode) follow-mode)) | |
759 (scroll-up arg)) | |
760 (arg | |
761 (save-excursion (scroll-up arg)) | |
762 (setq follow-internal-force-redisplay t)) | |
763 (t | |
764 (let* ((windows (follow-all-followers)) | |
765 (end (window-end (car (reverse windows))))) | |
766 (if (eq end (point-max)) | |
767 (signal 'end-of-buffer nil) | |
768 (select-window (car windows)) | |
21333
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
769 ;; `window-end' might return nil. |
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
770 (if end |
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
771 (goto-char end)) |
14578 | 772 (vertical-motion (- next-screen-context-lines)) |
773 (set-window-start (car windows) (point))))))) | |
774 | |
775 | |
776 (defun follow-scroll-down (&optional arg) | |
777 "Scroll text in a Follow Mode window chain down. | |
778 | |
779 If called with no ARG, the `next-screen-context-lines' top lines of | |
780 the top window in the chain will be visible in the bottom window. | |
781 | |
782 If called with an argument, scroll ARG lines down. | |
783 Negative ARG means scroll upward. | |
784 | |
785 Works like `scroll-up' when not in Follow Mode." | |
786 (interactive "P") | |
787 (cond ((not (and (boundp 'follow-mode) follow-mode)) | |
788 (scroll-up arg)) | |
789 (arg | |
790 (save-excursion (scroll-down arg))) | |
791 (t | |
792 (let* ((windows (follow-all-followers)) | |
793 (win (car (reverse windows))) | |
794 (start (window-start (car windows)))) | |
795 (if (eq start (point-min)) | |
796 (signal 'beginning-of-buffer nil) | |
797 (select-window win) | |
798 (goto-char start) | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
799 (vertical-motion (- (- (window-height win) |
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
800 1 |
14578 | 801 next-screen-context-lines))) |
802 (set-window-start win (point)) | |
803 (goto-char start) | |
804 (vertical-motion (- next-screen-context-lines 1)) | |
805 (setq follow-internal-force-redisplay t)))))) | |
806 | |
807 ;;}}} | |
808 ;;{{{ Buffer | |
809 | |
810 ;;;###autoload | |
811 (defun follow-delete-other-windows-and-split (&optional arg) | |
812 "Create two side by side windows and enter Follow Mode. | |
813 | |
814 Execute this command to display as much as possible of the text | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
815 in the selected window. All other windows, in the current |
14578 | 816 frame, are deleted and the selected window is split in two |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
817 side-by-side windows. Follow Mode is activated, hence the |
14578 | 818 two windows always will display two successive pages. |
819 \(If one window is moved, the other one will follow.) | |
820 | |
821 If ARG is positive, the leftmost window is selected. If it negative, | |
822 the rightmost is selected. If ARG is nil, the leftmost window is | |
823 selected if the original window is the first one in the frame. | |
824 | |
825 To bind this command to a hotkey, place the following line | |
826 in your `~/.emacs' file, replacing [f7] by your favourite key: | |
827 (global-set-key [f7] 'follow-delete-other-windows-and-split)" | |
828 (interactive "P") | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
829 (let ((other (or (and (null arg) |
14578 | 830 (not (eq (selected-window) |
831 (frame-first-window (selected-frame))))) | |
832 (and arg | |
833 (< (prefix-numeric-value arg) 0)))) | |
834 (start (window-start))) | |
835 (delete-other-windows) | |
836 (split-window-horizontally) | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
837 (if other |
14578 | 838 (progn |
839 (other-window 1) | |
840 (set-window-start (selected-window) start) | |
841 (setq follow-internal-force-redisplay t))) | |
842 (follow-mode 1))) | |
843 | |
844 (defun follow-switch-to-buffer (buffer) | |
845 "Show BUFFER in all windows in the current Follow Mode window chain." | |
846 (interactive "BSwitch to Buffer: ") | |
847 (let ((orig-window (selected-window)) | |
848 (windows (follow-all-followers))) | |
849 (while windows | |
850 (select-window (car windows)) | |
851 (switch-to-buffer buffer) | |
852 (setq windows (cdr windows))) | |
853 (select-window orig-window))) | |
854 | |
855 | |
856 (defun follow-switch-to-buffer-all (&optional buffer) | |
857 "Show BUFFER in all windows on this frame. | |
858 Defaults to current buffer." | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
859 (interactive (list (read-buffer "Switch to Buffer: " |
14578 | 860 (current-buffer)))) |
861 (or buffer (setq buffer (current-buffer))) | |
862 (let ((orig-window (selected-window))) | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
863 (walk-windows |
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
864 (function |
14578 | 865 (lambda (win) |
866 (select-window win) | |
867 (switch-to-buffer buffer)))) | |
868 (select-window orig-window) | |
869 (follow-redisplay))) | |
870 | |
871 | |
872 (defun follow-switch-to-current-buffer-all () | |
873 "Show current buffer in all windows on this frame, and enter Follow Mode. | |
874 | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
875 To bind this command to a hotkey place the following line |
14578 | 876 in your `~/.emacs' file: |
877 (global-set-key [f7] 'follow-switch-to-current-buffer-all)" | |
878 (interactive) | |
879 (or (and (boundp 'follow-mode) follow-mode) | |
880 (follow-mode 1)) | |
881 (follow-switch-to-buffer-all)) | |
882 | |
883 ;;}}} | |
884 ;;{{{ Movement | |
885 | |
886 ;; Note, these functions are not very useful, atleast not unless you | |
887 ;; rebind the rather cumbersome key sequence `C-c . p'. | |
888 | |
889 (defun follow-next-window () | |
890 "Select the next window showing the same buffer." | |
891 (interactive) | |
892 (let ((succ (cdr (follow-split-followers (follow-all-followers))))) | |
893 (if succ | |
894 (select-window (car succ)) | |
895 (error "%s" "No more windows")))) | |
896 | |
897 | |
898 (defun follow-previous-window () | |
899 "Select the previous window showing the same buffer." | |
900 (interactive) | |
901 (let ((pred (car (follow-split-followers (follow-all-followers))))) | |
902 (if pred | |
903 (select-window (car pred)) | |
904 (error "%s" "No more windows")))) | |
905 | |
906 | |
907 (defun follow-first-window () | |
908 "Select the first window in the frame showing the same buffer." | |
909 (interactive) | |
910 (select-window (car (follow-all-followers)))) | |
911 | |
912 | |
913 (defun follow-last-window () | |
914 "Select the last window in the frame showing the same buffer." | |
915 (interactive) | |
916 (select-window (car (reverse (follow-all-followers))))) | |
917 | |
918 ;;}}} | |
919 ;;{{{ Redraw | |
920 | |
921 (defun follow-recenter (&optional arg) | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
922 "Recenter the middle window around point. |
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
923 Rearrange all other windows around the middle window. |
14578 | 924 |
925 With a positive argument, place the current line ARG lines | |
926 from the top. With a negative, place it -ARG lines from the | |
927 bottom." | |
928 (interactive "P") | |
929 (if arg | |
930 (let ((p (point)) | |
931 (arg (prefix-numeric-value arg))) | |
932 (if (>= arg 0) | |
933 ;; Recenter relative to the top. | |
934 (progn | |
935 (follow-first-window) | |
936 (goto-char p) | |
937 (recenter arg)) | |
938 ;; Recenter relative to the bottom. | |
939 (follow-last-window) | |
940 (goto-char p) | |
941 (recenter arg) | |
942 ;; Otherwise, our post-command-hook will move the window | |
943 ;; right back. | |
944 (setq follow-internal-force-redisplay t))) | |
945 ;; Recenter in the middle. | |
946 (let* ((dest (point)) | |
947 (windows (follow-all-followers)) | |
948 (win (nth (/ (- (length windows) 1) 2) windows))) | |
949 (select-window win) | |
950 (goto-char dest) | |
951 (recenter) | |
952 ;;(setq follow-internal-force-redisplay t) | |
953 ))) | |
954 | |
955 | |
956 (defun follow-redraw () | |
957 "Arrange windows displaying the same buffer in successor order. | |
958 This function can be called even if the buffer is not in Follow mode. | |
959 | |
960 Hopefully, there should be no reason to call this function when in | |
961 Follow mode since the windows should always be aligned." | |
962 (interactive) | |
963 (sit-for 0) | |
964 (follow-redisplay)) | |
965 | |
966 ;;}}} | |
967 ;;{{{ End of buffer | |
968 | |
969 (defun follow-end-of-buffer (&optional arg) | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
970 "Move point to the end of the buffer, Follow Mode style. |
14578 | 971 |
972 If the end is not visible, it will be displayed in the last possible | |
973 window in the Follow Mode window chain. | |
974 | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
975 The mark is left at the previous position. With arg N, put point N/10 |
14578 | 976 of the way from the true end." |
977 (interactive "P") | |
978 (let ((followers (follow-all-followers)) | |
979 (pos (point))) | |
980 (cond (arg | |
981 (select-window (car (reverse followers)))) | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
982 ((follow-select-if-end-visible |
14578 | 983 (follow-windows-start-end followers))) |
984 (t | |
985 (select-window (car (reverse followers))))) | |
986 (goto-char pos) | |
987 (end-of-buffer arg))) | |
988 | |
989 ;;}}} | |
990 | |
991 ;;}}} | |
992 | |
993 ;;{{{ Display | |
994 | |
995 ;;;; The display routines | |
996 | |
997 ;;{{{ Information gathering functions | |
998 | |
999 (defun follow-all-followers (&optional testwin) | |
1000 "Return all windows displaying the same buffer as the TESTWIN. | |
1001 The list contains only windows displayed in the same frame as TESTWIN. | |
1002 If TESTWIN is nil the selected window is used." | |
1003 (or (and testwin (window-live-p testwin)) | |
1004 (setq testwin (selected-window))) | |
1005 (let* ((top (frame-first-window (window-frame testwin))) | |
1006 (win top) | |
1007 (done nil) | |
1008 (windows '()) | |
1009 (buffer (window-buffer testwin))) | |
1010 (while (and (not done) win) | |
1011 (if (eq (window-buffer win) buffer) | |
1012 (setq windows (cons win windows))) | |
1013 (setq win (next-window win 'not)) | |
1014 (if (eq win top) | |
1015 (setq done t))) | |
1016 (nreverse windows))) | |
1017 | |
1018 | |
1019 (defun follow-split-followers (windows &optional win) | |
1020 "Split the WINDOWS into the sets: predecessors and successors. | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1021 Return `(PRED . SUCC)' where `PRED' and `SUCC' are ordered starting |
14578 | 1022 from the selected window." |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1023 (or win |
14578 | 1024 (setq win (selected-window))) |
1025 (let ((pred '())) | |
1026 (while (not (eq (car windows) win)) | |
1027 (setq pred (cons (car windows) pred)) | |
1028 (setq windows (cdr windows))) | |
1029 (cons pred (cdr windows)))) | |
1030 | |
1031 | |
21333
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
1032 ;; This function is optimized function for speed! |
14578 | 1033 |
1034 (defun follow-calc-win-end (&optional win) | |
1035 "Calculate the presumed window end for WIN. | |
1036 | |
1037 Actually, the position returned is the start of the next | |
1038 window, normally is the end plus one. | |
1039 | |
1040 If WIN is nil, the selected window is used. | |
1041 | |
1042 Returns (end-pos end-of-buffer-p)" | |
1043 (if follow-emacs-version-xemacs-p | |
1044 ;; XEmacs can calculate the end of the window by using | |
1045 ;; the 'guarantee options. GOOD! | |
1046 (let ((end (window-end win t))) | |
1047 (if (= end (funcall (symbol-function 'point-max) | |
1048 (window-buffer win))) | |
1049 (list end t) | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1050 (list (+ end 1) nil))) |
21333
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
1051 ;; Emacs: We have to calculate the end by ourselves. |
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
1052 ;; This code works on both XEmacs and Emacs, but now |
14578 | 1053 ;; that XEmacs has got custom-written code, this could |
21333
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
1054 ;; be optimized for Emacs. |
14578 | 1055 (let ((orig-win (and win (selected-window))) |
1056 height | |
1057 buffer-end-p) | |
1058 (if win (select-window win)) | |
1059 (prog1 | |
1060 (save-excursion | |
1061 (goto-char (window-start)) | |
1062 (setq height (- (window-height) 1)) | |
1063 (setq buffer-end-p | |
1064 (if (bolp) | |
1065 (not (= height (vertical-motion height))) | |
1066 (save-restriction | |
1067 ;; Fix a mis-feature in `vertical-motion': | |
1068 ;; The start of the window is assumed to | |
1069 ;; coinside with the start of a line. | |
1070 (narrow-to-region (point) (point-max)) | |
1071 (not (= height (vertical-motion height)))))) | |
1072 (list (point) buffer-end-p)) | |
1073 (if orig-win | |
1074 (select-window orig-win)))))) | |
1075 | |
1076 | |
1077 ;; Can't use `save-window-excursion' since it triggers a redraw. | |
1078 (defun follow-calc-win-start (windows pos win) | |
1079 "Calculate where WIN will start if the first in WINDOWS start at POS. | |
1080 | |
1081 If WIN is nil the point below all windows is returned." | |
1082 (let (start) | |
1083 (while (and windows (not (eq (car windows) win))) | |
1084 (setq start (window-start (car windows))) | |
1085 (set-window-start (car windows) pos 'noforce) | |
1086 (setq pos (car (inline (follow-calc-win-end (car windows))))) | |
1087 (set-window-start (car windows) start 'noforce) | |
1088 (setq windows (cdr windows))) | |
1089 pos)) | |
1090 | |
1091 | |
14609
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1092 ;; The result from `follow-windows-start-end' is cached when using |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1093 ;; a handful simple commands, like cursor movement commands. |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1094 |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1095 (defsubst follow-cache-valid-p (windows) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1096 "Test if the cached value of `follow-windows-start-end' can be used. |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1097 Note that this handles the case when the cache has been set to nil." |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1098 (let ((res t) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1099 (cache follow-windows-start-end-cache)) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1100 (while (and res windows cache) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1101 (setq res (and (eq (car windows) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1102 (car (car cache))) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1103 (eq (window-start (car windows)) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1104 (car (cdr (car cache)))))) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1105 (setq windows (cdr windows)) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1106 (setq cache (cdr cache))) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1107 (and res (null windows) (null cache)))) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1108 |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1109 |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1110 (defsubst follow-invalidate-cache () |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1111 "Force `follow-windows-start-end' to recalculate the end of the window." |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1112 (setq follow-windows-start-end-cache nil)) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1113 |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1114 |
14578 | 1115 ;; Build a list of windows and their start and end positions. |
1116 ;; Useful to avoid calculating start/end position whenever they are needed. | |
1117 ;; The list has the format: | |
1118 ;; ((Win Start End End-of-buffer-visible-p) ...) | |
1119 | |
1120 ;; Used to have a `save-window-excursion', but it obviously triggered | |
1121 ;; redraws of the display. Check if I used it for anything. | |
1122 | |
1123 | |
1124 (defun follow-windows-start-end (windows) | |
1125 "Builds a list of (WIN START END BUFFER-END-P) for every window in WINDOWS." | |
14609
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1126 (if (follow-cache-valid-p windows) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1127 follow-windows-start-end-cache |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1128 (let ((win-start-end '()) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1129 (orig-win (selected-window))) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1130 (while windows |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1131 (select-window (car windows)) |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1132 (setq win-start-end |
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1133 (cons (cons (car windows) |
14609
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1134 (cons (window-start) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1135 (follow-calc-win-end))) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1136 win-start-end)) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1137 (setq windows (cdr windows))) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1138 (select-window orig-win) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1139 (setq follow-windows-start-end-cache (nreverse win-start-end)) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1140 follow-windows-start-end-cache))) |
14578 | 1141 |
1142 | |
14609
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1143 (defsubst follow-pos-visible (pos win win-start-end) |
14578 | 1144 "Non-nil when POS is visible in WIN." |
1145 (let ((wstart-wend-bend (cdr (assq win win-start-end)))) | |
1146 (and (>= pos (car wstart-wend-bend)) | |
1147 (or (< pos (car (cdr wstart-wend-bend))) | |
1148 (nth 2 wstart-wend-bend))))) | |
1149 | |
1150 | |
1151 ;; By `aligned' we mean that for all adjecent windows, the end of the | |
1152 ;; first is equal with the start of the successor. The first window | |
1153 ;; should start at a full screen line. | |
1154 | |
14609
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1155 (defsubst follow-windows-aligned-p (win-start-end) |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1156 "Non-nil if the follower WINDOWS are aligned." |
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1157 (let ((res t)) |
14578 | 1158 (save-excursion |
1159 (goto-char (window-start (car (car win-start-end)))) | |
1160 (if (bolp) | |
1161 nil | |
1162 (vertical-motion 0 (car (car win-start-end))) | |
1163 (setq res (eq (point) (window-start (car (car win-start-end))))))) | |
1164 (while (and res (cdr win-start-end)) | |
1165 ;; At least two followers left | |
14609
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1166 (setq res (eq (car (cdr (cdr (car win-start-end)))) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1167 (car (cdr (car (cdr win-start-end)))))) |
14578 | 1168 (setq win-start-end (cdr win-start-end))) |
1169 res)) | |
1170 | |
1171 | |
1172 ;; Check if the point is visible in all windows. (So that | |
1173 ;; no one will be recentered.) | |
1174 | |
1175 (defun follow-point-visible-all-windows-p (win-start-end) | |
1176 "Non-nil when the window-point is visible in all windows." | |
1177 (let ((res t)) | |
1178 (while (and res win-start-end) | |
14609
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1179 (setq res (follow-pos-visible (window-point (car (car win-start-end))) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1180 (car (car win-start-end)) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1181 win-start-end)) |
14578 | 1182 (setq win-start-end (cdr win-start-end))) |
1183 res)) | |
1184 | |
1185 | |
1186 ;; Make sure WIN always starts at the beginning of an whole screen | |
1187 ;; line. If WIN is not aligned the start is updated which probably | |
1188 ;; will lead to a redisplay of the screen later on. | |
1189 ;; | |
1190 ;; This is used with the first window in a follow chain. The reason | |
1191 ;; is that we want to detect that the point is outside the window. | |
1192 ;; (Without the update, the start of the window will move as the | |
1193 ;; user presses BackSpace, and the other window redisplay routines | |
1194 ;; will move the start of the window in the wrong direction.) | |
1195 | |
1196 (defun follow-update-window-start (win) | |
1197 "Make sure that the start of WIN starts at a full screen line." | |
1198 (save-excursion | |
1199 (goto-char (window-start win)) | |
1200 (if (bolp) | |
1201 nil | |
1202 (vertical-motion 0 win) | |
1203 (if (eq (point) (window-start win)) | |
1204 nil | |
1205 (vertical-motion 1 win) | |
1206 (set-window-start win (point) 'noforce))))) | |
1207 | |
1208 ;;}}} | |
1209 ;;{{{ Selection functions | |
1210 | |
1211 ;; Make a window in WINDOWS selected if it currently | |
1212 ;; is displaying the position DEST. | |
1213 ;; | |
1214 ;; We don't select a window if it just has been moved. | |
1215 | |
1216 (defun follow-select-if-visible (dest win-start-end) | |
1217 "Select and return a window, if DEST is visible in it. | |
1218 Return the selected window." | |
1219 (let ((win nil)) | |
1220 (while (and (not win) win-start-end) | |
21333
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
1221 ;; Don't select a window that was just moved. This makes it |
14578 | 1222 ;; possible to later select the last window after a `end-of-buffer' |
1223 ;; command. | |
1224 (if (follow-pos-visible dest (car (car win-start-end)) win-start-end) | |
1225 (progn | |
1226 (setq win (car (car win-start-end))) | |
1227 (select-window win))) | |
1228 (setq win-start-end (cdr win-start-end))) | |
1229 win)) | |
1230 | |
1231 | |
1232 ;; Lets select a window showing the end. Make sure we only select it if it | |
1233 ;; it wasn't just moved here. (i.e. M-> shall not unconditionally place | |
1234 ;; the point in the selected window.) | |
1235 ;; | |
21333
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
1236 ;; (Compability cludge: in Emacs `window-end' is equal to `point-max'; |
14578 | 1237 ;; in XEmacs, it is equal to `point-max + 1'. Should I really bother |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1238 ;; checking `window-end' now when I check `end-of-buffer' explicitly?) |
14578 | 1239 |
1240 (defun follow-select-if-end-visible (win-start-end) | |
1241 "Select and return a window, if end is visible in it." | |
1242 (let ((win nil)) | |
1243 (while (and (not win) win-start-end) | |
21333
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
1244 ;; Don't select a window that was just moved. This makes it |
14578 | 1245 ;; possible to later select the last window after a `end-of-buffer' |
1246 ;; command. | |
1247 (if (and (eq (point-max) (nth 2 (car win-start-end))) | |
1248 (nth 3 (car win-start-end)) | |
21333
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
1249 ;; `window-end' might return nil. |
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
1250 (let ((end (window-end (car (car win-start-end))))) |
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
1251 (and end |
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
1252 (eq (point-max) (min (point-max) end))))) |
14578 | 1253 (progn |
1254 (setq win (car (car win-start-end))) | |
1255 (select-window win))) | |
1256 (setq win-start-end (cdr win-start-end))) | |
1257 win)) | |
1258 | |
1259 | |
21333
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
1260 ;; Select a window that will display the point if the windows would |
14578 | 1261 ;; be redisplayed with the first window fixed. This is useful for |
1262 ;; example when the user has pressed return at the bottom of a window | |
1263 ;; as the point is not visible in any window. | |
1264 | |
1265 (defun follow-select-if-visible-from-first (dest windows) | |
1266 "Select and return a window with DEST, if WINDOWS are redrawn from top." | |
1267 (let ((win nil) | |
1268 end-pos-end-p) | |
1269 (save-excursion | |
1270 (goto-char (window-start (car windows))) | |
1271 ;; Make sure the line start in the beginning of a real screen | |
1272 ;; line. | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1273 (vertical-motion 0 (car windows)) |
14578 | 1274 (if (< dest (point)) |
1275 ;; Above the start, not visible. | |
1276 nil | |
1277 ;; At or below the start. Check the windows. | |
1278 (save-window-excursion | |
1279 (while (and (not win) windows) | |
1280 (set-window-start (car windows) (point) 'noforce) | |
1281 (setq end-pos-end-p (follow-calc-win-end (car windows))) | |
1282 (goto-char (car end-pos-end-p)) | |
1283 ;; Visible, if dest above end, or if eob is visible inside | |
1284 ;; the window. | |
1285 (if (or (car (cdr end-pos-end-p)) | |
1286 (< dest (point))) | |
1287 (setq win (car windows)) | |
1288 (setq windows (cdr windows))))))) | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1289 (if win |
14578 | 1290 (select-window win)) |
1291 win)) | |
1292 | |
1293 | |
1294 ;;}}} | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1295 ;;{{{ Redisplay |
14578 | 1296 |
1297 ;; Redraw all the windows on the screen, starting with the top window. | |
1298 ;; The window used as as marker is WIN, or the selcted window if WIN | |
1299 ;; is nil. | |
1300 | |
1301 (defun follow-redisplay (&optional windows win) | |
1302 "Reposition the WINDOWS around WIN. | |
1303 Should the point be too close to the roof we redisplay everything | |
1304 from the top. WINDOWS should contain a list of windows to | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1305 redisplay, it is assumed that WIN is a member of the list. |
14578 | 1306 Should WINDOWS be nil, the windows displaying the |
1307 same buffer as WIN, in the current frame, are used. | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1308 Should WIN be nil, the selected window is used." |
14578 | 1309 (or win |
1310 (setq win (selected-window))) | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1311 (or windows |
14578 | 1312 (setq windows (follow-all-followers win))) |
1313 (follow-downward windows (follow-calculate-first-window-start windows win))) | |
1314 | |
1315 | |
1316 ;; Redisplay a chain of windows. Start every window directly after the | |
1317 ;; end of the previous window, to make sure long lines are displayed | |
1318 ;; correctly. | |
1319 | |
1320 (defun follow-downward (windows pos) | |
1321 "Redisplay all WINDOWS starting at POS." | |
1322 (while windows | |
1323 (set-window-start (car windows) pos) | |
1324 (setq pos (car (follow-calc-win-end (car windows)))) | |
1325 (setq windows (cdr windows)))) | |
1326 | |
1327 | |
1328 ;;(defun follow-downward (windows pos) | |
1329 ;; "Redisplay all WINDOWS starting at POS." | |
1330 ;; (let (p) | |
1331 ;; (while windows | |
1332 ;; (setq p (window-point (car windows))) | |
1333 ;; (set-window-start (car windows) pos) | |
1334 ;; (set-window-point (car windows) (max p pos)) | |
1335 ;; (setq pos (car (follow-calc-win-end (car windows)))) | |
1336 ;; (setq windows (cdr windows))))) | |
1337 | |
1338 | |
1339 ;; Return the start of the first window. | |
1340 ;; | |
1341 ;; First, estimate the position. It the value is not perfect (i.e. we | |
1342 ;; have somewhere splited a line between windows) we try to enhance | |
1343 ;; the value. | |
1344 ;; | |
1345 ;; The guess is always perfect if no long lines is split between | |
1346 ;; windows. | |
1347 ;; | |
1348 ;; The worst case peformace of probably very bad, but it is very | |
1349 ;; unlikely that we ever will miss the correct start by more than one | |
1350 ;; or two lines. | |
1351 | |
1352 (defun follow-calculate-first-window-start (windows &optional win start) | |
1353 "Calculate the start of the first window. | |
1354 | |
1355 WINDOWS is a chain of windows to work with. WIN is the window | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1356 to recenter around. It is assumed that WIN starts at position |
14578 | 1357 START." |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1358 (or win |
14578 | 1359 (setq win (selected-window))) |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1360 (or start |
14578 | 1361 (setq start (window-start win))) |
1362 (let ((guess (follow-estimate-first-window-start windows win start))) | |
1363 (if (car guess) | |
1364 (cdr guess) | |
1365 ;; The guess wasn't exact, try to enhance it. | |
1366 (let ((win-start (follow-calc-win-start windows (cdr guess) win))) | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1367 (cond ((= win-start start) |
14578 | 1368 (follow-debug-message "exact") |
1369 (cdr guess)) | |
1370 ((< win-start start) | |
1371 (follow-debug-message "above") | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1372 (follow-calculate-first-window-start-from-above |
14578 | 1373 windows (cdr guess) win start)) |
1374 (t | |
1375 (follow-debug-message "below") | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1376 (follow-calculate-first-window-start-from-below |
14578 | 1377 windows (cdr guess) win start))))))) |
1378 | |
1379 | |
1380 ;; `exact' is disabled due to XEmacs and fonts of variable | |
1381 ;; height. | |
1382 (defun follow-estimate-first-window-start (windows win start) | |
1383 "Estimate the position of the first window. | |
1384 | |
1385 Returns (EXACT . POS). If EXACT is non-nil, POS is the starting | |
1386 position of the first window. Otherwise it is a good guess." | |
1387 (let ((pred (car (follow-split-followers windows win))) | |
1388 (exact nil)) | |
1389 (save-excursion | |
1390 (goto-char start) | |
1391 ;(setq exact (bolp)) | |
1392 (vertical-motion 0 win) | |
1393 (while pred | |
1394 (vertical-motion (- 1 (window-height (car pred))) (car pred)) | |
1395 (if (not (bolp)) | |
1396 (setq exact nil)) | |
1397 (setq pred (cdr pred))) | |
1398 (cons exact (point))))) | |
1399 | |
1400 | |
1401 ;; Find the starting point, start at GUESS and search downward. | |
1402 ;; The returned point is always a point below GUESS. | |
1403 | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1404 (defun follow-calculate-first-window-start-from-above |
14578 | 1405 (windows guess win start) |
1406 (save-excursion | |
1407 (let ((done nil) | |
1408 win-start | |
1409 res) | |
1410 (goto-char guess) | |
1411 (while (not done) | |
1412 (if (not (= (vertical-motion 1 (car windows)) 1)) | |
1413 ;; Hit bottom! (Can we really do this?) | |
1414 ;; We'll keep it, since it ensures termination. | |
1415 (progn | |
1416 (setq done t) | |
1417 (setq res (point-max))) | |
1418 (setq win-start (follow-calc-win-start windows (point) win)) | |
1419 (if (>= win-start start) | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1420 (progn |
14578 | 1421 (setq done t) |
1422 (setq res (point)))))) | |
1423 res))) | |
1424 | |
1425 | |
1426 ;; Find the starting point, start at GUESS and search upward. Return | |
1427 ;; a point on the same line as GUESS, or above. | |
1428 ;; | |
1429 ;; (Is this ever used? I must make sure it works just in case it is | |
1430 ;; ever called.) | |
1431 | |
1432 (defun follow-calculate-first-window-start-from-below | |
1433 (windows guess &optional win start) | |
1434 (setq win (or win (selected-window))) | |
1435 (setq start (or start (window-start win))) | |
1436 (save-excursion | |
1437 (let ((done nil) | |
1438 win-start | |
1439 res) | |
1440 ;; Always calculate what happend when no line is displayed in the first | |
1441 ;; window. (The `previous' res is needed below!) | |
1442 (goto-char guess) | |
1443 (vertical-motion 0 (car windows)) | |
1444 (setq res (point)) | |
1445 (while (not done) | |
1446 (if (not (= (vertical-motion -1 (car windows)) -1)) | |
1447 ;; Hit roof! | |
1448 (progn | |
1449 (setq done t) | |
1450 (setq res (point-min))) | |
1451 (setq win-start (follow-calc-win-start windows (point) win)) | |
1452 (cond ((= win-start start) ; Perfect match, use this value | |
1453 (setq done t) | |
1454 (setq res (point))) | |
1455 ((< win-start start) ; Walked to far, use preious result | |
1456 (setq done t)) | |
1457 (t ; Store result for next iteration | |
1458 (setq res (point)))))) | |
1459 res))) | |
1460 | |
1461 ;;}}} | |
1462 ;;{{{ Avoid tail recenter | |
1463 | |
1464 ;; This sets the window internal flag `force_start'. The effect is that | |
1465 ;; windows only displaying the tail isn't recentered. | |
1466 ;; Has to be called before every redisplay... (Great isn't it?) | |
1467 ;; | |
1468 ;; XEmacs doesn't recenter the tail, GOOD! | |
1469 ;; | |
1470 ;; A window displaying only the tail, is a windows whose | |
1471 ;; window-start position is equal to (point-max) of the buffer it | |
1472 ;; displays. | |
1473 ;; | |
1474 ;; This function is also added to `post-command-idle-hook', introduced | |
1475 ;; in Emacs 19.30. This is needed since the vaccine injected by the | |
1476 ;; call from `post-command-hook' only works until the next redisplay. | |
1477 ;; It is possible that the functions in the `post-command-idle-hook' | |
1478 ;; can cause a redisplay, and hence a new vaccine is needed. | |
1479 ;; | |
1480 ;; Sometimes, calling this function could actually cause a redisplay, | |
1481 ;; especially if it is placed in the debug filter section. I must | |
1482 ;; investigate this further... | |
1483 | |
1484 (defun follow-avoid-tail-recenter (&rest rest) | |
1485 "Make sure windows displaying the end of a buffer aren't recentered. | |
1486 | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1487 This is done by reading and rewriting the start positon of |
14578 | 1488 non-first windows in Follow Mode." |
1489 (if follow-avoid-tail-recenter-p | |
1490 (let* ((orig-buffer (current-buffer)) | |
14609
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1491 (top (frame-first-window (selected-frame))) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1492 (win top) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1493 (who '()) ; list of (buffer . frame) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1494 start |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1495 pair) ; (buffer . frame) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1496 ;; If the only window in the frame is a minibuffer |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1497 ;; window, `next-window' will never find it again... |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1498 (if (window-minibuffer-p top) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1499 nil |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1500 (while ;; look, no body! |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1501 (progn |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1502 (setq start (window-start win)) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1503 (set-buffer (window-buffer win)) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1504 (setq pair (cons (window-buffer win) (window-frame win))) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1505 (if (member pair who) |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1506 (if (and (boundp 'follow-mode) follow-mode |
14609
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1507 (eq (point-max) start)) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1508 ;; Write the same window start back, but don't |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1509 ;; set the NOFORCE flag. |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1510 (set-window-start win start)) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1511 (setq who (cons pair who))) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1512 (setq win (next-window win 'not t)) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1513 (not (eq win top)))) ;; Loop while this is true. |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1514 (set-buffer orig-buffer))))) |
14578 | 1515 |
1516 ;;}}} | |
1517 | |
1518 ;;}}} | |
1519 ;;{{{ Post Command Hook | |
1520 | |
1521 ;;; The magic little box. This function is called after every command. | |
1522 | |
1523 ;; This is not as complicated as it seems. It is simply a list of common | |
1524 ;; display situations and the actions to take, plus commands for redrawing | |
1525 ;; the screen if it should be unaligned. | |
1526 ;; | |
1527 ;; We divide the check into two parts; whether we are at the end or not. | |
1528 ;; This is due to the fact that the end can actaually be visible | |
1529 ;; in several window even though they are aligned. | |
1530 | |
1531 (defun follow-post-command-hook () | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1532 "Ensure that the windows in Follow mode are adjacent after each command." |
14578 | 1533 (setq follow-inside-post-command-hook t) |
1534 (if (or (not (input-pending-p)) | |
1535 ;; Sometimes, in XEmacs, mouse events are not handled | |
1536 ;; properly by `input-pending-p'. A typical example is | |
1537 ;; when clicking on a node in `info'. | |
1538 (and (boundp 'current-mouse-event) | |
1539 (symbol-value 'current-mouse-event) | |
1540 (fboundp 'button-event-p) | |
1541 (funcall (symbol-function 'button-event-p) | |
1542 (symbol-value 'current-mouse-event)))) | |
1543 ;; Work in the selected window, not in the current buffer. | |
1544 (let ((orig-buffer (current-buffer)) | |
1545 (win (selected-window))) | |
1546 (set-buffer (window-buffer win)) | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1547 (or (and (symbolp this-command) |
14609
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1548 (get this-command 'follow-mode-use-cache)) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1549 (follow-invalidate-cache)) |
14578 | 1550 (if (and (boundp 'follow-mode) follow-mode |
1551 (not (window-minibuffer-p win))) | |
1552 ;; The buffer shown in the selected window is in follow | |
1553 ;; mode, lets find the current state of the display and | |
1554 ;; cache the result for speed (i.e. `aligned' and `visible'.) | |
1555 (let* ((windows (inline (follow-all-followers win))) | |
1556 (dest (point)) | |
14609
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1557 (win-start-end (inline |
14578 | 1558 (follow-update-window-start (car windows)) |
1559 (follow-windows-start-end windows))) | |
1560 (aligned (follow-windows-aligned-p win-start-end)) | |
1561 (visible (follow-pos-visible dest win win-start-end))) | |
14609
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1562 (if (not (and aligned visible)) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1563 (follow-invalidate-cache)) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1564 (inline (follow-avoid-tail-recenter)) |
14578 | 1565 ;; Select a window to display the point. |
1566 (or follow-internal-force-redisplay | |
1567 (progn | |
1568 (if (eq dest (point-max)) | |
1569 ;; We're at the end, we have be be careful since | |
1570 ;; the display can be aligned while `dest' can | |
1571 ;; be visible in several windows. | |
1572 (cond | |
1573 ;; Select the current window, but only when | |
1574 ;; the display is correct. (When inserting | |
1575 ;; character in a tail window, the display is | |
1576 ;; not correct, as they are shown twice.) | |
1577 ;; | |
1578 ;; Never stick to the current window after a | |
1579 ;; deletion. The reason is cosmetic, when | |
1580 ;; typing `DEL' in a window showing only the | |
1581 ;; end of the file, character are removed | |
1582 ;; from the window above, which is very | |
1583 ;; unintuitive. | |
1584 ((and visible | |
1585 aligned | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1586 (not (memq this-command |
14578 | 1587 '(backward-delete-char |
1588 delete-backward-char | |
1589 backward-delete-char-untabify | |
1590 kill-region)))) | |
1591 (follow-debug-message "Max: same")) | |
1592 ;; If the end is visible, and the window | |
1593 ;; doesn't seems like it just has been moved, | |
1594 ;; select it. | |
1595 ((follow-select-if-end-visible win-start-end) | |
1596 (follow-debug-message "Max: end visible") | |
1597 (setq visible t) | |
1598 (setq aligned nil) | |
1599 (goto-char dest)) | |
1600 ;; Just show the end... | |
1601 (t | |
1602 (follow-debug-message "Max: default") | |
1603 (select-window (car (reverse windows))) | |
1604 (goto-char dest) | |
1605 (setq visible nil) | |
1606 (setq aligned nil))) | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1607 |
14578 | 1608 ;; We're not at the end, here life is much simpler. |
1609 (cond | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1610 ;; This is the normal case! |
14578 | 1611 ;; It should be optimized for speed. |
1612 ((and visible aligned) | |
1613 (follow-debug-message "same")) | |
1614 ;; Pick a position in any window. If the | |
1615 ;; display is ok, this will pick the `correct' | |
1616 ;; window. If the display is wierd do this | |
1617 ;; anyway, this will be the case after a delete | |
1618 ;; at the beginning of the window. | |
1619 ((follow-select-if-visible dest win-start-end) | |
1620 (follow-debug-message "visible") | |
1621 (setq visible t) | |
1622 (goto-char dest)) | |
1623 ;; Not visible anywhere else, lets pick this one. | |
1624 ;; (Is this case used?) | |
1625 (visible | |
1626 (follow-debug-message "visible in selected.")) | |
1627 ;; Far out! | |
1628 ((eq dest (point-min)) | |
1629 (follow-debug-message "min") | |
1630 (select-window (car windows)) | |
1631 (goto-char dest) | |
1632 (set-window-start (selected-window) (point-min)) | |
1633 (setq win-start-end (follow-windows-start-end windows)) | |
14609
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1634 (follow-invalidate-cache) |
14578 | 1635 (setq visible t) |
1636 (setq aligned nil)) | |
1637 ;; If we can position the cursor without moving the first | |
21333
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
1638 ;; window, do it. This is the case that catches `RET' |
14578 | 1639 ;; at the bottom of a window. |
1640 ((follow-select-if-visible-from-first dest windows) | |
1641 (follow-debug-message "Below first") | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1642 (setq visible t) |
14578 | 1643 (setq aligned t) |
1644 (follow-redisplay windows (car windows)) | |
1645 (goto-char dest)) | |
1646 ;; None of the above. For simplicity, we stick to the | |
1647 ;; selected window. | |
1648 (t | |
1649 (follow-debug-message "None") | |
1650 (setq visible nil) | |
1651 (setq aligned nil)))) | |
1652 ;; If a new window has been selected, make sure that the | |
1653 ;; old is not scrolled when the point is outside the | |
1654 ;; window. | |
1655 (or (eq win (selected-window)) | |
1656 (let ((p (window-point win))) | |
1657 (set-window-start win (window-start win) nil) | |
1658 (set-window-point win p))))) | |
1659 ;; Make sure the point is visible in the selected window. | |
1660 ;; (This could lead to a scroll.) | |
1661 (if (or visible | |
1662 (follow-pos-visible dest win win-start-end)) | |
1663 nil | |
1664 (sit-for 0) | |
1665 (follow-avoid-tail-recenter) | |
1666 (setq win-start-end (follow-windows-start-end windows)) | |
14609
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1667 (follow-invalidate-cache) |
14578 | 1668 (setq aligned nil)) |
1669 ;; Redraw the windows whenever needed. | |
1670 (if (or follow-internal-force-redisplay | |
1671 (not (or aligned | |
1672 (follow-windows-aligned-p win-start-end))) | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1673 (not (inline (follow-point-visible-all-windows-p |
14578 | 1674 win-start-end)))) |
1675 (progn | |
1676 (setq follow-internal-force-redisplay nil) | |
1677 (follow-redisplay windows (selected-window)) | |
1678 (setq win-start-end (follow-windows-start-end windows)) | |
14609
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1679 (follow-invalidate-cache) |
14578 | 1680 ;; When the point ends up in another window. This |
1681 ;; happends when dest is in the beginning of the | |
1682 ;; file and the selected window is not the first. | |
1683 ;; It can also, in rare situations happend when | |
1684 ;; long lines are used and there is a big | |
1685 ;; difference between the width of the windows. | |
1686 ;; (When scrolling one line in a wide window which | |
1687 ;; will cause a move larger that an entire small | |
1688 ;; window.) | |
1689 (if (follow-pos-visible dest win win-start-end) | |
1690 nil | |
1691 (follow-select-if-visible dest win-start-end) | |
1692 (goto-char dest)))) | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1693 |
14578 | 1694 ;; If the region is visible, make it look good when spanning |
1695 ;; multiple windows. | |
1696 (if (or (and (boundp 'mark-active) (symbol-value 'mark-active)) | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1697 (and (fboundp 'region-active-p) |
14578 | 1698 (funcall (symbol-function 'region-active-p)))) |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1699 (follow-maximize-region |
14578 | 1700 (selected-window) windows win-start-end)) |
1701 | |
14609
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
1702 (inline (follow-avoid-tail-recenter)) |
14578 | 1703 ;; DEBUG |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1704 ;;(if (not (follow-windows-aligned-p |
14578 | 1705 ;; (follow-windows-start-end windows))) |
1706 ;; (message "follow-mode: windows still unaligend!")) | |
1707 ;; END OF DEBUG | |
1708 ) ; Matches (let* | |
1709 ;; Buffer not in follow mode: | |
1710 ;; We still must update the windows displaying the tail so that | |
1711 ;; Emacs won't recenter them. | |
1712 (follow-avoid-tail-recenter)) | |
1713 (set-buffer orig-buffer))) | |
1714 (setq follow-inside-post-command-hook nil)) | |
1715 | |
1716 ;;}}} | |
1717 ;;{{{ The region | |
1718 | |
1719 ;; Tries to make the highlighted area representing the region look | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1720 ;; good when spanning several windows. |
14578 | 1721 ;; |
1722 ;; Not perfect, as the point can't be placed at window end, only at | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1723 ;; end-1. This will highlight a little bit in windows above |
14578 | 1724 ;; the current. |
1725 | |
1726 (defun follow-maximize-region (win windows win-start-end) | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1727 "Make a highlighted region stretching multiple windows look good." |
14578 | 1728 (let* ((all (follow-split-followers windows win)) |
1729 (pred (car all)) | |
1730 (succ (cdr all)) | |
1731 data) | |
1732 (while pred | |
1733 (setq data (assq (car pred) win-start-end)) | |
1734 (set-window-point (car pred) (max (nth 1 data) (- (nth 2 data) 1))) | |
1735 (setq pred (cdr pred))) | |
1736 (while succ | |
1737 (set-window-point (car succ) (nth 1 (assq (car succ) win-start-end))) | |
1738 (setq succ (cdr succ))))) | |
1739 | |
1740 ;;}}} | |
1741 ;;{{{ Scroll bar | |
1742 | |
1743 ;;;; Scroll-bar support code. | |
1744 | |
1745 ;;; Why is it needed? Well, if the selected window is in follow mode, | |
1746 ;;; all its follower stick to it blindly. If one of them is scrolled, | |
1747 ;;; it immediately returns to the original position when the mouse is | |
1748 ;;; released. If the selected window is not a follower of the dragged | |
1749 ;;; window the windows will be unaligned. | |
1750 | |
1751 ;;; The advices doesn't get compiled. Aestetically, this might be a | |
1752 ;;; problem but in practical life it isn't. | |
1753 | |
1754 ;;; Discussion: Now when the other windows in the chain follow the | |
1755 ;;; dragged, should we really select it? | |
1756 | |
1757 (cond ((fboundp 'scroll-bar-drag) | |
1758 ;;; | |
21333
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
1759 ;;; Emacs style scrollbars. |
14578 | 1760 ;;; |
1761 | |
1762 ;; Select the dragged window if it is a follower of the | |
1763 ;; selected window. | |
1764 ;; | |
1765 ;; Generate advices of the form: | |
1766 ;; (defadvice scroll-bar-drag (after follow-scroll-bar-drag activate) | |
1767 ;; "Adviced by `follow-mode'." | |
1768 ;; (follow-redraw-after-event (ad-get-arg 0))) | |
1769 (let ((cmds '(scroll-bar-drag | |
1770 scroll-bar-drag-1 ; Executed at every move. | |
1771 scroll-bar-scroll-down | |
1772 scroll-bar-scroll-up | |
1773 scroll-bar-set-window-start))) | |
1774 (while cmds | |
1775 (eval | |
1776 (` (defadvice (, (intern (symbol-name (car cmds)))) | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1777 (after |
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1778 (, (intern (concat "follow-" (symbol-name (car cmds))))) |
14578 | 1779 activate) |
1780 "Adviced by Follow Mode." | |
1781 (follow-redraw-after-event (ad-get-arg 0))))) | |
1782 (setq cmds (cdr cmds)))) | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1783 |
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1784 |
14578 | 1785 (defun follow-redraw-after-event (event) |
1786 "Adviced by Follow mode." | |
1787 (condition-case nil | |
1788 (let* ((orig-win (selected-window)) | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1789 (win (nth 0 (funcall |
14578 | 1790 (symbol-function 'event-start) event))) |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1791 (fmode (assq 'follow-mode |
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1792 (buffer-local-variables |
14578 | 1793 (window-buffer win))))) |
1794 (if (and fmode (cdr fmode)) | |
1795 ;; The selected window is in follow-mode | |
1796 (progn | |
1797 ;; Recenter around the dragged window. | |
1798 (select-window win) | |
1799 (follow-redisplay) | |
1800 (select-window orig-win)))) | |
1801 (error nil)))) | |
1802 | |
1803 | |
1804 ((fboundp 'scrollbar-vertical-drag) | |
1805 ;;; | |
1806 ;;; XEmacs style scrollbars. | |
1807 ;;; | |
1808 | |
1809 ;; Advice all scrollbar functions on the form: | |
1810 ;; | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1811 ;; (defadvice scrollbar-line-down |
14578 | 1812 ;; (after follow-scrollbar-line-down activate) |
1813 ;; (follow-xemacs-scrollbar-support (ad-get-arg 0))) | |
1814 | |
1815 (let ((cmds '(scrollbar-line-down ; Window | |
1816 scrollbar-line-up | |
1817 scrollbar-page-down ; Object | |
1818 scrollbar-page-up | |
1819 scrollbar-to-bottom ; Window | |
1820 scrollbar-to-top | |
1821 scrollbar-vertical-drag ; Object | |
1822 ))) | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1823 |
14578 | 1824 (while cmds |
1825 (eval | |
1826 (` (defadvice (, (intern (symbol-name (car cmds)))) | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1827 (after |
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1828 (, (intern (concat "follow-" (symbol-name (car cmds))))) |
14578 | 1829 activate) |
1830 "Adviced by `follow-mode'." | |
1831 (follow-xemacs-scrollbar-support (ad-get-arg 0))))) | |
1832 (setq cmds (cdr cmds)))) | |
1833 | |
1834 | |
1835 (defun follow-xemacs-scrollbar-support (window) | |
1836 "Redraw windows showing the same buffer as shown in WINDOW. | |
1837 WINDOW is either the dragged window, or a cons containing the | |
1838 window as its first element. This is called while the user drags | |
1839 the scrollbar. | |
1840 | |
1841 WINDOW can be an object or a window." | |
1842 (condition-case nil | |
1843 (progn | |
1844 (if (consp window) | |
1845 (setq window (car window))) | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1846 (let ((fmode (assq 'follow-mode |
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1847 (buffer-local-variables |
14578 | 1848 (window-buffer window)))) |
1849 (orig-win (selected-window))) | |
1850 (if (and fmode (cdr fmode)) | |
1851 (progn | |
1852 ;; Recenter around the dragged window. | |
1853 (select-window window) | |
1854 (follow-redisplay) | |
1855 (select-window orig-win))))) | |
1856 (error nil))))) | |
1857 | |
1858 ;;}}} | |
1859 ;;{{{ Process output | |
1860 | |
21333
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
1861 ;;; The following sections installs a spy that listens to process |
14578 | 1862 ;;; output and tries to reposition the windows whose buffers are in |
1863 ;;; Follow mode. We play safe as much as possible... | |
1864 ;;; | |
1865 ;;; When follow-mode is activated all active processes are | |
21333
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
1866 ;;; intercepted. All new processes that change their filter function |
14578 | 1867 ;;; using `set-process-filter' are also intercepted. The reason is |
1868 ;;; that a process can cause a redisplay recentering "tail" windows. | |
1869 ;;; Note that it doesn't hurt to spy on more processes than needed. | |
1870 ;;; | |
1871 ;;; Technically, we set the process filter to `follow-generic-filter'. | |
1872 ;;; The original filter is stored in `follow-process-filter-alist'. | |
1873 ;;; Our generic filter calls the original filter, or inserts the | |
1874 ;;; output into the buffer, if the buffer originally didn't have an | |
1875 ;;; output filter. It also makes sure that the windows connected to | |
1876 ;;; the buffer are aligned. | |
1877 ;;; | |
21333
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
1878 ;;; Discussion: How do we find processes that don't call |
14578 | 1879 ;;; `set-process-filter'? (How often are processes created in a |
1880 ;;; buffer after Follow mode are activated?) | |
1881 ;;; | |
1882 ;;; Discussion: Should we also advice `process-filter' to make our | |
1883 ;;; filter invisible to others? | |
1884 | |
1885 ;;{{{ Advice for `set-process-filter' | |
1886 | |
1887 ;; Do not call this with 'follow-generic-filter as the name of the | |
1888 ;; filter... | |
1889 | |
1890 (defadvice set-process-filter (before follow-set-process-filter activate) | |
18144
f8860990bdf7
(set-process-filter): Advice doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18133
diff
changeset
|
1891 "Ensure process output will be displayed correctly in Follow Mode buffers. |
14578 | 1892 |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1893 Follow Mode inserts its own process filter to do its |
14578 | 1894 magic stuff before the real process filter is called." |
1895 (if follow-intercept-processes | |
1896 (progn | |
1897 (setq follow-process-filter-alist | |
1898 (delq (assq (ad-get-arg 0) follow-process-filter-alist) | |
1899 follow-process-filter-alist)) | |
1900 (follow-tidy-process-filter-alist) | |
1901 (cond ((eq (ad-get-arg 1) t)) | |
1902 ((eq (ad-get-arg 1) nil) | |
1903 (ad-set-arg 1 'follow-generic-filter)) | |
1904 (t | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1905 (setq follow-process-filter-alist |
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1906 (cons (cons (ad-get-arg 0) (ad-get-arg 1)) |
14578 | 1907 follow-process-filter-alist)) |
1908 (ad-set-arg 1 'follow-generic-filter)))))) | |
1909 | |
1910 | |
1911 (defun follow-call-set-process-filter (proc filter) | |
1912 "Call original `set-process-filter' without the Follow mode advice." | |
1913 (ad-disable-advice 'set-process-filter 'before | |
1914 'follow-set-process-filter) | |
1915 (ad-activate 'set-process-filter) | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1916 (prog1 |
14578 | 1917 (set-process-filter proc filter) |
1918 (ad-enable-advice 'set-process-filter 'before | |
1919 'follow-set-process-filter) | |
1920 (ad-activate 'set-process-filter))) | |
1921 | |
1922 | |
1923 (defadvice process-filter (after follow-process-filter activate) | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1924 "Return the original process filter, not `follow-generic-filter'." |
14578 | 1925 (cond ((eq ad-return-value 'follow-generic-filter) |
1926 (setq ad-return-value | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1927 (cdr-safe (assq (ad-get-arg 0) |
14578 | 1928 follow-process-filter-alist)))))) |
1929 | |
1930 | |
1931 (defun follow-call-process-filter (proc) | |
1932 "Call original `process-filter' without the Follow mode advice." | |
1933 (ad-disable-advice 'process-filter 'after | |
1934 'follow-process-filter) | |
1935 (ad-activate 'process-filter) | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1936 (prog1 |
14578 | 1937 (process-filter proc) |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1938 (ad-enable-advice 'process-filter 'after |
14578 | 1939 'follow-process-filter) |
1940 (ad-activate 'process-filter))) | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1941 |
14578 | 1942 |
1943 (defun follow-tidy-process-filter-alist () | |
1944 "Remove old processes from `follow-process-filter-alist'." | |
1945 (let ((alist follow-process-filter-alist) | |
1946 (ps (process-list)) | |
1947 (new ())) | |
1948 (while alist | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1949 (if (and (not (memq (process-status (car (car alist))) |
14578 | 1950 '(exit signal closed nil))) |
1951 (memq (car (car alist)) ps)) | |
1952 (setq new (cons (car alist) new))) | |
1953 (setq alist (cdr alist))) | |
1954 (setq follow-process-filter-alist new))) | |
1955 | |
1956 ;;}}} | |
1957 ;;{{{ Start/stop interception of processes. | |
1958 | |
1959 ;; Normally, all new processed are intercepted by our `set-process-filter'. | |
21333
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
1960 ;; This is needed to intercept old processed that were started before we were |
14578 | 1961 ;; loaded, and processes we have forgotten by calling |
1962 ;; `follow-stop-intercept-process-output'. | |
1963 | |
1964 (defun follow-intercept-process-output () | |
1965 "Intercept all active processes. | |
1966 | |
1967 This is needed so that Follow Mode can track all display events in the | |
1968 system. (See `follow-mode')" | |
1969 (interactive) | |
1970 (let ((list (process-list))) | |
1971 (while list | |
1972 (if (eq (process-filter (car list)) 'follow-generic-filter) | |
1973 nil | |
1974 ;; The custom `set-process-filter' defined above. | |
1975 (set-process-filter (car list) (process-filter (car list)))) | |
1976 (setq list (cdr list)))) | |
1977 (setq follow-intercept-processes t)) | |
1978 | |
1979 | |
1980 (defun follow-stop-intercept-process-output () | |
1981 "Stop Follow Mode from spying on processes. | |
1982 | |
1983 All current spypoints are removed and no new will be added. | |
1984 | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1985 The effect is that Follow mode won't be able to handle buffers |
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1986 connected to processes. |
14578 | 1987 |
1988 The only reason to call this function is if the Follow mode spy filter | |
1989 would interfere with some other package. If this happens, please | |
1990 report this using the `follow-submit-feedback' function." | |
1991 (interactive) | |
1992 (follow-tidy-process-filter-alist) | |
1993 (let ((list (process-list))) | |
1994 (while list | |
1995 (if (eq (process-filter (car list)) 'follow-generic-filter) | |
1996 (progn | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1997 (follow-call-set-process-filter |
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
1998 (car list) |
14578 | 1999 (cdr-safe (assq (car list) follow-process-filter-alist))) |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
2000 (setq follow-process-filter-alist |
14578 | 2001 (delq (assq (car list) follow-process-filter-alist) |
2002 follow-process-filter-alist)))) | |
2003 (setq list (cdr list)))) | |
2004 (setq follow-intercept-processes nil)) | |
2005 | |
2006 ;;}}} | |
2007 ;;{{{ The filter | |
2008 | |
2009 ;;; The following section is a naive method to make buffers with | |
2010 ;;; process output to work with Follow mode. Whenever the start of the | |
16425
215bd0423431
(set-process-filter): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
14992
diff
changeset
|
2011 ;;; window displaying the buffer is moved, we moves it back to its |
14578 | 2012 ;;; original position and try to select a new window. (If we fail, |
2013 ;;; the normal redisplay functions of Emacs will scroll it right | |
2014 ;;; back!) | |
2015 | |
2016 (defun follow-generic-filter (proc output) | |
2017 "Process output filter for process connected to buffers in Follow mode." | |
2018 (let* ((old-buffer (current-buffer)) | |
2019 (orig-win (selected-window)) | |
2020 (buf (process-buffer proc)) | |
2021 (win (and buf (if (eq buf (window-buffer orig-win)) | |
2022 orig-win | |
2023 (get-buffer-window buf t)))) | |
2024 (return-to-orig-win (and win (not (eq win orig-win)))) | |
2025 (orig-window-start (and win (window-start win)))) | |
2026 | |
2027 ;; If input is pending, the `sit-for' below won't redraw the | |
2028 ;; display. In that case, calling `follow-avoid-tail-recenter' may | |
2029 ;; provoke the process hadnling code to sceduling a redisplay. | |
2030 ;(or (input-pending-p) | |
2031 ; (follow-avoid-tail-recenter)) | |
2032 | |
2033 ;; Output the `output'. | |
2034 (let ((filter (cdr-safe (assq proc follow-process-filter-alist)))) | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
2035 (cond |
14578 | 2036 ;; Call the original filter function |
2037 (filter | |
2038 (funcall filter proc output)) | |
2039 | |
2040 ;; No filter, but we've got a buffer. Just output into it. | |
2041 (buf | |
2042 (set-buffer buf) | |
2043 (if (not (marker-buffer (process-mark proc))) | |
2044 (set-marker (process-mark proc) (point-max))) | |
2045 (let ((moving (= (point) (process-mark proc))) | |
2046 (odeactivate (and (boundp 'deactivate-mark) | |
2047 (symbol-value 'deactivate-mark))) | |
2048 (old-buffer-read-only buffer-read-only)) | |
2049 (setq buffer-read-only nil) | |
2050 (save-excursion | |
2051 (goto-char (process-mark proc)) | |
2052 ;; `insert-before-markers' just in case the users next | |
2053 ;; command is M-y. | |
2054 (insert-before-markers output) | |
2055 (set-marker (process-mark proc) (point))) | |
2056 (if moving (goto-char (process-mark proc))) | |
2057 (if (boundp 'deactivate-mark) | |
2058 ;; This could really be | |
2059 ;; (setq deactivate-mark odeactivate) | |
2060 ;; but this raises an error when compiling on XEmacs. | |
2061 (funcall (symbol-function 'set) | |
2062 'deactivate-mark odeactivate)) | |
2063 (setq buffer-read-only old-buffer-read-only))))) | |
2064 | |
2065 ;; If we're in follow mode, do our stuff. Select a new window and | |
2066 ;; redisplay. (Actually, it is redundant to check `buf', but I | |
2067 ;; feel it's more correct.) | |
2068 (if (and buf win (window-live-p win)) | |
2069 (progn | |
2070 (set-buffer buf) | |
2071 (if (and (boundp 'follow-mode) follow-mode) | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
2072 (progn |
14578 | 2073 (select-window win) |
2074 (let* ((windows (follow-all-followers win)) | |
2075 (win-start-end (follow-windows-start-end windows)) | |
2076 (new-window-start (window-start win)) | |
2077 (new-window-point (window-point win))) | |
2078 (cond | |
2079 ;; The window was moved. Move it back and | |
2080 ;; select a new. If no better could be found, | |
2081 ;; we stick the the new start position. This | |
2082 ;; is used when the original process filter | |
2083 ;; tries to position the cursor at the bottom | |
2084 ;; of the window. Example: `lyskom'. | |
2085 ((not (eq orig-window-start new-window-start)) | |
2086 (follow-debug-message "filter: Moved") | |
2087 (set-window-start win orig-window-start) | |
2088 (follow-redisplay windows win) | |
2089 (setq win-start-end (follow-windows-start-end windows)) | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
2090 (follow-select-if-visible new-window-point |
14578 | 2091 win-start-end) |
2092 (goto-char new-window-point) | |
2093 (if (eq win (selected-window)) | |
2094 (set-window-start win new-window-start)) | |
2095 (setq win-start-end (follow-windows-start-end windows))) | |
2096 ;; Stick to this window, if point is visible in it. | |
2097 ((pos-visible-in-window-p new-window-point) | |
2098 (follow-debug-message "filter: Visible in window")) | |
2099 ;; Avoid redisplaying the first window. If the | |
2100 ;; point is visible at a window below, | |
2101 ;; redisplay and select it. | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
2102 ((follow-select-if-visible-from-first |
14578 | 2103 new-window-point windows) |
2104 (follow-debug-message "filter: Seen from first") | |
2105 (follow-redisplay windows (car windows)) | |
2106 (goto-char new-window-point) | |
2107 (setq win-start-end | |
2108 (follow-windows-start-end windows))) | |
2109 ;; None of the above. We stick to the current window. | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
2110 (t |
14578 | 2111 (follow-debug-message "filter: nothing"))) |
2112 | |
2113 ;; Here we have slected a window. Make sure the | |
2114 ;; windows are aligned and the point is visible | |
2115 ;; in the selected window. | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
2116 (if (and (not (follow-pos-visible |
14578 | 2117 (point) (selected-window) win-start-end)) |
2118 (not return-to-orig-win)) | |
2119 (progn | |
2120 (sit-for 0) | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
2121 (setq win-start-end |
14578 | 2122 (follow-windows-start-end windows)))) |
2123 | |
2124 (if (or follow-internal-force-redisplay | |
2125 (not (follow-windows-aligned-p win-start-end))) | |
2126 (follow-redisplay windows))))))) | |
2127 | |
2128 ;; return to the original window. | |
2129 (if return-to-orig-win | |
2130 (select-window orig-win)) | |
18028
89f6e1e17d2d
(follow-submit-feedback, follow-mode): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
16425
diff
changeset
|
2131 ;; Restore the orignal buffer, unless the filter explicitly |
89f6e1e17d2d
(follow-submit-feedback, follow-mode): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
16425
diff
changeset
|
2132 ;; changed buffer or killed the old buffer. |
89f6e1e17d2d
(follow-submit-feedback, follow-mode): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
16425
diff
changeset
|
2133 (if (and (eq buf (current-buffer)) |
89f6e1e17d2d
(follow-submit-feedback, follow-mode): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
16425
diff
changeset
|
2134 (buffer-name old-buffer)) |
89f6e1e17d2d
(follow-submit-feedback, follow-mode): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
16425
diff
changeset
|
2135 (set-buffer old-buffer))) |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
2136 |
14609
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
2137 (follow-invalidate-cache) |
14578 | 2138 |
14609
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
2139 ;; Normally, if the display has been changed, it is redrawn. All |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
2140 ;; windows showing only the end of a buffer is unconditionally |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
2141 ;; recentered, we can't prevent it by calling |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
2142 ;; `follow-avoid-tail-recenter'. |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
2143 ;; |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
2144 ;; By performing a redisplay on our own, Emacs need not perform |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
2145 ;; the above described redisplay. (However, bu performing it when |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
2146 ;; there are input available just seems to make things worse.) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
2147 (if (and follow-avoid-tail-recenter-p |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
2148 (not (input-pending-p))) |
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
2149 (sit-for 0))) |
14578 | 2150 |
2151 ;;}}} | |
2152 | |
2153 ;;}}} | |
2154 ;;{{{ Window size change | |
2155 | |
2156 ;; In Emacs 19.29, the functions in `window-size-change-functions' are | |
2157 ;; called every time a window in a frame changes size. Most notably, it | |
2158 ;; is called after the frame has been resized. | |
2159 ;; | |
21333
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
2160 ;; We basically call our post-command-hook for every buffer that is |
14578 | 2161 ;; visible in any window in the resized frame, which is in follow-mode. |
2162 ;; | |
2163 ;; Since this function can be called indirectly from | |
2164 ;; `follow-post-command-hook' we have a potential infinite loop. We | |
2165 ;; handle this problem by simply not doing anything at all in this | |
2166 ;; situation. The variable `follow-inside-post-command-hook' contains | |
2167 ;; information about whether the execution actually is inside the | |
2168 ;; post-command-hook or not. | |
2169 | |
2170 (if (boundp 'window-size-change-functions) | |
2171 (add-hook 'window-size-change-functions 'follow-window-size-change)) | |
2172 | |
2173 | |
2174 (defun follow-window-size-change (frame) | |
2175 "Redraw all windows in FRAME, when in Follow mode." | |
2176 ;; Below, we call `post-command-hook'. This makes sure that we | |
2177 ;; doesn't start a mutally recursive endless loop. | |
2178 (if follow-inside-post-command-hook | |
2179 nil | |
2180 (let ((buffers '()) | |
2181 (orig-window (selected-window)) | |
2182 (orig-buffer (current-buffer)) | |
2183 (orig-frame (selected-frame)) | |
2184 windows | |
2185 buf) | |
2186 (select-frame frame) | |
2187 (unwind-protect | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
2188 (walk-windows |
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
2189 (function |
14578 | 2190 (lambda (win) |
2191 (setq buf (window-buffer win)) | |
2192 (if (memq buf buffers) | |
2193 nil | |
2194 (set-buffer buf) | |
2195 (if (and (boundp 'follow-mode) | |
2196 follow-mode) | |
2197 (progn | |
2198 (setq windows (follow-all-followers win)) | |
2199 (if (memq orig-window windows) | |
2200 (progn | |
2201 ;; Make sure we're redrawing around the | |
2202 ;; selected window. | |
2203 ;; | |
2204 ;; We must be really careful not to do this | |
2205 ;; when we are (indirectly) called by | |
2206 ;; `post-command-hook'. | |
2207 (select-window orig-window) | |
2208 (follow-post-command-hook) | |
2209 (setq orig-window (selected-window))) | |
2210 (follow-redisplay windows win)) | |
2211 (setq buffers (cons buf buffers)))))))) | |
2212 (select-frame orig-frame) | |
2213 (set-buffer orig-buffer) | |
2214 (select-window orig-window))))) | |
2215 | |
2216 ;;}}} | |
2217 | |
2218 ;;{{{ XEmacs isearch | |
2219 | |
2220 ;; In XEmacs, isearch often finds matches in other windows than the | |
2221 ;; currently selected. However, when exiting the old window | |
2222 ;; configuration is restored, with the exception of the beginning of | |
2223 ;; the start of the window for the selected window. This is not much | |
2224 ;; help for us. | |
2225 ;; | |
2226 ;; We overwrite the stored window configuration with the current, | |
2227 ;; unless we are in `slow-search-mode', i.e. only a few lines | |
2228 ;; of text is visible. | |
2229 | |
2230 (if follow-emacs-version-xemacs-p | |
2231 (defadvice isearch-done (before follow-isearch-done activate) | |
2232 (if (and (boundp 'follow-mode) | |
2233 follow-mode | |
2234 (boundp 'isearch-window-configuration) | |
2235 isearch-window-configuration | |
2236 (boundp 'isearch-slow-terminal-mode) | |
2237 (not isearch-slow-terminal-mode)) | |
2238 (let ((buf (current-buffer))) | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
2239 (setq isearch-window-configuration |
14578 | 2240 (current-window-configuration)) |
2241 (set-buffer buf))))) | |
2242 | |
2243 ;;}}} | |
2244 ;;{{{ Tail window handling | |
2245 | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
2246 ;;; In Emacs (not XEmacs) windows showing nothing are sometimes |
14578 | 2247 ;;; recentered. When in Follow Mode, this is not desireable for |
2248 ;;; non-first windows in the window chain. This section tries to | |
2249 ;;; make the windows stay where they should be. | |
2250 ;;; | |
2251 ;;; If the display is updated, all windows starting at (point-max) are | |
2252 ;;; going to be recentered at the next redisplay, unless we do a | |
2253 ;;; read-and-write cycle to update the `force' flag inside the windows. | |
2254 ;;; | |
2255 ;;; In 19.30, a new varible `window-scroll-functions' is called every | |
2256 ;;; time a window is recentered. It is not perfect for our situation, | |
2257 ;;; since when it is called for a tail window, it is to late. However, | |
2258 ;;; if it is called for another window, we can try to update our | |
2259 ;;; windows. | |
2260 ;;; | |
2261 ;;; By patching `sit-for' we can make sure that to catch all explicit | |
2262 ;;; updates initiated by lisp programs. Internal calls, on the other | |
2263 ;;; hand, are not handled. | |
2264 ;;; | |
2265 ;;; Please note that the function `follow-avoid-tail-recenter' is also | |
2266 ;;; called from other places, e.g. `post-command-hook' and | |
2267 ;;; `post-command-idle-hook'. | |
2268 | |
18028
89f6e1e17d2d
(follow-submit-feedback, follow-mode): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
16425
diff
changeset
|
2269 ;; If this function is called it is too late for this window, but |
89f6e1e17d2d
(follow-submit-feedback, follow-mode): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
16425
diff
changeset
|
2270 ;; we might save other windows from being recentered. |
14578 | 2271 |
2272 (if (and follow-avoid-tail-recenter-p (boundp 'window-scroll-functions)) | |
2273 (add-hook 'window-scroll-functions 'follow-avoid-tail-recenter t)) | |
2274 | |
2275 | |
21333
a6119c0748e9
(follow-scroll-up): Cope if `window-end' returns nil.
Richard M. Stallman <rms@gnu.org>
parents:
21088
diff
changeset
|
2276 ;; This prevents all packages that calls `sit-for' directly |
14578 | 2277 ;; to recenter tail windows. |
2278 | |
2279 (if follow-avoid-tail-recenter-p | |
2280 (defadvice sit-for (before follow-sit-for activate) | |
2281 "Adviced by Follow Mode. | |
2282 | |
2283 Avoid to recenter windows displaying only the end of a file as when | |
2284 displaying a short file in two windows, using Follow Mode." | |
2285 (follow-avoid-tail-recenter))) | |
2286 | |
2287 | |
2288 ;; Without this advice, `mouse-drag-region' would start to recenter | |
2289 ;; tail windows. | |
2290 | |
2291 (if (and follow-avoid-tail-recenter-p | |
2292 (fboundp 'move-overlay)) | |
2293 (defadvice move-overlay (before follow-move-overlay activate) | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
2294 "Adviced by Follow Mode. |
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
2295 Don't recenter windows showing only the end of a buffer. |
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
2296 This prevents `mouse-drag-region' from messing things up." |
14578 | 2297 (follow-avoid-tail-recenter))) |
2298 | |
2299 ;;}}} | |
2300 ;;{{{ profile support | |
2301 | |
2302 ;; The following (non-evaluated) section can be used to | |
2303 ;; profile this package using `elp'. | |
2304 ;; | |
2305 ;; Invalid indentation on purpose! | |
2306 | |
2307 (cond (nil | |
2308 (setq elp-function-list | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
2309 '(window-end |
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
2310 vertical-motion |
14578 | 2311 ; sit-for ;; elp can't handle advices... |
2312 follow-mode | |
2313 follow-all-followers | |
18133
7900f6f3c36e
(follow-windows-aligned-p): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18028
diff
changeset
|
2314 follow-split-followers |
14578 | 2315 follow-redisplay |
2316 follow-downward | |
2317 follow-calculate-first-window-start | |
2318 follow-estimate-first-window-start | |
2319 follow-calculate-first-window-start-from-above | |
2320 follow-calculate-first-window-start-from-below | |
2321 follow-calc-win-end | |
2322 follow-calc-win-start | |
2323 follow-pos-visible | |
2324 follow-windows-start-end | |
14609
a8eeafa7c4af
Update some doc string. Call `add-minor-mode'.
Karl Heuer <kwzh@gnu.org>
parents:
14578
diff
changeset
|
2325 follow-cache-valid-p |
14578 | 2326 follow-select-if-visible |
2327 follow-select-if-visible-from-first | |
2328 follow-windows-aligned-p | |
2329 follow-point-visible-all-windows-p | |
2330 follow-avoid-tail-recenter | |
2331 follow-update-window-start | |
2332 follow-post-command-hook | |
2333 )))) | |
2334 | |
2335 ;;}}} | |
2336 | |
2337 ;;{{{ The end | |
2338 | |
2339 ;;; | |
2340 ;;; We're done! | |
2341 ;;; | |
2342 | |
2343 (provide 'follow) | |
2344 | |
2345 ;;}}} | |
2346 | |
2347 ;; /------------------------------------------------------------------------\ | |
2348 ;; | "I [..] am rarely happier then when spending an entire day programming | | |
2349 ;; | my computer to perform automatically a task that it would otherwise | | |
2350 ;; | take me a good ten seconds to do by hand. Ten seconds, I tell myself, | | |
2351 ;; | is ten seconds. Time is valuable and ten seconds' worth of it is well | | |
2352 ;; | worth the investment of a day's happy activity working out a way to | | |
2353 ;; | save it". -- Douglas Adams, "Last Chance to See" | | |
2354 ;; \------------------------------------------------------------------------/ | |
2355 | |
2356 ;;; follow.el ends here |