Mercurial > emacs
annotate lisp/scroll-bar.el @ 2004:6469a137fea6
(C_entries): New local variable quotednl. Used for
parsing of #define's spanning multiple lines.
(C_entries): Save the definedef status
even when a newline is met inside a string.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Wed, 03 Mar 1993 06:20:12 +0000 |
parents | bde0ca7e33b3 |
children | 4f9d60f7de9d |
rev | line source |
---|---|
1981
bde0ca7e33b3
Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents:
1973
diff
changeset
|
1 ;;; scroll-bar.el -- window system-independent scroll bar support. |
1772 | 2 |
3 ;;; Copyright (C) 1993 Free Software Foundation, Inc. | |
4 | |
5 ;; Maintainer: FSF | |
6 ;; Keywords: hardware | |
7 | |
8 ;;; This file is part of GNU Emacs. | |
9 | |
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 2, or (at your option) | |
13 ;;; any later version. | |
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 | |
21 ;;; along with GNU Emacs; see the file COPYING. If not, write to | |
22 ;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
23 | |
1821
04fb1d3d6992
JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents:
1772
diff
changeset
|
24 (require 'mouse) |
04fb1d3d6992
JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents:
1772
diff
changeset
|
25 |
1772 | 26 |
27 ;;;; Utilities. | |
28 | |
1981
bde0ca7e33b3
Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents:
1973
diff
changeset
|
29 (defun scroll-bar-scale (num-denom whole) |
1772 | 30 "Given a pair (NUM . DENOM) and WHOLE, return (/ (* NUM WHOLE) DENOM). |
1981
bde0ca7e33b3
Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents:
1973
diff
changeset
|
31 This is handy for scaling a position on a scroll bar into real units, |
bde0ca7e33b3
Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents:
1973
diff
changeset
|
32 like buffer positions. If SCROLL-BAR-POS is the (PORTION . WHOLE) pair |
bde0ca7e33b3
Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents:
1973
diff
changeset
|
33 from a scroll bar event, then (scroll-bar-scale SCROLL-BAR-POS |
1772 | 34 \(buffer-size)) is the position in the current buffer corresponding to |
1981
bde0ca7e33b3
Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents:
1973
diff
changeset
|
35 that scroll bar position." |
1772 | 36 ;; We multiply before we divide to maintain precision. |
37 ;; We use floating point because the product of a large buffer size | |
1981
bde0ca7e33b3
Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents:
1973
diff
changeset
|
38 ;; with a large scroll bar portion can easily overflow a lisp int. |
1772 | 39 (truncate (/ (* (float (car num-denom)) whole) (cdr num-denom)))) |
40 | |
41 | |
1954
059d99d03aae
* term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
42 ;;;; Helpful functions for enabling and disabling scroll bars. |
059d99d03aae
* term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
43 (defvar scroll-bar-mode nil) |
059d99d03aae
* term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
44 |
059d99d03aae
* term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
45 (defun scroll-bar-mode (flag) |
059d99d03aae
* term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
46 "Toggle display of vertical scroll bars on each frame. |
059d99d03aae
* term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
47 This command applies to all frames that exist and frames to be |
059d99d03aae
* term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
48 created in the future. |
059d99d03aae
* term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
49 With a numeric argument, if the argument is negative, |
059d99d03aae
* term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
50 turn off scroll bars; otherwise, turn on scroll bars." |
059d99d03aae
* term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
51 (interactive "P") |
059d99d03aae
* term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
52 (setq scroll-bar-mode (if (null flag) (not scroll-bar-mode) |
059d99d03aae
* term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
53 (or (not (numberp flag)) (>= flag 0)))) |
059d99d03aae
* term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
54 (mapcar |
059d99d03aae
* term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
55 (function |
059d99d03aae
* term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
56 (lambda (param-name) |
059d99d03aae
* term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
57 (let ((parameter (assq param-name default-frame-alist))) |
059d99d03aae
* term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
58 (if (consp parameter) |
059d99d03aae
* term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
59 (setcdr parameter scroll-bar-mode) |
059d99d03aae
* term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
60 (setq default-frame-alist |
059d99d03aae
* term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
61 (cons (cons param-name scroll-bar-mode) |
059d99d03aae
* term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
62 default-frame-alist)))))) |
1981
bde0ca7e33b3
Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents:
1973
diff
changeset
|
63 '(vertical-scroll-bars horizontal-scroll-bars)) |
1954
059d99d03aae
* term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
64 (let ((frames (frame-list))) |
059d99d03aae
* term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
65 (while frames |
059d99d03aae
* term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
66 (modify-frame-parameters |
059d99d03aae
* term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
67 (car frames) |
1981
bde0ca7e33b3
Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents:
1973
diff
changeset
|
68 (list (cons 'vertical-scroll-bars scroll-bar-mode) |
bde0ca7e33b3
Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents:
1973
diff
changeset
|
69 (cons 'horizontal-scroll-bars scroll-bar-mode))) |
1954
059d99d03aae
* term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
70 (setq frames (cdr frames))))) |
059d99d03aae
* term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
71 |
1981
bde0ca7e33b3
Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents:
1973
diff
changeset
|
72 ;;;; Buffer navigation using the scroll bar. |
1772 | 73 |
1981
bde0ca7e33b3
Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents:
1973
diff
changeset
|
74 (defun scroll-bar-set-window-start (event) |
bde0ca7e33b3
Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents:
1973
diff
changeset
|
75 "Set the window start according to where the scroll bar is dragged. |
bde0ca7e33b3
Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents:
1973
diff
changeset
|
76 EVENT should be a scroll bar click or drag event." |
1772 | 77 (interactive "e") |
1821
04fb1d3d6992
JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents:
1772
diff
changeset
|
78 (let* ((end-position (event-end event)) |
1772 | 79 (window (nth 0 end-position)) |
80 (portion-whole (nth 2 end-position))) | |
81 (save-excursion | |
82 (set-buffer (window-buffer window)) | |
83 (save-excursion | |
1981
bde0ca7e33b3
Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents:
1973
diff
changeset
|
84 (goto-char (scroll-bar-scale portion-whole (buffer-size))) |
1772 | 85 (beginning-of-line) |
86 (set-window-start window (point)))))) | |
87 | |
1981
bde0ca7e33b3
Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents:
1973
diff
changeset
|
88 (defun scroll-bar-scroll-down (event) |
bde0ca7e33b3
Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents:
1973
diff
changeset
|
89 "Scroll the window's top line down to the location of the scroll bar click. |
bde0ca7e33b3
Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents:
1973
diff
changeset
|
90 EVENT should be a scroll bar click." |
1772 | 91 (interactive "e") |
92 (let ((old-selected-window (selected-window))) | |
93 (unwind-protect | |
94 (progn | |
1821
04fb1d3d6992
JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents:
1772
diff
changeset
|
95 (let* ((end-position (event-end event)) |
1772 | 96 (window (nth 0 end-position)) |
97 (portion-whole (nth 2 end-position))) | |
98 (select-window window) | |
99 (scroll-down | |
1981
bde0ca7e33b3
Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents:
1973
diff
changeset
|
100 (scroll-bar-scale portion-whole (1- (window-height)))))) |
1772 | 101 (select-window old-selected-window)))) |
102 | |
1981
bde0ca7e33b3
Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents:
1973
diff
changeset
|
103 (defun scroll-bar-scroll-up (event) |
bde0ca7e33b3
Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents:
1973
diff
changeset
|
104 "Scroll the line next to the scroll bar click to the top of the window. |
bde0ca7e33b3
Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents:
1973
diff
changeset
|
105 EVENT should be a scroll bar click." |
1772 | 106 (interactive "e") |
107 (let ((old-selected-window (selected-window))) | |
108 (unwind-protect | |
109 (progn | |
1821
04fb1d3d6992
JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents:
1772
diff
changeset
|
110 (let* ((end-position (event-end event)) |
1772 | 111 (window (nth 0 end-position)) |
112 (portion-whole (nth 2 end-position))) | |
113 (select-window window) | |
114 (scroll-up | |
1981
bde0ca7e33b3
Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents:
1973
diff
changeset
|
115 (scroll-bar-scale portion-whole (1- (window-height)))))) |
1772 | 116 (select-window old-selected-window)))) |
117 | |
118 | |
119 ;;;; Bindings. | |
120 | |
121 ;;; For now, we'll set things up to work like xterm. | |
1981
bde0ca7e33b3
Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents:
1973
diff
changeset
|
122 (global-set-key [vertical-scroll-bar mouse-1] 'scroll-bar-scroll-up) |
bde0ca7e33b3
Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents:
1973
diff
changeset
|
123 (global-set-key [vertical-scroll-bar drag-mouse-1] 'scroll-bar-scroll-up) |
1772 | 124 |
1981
bde0ca7e33b3
Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents:
1973
diff
changeset
|
125 (global-set-key [vertical-scroll-bar mouse-2] 'scroll-bar-set-window-start) |
bde0ca7e33b3
Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents:
1973
diff
changeset
|
126 (global-set-key [vertical-scroll-bar drag-mouse-2] 'scroll-bar-set-window-start) |
1772 | 127 |
1981
bde0ca7e33b3
Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents:
1973
diff
changeset
|
128 (global-set-key [vertical-scroll-bar mouse-3] 'scroll-bar-scroll-down) |
bde0ca7e33b3
Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents:
1973
diff
changeset
|
129 (global-set-key [vertical-scroll-bar drag-mouse-3] 'scroll-bar-scroll-down) |
1772 | 130 |
131 | |
1973
3a08dacd8bfb
These are in preparation for a more thorough renaming to occur soon.
Jim Blandy <jimb@redhat.com>
parents:
1954
diff
changeset
|
132 (provide 'scroll-bar) |
1772 | 133 |
1981
bde0ca7e33b3
Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents:
1973
diff
changeset
|
134 ;;; scroll-bar.el ends here |