annotate lisp/scroll-bar.el @ 79119:f17c3647c3fe

* longlines.el (longlines-wrap-follows-window-size): Integer value specifies wrapping margin. (longlines-mode, longlines-window-change-function): Set window-specific wrapping margin based on the above.
author Chong Yidong <cyd@stupidchicken.com>
date Wed, 17 Oct 2007 02:47:28 +0000
parents 9355f9b7bbff
children 73661ddc7ac7 65663fcd2caa f55f9811f5d7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38412
253f761ad37b Some fixes to follow coding conventions in files maintained by FSF.
Pavel Janík <Pavel@Janik.cz>
parents: 36803
diff changeset
1 ;;; scroll-bar.el --- window system-independent scroll bar support
1772
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
2
64762
41bb365f41c4 Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64091
diff changeset
3 ;; Copyright (C) 1993, 1994, 1995, 1999, 2000, 2001, 2002, 2003,
75347
e3694f1cb928 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 74982
diff changeset
4 ;; 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
1772
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
5
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
6 ;; Maintainer: FSF
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
7 ;; Keywords: hardware
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
8
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 12040
diff changeset
9 ;; This file is part of GNU Emacs.
1772
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
10
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 12040
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 12040
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
78236
9355f9b7bbff Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents: 75347
diff changeset
13 ;; the Free Software Foundation; either version 3, or (at your option)
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 12040
diff changeset
14 ;; any later version.
1772
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
15
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 12040
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 12040
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 12040
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 12040
diff changeset
19 ;; GNU General Public License for more details.
1772
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
20
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 12040
diff changeset
21 ;; You should have received a copy of the GNU General Public License
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 12040
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
64091
6fb026ad601f Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 54399
diff changeset
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
6fb026ad601f Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 54399
diff changeset
24 ;; Boston, MA 02110-1301, USA.
2233
fb0ed5a1d0f3 Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2232
diff changeset
25
2315
9e7ec92a4fdf Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2233
diff changeset
26 ;;; Commentary:
9e7ec92a4fdf Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2233
diff changeset
27
9e7ec92a4fdf Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2233
diff changeset
28 ;; Window-system-independent bindings of mouse clicks on the scroll bar.
9e7ec92a4fdf Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2233
diff changeset
29 ;; Presently emulates the scroll-bar behavior of xterm.
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 12040
diff changeset
30
2315
9e7ec92a4fdf Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2233
diff changeset
31 ;;; Code:
9e7ec92a4fdf Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2233
diff changeset
32
1821
04fb1d3d6992 JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents: 1772
diff changeset
33 (require 'mouse)
04fb1d3d6992 JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents: 1772
diff changeset
34
1772
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
35
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
36 ;;;; Utilities.
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
37
7222
3dae5675cd3e (scroll-bar-event-ratio): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4469
diff changeset
38 (defun scroll-bar-event-ratio (event)
3dae5675cd3e (scroll-bar-event-ratio): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4469
diff changeset
39 "Given a scroll bar event EVENT, return the scroll bar position as a ratio.
3dae5675cd3e (scroll-bar-event-ratio): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4469
diff changeset
40 The value is a cons cell (PORTION . WHOLE) containing two integers
3dae5675cd3e (scroll-bar-event-ratio): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4469
diff changeset
41 whose ratio gives the event's vertical position in the scroll bar, with 0
3dae5675cd3e (scroll-bar-event-ratio): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4469
diff changeset
42 referring to the top and 1 to the bottom."
3dae5675cd3e (scroll-bar-event-ratio): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4469
diff changeset
43 (nth 2 event))
3dae5675cd3e (scroll-bar-event-ratio): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4469
diff changeset
44
1981
bde0ca7e33b3 Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents: 1973
diff changeset
45 (defun scroll-bar-scale (num-denom whole)
1772
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
46 "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
47 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
48 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
49 from a scroll bar event, then (scroll-bar-scale SCROLL-BAR-POS
1772
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
50 \(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
51 that scroll bar position."
1772
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
52 ;; We multiply before we divide to maintain precision.
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
53 ;; 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
54 ;; with a large scroll bar portion can easily overflow a lisp int.
1772
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
55 (truncate (/ (* (float (car num-denom)) whole) (cdr num-denom))))
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
56
54399
ad02f6299e9a 2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents: 52558
diff changeset
57 (defun scroll-bar-columns (side)
ad02f6299e9a 2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents: 52558
diff changeset
58 "Return the width, measured in columns, of the vertical scrollbar on SIDE.
ad02f6299e9a 2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents: 52558
diff changeset
59 SIDE must be the symbol `left' or `right'."
ad02f6299e9a 2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents: 52558
diff changeset
60 (let* ((wsb (window-scroll-bars))
ad02f6299e9a 2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents: 52558
diff changeset
61 (vtype (nth 2 wsb))
ad02f6299e9a 2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents: 52558
diff changeset
62 (cols (nth 1 wsb)))
ad02f6299e9a 2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents: 52558
diff changeset
63 (cond
ad02f6299e9a 2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents: 52558
diff changeset
64 ((not (memq side '(left right)))
ad02f6299e9a 2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents: 52558
diff changeset
65 (error "`left' or `right' expected instead of %S" side))
ad02f6299e9a 2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents: 52558
diff changeset
66 ((and (eq vtype side) cols))
ad02f6299e9a 2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents: 52558
diff changeset
67 ((eq (frame-parameter nil 'vertical-scroll-bars) side)
ad02f6299e9a 2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents: 52558
diff changeset
68 ;; nil means it's a non-toolkit scroll bar, and its width in
ad02f6299e9a 2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents: 52558
diff changeset
69 ;; columns is 14 pixels rounded up.
ad02f6299e9a 2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents: 52558
diff changeset
70 (ceiling (or (frame-parameter nil 'scroll-bar-width) 14)
ad02f6299e9a 2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents: 52558
diff changeset
71 (frame-char-width)))
ad02f6299e9a 2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents: 52558
diff changeset
72 (0))))
ad02f6299e9a 2004-03-15 Masatake YAMATO <jet@gyve.org>
Masatake YAMATO <jet@gyve.org>
parents: 52558
diff changeset
73
1772
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
74
1954
059d99d03aae * term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents: 1821
diff changeset
75 ;;;; 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
76
18480
f0c705a82dca (scroll-bar-mode): Extra defvar to avoid warning.
Richard M. Stallman <rms@gnu.org>
parents: 18479
diff changeset
77 (defvar scroll-bar-mode)
74982
3b9c6c0ac744 (previous-scroll-bar-mode): New variable
Jan Djärv <jan.h.d@swipnet.se>
parents: 68651
diff changeset
78 (defvar previous-scroll-bar-mode nil)
18480
f0c705a82dca (scroll-bar-mode): Extra defvar to avoid warning.
Richard M. Stallman <rms@gnu.org>
parents: 18479
diff changeset
79
18891
86c0d896480e (scroll-bar-mode-explicit): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 18480
diff changeset
80 (defvar scroll-bar-mode-explicit nil
86c0d896480e (scroll-bar-mode-explicit): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 18480
diff changeset
81 "Non-nil means `set-scroll-bar-mode' should really do something.
86c0d896480e (scroll-bar-mode-explicit): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 18480
diff changeset
82 This is nil while loading `scroll-bar.el', and t afterward.")
86c0d896480e (scroll-bar-mode-explicit): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 18480
diff changeset
83
20129
a68db1ead5cf (set-scroll-bar-mode): Take just one arg.
Karl Heuer <kwzh@gnu.org>
parents: 20061
diff changeset
84 (defun set-scroll-bar-mode-1 (ignore value)
a68db1ead5cf (set-scroll-bar-mode): Take just one arg.
Karl Heuer <kwzh@gnu.org>
parents: 20061
diff changeset
85 (set-scroll-bar-mode value))
a68db1ead5cf (set-scroll-bar-mode): Take just one arg.
Karl Heuer <kwzh@gnu.org>
parents: 20061
diff changeset
86
a68db1ead5cf (set-scroll-bar-mode): Take just one arg.
Karl Heuer <kwzh@gnu.org>
parents: 20061
diff changeset
87 (defun set-scroll-bar-mode (value)
18479
dedaafd841c0 (toggle-scroll-bar): Moved from frame.el.
Richard M. Stallman <rms@gnu.org>
parents: 15264
diff changeset
88 "Set `scroll-bar-mode' to VALUE and put the new value into effect."
74982
3b9c6c0ac744 (previous-scroll-bar-mode): New variable
Jan Djärv <jan.h.d@swipnet.se>
parents: 68651
diff changeset
89 (if scroll-bar-mode
3b9c6c0ac744 (previous-scroll-bar-mode): New variable
Jan Djärv <jan.h.d@swipnet.se>
parents: 68651
diff changeset
90 (setq previous-scroll-bar-mode scroll-bar-mode))
3b9c6c0ac744 (previous-scroll-bar-mode): New variable
Jan Djärv <jan.h.d@swipnet.se>
parents: 68651
diff changeset
91
18479
dedaafd841c0 (toggle-scroll-bar): Moved from frame.el.
Richard M. Stallman <rms@gnu.org>
parents: 15264
diff changeset
92 (setq scroll-bar-mode value)
dedaafd841c0 (toggle-scroll-bar): Moved from frame.el.
Richard M. Stallman <rms@gnu.org>
parents: 15264
diff changeset
93
18891
86c0d896480e (scroll-bar-mode-explicit): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 18480
diff changeset
94 (when scroll-bar-mode-explicit
86c0d896480e (scroll-bar-mode-explicit): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 18480
diff changeset
95 ;; Apply it to default-frame-alist.
86c0d896480e (scroll-bar-mode-explicit): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 18480
diff changeset
96 (let ((parameter (assq 'vertical-scroll-bars default-frame-alist)))
86c0d896480e (scroll-bar-mode-explicit): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 18480
diff changeset
97 (if (consp parameter)
86c0d896480e (scroll-bar-mode-explicit): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 18480
diff changeset
98 (setcdr parameter scroll-bar-mode)
86c0d896480e (scroll-bar-mode-explicit): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 18480
diff changeset
99 (setq default-frame-alist
86c0d896480e (scroll-bar-mode-explicit): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 18480
diff changeset
100 (cons (cons 'vertical-scroll-bars scroll-bar-mode)
86c0d896480e (scroll-bar-mode-explicit): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 18480
diff changeset
101 default-frame-alist))))
18479
dedaafd841c0 (toggle-scroll-bar): Moved from frame.el.
Richard M. Stallman <rms@gnu.org>
parents: 15264
diff changeset
102
18891
86c0d896480e (scroll-bar-mode-explicit): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 18480
diff changeset
103 ;; Apply it to existing frames.
86c0d896480e (scroll-bar-mode-explicit): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 18480
diff changeset
104 (let ((frames (frame-list)))
86c0d896480e (scroll-bar-mode-explicit): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 18480
diff changeset
105 (while frames
86c0d896480e (scroll-bar-mode-explicit): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 18480
diff changeset
106 (modify-frame-parameters
86c0d896480e (scroll-bar-mode-explicit): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 18480
diff changeset
107 (car frames)
86c0d896480e (scroll-bar-mode-explicit): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 18480
diff changeset
108 (list (cons 'vertical-scroll-bars scroll-bar-mode)))
86c0d896480e (scroll-bar-mode-explicit): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 18480
diff changeset
109 (setq frames (cdr frames))))))
18479
dedaafd841c0 (toggle-scroll-bar): Moved from frame.el.
Richard M. Stallman <rms@gnu.org>
parents: 15264
diff changeset
110
52558
3fb606ea8bf6 (set-scroll-bar-mode): Initialize to new built-in variable
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
111 (defcustom scroll-bar-mode default-frame-scroll-bars
18479
dedaafd841c0 (toggle-scroll-bar): Moved from frame.el.
Richard M. Stallman <rms@gnu.org>
parents: 15264
diff changeset
112 "*Specify whether to have vertical scroll bars, and on which side.
dedaafd841c0 (toggle-scroll-bar): Moved from frame.el.
Richard M. Stallman <rms@gnu.org>
parents: 15264
diff changeset
113 Possible values are nil (no scroll bars), `left' (scroll bars on left)
dedaafd841c0 (toggle-scroll-bar): Moved from frame.el.
Richard M. Stallman <rms@gnu.org>
parents: 15264
diff changeset
114 and `right' (scroll bars on right).
22908
53b018832269 (scroll-bar-mode): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 21734
diff changeset
115 To set this variable in a Lisp program, use `set-scroll-bar-mode'
53b018832269 (scroll-bar-mode): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 21734
diff changeset
116 to make it take real effect.
53b018832269 (scroll-bar-mode): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 21734
diff changeset
117 Setting the variable with a customization buffer also takes effect."
50398
1b58100e624c (scroll-bar-mode): Correctly specify `nil' choice.
Miles Bader <miles@gnu.org>
parents: 49016
diff changeset
118 :type '(choice (const :tag "none (nil)" nil)
18479
dedaafd841c0 (toggle-scroll-bar): Moved from frame.el.
Richard M. Stallman <rms@gnu.org>
parents: 15264
diff changeset
119 (const left)
dedaafd841c0 (toggle-scroll-bar): Moved from frame.el.
Richard M. Stallman <rms@gnu.org>
parents: 15264
diff changeset
120 (const right))
dedaafd841c0 (toggle-scroll-bar): Moved from frame.el.
Richard M. Stallman <rms@gnu.org>
parents: 15264
diff changeset
121 :group 'frames
47494
06a428ab2fcb (scroll-bar-mode): Specify :initialize.
Richard M. Stallman <rms@gnu.org>
parents: 42851
diff changeset
122 ;; The default value for :initialize would try to use :set
06a428ab2fcb (scroll-bar-mode): Specify :initialize.
Richard M. Stallman <rms@gnu.org>
parents: 42851
diff changeset
123 ;; when processing the file in cus-dep.el.
06a428ab2fcb (scroll-bar-mode): Specify :initialize.
Richard M. Stallman <rms@gnu.org>
parents: 42851
diff changeset
124 :initialize 'custom-initialize-default
20129
a68db1ead5cf (set-scroll-bar-mode): Take just one arg.
Karl Heuer <kwzh@gnu.org>
parents: 20061
diff changeset
125 :set 'set-scroll-bar-mode-1)
18479
dedaafd841c0 (toggle-scroll-bar): Moved from frame.el.
Richard M. Stallman <rms@gnu.org>
parents: 15264
diff changeset
126
18891
86c0d896480e (scroll-bar-mode-explicit): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 18480
diff changeset
127 ;; We just set scroll-bar-mode, but that was the default.
86c0d896480e (scroll-bar-mode-explicit): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 18480
diff changeset
128 ;; If it is set again, that is for real.
86c0d896480e (scroll-bar-mode-explicit): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 18480
diff changeset
129 (setq scroll-bar-mode-explicit t)
86c0d896480e (scroll-bar-mode-explicit): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 18480
diff changeset
130
42851
4c0ca26cfc69 (scroll-bar-mode): Make argument optional.
Pavel Janík <Pavel@Janik.cz>
parents: 38412
diff changeset
131 (defun scroll-bar-mode (&optional flag)
18479
dedaafd841c0 (toggle-scroll-bar): Moved from frame.el.
Richard M. Stallman <rms@gnu.org>
parents: 15264
diff changeset
132 "Toggle display of vertical scroll bars on all frames.
1954
059d99d03aae * term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents: 1821
diff changeset
133 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
134 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
135 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
136 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
137 (interactive "P")
3613
f37a9c897699 * scroll-bar.el (scroll-bar-mode): Variable deleted.
Jim Blandy <jimb@redhat.com>
parents: 3588
diff changeset
138
18479
dedaafd841c0 (toggle-scroll-bar): Moved from frame.el.
Richard M. Stallman <rms@gnu.org>
parents: 15264
diff changeset
139 ;; Tweedle the variable according to the argument.
52558
3fb606ea8bf6 (set-scroll-bar-mode): Initialize to new built-in variable
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
140 (set-scroll-bar-mode (if (if (null flag)
3fb606ea8bf6 (set-scroll-bar-mode): Initialize to new built-in variable
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
141 (not scroll-bar-mode)
3fb606ea8bf6 (set-scroll-bar-mode): Initialize to new built-in variable
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
142 (setq flag (prefix-numeric-value flag))
3fb606ea8bf6 (set-scroll-bar-mode): Initialize to new built-in variable
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
143 (or (not (numberp flag)) (>= flag 0)))
74982
3b9c6c0ac744 (previous-scroll-bar-mode): New variable
Jan Djärv <jan.h.d@swipnet.se>
parents: 68651
diff changeset
144 (or previous-scroll-bar-mode
3b9c6c0ac744 (previous-scroll-bar-mode): New variable
Jan Djärv <jan.h.d@swipnet.se>
parents: 68651
diff changeset
145 default-frame-scroll-bars))))
3613
f37a9c897699 * scroll-bar.el (scroll-bar-mode): Variable deleted.
Jim Blandy <jimb@redhat.com>
parents: 3588
diff changeset
146
18479
dedaafd841c0 (toggle-scroll-bar): Moved from frame.el.
Richard M. Stallman <rms@gnu.org>
parents: 15264
diff changeset
147 (defun toggle-scroll-bar (arg)
dedaafd841c0 (toggle-scroll-bar): Moved from frame.el.
Richard M. Stallman <rms@gnu.org>
parents: 15264
diff changeset
148 "Toggle whether or not the selected frame has vertical scroll bars.
dedaafd841c0 (toggle-scroll-bar): Moved from frame.el.
Richard M. Stallman <rms@gnu.org>
parents: 15264
diff changeset
149 With arg, turn vertical scroll bars on if and only if arg is positive.
dedaafd841c0 (toggle-scroll-bar): Moved from frame.el.
Richard M. Stallman <rms@gnu.org>
parents: 15264
diff changeset
150 The variable `scroll-bar-mode' controls which side the scroll bars are on
dedaafd841c0 (toggle-scroll-bar): Moved from frame.el.
Richard M. Stallman <rms@gnu.org>
parents: 15264
diff changeset
151 when they are turned on; if it is nil, they go on the left."
dedaafd841c0 (toggle-scroll-bar): Moved from frame.el.
Richard M. Stallman <rms@gnu.org>
parents: 15264
diff changeset
152 (interactive "P")
dedaafd841c0 (toggle-scroll-bar): Moved from frame.el.
Richard M. Stallman <rms@gnu.org>
parents: 15264
diff changeset
153 (if (null arg)
dedaafd841c0 (toggle-scroll-bar): Moved from frame.el.
Richard M. Stallman <rms@gnu.org>
parents: 15264
diff changeset
154 (setq arg
dedaafd841c0 (toggle-scroll-bar): Moved from frame.el.
Richard M. Stallman <rms@gnu.org>
parents: 15264
diff changeset
155 (if (cdr (assq 'vertical-scroll-bars
dedaafd841c0 (toggle-scroll-bar): Moved from frame.el.
Richard M. Stallman <rms@gnu.org>
parents: 15264
diff changeset
156 (frame-parameters (selected-frame))))
20061
fb0d3082b28c (toggle-scroll-bar): Call prefix-numeric-value.
Karl Heuer <kwzh@gnu.org>
parents: 19683
diff changeset
157 -1 1))
fb0d3082b28c (toggle-scroll-bar): Call prefix-numeric-value.
Karl Heuer <kwzh@gnu.org>
parents: 19683
diff changeset
158 (setq arg (prefix-numeric-value arg)))
21734
807f4e7fa560 (scroll-bar-mode, toggle-scroll-bar): By default,
Geoff Voelker <voelker@cs.washington.edu>
parents: 21427
diff changeset
159 (modify-frame-parameters
807f4e7fa560 (scroll-bar-mode, toggle-scroll-bar): By default,
Geoff Voelker <voelker@cs.washington.edu>
parents: 21427
diff changeset
160 (selected-frame)
807f4e7fa560 (scroll-bar-mode, toggle-scroll-bar): By default,
Geoff Voelker <voelker@cs.washington.edu>
parents: 21427
diff changeset
161 (list (cons 'vertical-scroll-bars
807f4e7fa560 (scroll-bar-mode, toggle-scroll-bar): By default,
Geoff Voelker <voelker@cs.washington.edu>
parents: 21427
diff changeset
162 (if (> arg 0)
52558
3fb606ea8bf6 (set-scroll-bar-mode): Initialize to new built-in variable
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
163 (or scroll-bar-mode default-frame-scroll-bars))))))
3613
f37a9c897699 * scroll-bar.el (scroll-bar-mode): Variable deleted.
Jim Blandy <jimb@redhat.com>
parents: 3588
diff changeset
164
18479
dedaafd841c0 (toggle-scroll-bar): Moved from frame.el.
Richard M. Stallman <rms@gnu.org>
parents: 15264
diff changeset
165 (defun toggle-horizontal-scroll-bar (arg)
dedaafd841c0 (toggle-scroll-bar): Moved from frame.el.
Richard M. Stallman <rms@gnu.org>
parents: 15264
diff changeset
166 "Toggle whether or not the selected frame has horizontal scroll bars.
dedaafd841c0 (toggle-scroll-bar): Moved from frame.el.
Richard M. Stallman <rms@gnu.org>
parents: 15264
diff changeset
167 With arg, turn horizontal scroll bars on if and only if arg is positive.
dedaafd841c0 (toggle-scroll-bar): Moved from frame.el.
Richard M. Stallman <rms@gnu.org>
parents: 15264
diff changeset
168 Horizontal scroll bars aren't implemented yet."
dedaafd841c0 (toggle-scroll-bar): Moved from frame.el.
Richard M. Stallman <rms@gnu.org>
parents: 15264
diff changeset
169 (interactive "P")
dedaafd841c0 (toggle-scroll-bar): Moved from frame.el.
Richard M. Stallman <rms@gnu.org>
parents: 15264
diff changeset
170 (error "Horizontal scroll bars aren't implemented yet"))
1954
059d99d03aae * term/x-win.el (scroll-bar-mode, scroll-bar-mode): Move these
Jim Blandy <jimb@redhat.com>
parents: 1821
diff changeset
171
1981
bde0ca7e33b3 Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents: 1973
diff changeset
172 ;;;; Buffer navigation using the scroll bar.
1772
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
173
2698
6940c6b5d988 (scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
174 ;;; This was used for up-events on button 2, but no longer.
1981
bde0ca7e33b3 Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents: 1973
diff changeset
175 (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
176 "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
177 EVENT should be a scroll bar click or drag event."
1772
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
178 (interactive "e")
1821
04fb1d3d6992 JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents: 1772
diff changeset
179 (let* ((end-position (event-end event))
1772
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
180 (window (nth 0 end-position))
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
181 (portion-whole (nth 2 end-position)))
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
182 (save-excursion
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
183 (set-buffer (window-buffer window))
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
184 (save-excursion
3588
9685f1d5545b * scroll-bar.el (scroll-bar-set-window-start): Remember that the
Jim Blandy <jimb@redhat.com>
parents: 3508
diff changeset
185 (goto-char (+ (point-min)
9685f1d5545b * scroll-bar.el (scroll-bar-set-window-start): Remember that the
Jim Blandy <jimb@redhat.com>
parents: 3508
diff changeset
186 (scroll-bar-scale portion-whole
9685f1d5545b * scroll-bar.el (scroll-bar-set-window-start): Remember that the
Jim Blandy <jimb@redhat.com>
parents: 3508
diff changeset
187 (- (point-max) (point-min)))))
1772
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
188 (beginning-of-line)
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
189 (set-window-start window (point))))))
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
190
15215
681866822119 (scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
191 (defun scroll-bar-drag-position (portion-whole)
681866822119 (scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
192 "Calculate new window start for drag event."
681866822119 (scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
193 (save-excursion
681866822119 (scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
194 (goto-char (+ (point-min)
681866822119 (scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
195 (scroll-bar-scale portion-whole
681866822119 (scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
196 (- (point-max) (point-min)))))
681866822119 (scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
197 (beginning-of-line)
681866822119 (scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
198 (point)))
681866822119 (scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
199
681866822119 (scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
200 (defun scroll-bar-maybe-set-window-start (event)
681866822119 (scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
201 "Set the window start according to where the scroll bar is dragged.
681866822119 (scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
202 Only change window start if the new start is substantially different.
681866822119 (scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
203 EVENT should be a scroll bar click or drag event."
681866822119 (scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
204 (interactive "e")
681866822119 (scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
205 (let* ((end-position (event-end event))
681866822119 (scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
206 (window (nth 0 end-position))
681866822119 (scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
207 (portion-whole (nth 2 end-position))
681866822119 (scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
208 (next-portion-whole (cons (1+ (car portion-whole))
681866822119 (scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
209 (cdr portion-whole)))
681866822119 (scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
210 portion-start
681866822119 (scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
211 next-portion-start
681866822119 (scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
212 (current-start (window-start window)))
681866822119 (scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
213 (save-excursion
681866822119 (scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
214 (set-buffer (window-buffer window))
681866822119 (scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
215 (setq portion-start (scroll-bar-drag-position portion-whole))
681866822119 (scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
216 (setq next-portion-start (max
681866822119 (scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
217 (scroll-bar-drag-position next-portion-whole)
681866822119 (scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
218 (1+ portion-start)))
19683
af32e336d12c (scroll-bar-maybe-set-window-start): Change window
Geoff Voelker <voelker@cs.washington.edu>
parents: 18891
diff changeset
219 (if (or (>= current-start next-portion-start)
15215
681866822119 (scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
220 (< current-start portion-start))
15264
0eb55cad57c6 (scroll-bar-maybe-set-window-start): Always set
Karl Heuer <kwzh@gnu.org>
parents: 15215
diff changeset
221 (set-window-start window portion-start)
0eb55cad57c6 (scroll-bar-maybe-set-window-start): Always set
Karl Heuer <kwzh@gnu.org>
parents: 15215
diff changeset
222 ;; Always set window start, to ensure scroll bar position is updated.
0eb55cad57c6 (scroll-bar-maybe-set-window-start): Always set
Karl Heuer <kwzh@gnu.org>
parents: 15215
diff changeset
223 (set-window-start window current-start)))))
15215
681866822119 (scroll-bar-drag-position): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
224
2698
6940c6b5d988 (scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
225 ;; Scroll the window to the proper position for EVENT.
6940c6b5d988 (scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
226 (defun scroll-bar-drag-1 (event)
6940c6b5d988 (scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
227 (let* ((start-position (event-start event))
6940c6b5d988 (scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
228 (window (nth 0 start-position))
6940c6b5d988 (scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
229 (portion-whole (nth 2 start-position)))
6940c6b5d988 (scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
230 (save-excursion
6940c6b5d988 (scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
231 (set-buffer (window-buffer window))
3508
dea00c8a47a6 (scroll-bar-drag-1):
Richard M. Stallman <rms@gnu.org>
parents: 3129
diff changeset
232 ;; Calculate position relative to the accessible part of the buffer.
dea00c8a47a6 (scroll-bar-drag-1):
Richard M. Stallman <rms@gnu.org>
parents: 3129
diff changeset
233 (goto-char (+ (point-min)
dea00c8a47a6 (scroll-bar-drag-1):
Richard M. Stallman <rms@gnu.org>
parents: 3129
diff changeset
234 (scroll-bar-scale portion-whole
dea00c8a47a6 (scroll-bar-drag-1):
Richard M. Stallman <rms@gnu.org>
parents: 3129
diff changeset
235 (- (point-max) (point-min)))))
50717
318f8d4ecf5a (scroll-bar-drag-1): Replace beginning-of-line with vertical-motion.
Juanma Barranquero <lekktu@gmail.com>
parents: 50398
diff changeset
236 (vertical-motion 0 window)
2698
6940c6b5d988 (scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
237 (set-window-start window (point)))))
6940c6b5d988 (scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
238
6940c6b5d988 (scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
239 (defun scroll-bar-drag (event)
6940c6b5d988 (scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
240 "Scroll the window by dragging the scroll bar slider.
6940c6b5d988 (scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
241 If you click outside the slider, the window scrolls to bring the slider there."
6940c6b5d988 (scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
242 (interactive "e")
11145
fb77829412af (scroll-bar-drag): Bind echo-keystrokes to 0.
Richard M. Stallman <rms@gnu.org>
parents: 10555
diff changeset
243 (let* (done
21427
b5a5ac474741 (scroll-bar-drag): Set point-before-scroll
Richard M. Stallman <rms@gnu.org>
parents: 20129
diff changeset
244 (echo-keystrokes 0)
b5a5ac474741 (scroll-bar-drag): Set point-before-scroll
Richard M. Stallman <rms@gnu.org>
parents: 20129
diff changeset
245 (end-position (event-end event))
b5a5ac474741 (scroll-bar-drag): Set point-before-scroll
Richard M. Stallman <rms@gnu.org>
parents: 20129
diff changeset
246 (window (nth 0 end-position))
b5a5ac474741 (scroll-bar-drag): Set point-before-scroll
Richard M. Stallman <rms@gnu.org>
parents: 20129
diff changeset
247 (before-scroll))
b5a5ac474741 (scroll-bar-drag): Set point-before-scroll
Richard M. Stallman <rms@gnu.org>
parents: 20129
diff changeset
248 (with-current-buffer (window-buffer window)
b5a5ac474741 (scroll-bar-drag): Set point-before-scroll
Richard M. Stallman <rms@gnu.org>
parents: 20129
diff changeset
249 (setq before-scroll point-before-scroll))
b5a5ac474741 (scroll-bar-drag): Set point-before-scroll
Richard M. Stallman <rms@gnu.org>
parents: 20129
diff changeset
250 (save-selected-window
b5a5ac474741 (scroll-bar-drag): Set point-before-scroll
Richard M. Stallman <rms@gnu.org>
parents: 20129
diff changeset
251 (select-window window)
b5a5ac474741 (scroll-bar-drag): Set point-before-scroll
Richard M. Stallman <rms@gnu.org>
parents: 20129
diff changeset
252 (setq before-scroll
b5a5ac474741 (scroll-bar-drag): Set point-before-scroll
Richard M. Stallman <rms@gnu.org>
parents: 20129
diff changeset
253 (or before-scroll (point))))
b5a5ac474741 (scroll-bar-drag): Set point-before-scroll
Richard M. Stallman <rms@gnu.org>
parents: 20129
diff changeset
254 (scroll-bar-drag-1 event)
b5a5ac474741 (scroll-bar-drag): Set point-before-scroll
Richard M. Stallman <rms@gnu.org>
parents: 20129
diff changeset
255 (track-mouse
b5a5ac474741 (scroll-bar-drag): Set point-before-scroll
Richard M. Stallman <rms@gnu.org>
parents: 20129
diff changeset
256 (while (not done)
b5a5ac474741 (scroll-bar-drag): Set point-before-scroll
Richard M. Stallman <rms@gnu.org>
parents: 20129
diff changeset
257 (setq event (read-event))
b5a5ac474741 (scroll-bar-drag): Set point-before-scroll
Richard M. Stallman <rms@gnu.org>
parents: 20129
diff changeset
258 (if (eq (car-safe event) 'mouse-movement)
b5a5ac474741 (scroll-bar-drag): Set point-before-scroll
Richard M. Stallman <rms@gnu.org>
parents: 20129
diff changeset
259 (setq event (read-event)))
b5a5ac474741 (scroll-bar-drag): Set point-before-scroll
Richard M. Stallman <rms@gnu.org>
parents: 20129
diff changeset
260 (cond ((eq (car-safe event) 'scroll-bar-movement)
b5a5ac474741 (scroll-bar-drag): Set point-before-scroll
Richard M. Stallman <rms@gnu.org>
parents: 20129
diff changeset
261 (scroll-bar-drag-1 event))
b5a5ac474741 (scroll-bar-drag): Set point-before-scroll
Richard M. Stallman <rms@gnu.org>
parents: 20129
diff changeset
262 (t
b5a5ac474741 (scroll-bar-drag): Set point-before-scroll
Richard M. Stallman <rms@gnu.org>
parents: 20129
diff changeset
263 ;; Exit when we get the drag event; ignore that event.
b5a5ac474741 (scroll-bar-drag): Set point-before-scroll
Richard M. Stallman <rms@gnu.org>
parents: 20129
diff changeset
264 (setq done t)))))
b5a5ac474741 (scroll-bar-drag): Set point-before-scroll
Richard M. Stallman <rms@gnu.org>
parents: 20129
diff changeset
265 (sit-for 0)
b5a5ac474741 (scroll-bar-drag): Set point-before-scroll
Richard M. Stallman <rms@gnu.org>
parents: 20129
diff changeset
266 (with-current-buffer (window-buffer window)
b5a5ac474741 (scroll-bar-drag): Set point-before-scroll
Richard M. Stallman <rms@gnu.org>
parents: 20129
diff changeset
267 (setq point-before-scroll before-scroll))))
2698
6940c6b5d988 (scroll-bar-drag, scroll-bar-drag-1): New functions.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
268
1981
bde0ca7e33b3 Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents: 1973
diff changeset
269 (defun scroll-bar-scroll-down (event)
bde0ca7e33b3 Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents: 1973
diff changeset
270 "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
271 EVENT should be a scroll bar click."
1772
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
272 (interactive "e")
21427
b5a5ac474741 (scroll-bar-drag): Set point-before-scroll
Richard M. Stallman <rms@gnu.org>
parents: 20129
diff changeset
273 (let* ((end-position (event-end event))
b5a5ac474741 (scroll-bar-drag): Set point-before-scroll
Richard M. Stallman <rms@gnu.org>
parents: 20129
diff changeset
274 (window (nth 0 end-position))
b5a5ac474741 (scroll-bar-drag): Set point-before-scroll
Richard M. Stallman <rms@gnu.org>
parents: 20129
diff changeset
275 (before-scroll))
b5a5ac474741 (scroll-bar-drag): Set point-before-scroll
Richard M. Stallman <rms@gnu.org>
parents: 20129
diff changeset
276 (with-current-buffer (window-buffer window)
b5a5ac474741 (scroll-bar-drag): Set point-before-scroll
Richard M. Stallman <rms@gnu.org>
parents: 20129
diff changeset
277 (setq before-scroll point-before-scroll))
23248
6119bb0ddd69 (scroll-bar-scroll-down, scroll-bar-scroll-up):
Karl Heuer <kwzh@gnu.org>
parents: 22908
diff changeset
278 (unwind-protect
6119bb0ddd69 (scroll-bar-scroll-down, scroll-bar-scroll-up):
Karl Heuer <kwzh@gnu.org>
parents: 22908
diff changeset
279 (save-selected-window
6119bb0ddd69 (scroll-bar-scroll-down, scroll-bar-scroll-up):
Karl Heuer <kwzh@gnu.org>
parents: 22908
diff changeset
280 (let ((portion-whole (nth 2 end-position)))
6119bb0ddd69 (scroll-bar-scroll-down, scroll-bar-scroll-up):
Karl Heuer <kwzh@gnu.org>
parents: 22908
diff changeset
281 (select-window window)
6119bb0ddd69 (scroll-bar-scroll-down, scroll-bar-scroll-up):
Karl Heuer <kwzh@gnu.org>
parents: 22908
diff changeset
282 (setq before-scroll
6119bb0ddd69 (scroll-bar-scroll-down, scroll-bar-scroll-up):
Karl Heuer <kwzh@gnu.org>
parents: 22908
diff changeset
283 (or before-scroll (point)))
6119bb0ddd69 (scroll-bar-scroll-down, scroll-bar-scroll-up):
Karl Heuer <kwzh@gnu.org>
parents: 22908
diff changeset
284 (scroll-down
6119bb0ddd69 (scroll-bar-scroll-down, scroll-bar-scroll-up):
Karl Heuer <kwzh@gnu.org>
parents: 22908
diff changeset
285 (scroll-bar-scale portion-whole (1- (window-height)))))
6119bb0ddd69 (scroll-bar-scroll-down, scroll-bar-scroll-up):
Karl Heuer <kwzh@gnu.org>
parents: 22908
diff changeset
286 (sit-for 0))
6119bb0ddd69 (scroll-bar-scroll-down, scroll-bar-scroll-up):
Karl Heuer <kwzh@gnu.org>
parents: 22908
diff changeset
287 (with-current-buffer (window-buffer window)
6119bb0ddd69 (scroll-bar-scroll-down, scroll-bar-scroll-up):
Karl Heuer <kwzh@gnu.org>
parents: 22908
diff changeset
288 (setq point-before-scroll before-scroll)))))
1772
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
289
1981
bde0ca7e33b3 Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents: 1973
diff changeset
290 (defun scroll-bar-scroll-up (event)
bde0ca7e33b3 Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents: 1973
diff changeset
291 "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
292 EVENT should be a scroll bar click."
1772
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
293 (interactive "e")
21427
b5a5ac474741 (scroll-bar-drag): Set point-before-scroll
Richard M. Stallman <rms@gnu.org>
parents: 20129
diff changeset
294 (let* ((end-position (event-end event))
b5a5ac474741 (scroll-bar-drag): Set point-before-scroll
Richard M. Stallman <rms@gnu.org>
parents: 20129
diff changeset
295 (window (nth 0 end-position))
b5a5ac474741 (scroll-bar-drag): Set point-before-scroll
Richard M. Stallman <rms@gnu.org>
parents: 20129
diff changeset
296 (before-scroll))
b5a5ac474741 (scroll-bar-drag): Set point-before-scroll
Richard M. Stallman <rms@gnu.org>
parents: 20129
diff changeset
297 (with-current-buffer (window-buffer window)
b5a5ac474741 (scroll-bar-drag): Set point-before-scroll
Richard M. Stallman <rms@gnu.org>
parents: 20129
diff changeset
298 (setq before-scroll point-before-scroll))
23248
6119bb0ddd69 (scroll-bar-scroll-down, scroll-bar-scroll-up):
Karl Heuer <kwzh@gnu.org>
parents: 22908
diff changeset
299 (unwind-protect
6119bb0ddd69 (scroll-bar-scroll-down, scroll-bar-scroll-up):
Karl Heuer <kwzh@gnu.org>
parents: 22908
diff changeset
300 (save-selected-window
6119bb0ddd69 (scroll-bar-scroll-down, scroll-bar-scroll-up):
Karl Heuer <kwzh@gnu.org>
parents: 22908
diff changeset
301 (let ((portion-whole (nth 2 end-position)))
6119bb0ddd69 (scroll-bar-scroll-down, scroll-bar-scroll-up):
Karl Heuer <kwzh@gnu.org>
parents: 22908
diff changeset
302 (select-window window)
6119bb0ddd69 (scroll-bar-scroll-down, scroll-bar-scroll-up):
Karl Heuer <kwzh@gnu.org>
parents: 22908
diff changeset
303 (setq before-scroll
6119bb0ddd69 (scroll-bar-scroll-down, scroll-bar-scroll-up):
Karl Heuer <kwzh@gnu.org>
parents: 22908
diff changeset
304 (or before-scroll (point)))
6119bb0ddd69 (scroll-bar-scroll-down, scroll-bar-scroll-up):
Karl Heuer <kwzh@gnu.org>
parents: 22908
diff changeset
305 (scroll-up
6119bb0ddd69 (scroll-bar-scroll-down, scroll-bar-scroll-up):
Karl Heuer <kwzh@gnu.org>
parents: 22908
diff changeset
306 (scroll-bar-scale portion-whole (1- (window-height)))))
6119bb0ddd69 (scroll-bar-scroll-down, scroll-bar-scroll-up):
Karl Heuer <kwzh@gnu.org>
parents: 22908
diff changeset
307 (sit-for 0))
6119bb0ddd69 (scroll-bar-scroll-down, scroll-bar-scroll-up):
Karl Heuer <kwzh@gnu.org>
parents: 22908
diff changeset
308 (with-current-buffer (window-buffer window)
6119bb0ddd69 (scroll-bar-scroll-down, scroll-bar-scroll-up):
Karl Heuer <kwzh@gnu.org>
parents: 22908
diff changeset
309 (setq point-before-scroll before-scroll)))))
1772
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
310
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
311
24981
55c4349025cb (scroll-bar-timer): New.
Gerd Moellmann <gerd@gnu.org>
parents: 23248
diff changeset
312 ;;; Tookit scroll bars.
55c4349025cb (scroll-bar-timer): New.
Gerd Moellmann <gerd@gnu.org>
parents: 23248
diff changeset
313
55c4349025cb (scroll-bar-timer): New.
Gerd Moellmann <gerd@gnu.org>
parents: 23248
diff changeset
314 (defun scroll-bar-toolkit-scroll (event)
55c4349025cb (scroll-bar-timer): New.
Gerd Moellmann <gerd@gnu.org>
parents: 23248
diff changeset
315 (interactive "e")
55c4349025cb (scroll-bar-timer): New.
Gerd Moellmann <gerd@gnu.org>
parents: 23248
diff changeset
316 (let* ((end-position (event-end event))
55c4349025cb (scroll-bar-timer): New.
Gerd Moellmann <gerd@gnu.org>
parents: 23248
diff changeset
317 (window (nth 0 end-position))
55c4349025cb (scroll-bar-timer): New.
Gerd Moellmann <gerd@gnu.org>
parents: 23248
diff changeset
318 (part (nth 4 end-position))
55c4349025cb (scroll-bar-timer): New.
Gerd Moellmann <gerd@gnu.org>
parents: 23248
diff changeset
319 before-scroll)
27421
34b81c946198 (scroll-bar-timer): Variable removed.
Gerd Moellmann <gerd@gnu.org>
parents: 26510
diff changeset
320 (cond ((eq part 'end-scroll))
24981
55c4349025cb (scroll-bar-timer): New.
Gerd Moellmann <gerd@gnu.org>
parents: 23248
diff changeset
321 (t
55c4349025cb (scroll-bar-timer): New.
Gerd Moellmann <gerd@gnu.org>
parents: 23248
diff changeset
322 (with-current-buffer (window-buffer window)
55c4349025cb (scroll-bar-timer): New.
Gerd Moellmann <gerd@gnu.org>
parents: 23248
diff changeset
323 (setq before-scroll point-before-scroll))
55c4349025cb (scroll-bar-timer): New.
Gerd Moellmann <gerd@gnu.org>
parents: 23248
diff changeset
324 (save-selected-window
55c4349025cb (scroll-bar-timer): New.
Gerd Moellmann <gerd@gnu.org>
parents: 23248
diff changeset
325 (select-window window)
55c4349025cb (scroll-bar-timer): New.
Gerd Moellmann <gerd@gnu.org>
parents: 23248
diff changeset
326 (setq before-scroll (or before-scroll (point)))
55c4349025cb (scroll-bar-timer): New.
Gerd Moellmann <gerd@gnu.org>
parents: 23248
diff changeset
327 (cond ((eq part 'above-handle)
55c4349025cb (scroll-bar-timer): New.
Gerd Moellmann <gerd@gnu.org>
parents: 23248
diff changeset
328 (scroll-up '-))
55c4349025cb (scroll-bar-timer): New.
Gerd Moellmann <gerd@gnu.org>
parents: 23248
diff changeset
329 ((eq part 'below-handle)
55c4349025cb (scroll-bar-timer): New.
Gerd Moellmann <gerd@gnu.org>
parents: 23248
diff changeset
330 (scroll-up nil))
26510
6866d2a9a421 (scroll-bar-toolkit-scroll): add handling of the `ratio'
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 24981
diff changeset
331 ((eq part 'ratio)
6866d2a9a421 (scroll-bar-toolkit-scroll): add handling of the `ratio'
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 24981
diff changeset
332 (let* ((portion-whole (nth 2 end-position))
6866d2a9a421 (scroll-bar-toolkit-scroll): add handling of the `ratio'
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 24981
diff changeset
333 (lines (scroll-bar-scale portion-whole
6866d2a9a421 (scroll-bar-toolkit-scroll): add handling of the `ratio'
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 24981
diff changeset
334 (1- (window-height)))))
6866d2a9a421 (scroll-bar-toolkit-scroll): add handling of the `ratio'
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 24981
diff changeset
335 (scroll-up (cond ((not (zerop lines)) lines)
6866d2a9a421 (scroll-bar-toolkit-scroll): add handling of the `ratio'
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 24981
diff changeset
336 ((< (car portion-whole) 0) -1)
6866d2a9a421 (scroll-bar-toolkit-scroll): add handling of the `ratio'
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 24981
diff changeset
337 (t 1)))))
24981
55c4349025cb (scroll-bar-timer): New.
Gerd Moellmann <gerd@gnu.org>
parents: 23248
diff changeset
338 ((eq part 'up)
55c4349025cb (scroll-bar-timer): New.
Gerd Moellmann <gerd@gnu.org>
parents: 23248
diff changeset
339 (scroll-up -1))
55c4349025cb (scroll-bar-timer): New.
Gerd Moellmann <gerd@gnu.org>
parents: 23248
diff changeset
340 ((eq part 'down)
55c4349025cb (scroll-bar-timer): New.
Gerd Moellmann <gerd@gnu.org>
parents: 23248
diff changeset
341 (scroll-up 1))
55c4349025cb (scroll-bar-timer): New.
Gerd Moellmann <gerd@gnu.org>
parents: 23248
diff changeset
342 ((eq part 'top)
55c4349025cb (scroll-bar-timer): New.
Gerd Moellmann <gerd@gnu.org>
parents: 23248
diff changeset
343 (set-window-start window (point-min)))
55c4349025cb (scroll-bar-timer): New.
Gerd Moellmann <gerd@gnu.org>
parents: 23248
diff changeset
344 ((eq part 'bottom)
55c4349025cb (scroll-bar-timer): New.
Gerd Moellmann <gerd@gnu.org>
parents: 23248
diff changeset
345 (goto-char (point-max))
55c4349025cb (scroll-bar-timer): New.
Gerd Moellmann <gerd@gnu.org>
parents: 23248
diff changeset
346 (recenter))
55c4349025cb (scroll-bar-timer): New.
Gerd Moellmann <gerd@gnu.org>
parents: 23248
diff changeset
347 ((eq part 'handle)
55c4349025cb (scroll-bar-timer): New.
Gerd Moellmann <gerd@gnu.org>
parents: 23248
diff changeset
348 (scroll-bar-drag-1 event))))
55c4349025cb (scroll-bar-timer): New.
Gerd Moellmann <gerd@gnu.org>
parents: 23248
diff changeset
349 (sit-for 0)
55c4349025cb (scroll-bar-timer): New.
Gerd Moellmann <gerd@gnu.org>
parents: 23248
diff changeset
350 (with-current-buffer (window-buffer window)
55c4349025cb (scroll-bar-timer): New.
Gerd Moellmann <gerd@gnu.org>
parents: 23248
diff changeset
351 (setq point-before-scroll before-scroll))))))
55c4349025cb (scroll-bar-timer): New.
Gerd Moellmann <gerd@gnu.org>
parents: 23248
diff changeset
352
55c4349025cb (scroll-bar-timer): New.
Gerd Moellmann <gerd@gnu.org>
parents: 23248
diff changeset
353
55c4349025cb (scroll-bar-timer): New.
Gerd Moellmann <gerd@gnu.org>
parents: 23248
diff changeset
354
1772
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
355 ;;;; Bindings.
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
356
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
357 ;;; For now, we'll set things up to work like xterm.
36803
4b1f1bdaf676 (toplevel): Test if `x-toolkit-scroll-bars' is
Gerd Moellmann <gerd@gnu.org>
parents: 34871
diff changeset
358 (cond ((and (boundp 'x-toolkit-scroll-bars) x-toolkit-scroll-bars)
24981
55c4349025cb (scroll-bar-timer): New.
Gerd Moellmann <gerd@gnu.org>
parents: 23248
diff changeset
359 (global-set-key [vertical-scroll-bar mouse-1]
55c4349025cb (scroll-bar-timer): New.
Gerd Moellmann <gerd@gnu.org>
parents: 23248
diff changeset
360 'scroll-bar-toolkit-scroll))
55c4349025cb (scroll-bar-timer): New.
Gerd Moellmann <gerd@gnu.org>
parents: 23248
diff changeset
361 (t
55c4349025cb (scroll-bar-timer): New.
Gerd Moellmann <gerd@gnu.org>
parents: 23248
diff changeset
362 (global-set-key [vertical-scroll-bar mouse-1]
55c4349025cb (scroll-bar-timer): New.
Gerd Moellmann <gerd@gnu.org>
parents: 23248
diff changeset
363 'scroll-bar-scroll-up)
55c4349025cb (scroll-bar-timer): New.
Gerd Moellmann <gerd@gnu.org>
parents: 23248
diff changeset
364 (global-set-key [vertical-scroll-bar drag-mouse-1]
55c4349025cb (scroll-bar-timer): New.
Gerd Moellmann <gerd@gnu.org>
parents: 23248
diff changeset
365 'scroll-bar-scroll-up)
55c4349025cb (scroll-bar-timer): New.
Gerd Moellmann <gerd@gnu.org>
parents: 23248
diff changeset
366 (global-set-key [vertical-scroll-bar down-mouse-2]
55c4349025cb (scroll-bar-timer): New.
Gerd Moellmann <gerd@gnu.org>
parents: 23248
diff changeset
367 'scroll-bar-drag)
55c4349025cb (scroll-bar-timer): New.
Gerd Moellmann <gerd@gnu.org>
parents: 23248
diff changeset
368 (global-set-key [vertical-scroll-bar mouse-3]
55c4349025cb (scroll-bar-timer): New.
Gerd Moellmann <gerd@gnu.org>
parents: 23248
diff changeset
369 'scroll-bar-scroll-down)
55c4349025cb (scroll-bar-timer): New.
Gerd Moellmann <gerd@gnu.org>
parents: 23248
diff changeset
370 (global-set-key [vertical-scroll-bar drag-mouse-3]
55c4349025cb (scroll-bar-timer): New.
Gerd Moellmann <gerd@gnu.org>
parents: 23248
diff changeset
371 'scroll-bar-scroll-down)))
1772
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
372
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
373
1973
3a08dacd8bfb These are in preparation for a more thorough renaming to occur soon.
Jim Blandy <jimb@redhat.com>
parents: 1954
diff changeset
374 (provide 'scroll-bar)
1772
86f58433c8aa * scrollbar.el: New file.
Jim Blandy <jimb@redhat.com>
parents: 1768
diff changeset
375
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 50717
diff changeset
376 ;;; arch-tag: 6f1d01d0-0b1e-4bf8-86db-d491e0f399f3
1981
bde0ca7e33b3 Use the term `scroll bar', instead of `scrollbar'.
Jim Blandy <jimb@redhat.com>
parents: 1973
diff changeset
377 ;;; scroll-bar.el ends here