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