(comint-filter): Put window-start before the input.
[bpt/emacs.git] / lisp / scroll-bar.el
index a924295..cddce3e 100644 (file)
 
 ;;; Code:
 
+;;; Commentary:
+
+;; Window-system-independent bindings of mouse clicks on the scroll bar.
+;; Presently emulates the scroll-bar behavior of xterm.
+;;; Code:
+
 (require 'mouse)
 
 \f
@@ -42,7 +48,9 @@ that scroll bar position."
 
 \f
 ;;;; Helpful functions for enabling and disabling scroll bars.
-(defvar scroll-bar-mode nil)
+;;; This is not documented because you can't change the 
+;;; mode properly by setting it.
+(defvar scroll-bar-mode t)
 
 (defun scroll-bar-mode (flag)
   "Toggle display of vertical scroll bars on each frame.
@@ -73,6 +81,7 @@ turn off scroll bars; otherwise, turn on scroll bars."
 \f
 ;;;; Buffer navigation using the scroll bar.
 
+;;; This was used for up-events on button 2, but no longer.
 (defun scroll-bar-set-window-start (event)
   "Set the window start according to where the scroll bar is dragged.
 EVENT should be a scroll bar click or drag event."
@@ -87,6 +96,34 @@ EVENT should be a scroll bar click or drag event."
        (beginning-of-line)
        (set-window-start window (point))))))
 
+;; Scroll the window to the proper position for EVENT.
+(defun scroll-bar-drag-1 (event)
+  (let* ((start-position (event-start event))
+        (window (nth 0 start-position))
+        (portion-whole (nth 2 start-position)))
+    (save-excursion
+      (set-buffer (window-buffer window))
+      (goto-char (scroll-bar-scale portion-whole (buffer-size)))
+      (beginning-of-line)
+      (set-window-start window (point)))))
+
+(defun scroll-bar-drag (event)
+  "Scroll the window by dragging the scroll bar slider.
+If you click outside the slider, the window scrolls to bring the slider there."
+  (interactive "e")
+  (let* (done)
+    (scroll-bar-drag-1 event)
+    (track-mouse
+      (while (not done)
+       (setq event (read-event))
+       (if (eq (car-safe event) 'mouse-movement)
+           (setq event (read-event)))
+       (cond ((eq (car-safe event) 'scroll-bar-movement)
+              (scroll-bar-drag-1 event))
+             (t
+              ;; Exit when we get the drag event; ignore that event.
+              (setq done t)))))))
+
 (defun scroll-bar-scroll-down (event)
   "Scroll the window's top line down to the location of the scroll bar click.
 EVENT should be a scroll bar click."
@@ -124,9 +161,8 @@ EVENT should be a scroll bar click."
 (global-set-key [vertical-scroll-bar mouse-1] 'scroll-bar-scroll-up)
 (global-set-key [vertical-scroll-bar drag-mouse-1] 'scroll-bar-scroll-up)
 
-(global-set-key [vertical-scroll-bar mouse-2] 'scroll-bar-set-window-start)
-(global-set-key [vertical-scroll-bar drag-mouse-2] 'scroll-bar-set-window-start)
-      
+(global-set-key [vertical-scroll-bar down-mouse-2] 'scroll-bar-drag)
+
 (global-set-key [vertical-scroll-bar mouse-3] 'scroll-bar-scroll-down)
 (global-set-key [vertical-scroll-bar drag-mouse-3] 'scroll-bar-scroll-down)