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