72
|
1 ;; @(#) scroll-lock.el -- scroll-locking minor mode
|
|
2
|
|
3 ;; Authors:
|
|
4 ;; Gary D. Foster <Gary.Foster@corp.sun.com>
|
|
5 ;; with contributions/suggestions/ideas from:
|
|
6 ;; Rick Macdonald <rickm@vsl.com>
|
|
7 ;; Anders Lindgren <andersl@csd.uu.se>
|
|
8 ;; $Revision: 1.1.1.1 $
|
|
9 ;; Keywords: scroll crisp brief lock
|
|
10
|
|
11 ;; This file is part of GNU Emacs.
|
|
12
|
|
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
14 ;; it under the terms of the GNU General Public License as published by
|
|
15 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
16 ;; any later version.
|
|
17
|
|
18 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
21 ;; GNU General Public License for more details.
|
|
22
|
|
23 ;; You should have received a copy of the GNU General Public License
|
|
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
26 ;; Boston, MA 02111-1307, USA.
|
|
27
|
|
28 ;; Commentary
|
|
29 ;; This mode allows multiple buffers to be 'locked' so that scrolling
|
|
30 ;; up or down lines in any buffer causes all the buffers to mirror
|
|
31 ;; the scrolling. It hooks into the post-command-hook to check for
|
|
32 ;; potential scrolling commands and if we're locked, mirrors them in all
|
|
33 ;; windows. This allows us to grab line-at-a-time scrolling as well as
|
|
34 ;; screen-at-a-time scrolling, and doesn't remap any of the keyboard
|
|
35 ;; commands to do it.
|
|
36
|
|
37 ;; This minor mode is normally autoloaded from the scroll-lock package.
|
|
38 ;; You can disable autoloading of this package by placing
|
|
39 ;; (setq crisp-load-scroll-lock nil) in your .emacs before loading
|
|
40 ;; the crisp package. If you want to use this package by itself,
|
|
41 ;; you can enable it by placing the following in your .emacs:
|
|
42
|
|
43 ;; (require 'scroll-lock)
|
|
44
|
|
45 ;; In the first (autoloaded) case, meta-f1 is bound to the command to
|
|
46 ;; toggle the scroll-lock mode. In the second (non-autoloaded) case,
|
|
47 ;; you can enable and disable it with the 'scroll-lock-mode' command.
|
|
48
|
|
49 (defvar scroll-lock-running-xemacs (string-match "XEmacs\\|Lucid" emacs-version))
|
|
50
|
|
51 (defvar scroll-lock-modeline-string " *SL*"
|
|
52 "String to display in the modeline when Scroll Lock mode is enabled.")
|
|
53
|
|
54 (defvar scroll-lock-is-locked nil
|
|
55 "Track status of scroll locking.")
|
|
56 (if scroll-lock-running-xemacs
|
|
57 (add-minor-mode 'scroll-lock-is-locked scroll-lock-modeline-string)
|
|
58 (or (assq 'scroll-lock-is-locked minor-mode-alist)
|
|
59 (setq minor-mode-alist
|
|
60 (cons '(scroll-lock-is-locked scroll-lock-modeline-string) minor-mode-alist))))
|
|
61
|
|
62 (defun scroll-lock-scroll-down-all (arg)
|
|
63 "Scroll-down all visible windows."
|
|
64 (interactive "P")
|
|
65 (let ((num-windows (count-windows))
|
|
66 (count 1))
|
|
67 (if (> num-windows 1)
|
|
68 ( progn (other-window 1)
|
|
69 (while (< count num-windows)
|
|
70 (if (not (eq (point) (point-max)))
|
|
71 (progn (call-interactively 'next-line)))
|
|
72 (other-window 1)
|
|
73 (setq count (1+ count)))))))
|
|
74
|
|
75 (defun scroll-lock-scroll-up-all (arg)
|
|
76 "Scroll-up all visible windows."
|
|
77 (interactive "P")
|
|
78 (let ((num-windows (count-windows))
|
|
79 (count 1))
|
|
80 (if (> num-windows 1)
|
|
81 ( progn (other-window 1)
|
|
82 (while (< count num-windows)
|
|
83 (if (not (eq (point) (point-min)))
|
|
84 (progn (call-interactively 'previous-line)))
|
|
85 (other-window 1)
|
|
86 (setq count (1+ count)))))))
|
|
87
|
|
88 (defun scroll-lock-page-down-all (arg)
|
|
89 "Page-down all visible windows."
|
|
90 (interactive "P")
|
|
91 (let ((num-windows (count-windows))
|
|
92 (count 1))
|
|
93 (if (> num-windows 1)
|
|
94 (progn (other-window 1)
|
|
95 (while (< count num-windows)
|
|
96 (call-interactively 'fkey-scroll-up)
|
|
97 (other-window 1)
|
|
98 (setq count (1+ count)))))))
|
|
99
|
|
100 (defun scroll-lock-page-up-all (arg)
|
|
101 "Page-up all visible windows."
|
|
102 (interactive "P")
|
|
103 (let ((num-windows (count-windows))
|
|
104 (count 1))
|
|
105 (if (> num-windows 1)
|
|
106 (progn (other-window 1)
|
|
107 (while (< count num-windows)
|
|
108 (call-interactively 'fkey-scroll-down)
|
|
109 (other-window 1)
|
|
110 (setq count (1+ count)))))))
|
|
111
|
|
112
|
|
113 (defun scroll-lock-check-to-scroll ()
|
|
114 "Check last-command to see if a scroll was done."
|
|
115 (if (eq this-command 'next-line)
|
|
116 (call-interactively 'scroll-lock-scroll-down-all))
|
|
117 (if (eq this-command 'previous-line)
|
|
118 (call-interactively 'scroll-lock-scroll-up-all))
|
|
119 (if (eq this-command 'fkey-scroll-up)
|
|
120 (call-interactively 'scroll-lock-page-down-all))
|
|
121 (if (eq this-command 'fkey-scroll-down)
|
|
122 (call-interactively 'scroll-lock-page-up-all)))
|
|
123
|
|
124
|
|
125 (defun scroll-lock-mode (arg)
|
|
126 "Toggle scroll-lock minor mode."
|
|
127 (interactive "P")
|
|
128 (setq scroll-lock-is-locked (not scroll-lock-is-locked))
|
|
129 (cond
|
|
130 ((eq scroll-lock-is-locked 't)
|
|
131 (add-hook 'post-command-hook 'scroll-lock-check-to-scroll))
|
|
132 ((eq scroll-lock-is-locked 'nil)
|
|
133 (remove-hook 'post-command-hook 'scroll-lock-check-to-scroll))))
|
|
134
|
|
135 (provide 'scroll-lock)
|
|
136
|
|
137 ;;; scroll-lock.el ends here
|