Mercurial > emacs
annotate lisp/mouse-drag.el @ 95647:0f6a0e86ee24
Remove platform-independent menu definitions.
(menu_items menu_items_inuse, menu_items_allocated)
(menu_items_used, menu_items_n_panes)
(menu_items_submenu_depth): Move to keyboard.h.
(init_menu_items, finish_menu_items, unuse_menu_items)
(discard_menu_items, restore_menu_items, save_menu_items)
(grow_menu_items, push_submenu_start, push_submenu_end)
(push_left_right_boundary, push_menu_pane, push_menu_item)
(keymap_panes, single_keymap_panes, single_menu_item)
(list_of_panes, list_of_items, find_and_call_menu_selection)
(xmalloc_widget_value, free_menubar_widget_value_tree)
(parse_single_submenu, digest_single_submenu)
(update_submenu_strings): Move to menu.c.
author | Chong Yidong <cyd@stupidchicken.com> |
---|---|
date | Sun, 08 Jun 2008 04:36:46 +0000 |
parents | ee5932bf781d |
children | ad09327f37a0 |
rev | line source |
---|---|
17517 | 1 ;;; mouse-drag.el --- use mouse-2 to do a new style of scrolling |
2 | |
64762
41bb365f41c4
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64091
diff
changeset
|
3 ;; Copyright (C) 1996, 1997, 2001, 2002, 2003, 2004, |
79721 | 4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
16319 | 5 |
16322 | 6 ;; Author: John Heidemann <johnh@ISI.EDU> |
7 ;; Keywords: mouse | |
16319 | 8 |
9 ;; This file is part of GNU Emacs. | |
10 | |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94102
diff
changeset
|
11 ;; GNU Emacs is free software: you can redistribute it and/or modify |
16319 | 12 ;; it under the terms of the GNU General Public License as published by |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94102
diff
changeset
|
13 ;; the Free Software Foundation, either version 3 of the License, or |
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94102
diff
changeset
|
14 ;; (at your option) any later version. |
16319 | 15 |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94102
diff
changeset
|
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
16319 | 23 |
24 ;;; Commentary: | |
25 | |
94100
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
26 ;; What is ``mouse-drag.el''? |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
27 ;; |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
28 ;; Doesn't that scroll bar seem far away when you want to scroll? |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
29 ;; This module overloads mouse-2 to do ``throw'' scrolling. You |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
30 ;; click and drag. The distance you move from your original click |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
31 ;; turns into a scroll amount. The scroll amount is scaled |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
32 ;; exponentially to make both large moves and short adjustments easy. |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
33 ;; What this boils down to is that you can easily scroll around the |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
34 ;; buffer without much mouse movement. Finally, clicks which aren't |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
35 ;; drags are passed off to the old mouse-2 binding, so old mouse-2 |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
36 ;; operations (find-file in dired-mode, yanking in most other modes) |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
37 ;; still work. |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
38 ;; |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
39 ;; There is an alternative way to scroll, ``drag'' scrolling. You |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
40 ;; can click on a character and then drag it around, scrolling the |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
41 ;; buffer with you. The character always stays under the mouse. |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
42 ;; Compared to throw-scrolling, this approach provides direct |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
43 ;; manipulation (nice) but requires more mouse movement |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
44 ;; (unfortunate). It is offered as an alternative for those who |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
45 ;; prefer it. |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
46 ;; |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
47 ;; If you like mouse-drag, you should also check out mouse-copy |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
48 ;; for ``one-click text copy and move''. |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
49 ;; |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
50 ;; To use mouse-drag, place the following in your .emacs file: |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
51 ;; (require 'mouse-drag) |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
52 ;; -and either- |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
53 ;; (global-set-key [down-mouse-2] 'mouse-drag-throw) |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
54 ;; -or- |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
55 ;; (global-set-key [down-mouse-2] 'mouse-drag-drag) |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
56 ;; |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
57 ;; |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
58 ;; |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
59 ;; Options: |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
60 ;; |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
61 ;; - reverse the throw-scroll direction with \\[mouse-throw-with-scroll-bar] |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
62 ;; - work around a bug with \\[mouse-extras-work-around-drag-bug] |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
63 ;; - auto-enable horizontal scrolling with |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
64 ;; \\[mouse-drag-electric-col-scrolling] |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
65 ;; |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
66 ;; |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
67 ;; History and related work: |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
68 ;; |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
69 ;; One-click copying and moving was inspired by lemacs-19.8. |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
70 ;; Throw-scrolling was inspired by MacPaint's ``hand'' and by Tk's |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
71 ;; mouse-2 scrolling. The package mouse-scroll.el by Tom Wurgler |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
72 ;; <twurgler@goodyear.com> is similar to mouse-drag-throw, but |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
73 ;; doesn't pass clicks through. |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
74 ;; |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
75 ;; These functions have been tested in emacs version 19.30, |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
76 ;; and this package has run in the past on 19.25-19.29. |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
77 ;; |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
78 ;; Originally mouse-drag was part of a larger package. |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
79 ;; As of 11 July 96 the scrolling functions were split out |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
80 ;; in preparation for incorporation into (the future) emacs-19.32. |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
81 ;; |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
82 ;; Thanks: |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
83 ;; |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
84 ;; Thanks to Kai Grossjohann |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
85 ;; <grossjoh@dusty.informatik.uni-dortmund.de> for reporting bugs, to |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
86 ;; Tom Wurgler <twurgler@goodyear.com> for reporting bugs and |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
87 ;; suggesting fixes, and to Joel Graber <jgraber@ti.com> for |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
88 ;; prompting me to do drag-scrolling and for an initial |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
89 ;; implementation of horizontal drag-scrolling. |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
90 ;; |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
91 ;; -johnh@isi.edu, 11-Jul-96 |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
92 ;; |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
93 ;; |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
94 ;; What's new with mouse-drag 2.24? |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
95 ;; |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
96 ;; - mouse-drag-electric-col-scrolling (default: on) |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
97 ;; auto-enables horizontal scrolling when clicks on wrapped |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
98 ;; lines occur |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
99 |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
100 ;; TODO: |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
101 ;; - For mouse-drag-throw, we should try and place some visual indicator |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
102 ;; of the original mouse position (like Firefox does). |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
103 |
16319 | 104 ;;; Code: |
105 | |
106 ;; | |
107 ;; scrolling code | |
108 ;; | |
109 | |
110 (defun mouse-drag-safe-scroll (row-delta &optional col-delta) | |
18134
2441b667abdd
(mouse-drag-safe-scroll): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18026
diff
changeset
|
111 "Scroll down ROW-DELTA lines and right COL-DELTA, ignoring buffer edge errors. |
16319 | 112 Keep the cursor on the screen as needed." |
35085
acc3474759c0
(mouse-drag-safe-scroll): Bind
Gerd Moellmann <gerd@gnu.org>
parents:
18134
diff
changeset
|
113 (let ((scroll-preserve-screen-position nil)) |
acc3474759c0
(mouse-drag-safe-scroll): Bind
Gerd Moellmann <gerd@gnu.org>
parents:
18134
diff
changeset
|
114 (if (and row-delta |
acc3474759c0
(mouse-drag-safe-scroll): Bind
Gerd Moellmann <gerd@gnu.org>
parents:
18134
diff
changeset
|
115 (/= 0 row-delta)) |
acc3474759c0
(mouse-drag-safe-scroll): Bind
Gerd Moellmann <gerd@gnu.org>
parents:
18134
diff
changeset
|
116 (condition-case nil ;; catch and ignore movement errors |
acc3474759c0
(mouse-drag-safe-scroll): Bind
Gerd Moellmann <gerd@gnu.org>
parents:
18134
diff
changeset
|
117 (scroll-down row-delta) |
acc3474759c0
(mouse-drag-safe-scroll): Bind
Gerd Moellmann <gerd@gnu.org>
parents:
18134
diff
changeset
|
118 (beginning-of-buffer (message "Beginning of buffer")) |
acc3474759c0
(mouse-drag-safe-scroll): Bind
Gerd Moellmann <gerd@gnu.org>
parents:
18134
diff
changeset
|
119 (end-of-buffer (message "End of buffer")))) |
acc3474759c0
(mouse-drag-safe-scroll): Bind
Gerd Moellmann <gerd@gnu.org>
parents:
18134
diff
changeset
|
120 (if (and col-delta |
acc3474759c0
(mouse-drag-safe-scroll): Bind
Gerd Moellmann <gerd@gnu.org>
parents:
18134
diff
changeset
|
121 (/= 0 col-delta)) |
acc3474759c0
(mouse-drag-safe-scroll): Bind
Gerd Moellmann <gerd@gnu.org>
parents:
18134
diff
changeset
|
122 (progn |
acc3474759c0
(mouse-drag-safe-scroll): Bind
Gerd Moellmann <gerd@gnu.org>
parents:
18134
diff
changeset
|
123 (scroll-right col-delta) |
acc3474759c0
(mouse-drag-safe-scroll): Bind
Gerd Moellmann <gerd@gnu.org>
parents:
18134
diff
changeset
|
124 ;; Make sure that the point stays on the visible screen |
acc3474759c0
(mouse-drag-safe-scroll): Bind
Gerd Moellmann <gerd@gnu.org>
parents:
18134
diff
changeset
|
125 ;; (if truncation-lines in set). |
acc3474759c0
(mouse-drag-safe-scroll): Bind
Gerd Moellmann <gerd@gnu.org>
parents:
18134
diff
changeset
|
126 ;; This code mimics the behavior we automatically get |
acc3474759c0
(mouse-drag-safe-scroll): Bind
Gerd Moellmann <gerd@gnu.org>
parents:
18134
diff
changeset
|
127 ;; when doing vertical scrolling. |
acc3474759c0
(mouse-drag-safe-scroll): Bind
Gerd Moellmann <gerd@gnu.org>
parents:
18134
diff
changeset
|
128 ;; Problem identified and a fix suggested by Tom Wurgler. |
acc3474759c0
(mouse-drag-safe-scroll): Bind
Gerd Moellmann <gerd@gnu.org>
parents:
18134
diff
changeset
|
129 (cond |
acc3474759c0
(mouse-drag-safe-scroll): Bind
Gerd Moellmann <gerd@gnu.org>
parents:
18134
diff
changeset
|
130 ((< (current-column) (window-hscroll)) |
acc3474759c0
(mouse-drag-safe-scroll): Bind
Gerd Moellmann <gerd@gnu.org>
parents:
18134
diff
changeset
|
131 (move-to-column (window-hscroll))) ; make on left column |
acc3474759c0
(mouse-drag-safe-scroll): Bind
Gerd Moellmann <gerd@gnu.org>
parents:
18134
diff
changeset
|
132 ((> (- (current-column) (window-hscroll) (window-width) -2) 0) |
acc3474759c0
(mouse-drag-safe-scroll): Bind
Gerd Moellmann <gerd@gnu.org>
parents:
18134
diff
changeset
|
133 (move-to-column (+ (window-width) (window-hscroll) -3)))))))) |
16319 | 134 |
135 (defun mouse-drag-repeatedly-safe-scroll (row-delta &optional col-delta) | |
18134
2441b667abdd
(mouse-drag-safe-scroll): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18026
diff
changeset
|
136 "Scroll ROW-DELTA rows and COL-DELTA cols until an event happens." |
16319 | 137 (while (sit-for mouse-scroll-delay) |
138 (mouse-drag-safe-scroll row-delta col-delta))) | |
139 | |
140 (defun mouse-drag-events-are-point-events-p (start-posn end-posn) | |
18134
2441b667abdd
(mouse-drag-safe-scroll): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18026
diff
changeset
|
141 "Determine if START-POSN and END-POSN are \"close\"." |
16319 | 142 (let* |
143 ((start-col-row (posn-col-row start-posn)) | |
144 (end-col-row (posn-col-row end-posn))) | |
145 (and | |
94100
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
146 ;; ;; We no longer exclude things by time. |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
147 ;; (< (- (posn-timestamp end-posn) (posn-timestamp start-posn)) |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
148 ;; (if (numberp double-click-time) |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
149 ;; (* 2 double-click-time) ;; stretch it a little |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
150 ;; 999999)) ;; non-numeric => check by position alone |
16319 | 151 (= (car start-col-row) (car end-col-row)) |
152 (= (cdr start-col-row) (cdr end-col-row))))) | |
153 | |
18026
e3b0e7dc5efd
* mouse-drag.el (mouse-drag-electric-col-scrolling): New variable;
Karl Heuer <kwzh@gnu.org>
parents:
17517
diff
changeset
|
154 (defvar mouse-drag-electric-col-scrolling t |
e3b0e7dc5efd
* mouse-drag.el (mouse-drag-electric-col-scrolling): New variable;
Karl Heuer <kwzh@gnu.org>
parents:
17517
diff
changeset
|
155 "If non-nil, mouse-drag on a long line enables truncate-lines.") |
e3b0e7dc5efd
* mouse-drag.el (mouse-drag-electric-col-scrolling): New variable;
Karl Heuer <kwzh@gnu.org>
parents:
17517
diff
changeset
|
156 |
16319 | 157 (defun mouse-drag-should-do-col-scrolling () |
18134
2441b667abdd
(mouse-drag-safe-scroll): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18026
diff
changeset
|
158 "Determine if it's wise to enable col-scrolling for the current window. |
18026
e3b0e7dc5efd
* mouse-drag.el (mouse-drag-electric-col-scrolling): New variable;
Karl Heuer <kwzh@gnu.org>
parents:
17517
diff
changeset
|
159 Basically, we check for existing horizontal scrolling." |
16319 | 160 (or truncate-lines |
161 (> (window-hscroll (selected-window)) 0) | |
78463
ad7b04a38ce4
Use window-full-width-p instead of comparing frame-width and
Martin Rudalics <rudalics@gmx.at>
parents:
78236
diff
changeset
|
162 (not (window-full-width-p)) |
18026
e3b0e7dc5efd
* mouse-drag.el (mouse-drag-electric-col-scrolling): New variable;
Karl Heuer <kwzh@gnu.org>
parents:
17517
diff
changeset
|
163 (and |
e3b0e7dc5efd
* mouse-drag.el (mouse-drag-electric-col-scrolling): New variable;
Karl Heuer <kwzh@gnu.org>
parents:
17517
diff
changeset
|
164 mouse-drag-electric-col-scrolling |
e3b0e7dc5efd
* mouse-drag.el (mouse-drag-electric-col-scrolling): New variable;
Karl Heuer <kwzh@gnu.org>
parents:
17517
diff
changeset
|
165 (save-excursion ;; on a long line? |
e3b0e7dc5efd
* mouse-drag.el (mouse-drag-electric-col-scrolling): New variable;
Karl Heuer <kwzh@gnu.org>
parents:
17517
diff
changeset
|
166 (let |
e3b0e7dc5efd
* mouse-drag.el (mouse-drag-electric-col-scrolling): New variable;
Karl Heuer <kwzh@gnu.org>
parents:
17517
diff
changeset
|
167 ((beg (progn (beginning-of-line) (point))) |
e3b0e7dc5efd
* mouse-drag.el (mouse-drag-electric-col-scrolling): New variable;
Karl Heuer <kwzh@gnu.org>
parents:
17517
diff
changeset
|
168 (end (progn (end-of-line) (point)))) |
e3b0e7dc5efd
* mouse-drag.el (mouse-drag-electric-col-scrolling): New variable;
Karl Heuer <kwzh@gnu.org>
parents:
17517
diff
changeset
|
169 (if (> (- end beg) (window-width)) |
e3b0e7dc5efd
* mouse-drag.el (mouse-drag-electric-col-scrolling): New variable;
Karl Heuer <kwzh@gnu.org>
parents:
17517
diff
changeset
|
170 (setq truncate-lines t) |
e3b0e7dc5efd
* mouse-drag.el (mouse-drag-electric-col-scrolling): New variable;
Karl Heuer <kwzh@gnu.org>
parents:
17517
diff
changeset
|
171 nil)))))) |
16319 | 172 |
173 (defvar mouse-throw-with-scroll-bar nil | |
18134
2441b667abdd
(mouse-drag-safe-scroll): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
18026
diff
changeset
|
174 "*Set direction of mouse-throwing. |
16319 | 175 If nil, the text moves in the direction the mouse moves. |
176 If t, the scroll bar moves in the direction the mouse moves.") | |
177 (defconst mouse-throw-magnifier-min -6) | |
178 (defconst mouse-throw-magnifier-max 6) | |
94100
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
179 (defconst mouse-throw-magnifier-base 1.5) |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
180 |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
181 (defun mouse-drag-scroll-delta (mouse-delta) |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
182 ;; Limit the exponential explosion. |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
183 (setq mouse-delta |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
184 (max mouse-throw-magnifier-min |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
185 (min mouse-throw-magnifier-max mouse-delta))) |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
186 (* (round (exp (* (log mouse-throw-magnifier-base) (abs mouse-delta)))) |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
187 (if (< mouse-delta 0) -1 1) |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
188 (if mouse-throw-with-scroll-bar 1 -1))) |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
189 |
16319 | 190 |
191 (defun mouse-drag-throw (start-event) | |
192 "\"Throw\" the page according to a mouse drag. | |
193 | |
194 A \"throw\" is scrolling the page at a speed relative to the distance | |
195 from the original mouse click to the current mouse location. Try it; | |
196 you'll like it. It's easier to observe than to explain. | |
197 | |
198 If the mouse is clicked and released in the same place of time we | |
199 assume that the user didn't want to scdebugroll but wanted to whatever | |
200 mouse-2 used to do, so we pass it through. | |
201 | |
202 Throw scrolling was inspired (but is not identical to) the \"hand\" | |
203 option in MacPaint, or the middle button in Tk text widgets. | |
204 | |
205 If `mouse-throw-with-scroll-bar' is non-nil, then this command scrolls | |
206 in the opposite direction. (Different people have different ideas | |
207 about which direction is natural. Perhaps it has to do with which | |
208 hemisphere you're in.) | |
209 | |
210 To test this function, evaluate: | |
211 (global-set-key [down-mouse-2] 'mouse-drag-throw)" | |
212 (interactive "e") | |
213 ;; we want to do save-selected-window, but that requires 19.29 | |
214 (let* ((start-posn (event-start start-event)) | |
215 (start-window (posn-window start-posn)) | |
216 (start-row (cdr (posn-col-row start-posn))) | |
217 (start-col (car (posn-col-row start-posn))) | |
218 (old-selected-window (selected-window)) | |
219 event end row mouse-delta scroll-delta | |
41217
096bd345e996
(mouse-drag-throw): Push back non-drag events
Richard M. Stallman <rms@gnu.org>
parents:
35141
diff
changeset
|
220 have-scrolled |
16319 | 221 window-last-row |
222 col mouse-col-delta window-last-col | |
223 (scroll-col-delta 0) | |
224 adjusted-mouse-col-delta | |
16320
56f494ed6b13
(mouse-drag-throw): Bind adjusted-mouse-delta.
Richard M. Stallman <rms@gnu.org>
parents:
16319
diff
changeset
|
225 adjusted-mouse-delta |
16319 | 226 ;; be conservative about allowing horizontal scrolling |
227 (col-scrolling-p (mouse-drag-should-do-col-scrolling))) | |
228 (select-window start-window) | |
229 (track-mouse | |
230 (while (progn | |
231 (setq event (read-event) | |
232 end (event-end event) | |
233 row (cdr (posn-col-row end)) | |
234 col (car (posn-col-row end))) | |
235 (or (mouse-movement-p event) | |
236 (eq (car-safe event) 'switch-frame))) | |
94100
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
237 (when (eq start-window (posn-window end)) |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
238 (when col-scrolling-p |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
239 (setq scroll-col-delta (mouse-drag-scroll-delta (- start-col col)))) |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
240 (setq scroll-delta (mouse-drag-scroll-delta (- start-row row)))) |
90fb63bd51c8
(mouse-throw-magnifier-with-scroll-bar)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93975
diff
changeset
|
241 |
16319 | 242 (if (or (/= 0 scroll-delta) |
243 (/= 0 scroll-col-delta)) | |
244 (progn | |
245 (setq have-scrolled t) | |
246 (mouse-drag-safe-scroll scroll-delta scroll-col-delta) | |
247 (mouse-drag-repeatedly-safe-scroll scroll-delta scroll-col-delta))))) ;xxx | |
248 ;; If it was a click and not a drag, prepare to pass the event on. | |
41217
096bd345e996
(mouse-drag-throw): Push back non-drag events
Richard M. Stallman <rms@gnu.org>
parents:
35141
diff
changeset
|
249 ;; Is there a more correct way to reconstruct the event? |
16319 | 250 (if (and (not have-scrolled) |
251 (mouse-drag-events-are-point-events-p start-posn end)) | |
41217
096bd345e996
(mouse-drag-throw): Push back non-drag events
Richard M. Stallman <rms@gnu.org>
parents:
35141
diff
changeset
|
252 (push (cons (event-basic-type start-event) (cdr start-event)) |
096bd345e996
(mouse-drag-throw): Push back non-drag events
Richard M. Stallman <rms@gnu.org>
parents:
35141
diff
changeset
|
253 unread-command-events)) |
16319 | 254 ;; Now restore the old window. |
41217
096bd345e996
(mouse-drag-throw): Push back non-drag events
Richard M. Stallman <rms@gnu.org>
parents:
35141
diff
changeset
|
255 (select-window old-selected-window))) |
16319 | 256 |
257 (defun mouse-drag-drag (start-event) | |
258 "\"Drag\" the page according to a mouse drag. | |
259 | |
260 Drag scrolling moves the page according to the movement of the mouse. | |
261 You \"grab\" the character under the mouse and move it around. | |
262 | |
263 If the mouse is clicked and released in the same place of time we | |
264 assume that the user didn't want to scroll but wanted to whatever | |
265 mouse-2 used to do, so we pass it through. | |
266 | |
267 Drag scrolling is identical to the \"hand\" option in MacPaint, or the | |
268 middle button in Tk text widgets. | |
269 | |
270 To test this function, evaluate: | |
271 (global-set-key [down-mouse-2] 'mouse-drag-drag)" | |
272 (interactive "e") | |
273 ;; we want to do save-selected-window, but that requires 19.29 | |
274 (let* ((start-posn (event-start start-event)) | |
275 (start-window (posn-window start-posn)) | |
276 (start-row (cdr (posn-col-row start-posn))) | |
277 (start-col (car (posn-col-row start-posn))) | |
278 (old-selected-window (selected-window)) | |
279 event end row mouse-delta scroll-delta | |
41217
096bd345e996
(mouse-drag-throw): Push back non-drag events
Richard M. Stallman <rms@gnu.org>
parents:
35141
diff
changeset
|
280 have-scrolled |
16319 | 281 window-last-row |
282 col mouse-col-delta window-last-col | |
283 (scroll-col-delta 0) | |
284 ;; be conservative about allowing horizontal scrolling | |
285 (col-scrolling-p (mouse-drag-should-do-col-scrolling))) | |
286 (select-window start-window) | |
287 (setq window-last-row (- (window-height) 2) | |
288 window-last-col (- (window-width) 2)) | |
289 (track-mouse | |
290 (while (progn | |
291 (setq event (read-event) | |
292 end (event-end event) | |
293 row (cdr (posn-col-row end)) | |
294 col (car (posn-col-row end))) | |
295 (or (mouse-movement-p event) | |
296 (eq (car-safe event) 'switch-frame))) | |
297 ;; Scroll if see if we're on the edge. | |
298 ;; NEEDSWORK: should handle mouse-in-other window. | |
299 (cond | |
300 ((not (eq start-window (posn-window end))) | |
301 t) ; wait for return to original window | |
302 ((<= row 0) (mouse-drag-repeatedly-safe-scroll -1 0)) | |
303 ((>= row window-last-row) (mouse-drag-repeatedly-safe-scroll 1 0)) | |
304 ((and col-scrolling-p (<= col 1)) (mouse-drag-repeatedly-safe-scroll 0 -1)) | |
305 ((and col-scrolling-p (>= col window-last-col)) (mouse-drag-repeatedly-safe-scroll 0 1)) | |
306 (t | |
307 (setq scroll-delta (- row start-row) | |
308 start-row row) | |
309 (if col-scrolling-p | |
310 (setq scroll-col-delta (- col start-col) | |
311 start-col col)) | |
312 (if (or (/= 0 scroll-delta) | |
313 (/= 0 scroll-col-delta)) | |
314 (progn | |
315 (setq have-scrolled t) | |
316 (mouse-drag-safe-scroll scroll-delta scroll-col-delta))))))) | |
317 ;; If it was a click and not a drag, prepare to pass the event on. | |
41217
096bd345e996
(mouse-drag-throw): Push back non-drag events
Richard M. Stallman <rms@gnu.org>
parents:
35141
diff
changeset
|
318 ;; Is there a more correct way to reconstruct the event? |
16319 | 319 (if (and (not have-scrolled) |
320 (mouse-drag-events-are-point-events-p start-posn end)) | |
41217
096bd345e996
(mouse-drag-throw): Push back non-drag events
Richard M. Stallman <rms@gnu.org>
parents:
35141
diff
changeset
|
321 (push (cons (event-basic-type start-event) (cdr start-event)) |
096bd345e996
(mouse-drag-throw): Push back non-drag events
Richard M. Stallman <rms@gnu.org>
parents:
35141
diff
changeset
|
322 unread-command-events)) |
16319 | 323 ;; Now restore the old window. |
41217
096bd345e996
(mouse-drag-throw): Push back non-drag events
Richard M. Stallman <rms@gnu.org>
parents:
35141
diff
changeset
|
324 (select-window old-selected-window))) |
096bd345e996
(mouse-drag-throw): Push back non-drag events
Richard M. Stallman <rms@gnu.org>
parents:
35141
diff
changeset
|
325 |
16319 | 326 |
327 (provide 'mouse-drag) | |
328 | |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
79721
diff
changeset
|
329 ;; arch-tag: e47354ff-82f5-42c4-b3dc-88dd9c04b770 |
16319 | 330 ;;; mouse-drag.el ends here |