* net/tramp-cmds.el (tramp-append-tramp-buffers): Dump load-path shadows.
[emacs.git] / lisp / scroll-all.el
blob6dbdc9ab90dbc5453d40f5a9570c1b8003957aec
1 ;;; scroll-all.el --- scroll all buffers together minor mode
3 ;; Copyright (C) 1997, 2001-2011 Free Software Foundation, Inc.
5 ;; Author: Gary D. Foster <Gary.Foster@corp.sun.com>
6 ;; Keywords: scroll crisp brief 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/>.
23 ;;; Commentary:
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
30 ;; commands to do it.
32 ;; You can enable and disable this mode with the 'scroll-all-mode' command.
34 ;; Suggestions/ideas from:
35 ;; Rick Macdonald <rickm@vsl.com>
36 ;; Anders Lindgren <andersl@csd.uu.se>
38 ;;; Code:
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))
43 (count 1))
44 (when (> num-windows 1)
45 (other-window 1)
46 (while (< count num-windows)
47 (condition-case nil
48 (funcall func arg)
49 ;; Ignore beginning- or end-of-buffer error in other windows.
50 (error nil)
52 (other-window 1)
53 (setq count (1+ count))))))
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))
60 (defun scroll-all-scroll-up-all (arg)
61 "Scroll up in all visible windows."
62 (interactive "p")
63 (scroll-all-function-all 'previous-line arg))
65 (defun scroll-all-page-down-all (arg)
66 "Page down in all visible windows."
67 (interactive "P")
68 (scroll-all-function-all 'scroll-up arg))
70 (defun scroll-all-page-up-all (arg)
71 "Page up in all visible windows."
72 (interactive "P")
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."
77 (interactive "P")
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."
82 (interactive "P")
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))))
102 ;;;###autoload
103 (define-minor-mode scroll-all-mode
104 "Toggle Scroll-All minor mode.
105 With ARG, turn Scroll-All minor mode on if ARG is positive, off otherwise.
106 When Scroll-All mode is on, scrolling commands entered in one window
107 apply to all visible windows in the same frame."
108 nil " *SL*" nil
109 :global t
110 :group 'windows
111 :group 'scrolling
112 (if scroll-all-mode
113 (add-hook 'post-command-hook 'scroll-all-check-to-scroll)
114 (remove-hook 'post-command-hook 'scroll-all-check-to-scroll)))
116 (provide 'scroll-all)
118 ;;; scroll-all.el ends here