Mercurial > emacs
comparison lisp/scroll-bar.el @ 15215:681866822119
(scroll-bar-drag-position): New function.
(scroll-bar-maybe-set-window-start): New function.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sat, 11 May 1996 18:30:16 +0000 |
parents | 83f275dcd93a |
children | 0eb55cad57c6 |
comparison
equal
deleted
inserted
replaced
15214:308abb9a57f4 | 15215:681866822119 |
---|---|
111 (goto-char (+ (point-min) | 111 (goto-char (+ (point-min) |
112 (scroll-bar-scale portion-whole | 112 (scroll-bar-scale portion-whole |
113 (- (point-max) (point-min))))) | 113 (- (point-max) (point-min))))) |
114 (beginning-of-line) | 114 (beginning-of-line) |
115 (set-window-start window (point)))))) | 115 (set-window-start window (point)))))) |
116 | |
117 (defun scroll-bar-drag-position (portion-whole) | |
118 "Calculate new window start for drag event." | |
119 (save-excursion | |
120 (goto-char (+ (point-min) | |
121 (scroll-bar-scale portion-whole | |
122 (- (point-max) (point-min))))) | |
123 (beginning-of-line) | |
124 (point))) | |
125 | |
126 (defun scroll-bar-maybe-set-window-start (event) | |
127 "Set the window start according to where the scroll bar is dragged. | |
128 Only change window start if the new start is substantially different. | |
129 EVENT should be a scroll bar click or drag event." | |
130 (interactive "e") | |
131 (let* ((end-position (event-end event)) | |
132 (window (nth 0 end-position)) | |
133 (portion-whole (nth 2 end-position)) | |
134 (next-portion-whole (cons (1+ (car portion-whole)) | |
135 (cdr portion-whole))) | |
136 portion-start | |
137 next-portion-start | |
138 (current-start (window-start window))) | |
139 (save-excursion | |
140 (set-buffer (window-buffer window)) | |
141 (setq portion-start (scroll-bar-drag-position portion-whole)) | |
142 (setq next-portion-start (max | |
143 (scroll-bar-drag-position next-portion-whole) | |
144 (1+ portion-start))) | |
145 (if (or (> current-start next-portion-start) | |
146 (< current-start portion-start)) | |
147 (set-window-start window portion-start))))) | |
116 | 148 |
117 ;; Scroll the window to the proper position for EVENT. | 149 ;; Scroll the window to the proper position for EVENT. |
118 (defun scroll-bar-drag-1 (event) | 150 (defun scroll-bar-drag-1 (event) |
119 (let* ((start-position (event-start event)) | 151 (let* ((start-position (event-start event)) |
120 (window (nth 0 start-position)) | 152 (window (nth 0 start-position)) |