Function: mouse-drag-throw
mouse-drag-throw is an autoloaded, interactive and byte-compiled
function defined in mouse-drag.el.gz.
Signature
(mouse-drag-throw START-EVENT)
Documentation
"Throw" the page according to a mouse drag.
A "throw" is scrolling the page at a speed relative to the distance from the original mouse click to the current mouse location. Try it; you'll like it. It's easier to observe than to explain.
If the mouse is clicked and released in the same place of time we assume that the user didn't want to scroll but wanted to whatever mouse-2 used to do, so we pass it through.
Throw scrolling was inspired (but is not identical to) the "hand" option in MacPaint, or the middle button in Tk text widgets.
If mouse-throw-with-scroll-bar is non-nil, then this command scrolls
in the opposite direction. (Different people have different ideas
about which direction is natural. Perhaps it has to do with which
hemisphere you're in.)
To test this function, evaluate:
(keymap-global-set "<down-mouse-2>" 'mouse-drag-throw)
Probably introduced at or before Emacs version 20.1.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/mouse-drag.el.gz
;;;###autoload
(defun mouse-drag-throw (start-event)
"\"Throw\" the page according to a mouse drag.
A \"throw\" is scrolling the page at a speed relative to the distance
from the original mouse click to the current mouse location. Try it;
you'll like it. It's easier to observe than to explain.
If the mouse is clicked and released in the same place of time we
assume that the user didn't want to scroll but wanted to whatever
mouse-2 used to do, so we pass it through.
Throw scrolling was inspired (but is not identical to) the \"hand\"
option in MacPaint, or the middle button in Tk text widgets.
If `mouse-throw-with-scroll-bar' is non-nil, then this command scrolls
in the opposite direction. (Different people have different ideas
about which direction is natural. Perhaps it has to do with which
hemisphere you're in.)
To test this function, evaluate:
(keymap-global-set \"<down-mouse-2>\" \\='mouse-drag-throw)"
(interactive "e")
;; we want to do save-selected-window, but that requires 19.29
(let* ((start-posn (event-start start-event))
(start-window (posn-window start-posn))
(start-row (cdr (posn-col-row start-posn)))
(start-col (car (posn-col-row start-posn)))
(old-selected-window (selected-window))
event end row scroll-delta
have-scrolled
col
(scroll-col-delta 0)
;; be conservative about allowing horizontal scrolling
(col-scrolling-p (mouse-drag-should-do-col-scrolling)))
(select-window start-window)
(track-mouse
;; Don't change the mouse pointer shape while we drag.
(setq track-mouse 'dragging)
(while (progn
(setq event (read--potential-mouse-event)
end (event-end event)
row (cdr (posn-col-row end))
col (car (posn-col-row end)))
(or (mouse-movement-p event)
(eq (car-safe event) 'switch-frame)))
(when (eq start-window (posn-window end))
(when col-scrolling-p
(setq scroll-col-delta (mouse-drag-scroll-delta (- start-col col))))
(setq scroll-delta (mouse-drag-scroll-delta (- start-row row))))
(if (or (/= 0 scroll-delta)
(/= 0 scroll-col-delta))
(progn
(setq have-scrolled t)
(mouse-drag-safe-scroll scroll-delta scroll-col-delta)
(mouse-drag-repeatedly-safe-scroll scroll-delta scroll-col-delta))))) ;xxx
;; If it was a click and not a drag, prepare to pass the event on.
;; Is there a more correct way to reconstruct the event?
(if (and (not have-scrolled)
(mouse-drag-events-are-point-events-p start-posn end))
(push (cons (event-basic-type start-event) (cdr start-event))
unread-command-events))
;; Now restore the old window.
(select-window old-selected-window)))