1 ;;; scroll-all.el --- scroll all buffers together minor mode
3 ;; Copyright (C) 1997, 2001-2015 Free Software Foundation, Inc.
5 ;; Author: Gary D. Foster <Gary.Foster@corp.sun.com>
6 ;; Keywords: convenience scroll lock
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
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.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
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
28 ;; windows. This allows us to grab line-at-a-time scrolling as well as
29 ;; screen-at-a-time scrolling, and doesn't remap any of the keyboard
32 ;; You can enable and disable this mode with the 'scroll-all-mode' command.
34 ;; Suggestions/ideas from:
35 ;; Rick Macdonald <rickm@vsl.com>
40 (defun scroll-all-function-all (func arg
)
41 "Apply function FUNC with argument ARG to all visible windows."
42 (let ((num-windows (count-windows))
44 (when (> num-windows
1)
46 (while (< count num-windows
)
49 ;; Ignore beginning- or end-of-buffer error in other windows.
53 (setq count
(1+ count
))))))
55 (defun scroll-all-scroll-down-all (arg)
56 "Scroll down in all visible windows."
58 (scroll-all-function-all 'next-line arg
))
60 (defun scroll-all-scroll-up-all (arg)
61 "Scroll up in all visible windows."
63 (scroll-all-function-all 'previous-line arg
))
65 (defun scroll-all-page-down-all (arg)
66 "Page down in all visible windows."
68 (scroll-all-function-all 'scroll-up arg
))
70 (defun scroll-all-page-up-all (arg)
71 "Page up in all visible windows."
73 (scroll-all-function-all 'scroll-down arg
))
75 (defun scroll-all-beginning-of-buffer-all (arg)
76 "Go to the beginning of the buffer in all visible windows."
78 (scroll-all-function-all 'beginning-of-buffer arg
))
80 (defun scroll-all-end-of-buffer-all (arg)
81 "Go to the end of the buffer in all visible windows."
83 (scroll-all-function-all 'end-of-buffer arg
))
86 (defun scroll-all-check-to-scroll ()
87 "Check `this-command' to see if a scroll is to be done."
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
))
92 ((memq this-command
'(scroll-up scroll-up-command
))
93 (call-interactively 'scroll-all-page-down-all
))
94 ((memq this-command
'(scroll-down scroll-down-command
))
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
))))
103 (define-minor-mode scroll-all-mode
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.
109 When Scroll-All mode is enabled, scrolling commands invoked in
110 one window apply to all visible windows in the same frame."
115 (add-hook 'post-command-hook
'scroll-all-check-to-scroll
)
116 (remove-hook 'post-command-hook
'scroll-all-check-to-scroll
)))
118 (provide 'scroll-all
)
120 ;;; scroll-all.el ends here