Commit | Line | Data |
---|---|---|
e8af40ee | 1 | ;;; scroll-all.el --- scroll all buffers together minor mode |
11a66c13 | 2 | |
acaf905b | 3 | ;; Copyright (C) 1997, 2001-2012 Free Software Foundation, Inc. |
11a66c13 RS |
4 | |
5 | ;; Author: Gary D. Foster <Gary.Foster@corp.sun.com> | |
6 | ;; Keywords: scroll crisp brief lock | |
7 | ||
8 | ;; This file is part of GNU Emacs. | |
9 | ||
eb3fa2cf | 10 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
11a66c13 | 11 | ;; it under the terms of the GNU General Public License as published by |
eb3fa2cf GM |
12 | ;; the Free Software Foundation, either version 3 of the License, or |
13 | ;; (at your option) any later version. | |
11a66c13 RS |
14 | |
15 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | ;; GNU General Public License for more details. | |
19 | ||
20 | ;; You should have received a copy of the GNU General Public License | |
eb3fa2cf | 21 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
11a66c13 | 22 | |
e8af40ee | 23 | ;;; Commentary: |
11a66c13 RS |
24 | ;; This mode allows multiple buffers to be 'locked' so that scrolling |
25 | ;; up or down lines in any buffer causes all the buffers to mirror | |
26 | ;; the scrolling. It hooks into the post-command-hook to check for | |
27 | ;; potential scrolling commands and if we're locked, mirrors them in all | |
4fffd73b | 28 | ;; windows. This allows us to grab line-at-a-time scrolling as well as |
11a66c13 RS |
29 | ;; screen-at-a-time scrolling, and doesn't remap any of the keyboard |
30 | ;; commands to do it. | |
31 | ||
beaf629d | 32 | ;; You can enable and disable this mode with the 'scroll-all-mode' command. |
11a66c13 RS |
33 | |
34 | ;; Suggestions/ideas from: | |
35 | ;; Rick Macdonald <rickm@vsl.com> | |
36 | ;; Anders Lindgren <andersl@csd.uu.se> | |
37 | ||
e8af40ee PJ |
38 | ;;; Code: |
39 | ||
5e9f6c44 GM |
40 | (defun scroll-all-function-all (func arg) |
41 | "Apply function FUNC with argument ARG to all visible windows." | |
11a66c13 | 42 | (let ((num-windows (count-windows)) |
c9787897 | 43 | (count 1)) |
6036654e | 44 | (when (> num-windows 1) |
c9787897 RS |
45 | (other-window 1) |
46 | (while (< count num-windows) | |
5e9f6c44 GM |
47 | (condition-case nil |
48 | (funcall func arg) | |
49 | ;; Ignore beginning- or end-of-buffer error in other windows. | |
50 | (error nil) | |
51 | ) | |
c9787897 RS |
52 | (other-window 1) |
53 | (setq count (1+ count)))))) | |
11a66c13 | 54 | |
5e9f6c44 GM |
55 | (defun scroll-all-scroll-down-all (arg) |
56 | "Scroll down in all visible windows." | |
57 | (interactive "p") | |
58 | (scroll-all-function-all 'next-line arg)) | |
59 | ||
beaf629d | 60 | (defun scroll-all-scroll-up-all (arg) |
5e9f6c44 GM |
61 | "Scroll up in all visible windows." |
62 | (interactive "p") | |
63 | (scroll-all-function-all 'previous-line arg)) | |
11a66c13 | 64 | |
beaf629d RS |
65 | (defun scroll-all-page-down-all (arg) |
66 | "Page down in all visible windows." | |
11a66c13 | 67 | (interactive "P") |
5e9f6c44 | 68 | (scroll-all-function-all 'scroll-up arg)) |
11a66c13 | 69 | |
beaf629d RS |
70 | (defun scroll-all-page-up-all (arg) |
71 | "Page up in all visible windows." | |
11a66c13 | 72 | (interactive "P") |
5e9f6c44 | 73 | (scroll-all-function-all 'scroll-down arg)) |
6036654e GM |
74 | |
75 | (defun scroll-all-beginning-of-buffer-all (arg) | |
76 | "Go to the beginning of the buffer in all visible windows." | |
77 | (interactive "P") | |
5e9f6c44 | 78 | (scroll-all-function-all 'beginning-of-buffer arg)) |
6036654e GM |
79 | |
80 | (defun scroll-all-end-of-buffer-all (arg) | |
81 | "Go to the end of the buffer in all visible windows." | |
82 | (interactive "P") | |
5e9f6c44 | 83 | (scroll-all-function-all 'end-of-buffer arg)) |
11a66c13 RS |
84 | |
85 | ||
beaf629d | 86 | (defun scroll-all-check-to-scroll () |
75272a3a | 87 | "Check `this-command' to see if a scroll is to be done." |
c9787897 RS |
88 | (cond ((eq this-command 'next-line) |
89 | (call-interactively 'scroll-all-scroll-down-all)) | |
90 | ((eq this-command 'previous-line) | |
91 | (call-interactively 'scroll-all-scroll-up-all)) | |
841c4085 | 92 | ((memq this-command '(scroll-up scroll-up-command)) |
c9787897 | 93 | (call-interactively 'scroll-all-page-down-all)) |
841c4085 | 94 | ((memq this-command '(scroll-down scroll-down-command)) |
c9787897 RS |
95 | (call-interactively 'scroll-all-page-up-all)) |
96 | ((eq this-command 'beginning-of-buffer) | |
97 | (call-interactively 'scroll-all-beginning-of-buffer-all)) | |
98 | ((eq this-command 'end-of-buffer) | |
99 | (call-interactively 'scroll-all-end-of-buffer-all)))) | |
f1180544 | 100 | |
11a66c13 | 101 | |
052e4f5e | 102 | ;;;###autoload |
ddff27f9 | 103 | (define-minor-mode scroll-all-mode |
06e21633 CY |
104 | "Toggle shared scrolling in same-frame windows (Scroll-All mode). |
105 | With a prefix argument ARG, enable Scroll-All mode if ARG is | |
106 | positive, and disable it otherwise. If called from Lisp, enable | |
107 | the mode if ARG is omitted or nil. | |
108 | ||
109 | When Scroll-All mode is enabled, scrolling commands invoked in | |
110 | one window apply to all visible windows in the same frame." | |
ddff27f9 MR |
111 | nil " *SL*" nil |
112 | :global t | |
3ff2317b | 113 | :group 'windows |
091b5fdb GM |
114 | (if scroll-all-mode |
115 | (add-hook 'post-command-hook 'scroll-all-check-to-scroll) | |
116 | (remove-hook 'post-command-hook 'scroll-all-check-to-scroll))) | |
11a66c13 | 117 | |
beaf629d | 118 | (provide 'scroll-all) |
11a66c13 | 119 | |
e8af40ee | 120 | ;;; scroll-all.el ends here |