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