annotate lisp/follow.el @ 22608:e1e08f5e0662

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