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