diff options
| author | Richard M. Stallman | 1996-05-11 18:30:16 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1996-05-11 18:30:16 +0000 |
| commit | aeee66be3b17c883ee754ba733b7c7850b297b7c (patch) | |
| tree | c832a14f35f92f36a369cda72a7ab7e6dbcc3ad4 | |
| parent | 12c11fcd42eb8b8ef14f8b6c090d06d069a9043b (diff) | |
| download | emacs-aeee66be3b17c883ee754ba733b7c7850b297b7c.tar.gz emacs-aeee66be3b17c883ee754ba733b7c7850b297b7c.zip | |
(scroll-bar-drag-position): New function.
(scroll-bar-maybe-set-window-start): New function.
| -rw-r--r-- | lisp/scroll-bar.el | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lisp/scroll-bar.el b/lisp/scroll-bar.el index 07d78e2c985..98b90856574 100644 --- a/lisp/scroll-bar.el +++ b/lisp/scroll-bar.el | |||
| @@ -114,6 +114,38 @@ EVENT should be a scroll bar click or drag event." | |||
| 114 | (beginning-of-line) | 114 | (beginning-of-line) |
| 115 | (set-window-start window (point)))))) | 115 | (set-window-start window (point)))))) |
| 116 | 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))))) | ||
| 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)) |