Commit | Line | Data |
---|---|---|
be010748 | 1 | ;;; mouse.el --- window system-independent mouse support |
84176303 | 2 | |
0d30b337 | 3 | ;; Copyright (C) 1993, 1994, 1995, 1999, 2000, 2001, 2002, 2003, |
48d33090 | 4 | ;; 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
eea8d4ef | 5 | |
84176303 | 6 | ;; Maintainer: FSF |
de420e82 | 7 | ;; Keywords: hardware, mouse |
84176303 | 8 | |
be010748 | 9 | ;; This file is part of GNU Emacs. |
72ea54a4 | 10 | |
be010748 RS |
11 | ;; GNU Emacs is free software; you can redistribute it and/or modify |
12 | ;; it under the terms of the GNU General Public License as published by | |
b4aa6026 | 13 | ;; the Free Software Foundation; either version 3, or (at your option) |
be010748 | 14 | ;; any later version. |
72ea54a4 | 15 | |
be010748 RS |
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. | |
72ea54a4 | 20 | |
be010748 | 21 | ;; You should have received a copy of the GNU General Public License |
4c9afcbe | 22 | ;; along with GNU Emacs; see the file COPYING. If not, write to the |
086add15 LK |
23 | ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
24 | ;; Boston, MA 02110-1301, USA. | |
72ea54a4 | 25 | |
edbd2f74 ER |
26 | ;;; Commentary: |
27 | ||
28 | ;; This package provides various useful commands (including help | |
29 | ;; system access) through the mouse. All this code assumes that mouse | |
30 | ;; interpretation has been abstracted into Emacs input events. | |
31 | ;; | |
32 | ;; The code is rather X-dependent. | |
33 | ||
aae56ea7 ER |
34 | ;;; Code: |
35 | ||
cc0a8174 | 36 | ;;; Utility functions. |
72ea54a4 | 37 | |
ad0d18af | 38 | ;; Indent track-mouse like progn. |
cc0a8174 | 39 | (put 'track-mouse 'lisp-indent-function 0) |
72ea54a4 | 40 | |
3b558d41 RS |
41 | (defcustom mouse-yank-at-point nil |
42 | "*If non-nil, mouse yank commands yank at point instead of at click." | |
43 | :type 'boolean | |
44 | :group 'mouse) | |
b2dae92a KS |
45 | |
46 | (defcustom mouse-drag-copy-region t | |
47 | "*If non-nil, mouse drag copies region to kill-ring." | |
48 | :type 'boolean | |
bf247b6e | 49 | :version "22.1" |
b2dae92a KS |
50 | :group 'mouse) |
51 | ||
5dbda518 | 52 | (defcustom mouse-1-click-follows-link 450 |
787e24c3 | 53 | "Non-nil means that clicking Mouse-1 on a link follows the link. |
65f76581 | 54 | |
787e24c3 KS |
55 | With the default setting, an ordinary Mouse-1 click on a link |
56 | performs the same action as Mouse-2 on that link, while a longer | |
97b1270c | 57 | Mouse-1 click \(hold down the Mouse-1 button for more than 450 |
787e24c3 | 58 | milliseconds) performs the original Mouse-1 binding \(which |
65f76581 KS |
59 | typically sets point where you click the mouse). |
60 | ||
61 | If value is an integer, the time elapsed between pressing and | |
62 | releasing the mouse button determines whether to follow the link | |
787e24c3 | 63 | or perform the normal Mouse-1 action (typically set point). |
65f76581 KS |
64 | The absolute numeric value specifices the maximum duration of a |
65 | \"short click\" in milliseconds. A positive value means that a | |
66 | short click follows the link, and a longer click performs the | |
1d68acd3 | 67 | normal action. A negative value gives the opposite behavior. |
65f76581 KS |
68 | |
69 | If value is `double', a double click follows the link. | |
70 | ||
787e24c3 | 71 | Otherwise, a single Mouse-1 click unconditionally follows the link. |
65f76581 KS |
72 | |
73 | Note that dragging the mouse never follows the link. | |
74 | ||
75 | This feature only works in modes that specifically identify | |
76 | clickable text as links, so it may not work with some external | |
77 | packages. See `mouse-on-link-p' for details." | |
bf247b6e | 78 | :version "22.1" |
65f76581 KS |
79 | :type '(choice (const :tag "Disabled" nil) |
80 | (const :tag "Double click" double) | |
97b1270c | 81 | (number :tag "Single click time limit" :value 450) |
65f76581 KS |
82 | (other :tag "Single click" t)) |
83 | :group 'mouse) | |
84 | ||
185a53bb KS |
85 | (defcustom mouse-1-click-in-non-selected-windows t |
86 | "*If non-nil, a Mouse-1 click also follows links in non-selected windows. | |
87 | ||
88 | If nil, a Mouse-1 click on a link in a non-selected window performs | |
89 | the normal mouse-1 binding, typically selects the window and sets | |
90 | point at the click position." | |
91 | :type 'boolean | |
92 | :version "22.1" | |
93 | :group 'mouse) | |
94 | ||
95 | ||
cc0a8174 | 96 | \f |
95132d1c RS |
97 | ;; Provide a mode-specific menu on a mouse button. |
98 | ||
21ad0f7b SM |
99 | (defun popup-menu (menu &optional position prefix) |
100 | "Popup the given menu and call the selected option. | |
de420e82 DL |
101 | MENU can be a keymap, an easymenu-style menu or a list of keymaps as for |
102 | `x-popup-menu'. | |
21ad0f7b SM |
103 | POSITION can be a click event or ((XOFFSET YOFFSET) WINDOW) and defaults to |
104 | the current mouse position. | |
105 | PREFIX is the prefix argument (if any) to pass to the command." | |
de420e82 DL |
106 | (let* ((map (cond |
107 | ((keymapp menu) menu) | |
108 | ((and (listp menu) (keymapp (car menu))) menu) | |
109 | (t (let* ((map (easy-menu-create-menu (car menu) (cdr menu))) | |
72596e2f SM |
110 | (filter (when (symbolp map) |
111 | (plist-get (get map 'menu-prop) :filter)))) | |
112 | (if filter (funcall filter (symbol-function map)) map))))) | |
0dd672a6 | 113 | event cmd) |
b52a30d8 | 114 | (unless position |
d32af6dd | 115 | (let ((mp (mouse-pixel-position))) |
b52a30d8 | 116 | (setq position (list (list (cadr mp) (cddr mp)) (car mp))))) |
21ad0f7b | 117 | ;; The looping behavior was taken from lmenu's popup-menu-popup |
7636d2a3 EZ |
118 | (while (and map (setq event |
119 | ;; map could be a prefix key, in which case | |
120 | ;; we need to get its function cell | |
121 | ;; definition. | |
d32af6dd | 122 | (x-popup-menu position (indirect-function map)))) |
21ad0f7b SM |
123 | ;; Strangely x-popup-menu returns a list. |
124 | ;; mouse-major-mode-menu was using a weird: | |
125 | ;; (key-binding (apply 'vector (append '(menu-bar) menu-prefix events))) | |
0dd672a6 SM |
126 | (setq cmd |
127 | (if (and (not (keymapp map)) (listp map)) | |
128 | ;; We were given a list of keymaps. Search them all | |
129 | ;; in sequence until a first binding is found. | |
130 | (let ((mouse-click (apply 'vector event)) | |
131 | binding) | |
132 | (while (and map (null binding)) | |
133 | (setq binding (lookup-key (car map) mouse-click)) | |
134 | (if (numberp binding) ; `too long' | |
135 | (setq binding nil)) | |
136 | (setq map (cdr map))) | |
137 | binding) | |
138 | ;; We were given a single keymap. | |
139 | (lookup-key map (apply 'vector event)))) | |
140 | ;; Clear out echoing, which perhaps shows a prefix arg. | |
141 | (message "") | |
142 | ;; Maybe try again but with the submap. | |
143 | (setq map (if (keymapp cmd) cmd))) | |
324cd972 RS |
144 | ;; If the user did not cancel by refusing to select, |
145 | ;; and if the result is a command, run it. | |
146 | (when (and (null map) (commandp cmd)) | |
0dd672a6 SM |
147 | (setq prefix-arg prefix) |
148 | ;; `setup-specified-language-environment', for instance, | |
149 | ;; expects this to be set from a menu keymap. | |
150 | (setq last-command-event (car (last event))) | |
151 | ;; mouse-major-mode-menu was using `command-execute' instead. | |
65b61266 | 152 | (call-interactively cmd)))) |
bcd010a0 | 153 | |
7e4e9c66 | 154 | (defun minor-mode-menu-from-indicator (indicator) |
fb1a03c9 DN |
155 | "Show menu for minor mode specified by INDICATOR. |
156 | Interactively, INDICATOR is read using completion. | |
157 | If there is no menu defined for the minor mode, then create one with | |
158 | items `Turn Off' and `Help'." | |
159 | (interactive | |
5e38cdab | 160 | (list (completing-read |
fb1a03c9 DN |
161 | "Minor mode indicator: " |
162 | (describe-minor-mode-completion-table-for-indicator)))) | |
7e4e9c66 | 163 | (let ((minor-mode (lookup-minor-mode-from-indicator indicator))) |
fb1a03c9 DN |
164 | (unless minor-mode (error "Cannot find minor mode for `%s'" indicator)) |
165 | (let* ((map (cdr-safe (assq minor-mode minor-mode-map-alist))) | |
166 | (menu (and (keymapp map) (lookup-key map [menu-bar])))) | |
ad0d18af SM |
167 | (setq menu |
168 | (if menu | |
169 | (mouse-menu-non-singleton menu) | |
fb1a03c9 | 170 | `(keymap |
ad0d18af SM |
171 | ,indicator |
172 | (turn-off menu-item "Turn Off minor mode" ,minor-mode) | |
173 | (help menu-item "Help for minor mode" | |
5e38cdab | 174 | (lambda () (interactive) |
ad0d18af | 175 | (describe-function ',minor-mode)))))) |
fb1a03c9 | 176 | (popup-menu menu)))) |
7e4e9c66 GM |
177 | |
178 | (defun mouse-minor-mode-menu (event) | |
179 | "Show minor-mode menu for EVENT on minor modes area of the mode line." | |
180 | (interactive "@e") | |
181 | (let ((indicator (car (nth 4 (car (cdr event)))))) | |
182 | (minor-mode-menu-from-indicator indicator))) | |
183 | ||
0b2b62ff | 184 | (defun mouse-menu-major-mode-map () |
ad0d18af SM |
185 | (let* (;; Keymap from which to inherit; may be null. |
186 | (ancestor (mouse-menu-non-singleton | |
b98e5762 | 187 | (and (current-local-map) |
25db2767 | 188 | (local-key-binding [menu-bar])))) |
b98e5762 DL |
189 | ;; Make a keymap in which our last command leads to a menu or |
190 | ;; default to the edit menu. | |
191 | (newmap (if ancestor | |
48d33090 SM |
192 | (make-sparse-keymap (concat (format-mode-line mode-name) |
193 | " Mode")) | |
0595c9f9 GM |
194 | menu-bar-edit-menu)) |
195 | uniq) | |
b98e5762 | 196 | (if ancestor |
00f7c5ed | 197 | (set-keymap-parent newmap ancestor)) |
0b2b62ff | 198 | newmap)) |
95132d1c | 199 | |
ad0d18af SM |
200 | (defun mouse-menu-non-singleton (menubar) |
201 | "Given menu keymap, | |
202 | if it defines exactly one submenu, return just that submenu. | |
203 | Otherwise return the whole menu." | |
95132d1c | 204 | (if menubar |
ad0d18af SM |
205 | (let (submap) |
206 | (map-keymap | |
207 | (lambda (k v) (setq submap (if submap t (cons k v)))) | |
00f7c5ed | 208 | (keymap-canonicalize menubar)) |
ad0d18af SM |
209 | (if (eq submap t) |
210 | menubar | |
211 | (lookup-key menubar (vector (car submap))))))) | |
de420e82 | 212 | |
0b2b62ff SM |
213 | (defun mouse-menu-bar-map () |
214 | "Return a keymap equivalent to the menu bar. | |
de420e82 DL |
215 | The contents are the items that would be in the menu bar whether or |
216 | not it is actually displayed." | |
7636d2a3 EZ |
217 | (let* ((local-menu (and (current-local-map) |
218 | (lookup-key (current-local-map) [menu-bar]))) | |
219 | (global-menu (lookup-key global-map [menu-bar])) | |
59836110 EZ |
220 | ;; If a keymap doesn't have a prompt string (a lazy |
221 | ;; programmer didn't bother to provide one), create it and | |
222 | ;; insert it into the keymap; each keymap gets its own | |
223 | ;; prompt. This is required for non-toolkit versions to | |
224 | ;; display non-empty menu pane names. | |
225 | (minor-mode-menus | |
226 | (mapcar | |
00f7c5ed SM |
227 | (lambda (menu) |
228 | (let* ((minor-mode (car menu)) | |
229 | (menu (cdr menu)) | |
230 | (title-or-map (cadr menu))) | |
231 | (or (stringp title-or-map) | |
232 | (setq menu | |
233 | (cons 'keymap | |
234 | (cons (concat | |
235 | (capitalize (subst-char-in-string | |
236 | ?- ?\s (symbol-name | |
237 | minor-mode))) | |
238 | " Menu") | |
239 | (cdr menu))))) | |
240 | menu)) | |
59836110 | 241 | (minor-mode-key-binding [menu-bar]))) |
7636d2a3 EZ |
242 | (local-title-or-map (and local-menu (cadr local-menu))) |
243 | (global-title-or-map (cadr global-menu))) | |
7636d2a3 EZ |
244 | (or (null local-menu) |
245 | (stringp local-title-or-map) | |
246 | (setq local-menu (cons 'keymap | |
b38f5e6f | 247 | (cons (concat (format-mode-line mode-name) |
48d33090 | 248 | " Mode Menu") |
7636d2a3 EZ |
249 | (cdr local-menu))))) |
250 | (or (stringp global-title-or-map) | |
251 | (setq global-menu (cons 'keymap | |
252 | (cons "Global Menu" | |
253 | (cdr global-menu))))) | |
de420e82 | 254 | ;; Supplying the list is faster than making a new map. |
0b2b62ff SM |
255 | ;; FIXME: We have a problem here: we have to use the global/local/minor |
256 | ;; so they're displayed in the expected order, but later on in the command | |
257 | ;; loop, they're actually looked up in the opposite order. | |
258 | (apply 'append | |
259 | global-menu | |
260 | local-menu | |
261 | minor-mode-menus))) | |
262 | ||
263 | (defun mouse-major-mode-menu (event &optional prefix) | |
264 | "Pop up a mode-specific menu of mouse commands. | |
265 | Default to the Edit menu if the major mode doesn't define a menu." | |
266 | (interactive "@e\nP") | |
267 | (run-hooks 'activate-menubar-hook 'menu-bar-update-hook) | |
268 | (popup-menu (mouse-menu-major-mode-map) event prefix)) | |
5e38cdab | 269 | (make-obsolete 'mouse-major-mode-menu 'mouse-menu-major-mode-map "23.1") |
0b2b62ff SM |
270 | |
271 | (defun mouse-popup-menubar (event prefix) | |
272 | "Pop up a menu equivalent to the menu bar for keyboard EVENT with PREFIX. | |
273 | The contents are the items that would be in the menu bar whether or | |
274 | not it is actually displayed." | |
275 | (interactive "@e \nP") | |
276 | (run-hooks 'activate-menubar-hook 'menu-bar-update-hook) | |
277 | (popup-menu (mouse-menu-bar-map) event prefix)) | |
5e38cdab | 278 | (make-obsolete 'mouse-popup-menubar 'mouse-menu-bar-map "23.1") |
de420e82 DL |
279 | |
280 | (defun mouse-popup-menubar-stuff (event prefix) | |
281 | "Popup a menu like either `mouse-major-mode-menu' or `mouse-popup-menubar'. | |
282 | Use the former if the menu bar is showing, otherwise the latter." | |
0b2b62ff SM |
283 | (interactive "@e\nP") |
284 | (run-hooks 'activate-menubar-hook 'menu-bar-update-hook) | |
285 | (popup-menu | |
286 | (if (zerop (or (frame-parameter nil 'menu-bar-lines) 0)) | |
287 | (mouse-menu-bar-map) | |
288 | (mouse-menu-major-mode-map)) | |
289 | event prefix)) | |
5e38cdab | 290 | (make-obsolete 'mouse-popup-menubar-stuff nil "23.1") |
95132d1c | 291 | \f |
544e7e73 RS |
292 | ;; Commands that operate on windows. |
293 | ||
d65147f6 KH |
294 | (defun mouse-minibuffer-check (event) |
295 | (let ((w (posn-window (event-start event)))) | |
296 | (and (window-minibuffer-p w) | |
297 | (not (minibuffer-window-active-p w)) | |
33c448cd RS |
298 | (error "Minibuffer window is not active"))) |
299 | ;; Give temporary modes such as isearch a chance to turn off. | |
300 | (run-hooks 'mouse-leave-buffer-hook)) | |
d65147f6 | 301 | |
cc0a8174 | 302 | (defun mouse-delete-window (click) |
947da0c4 | 303 | "Delete the window you click on. |
6b48d742 | 304 | Do nothing if the frame has just one window. |
a926a0fa | 305 | This command must be bound to a mouse click." |
ec558adc | 306 | (interactive "e") |
6b48d742 | 307 | (unless (one-window-p t) |
a926a0fa RS |
308 | (mouse-minibuffer-check click) |
309 | (delete-window (posn-window (event-start click))))) | |
cc0a8174 | 310 | |
3c2dd2c0 RS |
311 | (defun mouse-select-window (click) |
312 | "Select the window clicked on; don't move point." | |
313 | (interactive "e") | |
d65147f6 | 314 | (mouse-minibuffer-check click) |
3c2dd2c0 RS |
315 | (let ((oframe (selected-frame)) |
316 | (frame (window-frame (posn-window (event-start click))))) | |
317 | (select-window (posn-window (event-start click))) | |
318 | (raise-frame frame) | |
319 | (select-frame frame) | |
320 | (or (eq frame oframe) | |
e1877477 | 321 | (set-mouse-position (selected-frame) (1- (frame-width)) 0)))) |
3c2dd2c0 | 322 | |
b0f3a26b JB |
323 | (defun mouse-tear-off-window (click) |
324 | "Delete the window clicked on, and create a new frame displaying its buffer." | |
325 | (interactive "e") | |
d65147f6 | 326 | (mouse-minibuffer-check click) |
b0f3a26b JB |
327 | (let* ((window (posn-window (event-start click))) |
328 | (buf (window-buffer window)) | |
01a911e3 | 329 | (frame (make-frame))) |
b0f3a26b JB |
330 | (select-frame frame) |
331 | (switch-to-buffer buf) | |
332 | (delete-window window))) | |
333 | ||
b5370f03 | 334 | (defun mouse-delete-other-windows () |
5925bb84 | 335 | "Delete all windows except the one you click on." |
b5370f03 | 336 | (interactive "@") |
cc0a8174 | 337 | (delete-other-windows)) |
72ea54a4 | 338 | |
cc0a8174 JB |
339 | (defun mouse-split-window-vertically (click) |
340 | "Select Emacs window mouse is on, then split it vertically in half. | |
341 | The window is split at the line clicked on. | |
342 | This command must be bound to a mouse click." | |
947da0c4 | 343 | (interactive "@e") |
d65147f6 | 344 | (mouse-minibuffer-check click) |
b5370f03 JB |
345 | (let ((start (event-start click))) |
346 | (select-window (posn-window start)) | |
85d6b80b | 347 | (let ((new-height (1+ (cdr (posn-col-row (event-end click))))) |
5ba2dc3f JB |
348 | (first-line window-min-height) |
349 | (last-line (- (window-height) window-min-height))) | |
350 | (if (< last-line first-line) | |
0a50b993 | 351 | (error "Window too short to split") |
5ba2dc3f JB |
352 | (split-window-vertically |
353 | (min (max new-height first-line) last-line)))))) | |
cc0a8174 | 354 | |
947da0c4 RS |
355 | (defun mouse-split-window-horizontally (click) |
356 | "Select Emacs window mouse is on, then split it horizontally in half. | |
357 | The window is split at the column clicked on. | |
358 | This command must be bound to a mouse click." | |
359 | (interactive "@e") | |
d65147f6 | 360 | (mouse-minibuffer-check click) |
5ba2dc3f JB |
361 | (let ((start (event-start click))) |
362 | (select-window (posn-window start)) | |
363 | (let ((new-width (1+ (car (posn-col-row (event-end click))))) | |
364 | (first-col window-min-width) | |
365 | (last-col (- (window-width) window-min-width))) | |
366 | (if (< last-col first-col) | |
0a50b993 | 367 | (error "Window too narrow to split") |
5ba2dc3f JB |
368 | (split-window-horizontally |
369 | (min (max new-width first-col) last-col)))))) | |
947da0c4 | 370 | |
4a4fa24d RS |
371 | (defun mouse-drag-window-above (window) |
372 | "Return the (or a) window directly above WINDOW. | |
373 | That means one whose bottom edge is at the same height as WINDOW's top edge." | |
5915523a EZ |
374 | (let ((start-top (nth 1 (window-edges window))) |
375 | (start-left (nth 0 (window-edges window))) | |
376 | (start-right (nth 2 (window-edges window))) | |
4a4fa24d RS |
377 | (start-window window) |
378 | above-window) | |
379 | (setq window (previous-window window 0)) | |
380 | (while (and (not above-window) (not (eq window start-window))) | |
5915523a EZ |
381 | (let ((left (nth 0 (window-edges window))) |
382 | (right (nth 2 (window-edges window)))) | |
383 | (when (and (= (+ (window-height window) (nth 1 (window-edges window))) | |
384 | start-top) | |
385 | (or (and (<= left start-left) (<= start-right right)) | |
386 | (and (<= start-left left) (<= left start-right)) | |
387 | (and (<= start-left right) (<= right start-right)))) | |
388 | (setq above-window window))) | |
4a4fa24d RS |
389 | (setq window (previous-window window))) |
390 | above-window)) | |
391 | ||
392 | (defun mouse-drag-move-window-bottom (window growth) | |
393 | "Move the bottom of WINDOW up or down by GROWTH lines. | |
394 | Move it down if GROWTH is positive, or up if GROWTH is negative. | |
395 | If this would make WINDOW too short, | |
396 | shrink the window or windows above it to make room." | |
91d99be6 RS |
397 | (condition-case nil |
398 | (adjust-window-trailing-edge window growth nil) | |
399 | (error nil))) | |
4a4fa24d | 400 | |
7a892a8b DP |
401 | (defsubst mouse-drag-move-window-top (window growth) |
402 | "Move the top of WINDOW up or down by GROWTH lines. | |
403 | Move it down if GROWTH is positive, or up if GROWTH is negative. | |
404 | If this would make WINDOW too short, shrink the window or windows | |
405 | above it to make room." | |
406 | ;; Moving the top of WINDOW is actually moving the bottom of the | |
407 | ;; window above. | |
408 | (let ((window-above (mouse-drag-window-above window))) | |
409 | (and window-above | |
410 | (mouse-drag-move-window-bottom window-above (- growth))))) | |
411 | ||
b0d22e20 GM |
412 | (defun mouse-drag-mode-line-1 (start-event mode-line-p) |
413 | "Change the height of a window by dragging on the mode or header line. | |
414 | START-EVENT is the starting mouse-event of the drag action. | |
4a4fa24d | 415 | MODE-LINE-P non-nil means dragging a mode line; nil means a header line." |
33c448cd RS |
416 | ;; Give temporary modes such as isearch a chance to turn off. |
417 | (run-hooks 'mouse-leave-buffer-hook) | |
ee0e2bdd GM |
418 | (let* ((done nil) |
419 | (echo-keystrokes 0) | |
420 | (start (event-start start-event)) | |
421 | (start-event-window (posn-window start)) | |
422 | (start-event-frame (window-frame start-event-window)) | |
423 | (start-nwindows (count-windows t)) | |
ee0e2bdd GM |
424 | (minibuffer (frame-parameter nil 'minibuffer)) |
425 | should-enlarge-minibuffer event mouse y top bot edges wconfig growth) | |
544e7e73 RS |
426 | (track-mouse |
427 | (progn | |
544e7e73 RS |
428 | ;; if this is the bottommost ordinary window, then to |
429 | ;; move its modeline the minibuffer must be enlarged. | |
430 | (setq should-enlarge-minibuffer | |
431 | (and minibuffer | |
b0d22e20 | 432 | mode-line-p |
544e7e73 RS |
433 | (not (one-window-p t)) |
434 | (= (nth 1 (window-edges minibuffer)) | |
35da1e48 | 435 | (nth 3 (window-edges start-event-window))))) |
7b611de0 | 436 | |
544e7e73 RS |
437 | ;; loop reading events and sampling the position of |
438 | ;; the mouse. | |
439 | (while (not done) | |
440 | (setq event (read-event) | |
441 | mouse (mouse-position)) | |
7b611de0 | 442 | |
544e7e73 RS |
443 | ;; do nothing if |
444 | ;; - there is a switch-frame event. | |
445 | ;; - the mouse isn't in the frame that we started in | |
446 | ;; - the mouse isn't in any Emacs frame | |
447 | ;; drag if | |
448 | ;; - there is a mouse-movement event | |
449 | ;; - there is a scroll-bar-movement event | |
450 | ;; (same as mouse movement for our purposes) | |
451 | ;; quit if | |
c291e344 MR |
452 | ;; - there is a keyboard event or some other unknown event. |
453 | (cond ((not (consp event)) | |
544e7e73 | 454 | (setq done t)) |
7b611de0 | 455 | |
fbd8dc8a | 456 | ((memq (car event) '(switch-frame select-window)) |
544e7e73 | 457 | nil) |
7b611de0 | 458 | |
ee0e2bdd GM |
459 | ((not (memq (car event) '(mouse-movement scroll-bar-movement))) |
460 | (when (consp event) | |
c291e344 MR |
461 | ;; Do not unread a drag-mouse-1 event since it will cause the |
462 | ;; selection of the window above when dragging the modeline | |
463 | ;; above the selected window. | |
464 | (unless (eq (car event) 'drag-mouse-1) | |
465 | (push event unread-command-events))) | |
544e7e73 | 466 | (setq done t)) |
7b611de0 | 467 | |
544e7e73 RS |
468 | ((not (eq (car mouse) start-event-frame)) |
469 | nil) | |
7b611de0 | 470 | |
544e7e73 RS |
471 | ((null (car (cdr mouse))) |
472 | nil) | |
7b611de0 | 473 | |
544e7e73 RS |
474 | (t |
475 | (setq y (cdr (cdr mouse)) | |
35da1e48 | 476 | edges (window-edges start-event-window) |
544e7e73 RS |
477 | top (nth 1 edges) |
478 | bot (nth 3 edges)) | |
7b611de0 | 479 | |
544e7e73 | 480 | ;; compute size change needed |
b0d22e20 | 481 | (cond (mode-line-p |
b0d22e20 | 482 | (setq growth (- y bot -1))) |
739e92a7 EZ |
483 | (t ; header line |
484 | (when (< (- bot y) window-min-height) | |
485 | (setq y (- bot window-min-height))) | |
486 | ;; The window's top includes the header line! | |
487 | (setq growth (- top y)))) | |
b0d22e20 | 488 | (setq wconfig (current-window-configuration)) |
7b611de0 | 489 | |
951e0427 | 490 | ;; Check for an error case. |
ee0e2bdd GM |
491 | (when (and (/= growth 0) |
492 | (not minibuffer) | |
493 | (one-window-p t)) | |
494 | (error "Attempt to resize sole window")) | |
7b611de0 | 495 | |
544e7e73 RS |
496 | ;; grow/shrink minibuffer? |
497 | (if should-enlarge-minibuffer | |
ad64cd77 RS |
498 | (unless resize-mini-windows |
499 | (mouse-drag-move-window-bottom start-event-window growth)) | |
544e7e73 | 500 | ;; no. grow/shrink the selected window |
ee0e2bdd | 501 | ;(message "growth = %d" growth) |
7a892a8b DP |
502 | (if mode-line-p |
503 | (mouse-drag-move-window-bottom start-event-window growth) | |
504 | (mouse-drag-move-window-top start-event-window growth))) | |
7b611de0 | 505 | |
544e7e73 RS |
506 | ;; if this window's growth caused another |
507 | ;; window to be deleted because it was too | |
508 | ;; short, rescind the change. | |
509 | ;; | |
510 | ;; if size change caused space to be stolen | |
511 | ;; from a window above this one, rescind the | |
a45423d8 | 512 | ;; change, but only if we didn't grow/shrink |
544e7e73 RS |
513 | ;; the minibuffer. minibuffer size changes |
514 | ;; can cause all windows to shrink... no way | |
515 | ;; around it. | |
ee0e2bdd GM |
516 | (when (or (/= start-nwindows (count-windows t)) |
517 | (and (not should-enlarge-minibuffer) | |
4a4fa24d | 518 | (> growth 0) |
ee0e2bdd | 519 | mode-line-p |
c291e344 MR |
520 | (/= top |
521 | (nth 1 (window-edges | |
522 | ;; Choose right window. | |
523 | start-event-window))))) | |
ee0e2bdd | 524 | (set-window-configuration wconfig))))))))) |
b0d22e20 GM |
525 | |
526 | (defun mouse-drag-mode-line (start-event) | |
527 | "Change the height of a window by dragging on the mode line." | |
528 | (interactive "e") | |
529 | (mouse-drag-mode-line-1 start-event t)) | |
530 | ||
531 | (defun mouse-drag-header-line (start-event) | |
ee0e2bdd GM |
532 | "Change the height of a window by dragging on the header line. |
533 | Windows whose header-lines are at the top of the frame cannot be | |
534 | resized by dragging their header-line." | |
b0d22e20 | 535 | (interactive "e") |
ee0e2bdd GM |
536 | ;; Changing the window's size by dragging its header-line when the |
537 | ;; header-line is at the top of the frame is somewhat strange, | |
538 | ;; because the header-line doesn't move, so don't do it. | |
539 | (let* ((start (event-start start-event)) | |
540 | (window (posn-window start)) | |
541 | (frame (window-frame window)) | |
542 | (first-window (frame-first-window frame))) | |
efe4e5af CY |
543 | (unless (or (eq window first-window) |
544 | (= (nth 1 (window-edges window)) | |
545 | (nth 1 (window-edges first-window)))) | |
546 | (mouse-drag-mode-line-1 start-event nil)))) | |
b0d22e20 | 547 | |
544e7e73 | 548 | \f |
73c8f64c RS |
549 | (defun mouse-drag-vertical-line-rightward-window (window) |
550 | "Return a window that is immediately to the right of WINDOW, or nil." | |
551 | (let ((bottom (nth 3 (window-inside-edges window))) | |
552 | (left (nth 0 (window-inside-edges window))) | |
553 | best best-right | |
554 | (try (previous-window window))) | |
555 | (while (not (eq try window)) | |
556 | (let ((try-top (nth 1 (window-inside-edges try))) | |
557 | (try-bottom (nth 3 (window-inside-edges try))) | |
558 | (try-right (nth 2 (window-inside-edges try)))) | |
559 | (if (and (< try-top bottom) | |
560 | (>= try-bottom bottom) | |
561 | (< try-right left) | |
562 | (or (null best-right) (> try-right best-right))) | |
563 | (setq best-right try-right best try))) | |
564 | (setq try (previous-window try))) | |
565 | best)) | |
566 | ||
08a1c178 RS |
567 | (defun mouse-drag-vertical-line (start-event) |
568 | "Change the width of a window by dragging on the vertical line." | |
569 | (interactive "e") | |
570 | ;; Give temporary modes such as isearch a chance to turn off. | |
571 | (run-hooks 'mouse-leave-buffer-hook) | |
5d6a85e0 RS |
572 | (let* ((done nil) |
573 | (echo-keystrokes 0) | |
574 | (start-event-frame (window-frame (car (car (cdr start-event))))) | |
575 | (start-event-window (car (car (cdr start-event)))) | |
e9ae308c | 576 | event mouse x left right edges growth |
5d6a85e0 RS |
577 | (which-side |
578 | (or (cdr (assq 'vertical-scroll-bars (frame-parameters start-event-frame))) | |
579 | 'right))) | |
89a94f1e CY |
580 | (cond |
581 | ((one-window-p t) | |
582 | (error "Attempt to resize sole ordinary window")) | |
583 | ((and (eq which-side 'right) | |
584 | (>= (nth 2 (window-inside-edges start-event-window)) | |
585 | (frame-width start-event-frame))) | |
586 | (error "Attempt to drag rightmost scrollbar")) | |
587 | ((and (eq which-side 'left) | |
588 | (= (nth 0 (window-inside-edges start-event-window)) 0)) | |
589 | (error "Attempt to drag leftmost scrollbar"))) | |
08a1c178 RS |
590 | (track-mouse |
591 | (progn | |
08a1c178 RS |
592 | ;; loop reading events and sampling the position of |
593 | ;; the mouse. | |
594 | (while (not done) | |
595 | (setq event (read-event) | |
596 | mouse (mouse-position)) | |
597 | ;; do nothing if | |
598 | ;; - there is a switch-frame event. | |
599 | ;; - the mouse isn't in the frame that we started in | |
600 | ;; - the mouse isn't in any Emacs frame | |
601 | ;; drag if | |
602 | ;; - there is a mouse-movement event | |
603 | ;; - there is a scroll-bar-movement event | |
604 | ;; (same as mouse movement for our purposes) | |
605 | ;; quit if | |
606 | ;; - there is a keyboard event or some other unknown event | |
607 | ;; unknown event. | |
608 | (cond ((integerp event) | |
609 | (setq done t)) | |
fbd8dc8a | 610 | ((memq (car event) '(switch-frame select-window)) |
08a1c178 RS |
611 | nil) |
612 | ((not (memq (car event) | |
613 | '(mouse-movement scroll-bar-movement))) | |
614 | (if (consp event) | |
615 | (setq unread-command-events | |
616 | (cons event unread-command-events))) | |
617 | (setq done t)) | |
618 | ((not (eq (car mouse) start-event-frame)) | |
619 | nil) | |
620 | ((null (car (cdr mouse))) | |
621 | nil) | |
622 | (t | |
4199d5be RS |
623 | (let ((window |
624 | ;; If the scroll bar is on the window's left, | |
625 | ;; adjust the window on the left. | |
626 | (if (eq which-side 'right) | |
35da1e48 | 627 | start-event-window |
73c8f64c | 628 | (mouse-drag-vertical-line-rightward-window |
35da1e48 | 629 | start-event-window)))) |
b0ea497f | 630 | (setq x (- (car (cdr mouse)) |
4e363e7e | 631 | (if (eq which-side 'right) 0 2)) |
4199d5be | 632 | edges (window-edges window) |
b0ea497f KH |
633 | left (nth 0 edges) |
634 | right (nth 2 edges)) | |
635 | ;; scale back a move that would make the | |
636 | ;; window too thin. | |
637 | (if (< (- x left -1) window-min-width) | |
638 | (setq x (+ left window-min-width -1))) | |
639 | ;; compute size change needed | |
4199d5be RS |
640 | (setq growth (- x right -1)) |
641 | (condition-case nil | |
642 | (adjust-window-trailing-edge window growth t) | |
643 | (error nil)))))))))) | |
08a1c178 | 644 | \f |
2a5fa27b | 645 | (defun mouse-set-point (event) |
cc0a8174 | 646 | "Move point to the position clicked on with the mouse. |
2a5fa27b | 647 | This should be bound to a mouse click event type." |
ec558adc | 648 | (interactive "e") |
d65147f6 | 649 | (mouse-minibuffer-check event) |
2a5fa27b RS |
650 | ;; Use event-end in case called from mouse-drag-region. |
651 | ;; If EVENT is a click, event-end and event-start give same value. | |
541a44d2 | 652 | (posn-set-point (event-end event))) |
cc0a8174 | 653 | |
e6c2f5d4 RS |
654 | (defvar mouse-last-region-beg nil) |
655 | (defvar mouse-last-region-end nil) | |
656 | (defvar mouse-last-region-tick nil) | |
657 | ||
658 | (defun mouse-region-match () | |
659 | "Return non-nil if there's an active region that was set with the mouse." | |
660 | (and (mark t) mark-active | |
661 | (eq mouse-last-region-beg (region-beginning)) | |
662 | (eq mouse-last-region-end (region-end)) | |
663 | (eq mouse-last-region-tick (buffer-modified-tick)))) | |
664 | ||
652ccd35 | 665 | (defun mouse-set-region (click) |
e37de120 | 666 | "Set the region to the text dragged over, and copy to kill ring. |
2a5fa27b | 667 | This should be bound to a mouse drag event." |
652ccd35 | 668 | (interactive "e") |
d65147f6 | 669 | (mouse-minibuffer-check click) |
652ccd35 RS |
670 | (let ((posn (event-start click)) |
671 | (end (event-end click))) | |
672 | (select-window (posn-window posn)) | |
673 | (if (numberp (posn-point posn)) | |
674 | (goto-char (posn-point posn))) | |
fcfc3c63 | 675 | ;; If mark is highlighted, no need to bounce the cursor. |
33a35434 KH |
676 | ;; On X, we highlight while dragging, thus once again no need to bounce. |
677 | (or transient-mark-mode | |
14059374 | 678 | (memq (framep (selected-frame)) '(x pc w32 mac)) |
fcfc3c63 | 679 | (sit-for 1)) |
652ccd35 | 680 | (push-mark) |
1cc8a3f4 | 681 | (set-mark (point)) |
652ccd35 | 682 | (if (numberp (posn-point end)) |
e37de120 RS |
683 | (goto-char (posn-point end))) |
684 | ;; Don't set this-command to kill-region, so that a following | |
685 | ;; C-w will not double the text in the kill ring. | |
91a6bc10 | 686 | ;; Ignore last-command so we don't append to a preceding kill. |
b2dae92a KS |
687 | (when mouse-drag-copy-region |
688 | (let (this-command last-command deactivate-mark) | |
689 | (copy-region-as-kill (mark) (point)))) | |
e6c2f5d4 RS |
690 | (mouse-set-region-1))) |
691 | ||
692 | (defun mouse-set-region-1 () | |
a5809dbd | 693 | ;; Set transient-mark-mode for a little while. |
688468a0 CY |
694 | (unless (eq (car-safe transient-mark-mode) 'only) |
695 | (setq transient-mark-mode | |
696 | (cons 'only | |
697 | (unless (eq transient-mark-mode 'lambda) | |
698 | transient-mark-mode)))) | |
e6c2f5d4 RS |
699 | (setq mouse-last-region-beg (region-beginning)) |
700 | (setq mouse-last-region-end (region-end)) | |
701 | (setq mouse-last-region-tick (buffer-modified-tick))) | |
652ccd35 | 702 | |
3b558d41 | 703 | (defcustom mouse-scroll-delay 0.25 |
600c6e3a JB |
704 | "*The pause between scroll steps caused by mouse drags, in seconds. |
705 | If you drag the mouse beyond the edge of a window, Emacs scrolls the | |
706 | window to bring the text beyond that edge into view, with a delay of | |
707 | this many seconds between scroll steps. Scrolling stops when you move | |
708 | the mouse back into the window, or release the button. | |
709 | This variable's value may be non-integral. | |
3b558d41 RS |
710 | Setting this to zero causes Emacs to scroll as fast as it can." |
711 | :type 'number | |
712 | :group 'mouse) | |
600c6e3a | 713 | |
3b558d41 | 714 | (defcustom mouse-scroll-min-lines 1 |
a3d6bb97 RS |
715 | "*The minimum number of lines scrolled by dragging mouse out of window. |
716 | Moving the mouse out the top or bottom edge of the window begins | |
717 | scrolling repeatedly. The number of lines scrolled per repetition | |
718 | is normally equal to the number of lines beyond the window edge that | |
719 | the mouse has moved. However, it always scrolls at least the number | |
3b558d41 RS |
720 | of lines specified by this variable." |
721 | :type 'integer | |
722 | :group 'mouse) | |
08a1c178 | 723 | |
e919a622 RS |
724 | (defun mouse-scroll-subr (window jump &optional overlay start) |
725 | "Scroll the window WINDOW, JUMP lines at a time, until new input arrives. | |
600c6e3a JB |
726 | If OVERLAY is an overlay, let it stretch from START to the far edge of |
727 | the newly visible text. | |
728 | Upon exit, point is at the far edge of the newly visible text." | |
08a1c178 RS |
729 | (cond |
730 | ((and (> jump 0) (< jump mouse-scroll-min-lines)) | |
731 | (setq jump mouse-scroll-min-lines)) | |
732 | ((and (< jump 0) (< (- jump) mouse-scroll-min-lines)) | |
733 | (setq jump (- mouse-scroll-min-lines)))) | |
4e399a53 RS |
734 | (let ((opoint (point))) |
735 | (while (progn | |
736 | (goto-char (window-start window)) | |
737 | (if (not (zerop (vertical-motion jump window))) | |
738 | (progn | |
739 | (set-window-start window (point)) | |
740 | (if (natnump jump) | |
0320e66f RS |
741 | (if (window-end window) |
742 | (progn | |
743 | (goto-char (window-end window)) | |
744 | ;; window-end doesn't reflect the window's new | |
745 | ;; start position until the next redisplay. | |
746 | (vertical-motion (1- jump) window)) | |
747 | (vertical-motion (- (window-height window) 2))) | |
4e399a53 RS |
748 | (goto-char (window-start window))) |
749 | (if overlay | |
750 | (move-overlay overlay start (point))) | |
751 | ;; Now that we have scrolled WINDOW properly, | |
752 | ;; put point back where it was for the redisplay | |
753 | ;; so that we don't mess up the selected window. | |
754 | (or (eq window (selected-window)) | |
755 | (goto-char opoint)) | |
d2287ded | 756 | (sit-for mouse-scroll-delay))))) |
4e399a53 RS |
757 | (or (eq window (selected-window)) |
758 | (goto-char opoint)))) | |
fcfc3c63 | 759 | |
dc269e81 | 760 | ;; Create an overlay and immediately delete it, to get "overlay in no buffer". |
aaf15b8b SM |
761 | (defconst mouse-drag-overlay |
762 | (let ((ol (make-overlay (point-min) (point-min)))) | |
763 | (delete-overlay ol) | |
764 | (overlay-put ol 'face 'region) | |
765 | ol)) | |
600c6e3a | 766 | |
dd524dbd | 767 | (defvar mouse-selection-click-count 0) |
eb6ff46f | 768 | |
c8c5bd24 RS |
769 | (defvar mouse-selection-click-count-buffer nil) |
770 | ||
600c6e3a | 771 | (defun mouse-drag-region (start-event) |
bcd5aef1 | 772 | "Set the region to the text that the mouse is dragged over. |
78210c95 RS |
773 | Highlight the drag area as you move the mouse. |
774 | This must be bound to a button-down mouse event. | |
d017deb2 | 775 | In Transient Mark mode, the highlighting remains as long as the mark |
6454615c RS |
776 | remains active. Otherwise, it remains until the next input event. |
777 | ||
778 | If the click is in the echo area, display the `*Messages*' buffer." | |
bcd5aef1 | 779 | (interactive "e") |
fbd8dc8a SM |
780 | (let ((w (posn-window (event-start start-event)))) |
781 | (if (and (window-minibuffer-p w) | |
782 | (not (minibuffer-window-active-p w))) | |
6454615c | 783 | (save-excursion |
2e36c3b0 | 784 | ;; Swallow the up-event. |
6454615c | 785 | (read-event) |
4bdce438 | 786 | (set-buffer (get-buffer-create "*Messages*")) |
6454615c RS |
787 | (goto-char (point-max)) |
788 | (display-buffer (current-buffer))) | |
789 | ;; Give temporary modes such as isearch a chance to turn off. | |
790 | (run-hooks 'mouse-leave-buffer-hook) | |
f1c4f757 | 791 | (mouse-drag-track start-event t)))) |
6454615c | 792 | |
65f76581 | 793 | |
91a2acb2 | 794 | (defun mouse-posn-property (pos property) |
9ed38a84 DK |
795 | "Look for a property at click position. |
796 | POS may be either a buffer position or a click position like | |
89bf250e | 797 | those returned from `event-start'. If the click position is on |
9ed38a84 DK |
798 | a string, the text property PROPERTY is examined. |
799 | If this is nil or the click is not on a string, then | |
800 | the corresponding buffer position is searched for PROPERTY. | |
801 | If PROPERTY is encountered in one of those places, | |
802 | its value is returned." | |
91a2acb2 DK |
803 | (if (consp pos) |
804 | (let ((w (posn-window pos)) (pt (posn-point pos)) | |
805 | (str (posn-string pos))) | |
806 | (or (and str | |
807 | (get-text-property (cdr str) property (car str))) | |
808 | (and pt | |
809 | (get-char-property pt property w)))) | |
810 | (get-char-property pos property))) | |
811 | ||
65f76581 KS |
812 | (defun mouse-on-link-p (pos) |
813 | "Return non-nil if POS is on a link in the current buffer. | |
23eb76c4 TTN |
814 | POS must be a buffer position in the current buffer or a mouse |
815 | event location in the selected window (see `event-start'). | |
185a53bb KS |
816 | However, if `mouse-1-click-in-non-selected-windows' is non-nil, |
817 | POS may be a mouse event location in any window. | |
65f76581 KS |
818 | |
819 | A clickable link is identified by one of the following methods: | |
820 | ||
b41a4019 | 821 | - If the character at POS has a non-nil `follow-link' text or |
e5fb57e9 | 822 | overlay property, the value of that property determines what to do. |
65f76581 | 823 | |
b41a4019 KS |
824 | - If there is a local key-binding or a keybinding at position POS |
825 | for the `follow-link' event, the binding of that event determines | |
826 | what to do. | |
65f76581 | 827 | |
b41a4019 KS |
828 | The resulting value determine whether POS is inside a link: |
829 | ||
830 | - If the value is `mouse-face', POS is inside a link if there | |
65f76581 KS |
831 | is a non-nil `mouse-face' property at POS. Return t in this case. |
832 | ||
b41a4019 | 833 | - If the value is a function, FUNC, POS is inside a link if |
65f76581 | 834 | the call \(FUNC POS) returns non-nil. Return the return value |
23eb76c4 | 835 | from that call. Arg is \(posn-point POS) if POS is a mouse event. |
65f76581 | 836 | |
b41a4019 | 837 | - Otherwise, return the value itself. |
65f76581 KS |
838 | |
839 | The return value is interpreted as follows: | |
840 | ||
841 | - If it is a string, the mouse-1 event is translated into the | |
842 | first character of the string, i.e. the action of the mouse-1 | |
843 | click is the local or global binding of that character. | |
844 | ||
845 | - If it is a vector, the mouse-1 event is translated into the | |
846 | first element of that vector, i.e. the action of the mouse-1 | |
847 | click is the local or global binding of that event. | |
848 | ||
849 | - Otherwise, the mouse-1 event is translated into a mouse-2 event | |
850 | at the same position." | |
91a2acb2 DK |
851 | (let ((action |
852 | (and (or (not (consp pos)) | |
853 | mouse-1-click-in-non-selected-windows | |
854 | (eq (selected-window) (posn-window pos))) | |
855 | (or (mouse-posn-property pos 'follow-link) | |
856 | (key-binding [follow-link] nil t pos))))) | |
857 | (cond | |
858 | ((eq action 'mouse-face) | |
859 | (and (mouse-posn-property pos 'mouse-face) t)) | |
860 | ((functionp action) | |
9ed38a84 | 861 | ;; FIXME: This seems questionable if the click is not in a buffer. |
e9ae308c | 862 | ;; Should we instead decide that `action' takes a `posn'? |
9ed38a84 DK |
863 | (if (consp pos) |
864 | (with-current-buffer (window-buffer (posn-window pos)) | |
624c972d | 865 | (funcall action (posn-point pos))) |
9ed38a84 | 866 | (funcall action pos))) |
91a2acb2 | 867 | (t action)))) |
b0ca1b8a | 868 | |
5dbda518 KS |
869 | (defun mouse-fixup-help-message (msg) |
870 | "Fix help message MSG for `mouse-1-click-follows-link'." | |
871 | (let (mp pos) | |
872 | (if (and mouse-1-click-follows-link | |
873 | (stringp msg) | |
874 | (save-match-data | |
875 | (string-match "^mouse-2" msg)) | |
876 | (setq mp (mouse-pixel-position)) | |
877 | (consp (setq pos (cdr mp))) | |
878 | (car pos) (>= (car pos) 0) | |
879 | (cdr pos) (>= (cdr pos) 0) | |
880 | (setq pos (posn-at-x-y (car pos) (cdr pos) (car mp))) | |
881 | (windowp (posn-window pos))) | |
882 | (with-current-buffer (window-buffer (posn-window pos)) | |
883 | (if (mouse-on-link-p pos) | |
884 | (setq msg (concat | |
885 | (cond | |
886 | ((eq mouse-1-click-follows-link 'double) "double-") | |
887 | ((and (integerp mouse-1-click-follows-link) | |
888 | (< mouse-1-click-follows-link 0)) "Long ") | |
889 | (t "")) | |
890 | "mouse-1" (substring msg 7))))))) | |
891 | msg) | |
65f76581 | 892 | |
aaf15b8b SM |
893 | (defun mouse-move-drag-overlay (ol start end mode) |
894 | (unless (= start end) | |
895 | ;; Go to START first, so that when we move to END, if it's in the middle | |
896 | ;; of intangible text, point jumps in the direction away from START. | |
897 | ;; Don't do it if START=END otherwise a single click risks selecting | |
898 | ;; a region if it's on intangible text. This exception was originally | |
899 | ;; only applied on entry to mouse-drag-region, which had the problem | |
900 | ;; that a tiny move during a single-click would cause the intangible | |
901 | ;; text to be selected. | |
902 | (goto-char start) | |
39739f21 SM |
903 | (goto-char end) |
904 | (setq end (point))) | |
905 | (let ((range (mouse-start-end start end mode))) | |
aaf15b8b SM |
906 | (move-overlay ol (car range) (nth 1 range)))) |
907 | ||
624c972d | 908 | (defun mouse-drag-track (start-event &optional |
f1c4f757 S |
909 | do-mouse-drag-region-post-process) |
910 | "Track mouse drags by highlighting area between point and cursor. | |
911 | The region will be defined with mark and point, and the overlay | |
912 | will be deleted after return. DO-MOUSE-DRAG-REGION-POST-PROCESS | |
913 | should only be used by mouse-drag-region." | |
d65147f6 | 914 | (mouse-minibuffer-check start-event) |
aaf15b8b SM |
915 | (setq mouse-selection-click-count-buffer (current-buffer)) |
916 | (let* ((original-window (selected-window)) | |
917 | ;; We've recorded what we needed from the current buffer and | |
918 | ;; window, now let's jump to the place of the event, where things | |
919 | ;; are happening. | |
920 | (_ (mouse-set-point start-event)) | |
921 | (echo-keystrokes 0) | |
4c9afcbe | 922 | (start-posn (event-start start-event)) |
600c6e3a JB |
923 | (start-point (posn-point start-posn)) |
924 | (start-window (posn-window start-posn)) | |
02beb936 | 925 | (start-window-start (window-start start-window)) |
1853aa6b | 926 | (start-hscroll (window-hscroll start-window)) |
600c6e3a | 927 | (bounds (window-edges start-window)) |
8413d0d2 | 928 | (make-cursor-line-fully-visible nil) |
600c6e3a JB |
929 | (top (nth 1 bounds)) |
930 | (bottom (if (window-minibuffer-p start-window) | |
931 | (nth 3 bounds) | |
932 | ;; Don't count the mode line. | |
e37de120 | 933 | (1- (nth 3 bounds)))) |
b0ca1b8a | 934 | (on-link (and mouse-1-click-follows-link |
185a53bb | 935 | (or mouse-1-click-in-non-selected-windows |
aaf15b8b SM |
936 | (eq start-window original-window)) |
937 | ;; Use start-point before the intangibility | |
938 | ;; treatment, in case we click on a link inside an | |
939 | ;; intangible text. | |
91a2acb2 | 940 | (mouse-on-link-p start-posn))) |
aaf15b8b SM |
941 | (click-count (1- (event-click-count start-event))) |
942 | (remap-double-click (and on-link | |
943 | (eq mouse-1-click-follows-link 'double) | |
a9d01547 CY |
944 | (= click-count 1))) |
945 | ;; Suppress automatic hscrolling, because that is a nuisance | |
946 | ;; when setting point near the right fringe (but see below). | |
947 | (automatic-hscrolling-saved automatic-hscrolling) | |
948 | (automatic-hscrolling nil)) | |
eb6ff46f | 949 | (setq mouse-selection-click-count click-count) |
08a1c178 RS |
950 | ;; In case the down click is in the middle of some intangible text, |
951 | ;; use the end of that text, and put it in START-POINT. | |
952 | (if (< (point) start-point) | |
953 | (goto-char start-point)) | |
954 | (setq start-point (point)) | |
aaf15b8b | 955 | (if remap-double-click ;; Don't expand mouse overlay in links |
65f76581 | 956 | (setq click-count 0)) |
aaf15b8b SM |
957 | (mouse-move-drag-overlay mouse-drag-overlay start-point start-point |
958 | click-count) | |
959 | (overlay-put mouse-drag-overlay 'window start-window) | |
f767385c | 960 | (deactivate-mark) |
f002506f | 961 | (let (event end end-point last-end-point) |
bcd5aef1 | 962 | (track-mouse |
600c6e3a | 963 | (while (progn |
b846d039 | 964 | (setq event (read-event)) |
aaf15b8b SM |
965 | (or (mouse-movement-p event) |
966 | (memq (car-safe event) '(switch-frame select-window)))) | |
967 | (if (memq (car-safe event) '(switch-frame select-window)) | |
b846d039 | 968 | nil |
a9d01547 CY |
969 | ;; Automatic hscrolling did not occur during the call to |
970 | ;; `read-event'; but if the user subsequently drags the | |
971 | ;; mouse, go ahead and hscroll. | |
972 | (let ((automatic-hscrolling automatic-hscrolling-saved)) | |
973 | (redisplay)) | |
b846d039 JB |
974 | (setq end (event-end event) |
975 | end-point (posn-point end)) | |
3617aa76 | 976 | (if (numberp end-point) |
d5c847bb | 977 | (setq last-end-point end-point)) |
b846d039 JB |
978 | |
979 | (cond | |
b846d039 JB |
980 | ;; Are we moving within the original window? |
981 | ((and (eq (posn-window end) start-window) | |
982 | (integer-or-marker-p end-point)) | |
aaf15b8b | 983 | (mouse-move-drag-overlay mouse-drag-overlay start-point end-point click-count)) |
b846d039 | 984 | |
50e527bc KH |
985 | (t |
986 | (let ((mouse-row (cdr (cdr (mouse-position))))) | |
aaf15b8b SM |
987 | (cond |
988 | ((null mouse-row)) | |
989 | ((< mouse-row top) | |
990 | (mouse-scroll-subr start-window (- mouse-row top) | |
991 | mouse-drag-overlay start-point)) | |
992 | ((>= mouse-row bottom) | |
993 | (mouse-scroll-subr start-window (1+ (- mouse-row bottom)) | |
994 | mouse-drag-overlay start-point))))))))) | |
b2013aad | 995 | |
2e3329a5 RS |
996 | ;; In case we did not get a mouse-motion event |
997 | ;; for the final move of the mouse before a drag event | |
998 | ;; pretend that we did get one. | |
999 | (when (and (memq 'drag (event-modifiers (car-safe event))) | |
aaf15b8b | 1000 | (setq end (event-end event) |
2e3329a5 RS |
1001 | end-point (posn-point end)) |
1002 | (eq (posn-window end) start-window) | |
1003 | (integer-or-marker-p end-point)) | |
aaf15b8b | 1004 | (mouse-move-drag-overlay mouse-drag-overlay start-point end-point click-count)) |
2e3329a5 | 1005 | |
f1c4f757 | 1006 | ;; Handle the terminating event |
4e399a53 | 1007 | (if (consp event) |
f28e9cbd CY |
1008 | (let* ((fun (key-binding (vector (car event)))) |
1009 | (do-multi-click (and (> (event-click-count event) 0) | |
1010 | (functionp fun) | |
624c972d JB |
1011 | (not (memq fun |
1012 | '(mouse-set-point | |
f1c4f757 S |
1013 | mouse-set-region)))))) |
1014 | ;; Run the binding of the terminating up-event, if possible. | |
f28e9cbd CY |
1015 | (if (and (not (= (overlay-start mouse-drag-overlay) |
1016 | (overlay-end mouse-drag-overlay))) | |
1017 | (not do-multi-click)) | |
bb3aa835 RS |
1018 | (let* ((stop-point |
1019 | (if (numberp (posn-point (event-end event))) | |
1020 | (posn-point (event-end event)) | |
1021 | last-end-point)) | |
1022 | ;; The end that comes from where we ended the drag. | |
1023 | ;; Point goes here. | |
1024 | (region-termination | |
f1c4f757 S |
1025 | (if (and stop-point (< stop-point start-point)) |
1026 | (overlay-start mouse-drag-overlay) | |
1027 | (overlay-end mouse-drag-overlay))) | |
1028 | ;; The end that comes from where we started the drag. | |
1029 | ;; Mark goes there. | |
1030 | (region-commencement | |
1031 | (- (+ (overlay-end mouse-drag-overlay) | |
1032 | (overlay-start mouse-drag-overlay)) | |
1033 | region-termination)) | |
1034 | last-command this-command) | |
1035 | (push-mark region-commencement t t) | |
1036 | (goto-char region-termination) | |
1037 | (if (not do-mouse-drag-region-post-process) | |
1038 | ;; Skip all post-event handling, return immediately. | |
1039 | (delete-overlay mouse-drag-overlay) | |
1040 | ;; Don't let copy-region-as-kill set deactivate-mark. | |
1041 | (when mouse-drag-copy-region | |
1042 | (let (deactivate-mark) | |
1043 | (copy-region-as-kill (point) (mark t)))) | |
1044 | (let ((buffer (current-buffer))) | |
1045 | (mouse-show-mark) | |
1046 | ;; mouse-show-mark can call read-event, | |
1047 | ;; and that means the Emacs server could switch buffers | |
1048 | ;; under us. If that happened, | |
1049 | ;; avoid trying to use the region. | |
1050 | (and (mark t) mark-active | |
1051 | (eq buffer (current-buffer)) | |
1052 | (mouse-set-region-1))))) | |
aaf15b8b | 1053 | ;; Run the binding of the terminating up-event. |
f28e9cbd CY |
1054 | ;; If a multiple click is not bound to mouse-set-point, |
1055 | ;; cancel the effects of mouse-move-drag-overlay to | |
1056 | ;; avoid producing wrong results. | |
1057 | (if do-multi-click (goto-char start-point)) | |
1058 | (delete-overlay mouse-drag-overlay) | |
aaf15b8b | 1059 | (when (and (functionp fun) |
05b531f6 EZ |
1060 | (= start-hscroll (window-hscroll start-window)) |
1061 | ;; Don't run the up-event handler if the | |
1062 | ;; window start changed in a redisplay after | |
1063 | ;; the mouse-set-point for the down-mouse | |
1064 | ;; event at the beginning of this function. | |
1065 | ;; When the window start has changed, the | |
1066 | ;; up-mouse event will contain a different | |
1067 | ;; position due to the new window contents, | |
1068 | ;; and point is set again. | |
1069 | (or end-point | |
1070 | (= (window-start start-window) | |
1071 | start-window-start))) | |
1072 | (when (and on-link | |
18e980c2 RS |
1073 | (or (not end-point) (= end-point start-point)) |
1074 | (consp event) | |
1075 | (or remap-double-click | |
1076 | (and | |
1077 | (not (eq mouse-1-click-follows-link 'double)) | |
1078 | (= click-count 0) | |
1079 | (= (event-click-count event) 1) | |
18e980c2 RS |
1080 | (or (not (integerp mouse-1-click-follows-link)) |
1081 | (let ((t0 (posn-timestamp (event-start start-event))) | |
1082 | (t1 (posn-timestamp (event-end event)))) | |
1083 | (and (integerp t0) (integerp t1) | |
1084 | (if (> mouse-1-click-follows-link 0) | |
1085 | (<= (- t1 t0) mouse-1-click-follows-link) | |
1086 | (< (- t0 t1) mouse-1-click-follows-link)))))))) | |
745cfc57 | 1087 | ;; If we rebind to mouse-2, reselect previous selected window, |
18e980c2 RS |
1088 | ;; so that the mouse-2 event runs in the same |
1089 | ;; situation as if user had clicked it directly. | |
1090 | ;; Fixes the bug reported by juri@jurta.org on 2005-12-27. | |
18e980c2 RS |
1091 | (if (or (vectorp on-link) (stringp on-link)) |
1092 | (setq event (aref on-link 0)) | |
745cfc57 | 1093 | (select-window original-window) |
cbf090c4 RS |
1094 | (setcar event 'mouse-2) |
1095 | ;; If this mouse click has never been done by | |
1096 | ;; the user, it doesn't have the necessary | |
1097 | ;; property to be interpreted correctly. | |
1098 | (put 'mouse-2 'event-kind 'mouse-click))) | |
aaf15b8b SM |
1099 | (push event unread-command-events)))) |
1100 | ||
1101 | ;; Case where the end-event is not a cons cell (it's just a boring | |
1102 | ;; char-key-press). | |
e6c2f5d4 | 1103 | (delete-overlay mouse-drag-overlay))))) |
e37de120 RS |
1104 | \f |
1105 | ;; Commands to handle xterm-style multiple clicks. | |
e37de120 RS |
1106 | (defun mouse-skip-word (dir) |
1107 | "Skip over word, over whitespace, or over identical punctuation. | |
1108 | If DIR is positive skip forward; if negative, skip backward." | |
1109 | (let* ((char (following-char)) | |
1110 | (syntax (char-to-string (char-syntax char)))) | |
258e3295 KH |
1111 | (cond ((string= syntax "w") |
1112 | ;; Here, we can't use skip-syntax-forward/backward because | |
1113 | ;; they don't pay attention to word-separating-categories, | |
1114 | ;; and thus they will skip over a true word boundary. So, | |
1115 | ;; we simularte the original behaviour by using | |
1116 | ;; forward-word. | |
1117 | (if (< dir 0) | |
1118 | (if (not (looking-at "\\<")) | |
1119 | (forward-word -1)) | |
1120 | (if (or (looking-at "\\<") (not (looking-at "\\>"))) | |
1121 | (forward-word 1)))) | |
1122 | ((string= syntax " ") | |
08a1c178 RS |
1123 | (if (< dir 0) |
1124 | (skip-syntax-backward syntax) | |
1125 | (skip-syntax-forward syntax))) | |
1126 | ((string= syntax "_") | |
1127 | (if (< dir 0) | |
1128 | (skip-syntax-backward "w_") | |
1129 | (skip-syntax-forward "w_"))) | |
1130 | ((< dir 0) | |
1131 | (while (and (not (bobp)) (= (preceding-char) char)) | |
1132 | (forward-char -1))) | |
1133 | (t | |
1134 | (while (and (not (eobp)) (= (following-char) char)) | |
1135 | (forward-char 1)))))) | |
e37de120 | 1136 | |
eb6ff46f | 1137 | (defun mouse-start-end (start end mode) |
c3bb6d70 | 1138 | "Return a list of region bounds based on START and END according to MODE. |
a7df580d DL |
1139 | If MODE is 0 then set point to (min START END), mark to (max START END). |
1140 | If MODE is 1 then set point to start of word at (min START END), | |
1141 | mark to end of word at (max START END). | |
1142 | If MODE is 2 then do the same for lines." | |
e37de120 RS |
1143 | (if (> start end) |
1144 | (let ((temp start)) | |
1145 | (setq start end | |
1146 | end temp))) | |
9a974c88 | 1147 | (setq mode (mod mode 3)) |
e37de120 RS |
1148 | (cond ((= mode 0) |
1149 | (list start end)) | |
1150 | ((and (= mode 1) | |
1151 | (= start end) | |
1ec71583 | 1152 | (char-after start) |
e37de120 | 1153 | (= (char-syntax (char-after start)) ?\()) |
6f482eec RS |
1154 | (list start |
1155 | (save-excursion | |
1156 | (goto-char start) | |
1157 | (forward-sexp 1) | |
1158 | (point)))) | |
e37de120 RS |
1159 | ((and (= mode 1) |
1160 | (= start end) | |
1ec71583 | 1161 | (char-after start) |
e37de120 | 1162 | (= (char-syntax (char-after start)) ?\))) |
7b611de0 | 1163 | (list (save-excursion |
e37de120 | 1164 | (goto-char (1+ start)) |
d89a4a47 RS |
1165 | (backward-sexp 1) |
1166 | (point)) | |
e37de120 | 1167 | (1+ start))) |
53770877 RS |
1168 | ((and (= mode 1) |
1169 | (= start end) | |
1170 | (char-after start) | |
1171 | (= (char-syntax (char-after start)) ?\")) | |
1172 | (let ((open (or (eq start (point-min)) | |
1173 | (save-excursion | |
1174 | (goto-char (- start 1)) | |
1175 | (looking-at "\\s(\\|\\s \\|\\s>"))))) | |
1176 | (if open | |
1177 | (list start | |
1178 | (save-excursion | |
1179 | (condition-case nil | |
7b611de0 | 1180 | (progn |
53770877 RS |
1181 | (goto-char start) |
1182 | (forward-sexp 1) | |
1183 | (point)) | |
1184 | (error end)))) | |
f1017d55 | 1185 | (list (save-excursion |
53770877 RS |
1186 | (condition-case nil |
1187 | (progn | |
1188 | (goto-char (1+ start)) | |
1189 | (backward-sexp 1) | |
1190 | (point)) | |
f1017d55 RS |
1191 | (error end))) |
1192 | (1+ start))))) | |
e37de120 RS |
1193 | ((= mode 1) |
1194 | (list (save-excursion | |
1195 | (goto-char start) | |
1196 | (mouse-skip-word -1) | |
1197 | (point)) | |
1198 | (save-excursion | |
1199 | (goto-char end) | |
1200 | (mouse-skip-word 1) | |
1201 | (point)))) | |
1202 | ((= mode 2) | |
1203 | (list (save-excursion | |
1204 | (goto-char start) | |
1205 | (beginning-of-line 1) | |
1206 | (point)) | |
1207 | (save-excursion | |
1208 | (goto-char end) | |
1209 | (forward-line 1) | |
1210 | (point)))))) | |
e66feb07 | 1211 | \f |
3f26b32a RS |
1212 | ;; Subroutine: set the mark where CLICK happened, |
1213 | ;; but don't do anything else. | |
1214 | (defun mouse-set-mark-fast (click) | |
d65147f6 | 1215 | (mouse-minibuffer-check click) |
3f26b32a RS |
1216 | (let ((posn (event-start click))) |
1217 | (select-window (posn-window posn)) | |
1218 | (if (numberp (posn-point posn)) | |
1219 | (push-mark (posn-point posn) t t)))) | |
1220 | ||
98aac09d MB |
1221 | (defun mouse-undouble-last-event (events) |
1222 | (let* ((index (1- (length events))) | |
1223 | (last (nthcdr index events)) | |
1224 | (event (car last)) | |
1225 | (basic (event-basic-type event)) | |
397a88f3 RS |
1226 | (old-modifiers (event-modifiers event)) |
1227 | (modifiers (delq 'double (delq 'triple (copy-sequence old-modifiers)))) | |
98aac09d MB |
1228 | (new |
1229 | (if (consp event) | |
7132500b RS |
1230 | ;; Use reverse, not nreverse, since event-modifiers |
1231 | ;; does not copy the list it returns. | |
3bb846b8 | 1232 | (cons (event-convert-list (reverse (cons basic modifiers))) |
98aac09d MB |
1233 | (cdr event)) |
1234 | event))) | |
1235 | (setcar last new) | |
397a88f3 RS |
1236 | (if (and (not (equal modifiers old-modifiers)) |
1237 | (key-binding (apply 'vector events))) | |
98aac09d MB |
1238 | t |
1239 | (setcar last event) | |
1240 | nil))) | |
1241 | ||
7b611de0 | 1242 | ;; Momentarily show where the mark is, if highlighting doesn't show it. |
7aeb7370 | 1243 | |
c3bb6d70 RS |
1244 | (defcustom mouse-region-delete-keys '([delete] [deletechar] [backspace]) |
1245 | "List of keys that should cause the mouse region to be deleted." | |
1246 | :group 'mouse | |
1247 | :type '(repeat key-sequence)) | |
7aeb7370 | 1248 | |
3f26b32a | 1249 | (defun mouse-show-mark () |
d3d3d650 RS |
1250 | (let ((inhibit-quit t) |
1251 | (echo-keystrokes 0) | |
1252 | event events key ignore | |
b10c429f | 1253 | (x-lost-selection-functions |
ab60bd74 SS |
1254 | (when (boundp 'x-lost-selection-functions) |
1255 | (copy-sequence x-lost-selection-functions)))) | |
1256 | (add-hook 'x-lost-selection-functions | |
d3d3d650 | 1257 | (lambda (seltype) |
ab60bd74 SS |
1258 | (when (eq seltype 'PRIMARY) |
1259 | (setq ignore t) | |
1260 | (throw 'mouse-show-mark t)))) | |
d3d3d650 RS |
1261 | (if transient-mark-mode |
1262 | (delete-overlay mouse-drag-overlay) | |
1263 | (move-overlay mouse-drag-overlay (point) (mark t))) | |
1264 | (catch 'mouse-show-mark | |
1265 | ;; In this loop, execute scroll bar and switch-frame events. | |
fbd8dc8a | 1266 | ;; Should we similarly handle `select-window' events? --Stef |
d3d3d650 RS |
1267 | ;; Also ignore down-events that are undefined. |
1268 | (while (progn (setq event (read-event)) | |
1269 | (setq events (append events (list event))) | |
1270 | (setq key (apply 'vector events)) | |
1271 | (or (and (consp event) | |
1272 | (eq (car event) 'switch-frame)) | |
1273 | (and (consp event) | |
1274 | (eq (posn-point (event-end event)) | |
1275 | 'vertical-scroll-bar)) | |
1276 | (and (memq 'down (event-modifiers event)) | |
1277 | (not (key-binding key)) | |
1278 | (not (mouse-undouble-last-event events)) | |
1279 | (not (member key mouse-region-delete-keys))))) | |
1280 | (and (consp event) | |
1281 | (or (eq (car event) 'switch-frame) | |
1282 | (eq (posn-point (event-end event)) | |
1283 | 'vertical-scroll-bar)) | |
1284 | (let ((keys (vector 'vertical-scroll-bar event))) | |
1285 | (and (key-binding keys) | |
1286 | (progn | |
1287 | (call-interactively (key-binding keys) | |
1288 | nil keys) | |
1289 | (setq events nil))))))) | |
1290 | ;; If we lost the selection, just turn off the highlighting. | |
ab60bd74 | 1291 | (unless ignore |
d3d3d650 RS |
1292 | ;; For certain special keys, delete the region. |
1293 | (if (member key mouse-region-delete-keys) | |
760a2050 KS |
1294 | (progn |
1295 | ;; Since notionally this is a separate command, | |
1296 | ;; run all the hooks that would be run if it were | |
1297 | ;; executed separately. | |
1298 | (run-hooks 'post-command-hook) | |
1299 | (setq last-command this-command) | |
1300 | (setq this-original-command 'delete-region) | |
1301 | (setq this-command (or (command-remapping this-original-command) | |
1302 | this-original-command)) | |
1303 | (run-hooks 'pre-command-hook) | |
1304 | (call-interactively this-command)) | |
d3d3d650 RS |
1305 | ;; Otherwise, unread the key so it gets executed normally. |
1306 | (setq unread-command-events | |
1307 | (nconc events unread-command-events)))) | |
1308 | (setq quit-flag nil) | |
1309 | (unless transient-mark-mode | |
f4b60fe6 | 1310 | (delete-overlay mouse-drag-overlay)))) |
3f26b32a | 1311 | |
cc0a8174 JB |
1312 | (defun mouse-set-mark (click) |
1313 | "Set mark at the position clicked on with the mouse. | |
1314 | Display cursor at that position for a second. | |
1315 | This must be bound to a mouse click." | |
ec558adc | 1316 | (interactive "e") |
f598fb03 RS |
1317 | (mouse-minibuffer-check click) |
1318 | (select-window (posn-window (event-start click))) | |
1319 | ;; We don't use save-excursion because that preserves the mark too. | |
72ea54a4 RS |
1320 | (let ((point-save (point))) |
1321 | (unwind-protect | |
cc0a8174 | 1322 | (progn (mouse-set-point click) |
897897e3 RS |
1323 | (push-mark nil t t) |
1324 | (or transient-mark-mode | |
1325 | (sit-for 1))) | |
72ea54a4 RS |
1326 | (goto-char point-save)))) |
1327 | ||
cc0a8174 JB |
1328 | (defun mouse-kill (click) |
1329 | "Kill the region between point and the mouse click. | |
1330 | The text is saved in the kill ring, as with \\[kill-region]." | |
ec558adc | 1331 | (interactive "e") |
d65147f6 | 1332 | (mouse-minibuffer-check click) |
142c7672 KH |
1333 | (let* ((posn (event-start click)) |
1334 | (click-posn (posn-point posn))) | |
1335 | (select-window (posn-window posn)) | |
bd307392 JB |
1336 | (if (numberp click-posn) |
1337 | (kill-region (min (point) click-posn) | |
1338 | (max (point) click-posn))))) | |
72ea54a4 | 1339 | |
87ef29fd JB |
1340 | (defun mouse-yank-at-click (click arg) |
1341 | "Insert the last stretch of killed text at the position clicked on. | |
0e57ab65 | 1342 | Also move point to one end of the text thus inserted (normally the end), |
231c4d1a | 1343 | and set mark at the beginning. |
50f58001 RS |
1344 | Prefix arguments are interpreted as with \\[yank]. |
1345 | If `mouse-yank-at-point' is non-nil, insert at point | |
1346 | regardless of where you click." | |
a4cabe41 | 1347 | (interactive "e\nP") |
33c448cd RS |
1348 | ;; Give temporary modes such as isearch a chance to turn off. |
1349 | (run-hooks 'mouse-leave-buffer-hook) | |
50f58001 | 1350 | (or mouse-yank-at-point (mouse-set-point click)) |
d89a4a47 | 1351 | (setq this-command 'yank) |
a814e9df | 1352 | (setq mouse-selection-click-count 0) |
87ef29fd JB |
1353 | (yank arg)) |
1354 | ||
63571b5a RS |
1355 | (defun mouse-yank-primary (click) |
1356 | "Insert the primary selection at the position clicked on. | |
1357 | Move point to the end of the inserted text. | |
1358 | If `mouse-yank-at-point' is non-nil, insert at point | |
1359 | regardless of where you click." | |
1360 | (interactive "e") | |
1361 | ;; Give temporary modes such as isearch a chance to turn off. | |
1362 | (run-hooks 'mouse-leave-buffer-hook) | |
1363 | (or mouse-yank-at-point (mouse-set-point click)) | |
1364 | (let ((primary (x-get-selection 'PRIMARY))) | |
1365 | (if primary | |
1366 | (insert (x-get-selection 'PRIMARY)) | |
1367 | (error "No primary selection")))) | |
1368 | ||
87ef29fd | 1369 | (defun mouse-kill-ring-save (click) |
cc0a8174 JB |
1370 | "Copy the region between point and the mouse click in the kill ring. |
1371 | This does not delete the region; it acts like \\[kill-ring-save]." | |
ec558adc | 1372 | (interactive "e") |
3f26b32a | 1373 | (mouse-set-mark-fast click) |
6452d8a6 RS |
1374 | (let (this-command last-command) |
1375 | (kill-ring-save (point) (mark t))) | |
3f26b32a | 1376 | (mouse-show-mark)) |
72ea54a4 | 1377 | |
ad0d18af SM |
1378 | ;; This function used to delete the text between point and the mouse |
1379 | ;; whenever it was equal to the front of the kill ring, but some | |
1380 | ;; people found that confusing. | |
dbc4e1c1 | 1381 | |
ad0d18af SM |
1382 | ;; A list (TEXT START END), describing the text and position of the last |
1383 | ;; invocation of mouse-save-then-kill. | |
dbc4e1c1 JB |
1384 | (defvar mouse-save-then-kill-posn nil) |
1385 | ||
26d280b9 | 1386 | (defun mouse-save-then-kill-delete-region (beg end) |
9a974c88 RS |
1387 | ;; We must make our own undo boundaries |
1388 | ;; because they happen automatically only for the current buffer. | |
1389 | (undo-boundary) | |
dd524dbd RS |
1390 | (if (or (= beg end) (eq buffer-undo-list t)) |
1391 | ;; If we have no undo list in this buffer, | |
1392 | ;; just delete. | |
1393 | (delete-region beg end) | |
1394 | ;; Delete, but make the undo-list entry share with the kill ring. | |
1395 | ;; First, delete just one char, so in case buffer is being modified | |
1396 | ;; for the first time, the undo list records that fact. | |
8faa9707 | 1397 | (let (before-change-functions after-change-functions) |
2f4b15ef RS |
1398 | (delete-region beg |
1399 | (+ beg (if (> end beg) 1 -1)))) | |
dd524dbd RS |
1400 | (let ((buffer-undo-list buffer-undo-list)) |
1401 | ;; Undo that deletion--but don't change the undo list! | |
8faa9707 | 1402 | (let (before-change-functions after-change-functions) |
2f4b15ef | 1403 | (primitive-undo 1 buffer-undo-list)) |
dd524dbd RS |
1404 | ;; Now delete the rest of the specified region, |
1405 | ;; but don't record it. | |
1406 | (setq buffer-undo-list t) | |
9a974c88 RS |
1407 | (if (/= (length (car kill-ring)) (- (max end beg) (min end beg))) |
1408 | (error "Lossage in mouse-save-then-kill-delete-region")) | |
dd524dbd RS |
1409 | (delete-region beg end)) |
1410 | (let ((tail buffer-undo-list)) | |
1411 | ;; Search back in buffer-undo-list for the string | |
1412 | ;; that came from deleting one character. | |
1413 | (while (and tail (not (stringp (car (car tail))))) | |
1414 | (setq tail (cdr tail))) | |
1415 | ;; Replace it with an entry for the entire deleted text. | |
1416 | (and tail | |
9a974c88 RS |
1417 | (setcar tail (cons (car kill-ring) (min beg end)))))) |
1418 | (undo-boundary)) | |
eb6ff46f | 1419 | |
947da0c4 | 1420 | (defun mouse-save-then-kill (click) |
40a45a9f RS |
1421 | "Save text to point in kill ring; the second time, kill the text. |
1422 | If the text between point and the mouse is the same as what's | |
1423 | at the front of the kill ring, this deletes the text. | |
1424 | Otherwise, it adds the text to the kill ring, like \\[kill-ring-save], | |
eb6ff46f RS |
1425 | which prepares for a second click to delete the text. |
1426 | ||
1427 | If you have selected words or lines, this command extends the | |
1428 | selection through the word or line clicked on. If you do this | |
1429 | again in a different position, it extends the selection again. | |
7b611de0 | 1430 | If you do this twice in the same position, the selection is killed." |
947da0c4 | 1431 | (interactive "e") |
53016bea RS |
1432 | (let ((before-scroll |
1433 | (with-current-buffer (window-buffer (posn-window (event-start click))) | |
1434 | point-before-scroll))) | |
b64548c7 RS |
1435 | (mouse-minibuffer-check click) |
1436 | (let ((click-posn (posn-point (event-start click))) | |
1437 | ;; Don't let a subsequent kill command append to this one: | |
1438 | ;; prevent setting this-command to kill-region. | |
1439 | (this-command this-command)) | |
aaf15b8b SM |
1440 | (if (and (with-current-buffer |
1441 | (window-buffer (posn-window (event-start click))) | |
c8c5bd24 RS |
1442 | (and (mark t) (> (mod mouse-selection-click-count 3) 0) |
1443 | ;; Don't be fooled by a recent click in some other buffer. | |
7b611de0 | 1444 | (eq mouse-selection-click-count-buffer |
c8c5bd24 | 1445 | (current-buffer))))) |
b64548c7 RS |
1446 | (if (not (and (eq last-command 'mouse-save-then-kill) |
1447 | (equal click-posn | |
1448 | (car (cdr-safe (cdr-safe mouse-save-then-kill-posn)))))) | |
1449 | ;; Find both ends of the object selected by this click. | |
1450 | (let* ((range | |
1451 | (mouse-start-end click-posn click-posn | |
1452 | mouse-selection-click-count))) | |
1453 | ;; Move whichever end is closer to the click. | |
1454 | ;; That's what xterm does, and it seems reasonable. | |
1455 | (if (< (abs (- click-posn (mark t))) | |
1456 | (abs (- click-posn (point)))) | |
1457 | (set-mark (car range)) | |
1458 | (goto-char (nth 1 range))) | |
1459 | ;; We have already put the old region in the kill ring. | |
1460 | ;; Replace it with the extended region. | |
1461 | ;; (It would be annoying to make a separate entry.) | |
1462 | (kill-new (buffer-substring (point) (mark t)) t) | |
e6c2f5d4 | 1463 | (mouse-set-region-1) |
b64548c7 RS |
1464 | ;; Arrange for a repeated mouse-3 to kill this region. |
1465 | (setq mouse-save-then-kill-posn | |
1466 | (list (car kill-ring) (point) click-posn)) | |
1467 | (mouse-show-mark)) | |
1468 | ;; If we click this button again without moving it, | |
1469 | ;; that time kill. | |
bcde3748 | 1470 | (mouse-save-then-kill-delete-region (mark) (point)) |
b64548c7 | 1471 | (setq mouse-selection-click-count 0) |
dd524dbd | 1472 | (setq mouse-save-then-kill-posn nil)) |
b64548c7 RS |
1473 | (if (and (eq last-command 'mouse-save-then-kill) |
1474 | mouse-save-then-kill-posn | |
1475 | (eq (car mouse-save-then-kill-posn) (car kill-ring)) | |
1476 | (equal (cdr mouse-save-then-kill-posn) (list (point) click-posn))) | |
1477 | ;; If this is the second time we've called | |
1478 | ;; mouse-save-then-kill, delete the text from the buffer. | |
1479 | (progn | |
1480 | (mouse-save-then-kill-delete-region (point) (mark)) | |
1481 | ;; After we kill, another click counts as "the first time". | |
1482 | (setq mouse-save-then-kill-posn nil)) | |
c8f264ae RS |
1483 | ;; This is not a repetition. |
1484 | ;; We are adjusting an old selection or creating a new one. | |
b64548c7 RS |
1485 | (if (or (and (eq last-command 'mouse-save-then-kill) |
1486 | mouse-save-then-kill-posn) | |
1487 | (and mark-active transient-mark-mode) | |
1488 | (and (memq last-command | |
1489 | '(mouse-drag-region mouse-set-region)) | |
1490 | (or mark-even-if-inactive | |
1491 | (not transient-mark-mode)))) | |
1492 | ;; We have a selection or suitable region, so adjust it. | |
1493 | (let* ((posn (event-start click)) | |
1494 | (new (posn-point posn))) | |
1495 | (select-window (posn-window posn)) | |
1496 | (if (numberp new) | |
1497 | (progn | |
1498 | ;; Move whichever end of the region is closer to the click. | |
1499 | ;; That is what xterm does, and it seems reasonable. | |
ed784c53 | 1500 | (if (<= (abs (- new (point))) (abs (- new (mark t)))) |
b64548c7 RS |
1501 | (goto-char new) |
1502 | (set-mark new)) | |
1503 | (setq deactivate-mark nil))) | |
aaf15b8b | 1504 | (kill-new (buffer-substring (point) (mark t)) t)) |
b64548c7 RS |
1505 | ;; Set the mark where point is, then move where clicked. |
1506 | (mouse-set-mark-fast click) | |
1507 | (if before-scroll | |
1508 | (goto-char before-scroll)) | |
aaf15b8b SM |
1509 | (exchange-point-and-mark) ;Why??? --Stef |
1510 | (kill-new (buffer-substring (point) (mark t)))) | |
1511 | (mouse-show-mark) | |
e6c2f5d4 | 1512 | (mouse-set-region-1) |
b64548c7 RS |
1513 | (setq mouse-save-then-kill-posn |
1514 | (list (car kill-ring) (point) click-posn))))))) | |
e66feb07 RS |
1515 | \f |
1516 | (global-set-key [M-mouse-1] 'mouse-start-secondary) | |
1517 | (global-set-key [M-drag-mouse-1] 'mouse-set-secondary) | |
1518 | (global-set-key [M-down-mouse-1] 'mouse-drag-secondary) | |
1519 | (global-set-key [M-mouse-3] 'mouse-secondary-save-then-kill) | |
9a974c88 | 1520 | (global-set-key [M-mouse-2] 'mouse-yank-secondary) |
e66feb07 | 1521 | |
aaf15b8b SM |
1522 | (defconst mouse-secondary-overlay |
1523 | (let ((ol (make-overlay (point-min) (point-min)))) | |
1524 | (delete-overlay ol) | |
1525 | (overlay-put ol 'face 'secondary-selection) | |
1526 | ol) | |
1527 | "An overlay which records the current secondary selection. | |
1528 | It is deleted when there is no secondary selection.") | |
e66feb07 | 1529 | |
a94c7fcc RS |
1530 | (defvar mouse-secondary-click-count 0) |
1531 | ||
e66feb07 RS |
1532 | ;; A marker which records the specified first end for a secondary selection. |
1533 | ;; May be nil. | |
1534 | (defvar mouse-secondary-start nil) | |
1535 | ||
1536 | (defun mouse-start-secondary (click) | |
1537 | "Set one end of the secondary selection to the position clicked on. | |
1538 | Use \\[mouse-secondary-save-then-kill] to set the other end | |
1539 | and complete the secondary selection." | |
1540 | (interactive "e") | |
d65147f6 | 1541 | (mouse-minibuffer-check click) |
e66feb07 | 1542 | (let ((posn (event-start click))) |
aaf15b8b | 1543 | (with-current-buffer (window-buffer (posn-window posn)) |
230aaa73 | 1544 | ;; Cancel any preexisting secondary selection. |
aaf15b8b | 1545 | (delete-overlay mouse-secondary-overlay) |
230aaa73 RS |
1546 | (if (numberp (posn-point posn)) |
1547 | (progn | |
1548 | (or mouse-secondary-start | |
1549 | (setq mouse-secondary-start (make-marker))) | |
1550 | (move-marker mouse-secondary-start (posn-point posn))))))) | |
e66feb07 RS |
1551 | |
1552 | (defun mouse-set-secondary (click) | |
1553 | "Set the secondary selection to the text that the mouse is dragged over. | |
1554 | This must be bound to a mouse drag event." | |
1555 | (interactive "e") | |
d65147f6 | 1556 | (mouse-minibuffer-check click) |
e66feb07 RS |
1557 | (let ((posn (event-start click)) |
1558 | beg | |
1559 | (end (event-end click))) | |
aaf15b8b | 1560 | (with-current-buffer (window-buffer (posn-window posn)) |
230aaa73 RS |
1561 | (if (numberp (posn-point posn)) |
1562 | (setq beg (posn-point posn))) | |
3e4f866b CY |
1563 | (move-overlay mouse-secondary-overlay beg (posn-point end)) |
1564 | (x-set-selection | |
1565 | 'SECONDARY | |
1566 | (buffer-substring (overlay-start mouse-secondary-overlay) | |
1567 | (overlay-end mouse-secondary-overlay)))))) | |
947da0c4 | 1568 | |
d89a4a47 | 1569 | (defun mouse-drag-secondary (start-event) |
e66feb07 | 1570 | "Set the secondary selection to the text that the mouse is dragged over. |
d89a4a47 | 1571 | Highlight the drag area as you move the mouse. |
efc10c97 RS |
1572 | This must be bound to a button-down mouse event. |
1573 | The function returns a non-nil value if it creates a secondary selection." | |
e66feb07 | 1574 | (interactive "e") |
d65147f6 | 1575 | (mouse-minibuffer-check start-event) |
4c9afcbe RS |
1576 | (let* ((echo-keystrokes 0) |
1577 | (start-posn (event-start start-event)) | |
d89a4a47 RS |
1578 | (start-point (posn-point start-posn)) |
1579 | (start-window (posn-window start-posn)) | |
d89a4a47 RS |
1580 | (bounds (window-edges start-window)) |
1581 | (top (nth 1 bounds)) | |
1582 | (bottom (if (window-minibuffer-p start-window) | |
1583 | (nth 3 bounds) | |
1584 | ;; Don't count the mode line. | |
1585 | (1- (nth 3 bounds)))) | |
1586 | (click-count (1- (event-click-count start-event)))) | |
aaf15b8b | 1587 | (with-current-buffer (window-buffer start-window) |
a94c7fcc | 1588 | (setq mouse-secondary-click-count click-count) |
9a974c88 | 1589 | (if (> (mod click-count 3) 0) |
26d280b9 RS |
1590 | ;; Double or triple press: make an initial selection |
1591 | ;; of one word or line. | |
d89a4a47 RS |
1592 | (let ((range (mouse-start-end start-point start-point click-count))) |
1593 | (set-marker mouse-secondary-start nil) | |
aaf15b8b SM |
1594 | ;; Why the double move? --Stef |
1595 | ;; (move-overlay mouse-secondary-overlay 1 1 | |
1596 | ;; (window-buffer start-window)) | |
d89a4a47 RS |
1597 | (move-overlay mouse-secondary-overlay (car range) (nth 1 range) |
1598 | (window-buffer start-window))) | |
26d280b9 | 1599 | ;; Single-press: cancel any preexisting secondary selection. |
d89a4a47 RS |
1600 | (or mouse-secondary-start |
1601 | (setq mouse-secondary-start (make-marker))) | |
1602 | (set-marker mouse-secondary-start start-point) | |
1603 | (delete-overlay mouse-secondary-overlay)) | |
1604 | (let (event end end-point) | |
1605 | (track-mouse | |
1606 | (while (progn | |
1607 | (setq event (read-event)) | |
1608 | (or (mouse-movement-p event) | |
fbd8dc8a | 1609 | (memq (car-safe event) '(switch-frame select-window)))) |
d89a4a47 | 1610 | |
fbd8dc8a | 1611 | (if (memq (car-safe event) '(switch-frame select-window)) |
d89a4a47 RS |
1612 | nil |
1613 | (setq end (event-end event) | |
1614 | end-point (posn-point end)) | |
1615 | (cond | |
d89a4a47 RS |
1616 | ;; Are we moving within the original window? |
1617 | ((and (eq (posn-window end) start-window) | |
1618 | (integer-or-marker-p end-point)) | |
d89a4a47 RS |
1619 | (let ((range (mouse-start-end start-point end-point |
1620 | click-count))) | |
0136e1e3 RS |
1621 | (if (or (/= start-point end-point) |
1622 | (null (marker-position mouse-secondary-start))) | |
1623 | (progn | |
1624 | (set-marker mouse-secondary-start nil) | |
1625 | (move-overlay mouse-secondary-overlay | |
1626 | (car range) (nth 1 range)))))) | |
3b0aebe9 RS |
1627 | (t |
1628 | (let ((mouse-row (cdr (cdr (mouse-position))))) | |
1629 | (cond | |
1630 | ((null mouse-row)) | |
1631 | ((< mouse-row top) | |
e919a622 RS |
1632 | (mouse-scroll-subr start-window (- mouse-row top) |
1633 | mouse-secondary-overlay start-point)) | |
d2287ded | 1634 | ((>= mouse-row bottom) |
e919a622 | 1635 | (mouse-scroll-subr start-window (1+ (- mouse-row bottom)) |
3b0aebe9 | 1636 | mouse-secondary-overlay start-point))))))))) |
d89a4a47 | 1637 | |
4e399a53 | 1638 | (if (consp event) |
d89a4a47 RS |
1639 | (if (marker-position mouse-secondary-start) |
1640 | (save-window-excursion | |
1641 | (delete-overlay mouse-secondary-overlay) | |
9a974c88 | 1642 | (x-set-selection 'SECONDARY nil) |
d89a4a47 RS |
1643 | (select-window start-window) |
1644 | (save-excursion | |
1645 | (goto-char mouse-secondary-start) | |
efc10c97 RS |
1646 | (sit-for 1) |
1647 | nil)) | |
9a974c88 RS |
1648 | (x-set-selection |
1649 | 'SECONDARY | |
1650 | (buffer-substring (overlay-start mouse-secondary-overlay) | |
1651 | (overlay-end mouse-secondary-overlay))))))))) | |
e66feb07 | 1652 | |
9a974c88 | 1653 | (defun mouse-yank-secondary (click) |
50f58001 RS |
1654 | "Insert the secondary selection at the position clicked on. |
1655 | Move point to the end of the inserted text. | |
1656 | If `mouse-yank-at-point' is non-nil, insert at point | |
1657 | regardless of where you click." | |
a4cabe41 | 1658 | (interactive "e") |
33c448cd RS |
1659 | ;; Give temporary modes such as isearch a chance to turn off. |
1660 | (run-hooks 'mouse-leave-buffer-hook) | |
50f58001 | 1661 | (or mouse-yank-at-point (mouse-set-point click)) |
b3709a53 RS |
1662 | (let ((secondary (x-get-selection 'SECONDARY))) |
1663 | (if secondary | |
1664 | (insert (x-get-selection 'SECONDARY)) | |
1665 | (error "No secondary selection")))) | |
9a974c88 | 1666 | |
7e6404f6 | 1667 | (defun mouse-kill-secondary () |
9a974c88 RS |
1668 | "Kill the text in the secondary selection. |
1669 | This is intended more as a keyboard command than as a mouse command | |
1670 | but it can work as either one. | |
1671 | ||
1672 | The current buffer (in case of keyboard use), or the buffer clicked on, | |
1673 | must be the one that the secondary selection is in. This requirement | |
1674 | is to prevent accidents." | |
7e6404f6 RS |
1675 | (interactive) |
1676 | (let* ((keys (this-command-keys)) | |
1677 | (click (elt keys (1- (length keys))))) | |
1678 | (or (eq (overlay-buffer mouse-secondary-overlay) | |
1679 | (if (listp click) | |
1680 | (window-buffer (posn-window (event-start click))) | |
1681 | (current-buffer))) | |
1682 | (error "Select or click on the buffer where the secondary selection is"))) | |
9dfab550 | 1683 | (let (this-command) |
aaf15b8b | 1684 | (with-current-buffer (overlay-buffer mouse-secondary-overlay) |
9dfab550 RS |
1685 | (kill-region (overlay-start mouse-secondary-overlay) |
1686 | (overlay-end mouse-secondary-overlay)))) | |
e66feb07 | 1687 | (delete-overlay mouse-secondary-overlay) |
9dfab550 | 1688 | ;;; (x-set-selection 'SECONDARY nil) |
aaf15b8b | 1689 | ) |
e66feb07 RS |
1690 | |
1691 | (defun mouse-secondary-save-then-kill (click) | |
d89a4a47 | 1692 | "Save text to point in kill ring; the second time, kill the text. |
7bbe2cc7 RS |
1693 | You must use this in a buffer where you have recently done \\[mouse-start-secondary]. |
1694 | If the text between where you did \\[mouse-start-secondary] and where | |
1695 | you use this command matches the text at the front of the kill ring, | |
1696 | this command deletes the text. | |
e66feb07 | 1697 | Otherwise, it adds the text to the kill ring, like \\[kill-ring-save], |
7bbe2cc7 | 1698 | which prepares for a second click with this command to delete the text. |
d89a4a47 | 1699 | |
7bbe2cc7 RS |
1700 | If you have already made a secondary selection in that buffer, |
1701 | this command extends or retracts the selection to where you click. | |
1702 | If you do this again in a different position, it extends or retracts | |
1703 | again. If you do this twice in the same position, it kills the selection." | |
e66feb07 | 1704 | (interactive "e") |
d65147f6 | 1705 | (mouse-minibuffer-check click) |
d89a4a47 RS |
1706 | (let ((posn (event-start click)) |
1707 | (click-posn (posn-point (event-start click))) | |
e66feb07 RS |
1708 | ;; Don't let a subsequent kill command append to this one: |
1709 | ;; prevent setting this-command to kill-region. | |
1710 | (this-command this-command)) | |
9a974c88 | 1711 | (or (eq (window-buffer (posn-window posn)) |
aaf15b8b | 1712 | (or (overlay-buffer mouse-secondary-overlay) |
9a974c88 RS |
1713 | (if mouse-secondary-start |
1714 | (marker-buffer mouse-secondary-start)))) | |
1715 | (error "Wrong buffer")) | |
aaf15b8b | 1716 | (with-current-buffer (window-buffer (posn-window posn)) |
a94c7fcc | 1717 | (if (> (mod mouse-secondary-click-count 3) 0) |
9a974c88 RS |
1718 | (if (not (and (eq last-command 'mouse-secondary-save-then-kill) |
1719 | (equal click-posn | |
1720 | (car (cdr-safe (cdr-safe mouse-save-then-kill-posn)))))) | |
1721 | ;; Find both ends of the object selected by this click. | |
1722 | (let* ((range | |
1723 | (mouse-start-end click-posn click-posn | |
a94c7fcc | 1724 | mouse-secondary-click-count))) |
9a974c88 RS |
1725 | ;; Move whichever end is closer to the click. |
1726 | ;; That's what xterm does, and it seems reasonable. | |
1727 | (if (< (abs (- click-posn (overlay-start mouse-secondary-overlay))) | |
1728 | (abs (- click-posn (overlay-end mouse-secondary-overlay)))) | |
1729 | (move-overlay mouse-secondary-overlay (car range) | |
1730 | (overlay-end mouse-secondary-overlay)) | |
d89a4a47 RS |
1731 | (move-overlay mouse-secondary-overlay |
1732 | (overlay-start mouse-secondary-overlay) | |
1733 | (nth 1 range))) | |
9a974c88 RS |
1734 | ;; We have already put the old region in the kill ring. |
1735 | ;; Replace it with the extended region. | |
1736 | ;; (It would be annoying to make a separate entry.) | |
f69140fd KH |
1737 | (kill-new (buffer-substring |
1738 | (overlay-start mouse-secondary-overlay) | |
1739 | (overlay-end mouse-secondary-overlay)) t) | |
9a974c88 RS |
1740 | ;; Arrange for a repeated mouse-3 to kill this region. |
1741 | (setq mouse-save-then-kill-posn | |
1742 | (list (car kill-ring) (point) click-posn))) | |
1743 | ;; If we click this button again without moving it, | |
1744 | ;; that time kill. | |
d89a4a47 | 1745 | (progn |
9a974c88 RS |
1746 | (mouse-save-then-kill-delete-region |
1747 | (overlay-start mouse-secondary-overlay) | |
1748 | (overlay-end mouse-secondary-overlay)) | |
1749 | (setq mouse-save-then-kill-posn nil) | |
a94c7fcc | 1750 | (setq mouse-secondary-click-count 0) |
9a974c88 RS |
1751 | (delete-overlay mouse-secondary-overlay))) |
1752 | (if (and (eq last-command 'mouse-secondary-save-then-kill) | |
1753 | mouse-save-then-kill-posn | |
1754 | (eq (car mouse-save-then-kill-posn) (car kill-ring)) | |
1755 | (equal (cdr mouse-save-then-kill-posn) (list (point) click-posn))) | |
1756 | ;; If this is the second time we've called | |
1757 | ;; mouse-secondary-save-then-kill, delete the text from the buffer. | |
1758 | (progn | |
1759 | (mouse-save-then-kill-delete-region | |
1760 | (overlay-start mouse-secondary-overlay) | |
1761 | (overlay-end mouse-secondary-overlay)) | |
1762 | (setq mouse-save-then-kill-posn nil) | |
1763 | (delete-overlay mouse-secondary-overlay)) | |
1764 | (if (overlay-start mouse-secondary-overlay) | |
1765 | ;; We have a selection, so adjust it. | |
1766 | (progn | |
1767 | (if (numberp click-posn) | |
1768 | (progn | |
1769 | ;; Move whichever end of the region is closer to the click. | |
1770 | ;; That is what xterm does, and it seems reasonable. | |
1771 | (if (< (abs (- click-posn (overlay-start mouse-secondary-overlay))) | |
1772 | (abs (- click-posn (overlay-end mouse-secondary-overlay)))) | |
1773 | (move-overlay mouse-secondary-overlay click-posn | |
1774 | (overlay-end mouse-secondary-overlay)) | |
d89a4a47 RS |
1775 | (move-overlay mouse-secondary-overlay |
1776 | (overlay-start mouse-secondary-overlay) | |
1777 | click-posn)) | |
9a974c88 | 1778 | (setq deactivate-mark nil))) |
0136e1e3 | 1779 | (if (eq last-command 'mouse-secondary-save-then-kill) |
7b611de0 | 1780 | ;; If the front of the kill ring comes from |
f69140fd KH |
1781 | ;; an immediately previous use of this command, |
1782 | ;; replace it with the extended region. | |
1783 | ;; (It would be annoying to make a separate entry.) | |
1784 | (kill-new (buffer-substring | |
0136e1e3 | 1785 | (overlay-start mouse-secondary-overlay) |
f69140fd | 1786 | (overlay-end mouse-secondary-overlay)) t) |
1fa01bcd RS |
1787 | (let (deactivate-mark) |
1788 | (copy-region-as-kill (overlay-start mouse-secondary-overlay) | |
1789 | (overlay-end mouse-secondary-overlay))))) | |
9a974c88 RS |
1790 | (if mouse-secondary-start |
1791 | ;; All we have is one end of a selection, | |
1792 | ;; so put the other end here. | |
1793 | (let ((start (+ 0 mouse-secondary-start))) | |
1794 | (kill-ring-save start click-posn) | |
aaf15b8b | 1795 | (move-overlay mouse-secondary-overlay start click-posn)))) |
9a974c88 RS |
1796 | (setq mouse-save-then-kill-posn |
1797 | (list (car kill-ring) (point) click-posn)))) | |
fb28fd5b RS |
1798 | (if (overlay-buffer mouse-secondary-overlay) |
1799 | (x-set-selection 'SECONDARY | |
9a974c88 RS |
1800 | (buffer-substring |
1801 | (overlay-start mouse-secondary-overlay) | |
1802 | (overlay-end mouse-secondary-overlay))))))) | |
e66feb07 | 1803 | \f |
0d9be91c | 1804 | (defcustom mouse-buffer-menu-maxlen 20 |
f1107960 RS |
1805 | "*Number of buffers in one pane (submenu) of the buffer menu. |
1806 | If we have lots of buffers, divide them into groups of | |
0d9be91c | 1807 | `mouse-buffer-menu-maxlen' and make a pane (or submenu) for each one." |
3b558d41 RS |
1808 | :type 'integer |
1809 | :group 'mouse) | |
f1107960 | 1810 | |
3ca87c7b RS |
1811 | (defcustom mouse-buffer-menu-mode-mult 4 |
1812 | "*Group the buffers by the major mode groups on \\[mouse-buffer-menu]? | |
1813 | This number which determines (in a hairy way) whether \\[mouse-buffer-menu] | |
1814 | will split the buffer menu by the major modes (see | |
1815 | `mouse-buffer-menu-mode-groups') or just by menu length. | |
1816 | Set to 1 (or even 0!) if you want to group by major mode always, and to | |
1817 | a large number if you prefer a mixed multitude. The default is 4." | |
1818 | :type 'integer | |
1819 | :group 'mouse | |
1820 | :version "20.3") | |
1821 | ||
284a88a3 RS |
1822 | (defvar mouse-buffer-menu-mode-groups |
1823 | '(("Info\\|Help\\|Apropos\\|Man" . "Help") | |
1824 | ("\\bVM\\b\\|\\bMH\\b\\|Message\\|Mail\\|Group\\|Score\\|Summary\\|Article" | |
1825 | . "Mail/News") | |
1826 | ("\\<C\\>" . "C") | |
1827 | ("ObjC" . "C") | |
1828 | ("Text" . "Text") | |
1829 | ("Outline" . "Text") | |
c71a58a3 SS |
1830 | ("\\(HT\\|SG\\|X\\|XHT\\)ML" . "SGML") |
1831 | ("log\\|diff\\|vc\\|cvs" . "Version Control") ; "Change Management"? | |
284a88a3 RS |
1832 | ("Lisp" . "Lisp")) |
1833 | "How to group various major modes together in \\[mouse-buffer-menu]. | |
1834 | Each element has the form (REGEXP . GROUPNAME). | |
1835 | If the major mode's name string matches REGEXP, use GROUPNAME instead.") | |
1836 | ||
8b34e79d | 1837 | (defun mouse-buffer-menu (event) |
2d82f7b9 RS |
1838 | "Pop up a menu of buffers for selection with the mouse. |
1839 | This switches buffers in the window that you clicked on, | |
1840 | and selects that window." | |
ec558adc | 1841 | (interactive "e") |
d65147f6 | 1842 | (mouse-minibuffer-check event) |
3ca87c7b | 1843 | (let ((buffers (buffer-list)) alist menu split-by-major-mode sum-of-squares) |
284a88a3 | 1844 | ;; Make an alist of elements that look like (MENU-ITEM . BUFFER). |
cc2ee8ec SS |
1845 | (dolist (buf buffers) |
1846 | ;; Divide all buffers into buckets for various major modes. | |
1847 | ;; Each bucket looks like (MODE NAMESTRING BUFFERS...). | |
1848 | (with-current-buffer buf | |
1849 | (let* ((adjusted-major-mode major-mode) elt) | |
1850 | (dolist (group mouse-buffer-menu-mode-groups) | |
1851 | (when (string-match (car group) (format-mode-line mode-name)) | |
1852 | (setq adjusted-major-mode (cdr group)))) | |
1853 | (setq elt (assoc adjusted-major-mode split-by-major-mode)) | |
1854 | (unless elt | |
1855 | (setq elt (list adjusted-major-mode | |
1856 | (if (stringp adjusted-major-mode) | |
1857 | adjusted-major-mode | |
48d33090 | 1858 | (format-mode-line mode-name nil nil buf))) |
cc2ee8ec SS |
1859 | split-by-major-mode (cons elt split-by-major-mode))) |
1860 | (or (memq buf (cdr (cdr elt))) | |
1861 | (setcdr (cdr elt) (cons buf (cdr (cdr elt)))))))) | |
284a88a3 RS |
1862 | ;; Compute the sum of squares of sizes of the major-mode buckets. |
1863 | (let ((tail split-by-major-mode)) | |
1864 | (setq sum-of-squares 0) | |
1865 | (while tail | |
1866 | (setq sum-of-squares | |
1867 | (+ sum-of-squares | |
3ca87c7b | 1868 | (let ((len (length (cdr (cdr (car tail)))))) (* len len)))) |
284a88a3 | 1869 | (setq tail (cdr tail)))) |
3ca87c7b RS |
1870 | (if (< (* sum-of-squares mouse-buffer-menu-mode-mult) |
1871 | (* (length buffers) (length buffers))) | |
284a88a3 RS |
1872 | ;; Subdividing by major modes really helps, so let's do it. |
1873 | (let (subdivided-menus (buffers-left (length buffers))) | |
1874 | ;; Sort the list to put the most popular major modes first. | |
1875 | (setq split-by-major-mode | |
1876 | (sort split-by-major-mode | |
1877 | (function (lambda (elt1 elt2) | |
1878 | (> (length elt1) (length elt2)))))) | |
1879 | ;; Make a separate submenu for each major mode | |
1880 | ;; that has more than one buffer, | |
1881 | ;; unless all the remaining buffers are less than 1/10 of them. | |
1882 | (while (and split-by-major-mode | |
1883 | (and (> (length (car split-by-major-mode)) 3) | |
1884 | (> (* buffers-left 10) (length buffers)))) | |
4b4ea1dc EZ |
1885 | (let ((this-mode-list (mouse-buffer-menu-alist |
1886 | (cdr (cdr (car split-by-major-mode)))))) | |
1887 | (and this-mode-list | |
1888 | (setq subdivided-menus | |
1889 | (cons (cons | |
1890 | (nth 1 (car split-by-major-mode)) | |
1891 | this-mode-list) | |
1892 | subdivided-menus)))) | |
284a88a3 RS |
1893 | (setq buffers-left |
1894 | (- buffers-left (length (cdr (car split-by-major-mode))))) | |
1895 | (setq split-by-major-mode (cdr split-by-major-mode))) | |
1896 | ;; If any major modes are left over, | |
1897 | ;; make a single submenu for them. | |
1898 | (if split-by-major-mode | |
4b4ea1dc EZ |
1899 | (let ((others-list |
1900 | (mouse-buffer-menu-alist | |
1901 | ;; we don't need split-by-major-mode any more, | |
1902 | ;; so we can ditch it with nconc. | |
1903 | (apply 'nconc (mapcar 'cddr split-by-major-mode))))) | |
1904 | (and others-list | |
1905 | (setq subdivided-menus | |
1906 | (cons (cons "Others" others-list) | |
1907 | subdivided-menus))))) | |
3ca87c7b | 1908 | (setq menu (cons "Buffer Menu" (nreverse subdivided-menus)))) |
284a88a3 RS |
1909 | (progn |
1910 | (setq alist (mouse-buffer-menu-alist buffers)) | |
1911 | (setq menu (cons "Buffer Menu" | |
1912 | (mouse-buffer-menu-split "Select Buffer" alist))))) | |
2d82f7b9 RS |
1913 | (let ((buf (x-popup-menu event menu)) |
1914 | (window (posn-window (event-start event)))) | |
3ca87c7b | 1915 | (when buf |
f134ad18 RS |
1916 | (select-window |
1917 | (if (framep window) (frame-selected-window window) | |
1918 | window)) | |
3ca87c7b | 1919 | (switch-to-buffer buf))))) |
284a88a3 RS |
1920 | |
1921 | (defun mouse-buffer-menu-alist (buffers) | |
1922 | (let (tail | |
1923 | (maxlen 0) | |
1924 | head) | |
1925 | (setq buffers | |
1926 | (sort buffers | |
1927 | (function (lambda (elt1 elt2) | |
1928 | (string< (buffer-name elt1) (buffer-name elt2)))))) | |
1929 | (setq tail buffers) | |
1930 | (while tail | |
fc2b429e | 1931 | (or (eq ?\s (aref (buffer-name (car tail)) 0)) |
284a88a3 RS |
1932 | (setq maxlen |
1933 | (max maxlen | |
1934 | (length (buffer-name (car tail)))))) | |
1935 | (setq tail (cdr tail))) | |
1936 | (setq tail buffers) | |
1937 | (while tail | |
1938 | (let ((elt (car tail))) | |
66564ab0 | 1939 | (if (/= (aref (buffer-name elt) 0) ?\s) |
284a88a3 RS |
1940 | (setq head |
1941 | (cons | |
1942 | (cons | |
1943 | (format | |
fc1f472b | 1944 | (format "%%-%ds %%s%%s %%s" maxlen) |
284a88a3 RS |
1945 | (buffer-name elt) |
1946 | (if (buffer-modified-p elt) "*" " ") | |
1947 | (save-excursion | |
1948 | (set-buffer elt) | |
1949 | (if buffer-read-only "%" " ")) | |
7b611de0 | 1950 | (or (buffer-file-name elt) |
284a88a3 RS |
1951 | (save-excursion |
1952 | (set-buffer elt) | |
1953 | (if list-buffers-directory | |
1954 | (expand-file-name | |
1955 | list-buffers-directory))) | |
1956 | "")) | |
1957 | elt) | |
1958 | head)))) | |
1959 | (setq tail (cdr tail))) | |
1960 | ;; Compensate for the reversal that the above loop does. | |
1961 | (nreverse head))) | |
1962 | ||
1963 | (defun mouse-buffer-menu-split (title alist) | |
1964 | ;; If we have lots of buffers, divide them into groups of 20 | |
1965 | ;; and make a pane (or submenu) for each one. | |
0d9be91c | 1966 | (if (> (length alist) (/ (* mouse-buffer-menu-maxlen 3) 2)) |
284a88a3 RS |
1967 | (let ((alist alist) sublists next |
1968 | (i 1)) | |
1969 | (while alist | |
0d9be91c | 1970 | ;; Pull off the next mouse-buffer-menu-maxlen buffers |
284a88a3 | 1971 | ;; and make them the next element of sublist. |
0d9be91c | 1972 | (setq next (nthcdr mouse-buffer-menu-maxlen alist)) |
284a88a3 | 1973 | (if next |
0d9be91c | 1974 | (setcdr (nthcdr (1- mouse-buffer-menu-maxlen) alist) |
284a88a3 RS |
1975 | nil)) |
1976 | (setq sublists (cons (cons (format "Buffers %d" i) alist) | |
1977 | sublists)) | |
1978 | (setq i (1+ i)) | |
1979 | (setq alist next)) | |
1980 | (nreverse sublists)) | |
1981 | ;; Few buffers--put them all in one pane. | |
1982 | (list (cons title alist)))) | |
72ea54a4 | 1983 | \f |
ad0d18af SM |
1984 | ;; These need to be rewritten for the new scroll bar implementation. |
1985 | ||
1986 | ;;!! ;; Commands for the scroll bar. | |
1987 | ;;!! | |
1988 | ;;!! (defun mouse-scroll-down (click) | |
1989 | ;;!! (interactive "@e") | |
1990 | ;;!! (scroll-down (1+ (cdr (mouse-coords click))))) | |
1991 | ;;!! | |
1992 | ;;!! (defun mouse-scroll-up (click) | |
1993 | ;;!! (interactive "@e") | |
1994 | ;;!! (scroll-up (1+ (cdr (mouse-coords click))))) | |
1995 | ;;!! | |
1996 | ;;!! (defun mouse-scroll-down-full () | |
1997 | ;;!! (interactive "@") | |
1998 | ;;!! (scroll-down nil)) | |
1999 | ;;!! | |
2000 | ;;!! (defun mouse-scroll-up-full () | |
2001 | ;;!! (interactive "@") | |
2002 | ;;!! (scroll-up nil)) | |
2003 | ;;!! | |
2004 | ;;!! (defun mouse-scroll-move-cursor (click) | |
2005 | ;;!! (interactive "@e") | |
2006 | ;;!! (move-to-window-line (1+ (cdr (mouse-coords click))))) | |
2007 | ;;!! | |
2008 | ;;!! (defun mouse-scroll-absolute (event) | |
2009 | ;;!! (interactive "@e") | |
2010 | ;;!! (let* ((pos (car event)) | |
2011 | ;;!! (position (car pos)) | |
2012 | ;;!! (length (car (cdr pos)))) | |
2013 | ;;!! (if (<= length 0) (setq length 1)) | |
2014 | ;;!! (let* ((scale-factor (max 1 (/ length (/ 8000000 (buffer-size))))) | |
2015 | ;;!! (newpos (* (/ (* (/ (buffer-size) scale-factor) | |
2016 | ;;!! position) | |
2017 | ;;!! length) | |
2018 | ;;!! scale-factor))) | |
2019 | ;;!! (goto-char newpos) | |
2020 | ;;!! (recenter '(4))))) | |
2021 | ;;!! | |
2022 | ;;!! (defun mouse-scroll-left (click) | |
2023 | ;;!! (interactive "@e") | |
2024 | ;;!! (scroll-left (1+ (car (mouse-coords click))))) | |
2025 | ;;!! | |
2026 | ;;!! (defun mouse-scroll-right (click) | |
2027 | ;;!! (interactive "@e") | |
2028 | ;;!! (scroll-right (1+ (car (mouse-coords click))))) | |
2029 | ;;!! | |
2030 | ;;!! (defun mouse-scroll-left-full () | |
2031 | ;;!! (interactive "@") | |
2032 | ;;!! (scroll-left nil)) | |
2033 | ;;!! | |
2034 | ;;!! (defun mouse-scroll-right-full () | |
2035 | ;;!! (interactive "@") | |
2036 | ;;!! (scroll-right nil)) | |
2037 | ;;!! | |
2038 | ;;!! (defun mouse-scroll-move-cursor-horizontally (click) | |
2039 | ;;!! (interactive "@e") | |
2040 | ;;!! (move-to-column (1+ (car (mouse-coords click))))) | |
2041 | ;;!! | |
2042 | ;;!! (defun mouse-scroll-absolute-horizontally (event) | |
2043 | ;;!! (interactive "@e") | |
2044 | ;;!! (let* ((pos (car event)) | |
2045 | ;;!! (position (car pos)) | |
2046 | ;;!! (length (car (cdr pos)))) | |
2047 | ;;!! (set-window-hscroll (selected-window) 33))) | |
2048 | ;;!! | |
2049 | ;;!! (global-set-key [scroll-bar mouse-1] 'mouse-scroll-up) | |
2050 | ;;!! (global-set-key [scroll-bar mouse-2] 'mouse-scroll-absolute) | |
2051 | ;;!! (global-set-key [scroll-bar mouse-3] 'mouse-scroll-down) | |
2052 | ;;!! | |
2053 | ;;!! (global-set-key [vertical-slider mouse-1] 'mouse-scroll-move-cursor) | |
2054 | ;;!! (global-set-key [vertical-slider mouse-2] 'mouse-scroll-move-cursor) | |
2055 | ;;!! (global-set-key [vertical-slider mouse-3] 'mouse-scroll-move-cursor) | |
2056 | ;;!! | |
2057 | ;;!! (global-set-key [thumbup mouse-1] 'mouse-scroll-up-full) | |
2058 | ;;!! (global-set-key [thumbup mouse-2] 'mouse-scroll-up-full) | |
2059 | ;;!! (global-set-key [thumbup mouse-3] 'mouse-scroll-up-full) | |
2060 | ;;!! | |
2061 | ;;!! (global-set-key [thumbdown mouse-1] 'mouse-scroll-down-full) | |
2062 | ;;!! (global-set-key [thumbdown mouse-2] 'mouse-scroll-down-full) | |
2063 | ;;!! (global-set-key [thumbdown mouse-3] 'mouse-scroll-down-full) | |
2064 | ;;!! | |
2065 | ;;!! (global-set-key [horizontal-scroll-bar mouse-1] 'mouse-scroll-left) | |
2066 | ;;!! (global-set-key [horizontal-scroll-bar mouse-2] | |
2067 | ;;!! 'mouse-scroll-absolute-horizontally) | |
2068 | ;;!! (global-set-key [horizontal-scroll-bar mouse-3] 'mouse-scroll-right) | |
2069 | ;;!! | |
2070 | ;;!! (global-set-key [horizontal-slider mouse-1] | |
2071 | ;;!! 'mouse-scroll-move-cursor-horizontally) | |
2072 | ;;!! (global-set-key [horizontal-slider mouse-2] | |
2073 | ;;!! 'mouse-scroll-move-cursor-horizontally) | |
2074 | ;;!! (global-set-key [horizontal-slider mouse-3] | |
2075 | ;;!! 'mouse-scroll-move-cursor-horizontally) | |
2076 | ;;!! | |
2077 | ;;!! (global-set-key [thumbleft mouse-1] 'mouse-scroll-left-full) | |
2078 | ;;!! (global-set-key [thumbleft mouse-2] 'mouse-scroll-left-full) | |
2079 | ;;!! (global-set-key [thumbleft mouse-3] 'mouse-scroll-left-full) | |
2080 | ;;!! | |
2081 | ;;!! (global-set-key [thumbright mouse-1] 'mouse-scroll-right-full) | |
2082 | ;;!! (global-set-key [thumbright mouse-2] 'mouse-scroll-right-full) | |
2083 | ;;!! (global-set-key [thumbright mouse-3] 'mouse-scroll-right-full) | |
2084 | ;;!! | |
2085 | ;;!! (global-set-key [horizontal-scroll-bar S-mouse-2] | |
2086 | ;;!! 'mouse-split-window-horizontally) | |
2087 | ;;!! (global-set-key [mode-line S-mouse-2] | |
2088 | ;;!! 'mouse-split-window-horizontally) | |
2089 | ;;!! (global-set-key [vertical-scroll-bar S-mouse-2] | |
2090 | ;;!! 'mouse-split-window) | |
6b2154de | 2091 | \f |
ad0d18af SM |
2092 | ;;!! ;;;; |
2093 | ;;!! ;;;; Here are experimental things being tested. Mouse events | |
2094 | ;;!! ;;;; are of the form: | |
2095 | ;;!! ;;;; ((x y) window screen-part key-sequence timestamp) | |
2096 | ;;!! ;; | |
2097 | ;;!! ;;;; | |
2098 | ;;!! ;;;; Dynamically track mouse coordinates | |
2099 | ;;!! ;;;; | |
2100 | ;;!! ;; | |
2101 | ;;!! ;;(defun track-mouse (event) | |
2102 | ;;!! ;; "Track the coordinates, absolute and relative, of the mouse." | |
2103 | ;;!! ;; (interactive "@e") | |
2104 | ;;!! ;; (while mouse-grabbed | |
2105 | ;;!! ;; (let* ((pos (read-mouse-position (selected-screen))) | |
2106 | ;;!! ;; (abs-x (car pos)) | |
2107 | ;;!! ;; (abs-y (cdr pos)) | |
2108 | ;;!! ;; (relative-coordinate (coordinates-in-window-p | |
2109 | ;;!! ;; (list (car pos) (cdr pos)) | |
2110 | ;;!! ;; (selected-window)))) | |
2111 | ;;!! ;; (if (consp relative-coordinate) | |
2112 | ;;!! ;; (message "mouse: [%d %d], (%d %d)" abs-x abs-y | |
2113 | ;;!! ;; (car relative-coordinate) | |
2114 | ;;!! ;; (car (cdr relative-coordinate))) | |
2115 | ;;!! ;; (message "mouse: [%d %d]" abs-x abs-y))))) | |
2116 | ;;!! | |
2117 | ;;!! ;; | |
2118 | ;;!! ;; Dynamically put a box around the line indicated by point | |
2119 | ;;!! ;; | |
2120 | ;;!! ;; | |
2121 | ;;!! ;;(require 'backquote) | |
2122 | ;;!! ;; | |
2123 | ;;!! ;;(defun mouse-select-buffer-line (event) | |
2124 | ;;!! ;; (interactive "@e") | |
2125 | ;;!! ;; (let ((relative-coordinate | |
2126 | ;;!! ;; (coordinates-in-window-p (car event) (selected-window))) | |
2127 | ;;!! ;; (abs-y (car (cdr (car event))))) | |
2128 | ;;!! ;; (if (consp relative-coordinate) | |
2129 | ;;!! ;; (progn | |
2130 | ;;!! ;; (save-excursion | |
2131 | ;;!! ;; (move-to-window-line (car (cdr relative-coordinate))) | |
2132 | ;;!! ;; (x-draw-rectangle | |
2133 | ;;!! ;; (selected-screen) | |
2134 | ;;!! ;; abs-y 0 | |
2135 | ;;!! ;; (save-excursion | |
2136 | ;;!! ;; (move-to-window-line (car (cdr relative-coordinate))) | |
2137 | ;;!! ;; (end-of-line) | |
2138 | ;;!! ;; (push-mark nil t) | |
2139 | ;;!! ;; (beginning-of-line) | |
2140 | ;;!! ;; (- (region-end) (region-beginning))) 1)) | |
2141 | ;;!! ;; (sit-for 1) | |
2142 | ;;!! ;; (x-erase-rectangle (selected-screen)))))) | |
2143 | ;;!! ;; | |
2144 | ;;!! ;;(defvar last-line-drawn nil) | |
2145 | ;;!! ;;(defvar begin-delim "[^ \t]") | |
2146 | ;;!! ;;(defvar end-delim "[^ \t]") | |
2147 | ;;!! ;; | |
2148 | ;;!! ;;(defun mouse-boxing (event) | |
2149 | ;;!! ;; (interactive "@e") | |
2150 | ;;!! ;; (save-excursion | |
2151 | ;;!! ;; (let ((screen (selected-screen))) | |
2152 | ;;!! ;; (while (= (x-mouse-events) 0) | |
2153 | ;;!! ;; (let* ((pos (read-mouse-position screen)) | |
2154 | ;;!! ;; (abs-x (car pos)) | |
2155 | ;;!! ;; (abs-y (cdr pos)) | |
2156 | ;;!! ;; (relative-coordinate | |
2157 | ;;!! ;; (coordinates-in-window-p `(,abs-x ,abs-y) | |
2158 | ;;!! ;; (selected-window))) | |
2159 | ;;!! ;; (begin-reg nil) | |
2160 | ;;!! ;; (end-reg nil) | |
2161 | ;;!! ;; (end-column nil) | |
2162 | ;;!! ;; (begin-column nil)) | |
2163 | ;;!! ;; (if (and (consp relative-coordinate) | |
2164 | ;;!! ;; (or (not last-line-drawn) | |
2165 | ;;!! ;; (not (= last-line-drawn abs-y)))) | |
2166 | ;;!! ;; (progn | |
2167 | ;;!! ;; (move-to-window-line (car (cdr relative-coordinate))) | |
2168 | ;;!! ;; (if (= (following-char) 10) | |
2169 | ;;!! ;; () | |
2170 | ;;!! ;; (progn | |
2171 | ;;!! ;; (setq begin-reg (1- (re-search-forward end-delim))) | |
2172 | ;;!! ;; (setq begin-column (1- (current-column))) | |
2173 | ;;!! ;; (end-of-line) | |
2174 | ;;!! ;; (setq end-reg (1+ (re-search-backward begin-delim))) | |
2175 | ;;!! ;; (setq end-column (1+ (current-column))) | |
2176 | ;;!! ;; (message "%s" (buffer-substring begin-reg end-reg)) | |
2177 | ;;!! ;; (x-draw-rectangle screen | |
2178 | ;;!! ;; (setq last-line-drawn abs-y) | |
2179 | ;;!! ;; begin-column | |
2180 | ;;!! ;; (- end-column begin-column) 1)))))))))) | |
2181 | ;;!! ;; | |
2182 | ;;!! ;;(defun mouse-erase-box () | |
2183 | ;;!! ;; (interactive) | |
2184 | ;;!! ;; (if last-line-drawn | |
2185 | ;;!! ;; (progn | |
2186 | ;;!! ;; (x-erase-rectangle (selected-screen)) | |
2187 | ;;!! ;; (setq last-line-drawn nil)))) | |
2188 | ;;!! | |
2189 | ;;!! ;;; (defun test-x-rectangle () | |
2190 | ;;!! ;;; (use-local-mouse-map (setq rectangle-test-map (make-sparse-keymap))) | |
2191 | ;;!! ;;; (define-key rectangle-test-map mouse-motion-button-left 'mouse-boxing) | |
2192 | ;;!! ;;; (define-key rectangle-test-map mouse-button-left-up 'mouse-erase-box)) | |
2193 | ;;!! | |
2194 | ;;!! ;; | |
2195 | ;;!! ;; Here is how to do double clicking in lisp. About to change. | |
2196 | ;;!! ;; | |
2197 | ;;!! | |
2198 | ;;!! (defvar double-start nil) | |
2199 | ;;!! (defconst double-click-interval 300 | |
2200 | ;;!! "Max ticks between clicks") | |
2201 | ;;!! | |
2202 | ;;!! (defun double-down (event) | |
2203 | ;;!! (interactive "@e") | |
2204 | ;;!! (if double-start | |
2205 | ;;!! (let ((interval (- (nth 4 event) double-start))) | |
2206 | ;;!! (if (< interval double-click-interval) | |
2207 | ;;!! (progn | |
2208 | ;;!! (backward-up-list 1) | |
2209 | ;;!! ;; (message "Interval %d" interval) | |
2210 | ;;!! (sleep-for 1))) | |
2211 | ;;!! (setq double-start nil)) | |
2212 | ;;!! (setq double-start (nth 4 event)))) | |
2213 | ;;!! | |
2214 | ;;!! (defun double-up (event) | |
2215 | ;;!! (interactive "@e") | |
2216 | ;;!! (and double-start | |
2217 | ;;!! (> (- (nth 4 event ) double-start) double-click-interval) | |
2218 | ;;!! (setq double-start nil))) | |
2219 | ;;!! | |
2220 | ;;!! ;;; (defun x-test-doubleclick () | |
2221 | ;;!! ;;; (use-local-mouse-map (setq doubleclick-test-map (make-sparse-keymap))) | |
2222 | ;;!! ;;; (define-key doubleclick-test-map mouse-button-left 'double-down) | |
2223 | ;;!! ;;; (define-key doubleclick-test-map mouse-button-left-up 'double-up)) | |
2224 | ;;!! | |
2225 | ;;!! ;; | |
2226 | ;;!! ;; This scrolls while button is depressed. Use preferable in scroll bar. | |
2227 | ;;!! ;; | |
2228 | ;;!! | |
2229 | ;;!! (defvar scrolled-lines 0) | |
2230 | ;;!! (defconst scroll-speed 1) | |
2231 | ;;!! | |
2232 | ;;!! (defun incr-scroll-down (event) | |
2233 | ;;!! (interactive "@e") | |
2234 | ;;!! (setq scrolled-lines 0) | |
2235 | ;;!! (incremental-scroll scroll-speed)) | |
2236 | ;;!! | |
2237 | ;;!! (defun incr-scroll-up (event) | |
2238 | ;;!! (interactive "@e") | |
2239 | ;;!! (setq scrolled-lines 0) | |
2240 | ;;!! (incremental-scroll (- scroll-speed))) | |
2241 | ;;!! | |
2242 | ;;!! (defun incremental-scroll (n) | |
2243 | ;;!! (while (= (x-mouse-events) 0) | |
2244 | ;;!! (setq scrolled-lines (1+ (* scroll-speed scrolled-lines))) | |
2245 | ;;!! (scroll-down n) | |
2246 | ;;!! (sit-for 300 t))) | |
2247 | ;;!! | |
2248 | ;;!! (defun incr-scroll-stop (event) | |
2249 | ;;!! (interactive "@e") | |
2250 | ;;!! (message "Scrolled %d lines" scrolled-lines) | |
2251 | ;;!! (setq scrolled-lines 0) | |
2252 | ;;!! (sleep-for 1)) | |
2253 | ;;!! | |
2254 | ;;!! ;;; (defun x-testing-scroll () | |
2255 | ;;!! ;;; (let ((scrolling-map (function mouse-vertical-scroll-bar-prefix))) | |
2256 | ;;!! ;;; (define-key scrolling-map mouse-button-left 'incr-scroll-down) | |
2257 | ;;!! ;;; (define-key scrolling-map mouse-button-right 'incr-scroll-up) | |
2258 | ;;!! ;;; (define-key scrolling-map mouse-button-left-up 'incr-scroll-stop) | |
2259 | ;;!! ;;; (define-key scrolling-map mouse-button-right-up 'incr-scroll-stop))) | |
2260 | ;;!! | |
2261 | ;;!! ;; | |
2262 | ;;!! ;; Some playthings suitable for picture mode? They need work. | |
2263 | ;;!! ;; | |
2264 | ;;!! | |
2265 | ;;!! (defun mouse-kill-rectangle (event) | |
2266 | ;;!! "Kill the rectangle between point and the mouse cursor." | |
2267 | ;;!! (interactive "@e") | |
2268 | ;;!! (let ((point-save (point))) | |
2269 | ;;!! (save-excursion | |
2270 | ;;!! (mouse-set-point event) | |
2271 | ;;!! (push-mark nil t) | |
2272 | ;;!! (if (> point-save (point)) | |
2273 | ;;!! (kill-rectangle (point) point-save) | |
2274 | ;;!! (kill-rectangle point-save (point)))))) | |
2275 | ;;!! | |
2276 | ;;!! (defun mouse-open-rectangle (event) | |
2277 | ;;!! "Kill the rectangle between point and the mouse cursor." | |
2278 | ;;!! (interactive "@e") | |
2279 | ;;!! (let ((point-save (point))) | |
2280 | ;;!! (save-excursion | |
2281 | ;;!! (mouse-set-point event) | |
2282 | ;;!! (push-mark nil t) | |
2283 | ;;!! (if (> point-save (point)) | |
2284 | ;;!! (open-rectangle (point) point-save) | |
2285 | ;;!! (open-rectangle point-save (point)))))) | |
2286 | ;;!! | |
2287 | ;;!! ;; Must be a better way to do this. | |
2288 | ;;!! | |
2289 | ;;!! (defun mouse-multiple-insert (n char) | |
2290 | ;;!! (while (> n 0) | |
2291 | ;;!! (insert char) | |
2292 | ;;!! (setq n (1- n)))) | |
2293 | ;;!! | |
2294 | ;;!! ;; What this could do is not finalize until button was released. | |
2295 | ;;!! | |
2296 | ;;!! (defun mouse-move-text (event) | |
2297 | ;;!! "Move text from point to cursor position, inserting spaces." | |
2298 | ;;!! (interactive "@e") | |
2299 | ;;!! (let* ((relative-coordinate | |
2300 | ;;!! (coordinates-in-window-p (car event) (selected-window)))) | |
2301 | ;;!! (if (consp relative-coordinate) | |
2302 | ;;!! (cond ((> (current-column) (car relative-coordinate)) | |
2303 | ;;!! (delete-char | |
2304 | ;;!! (- (car relative-coordinate) (current-column)))) | |
2305 | ;;!! ((< (current-column) (car relative-coordinate)) | |
2306 | ;;!! (mouse-multiple-insert | |
2307 | ;;!! (- (car relative-coordinate) (current-column)) " ")) | |
2308 | ;;!! ((= (current-column) (car relative-coordinate)) (ding)))))) | |
07a78410 | 2309 | \f |
f936ae06 RS |
2310 | ;; Choose a completion with the mouse. |
2311 | ||
2312 | (defun mouse-choose-completion (event) | |
49e61c42 | 2313 | "Click on an alternative in the `*Completions*' buffer to choose it." |
f936ae06 | 2314 | (interactive "e") |
33c448cd RS |
2315 | ;; Give temporary modes such as isearch a chance to turn off. |
2316 | (run-hooks 'mouse-leave-buffer-hook) | |
d89a4a47 | 2317 | (let ((buffer (window-buffer)) |
02680e9b RS |
2318 | choice |
2319 | base-size) | |
f936ae06 RS |
2320 | (save-excursion |
2321 | (set-buffer (window-buffer (posn-window (event-start event)))) | |
f36f4e9e RS |
2322 | (if completion-reference-buffer |
2323 | (setq buffer completion-reference-buffer)) | |
02680e9b | 2324 | (setq base-size completion-base-size) |
f936ae06 RS |
2325 | (save-excursion |
2326 | (goto-char (posn-point (event-start event))) | |
b6be5d95 | 2327 | (let (beg end) |
9a43a594 RS |
2328 | (if (and (not (eobp)) (get-text-property (point) 'mouse-face)) |
2329 | (setq end (point) beg (1+ (point)))) | |
2330 | (if (null beg) | |
2331 | (error "No completion here")) | |
2332 | (setq beg (previous-single-property-change beg 'mouse-face)) | |
2f5ed2e8 RS |
2333 | (setq end (or (next-single-property-change end 'mouse-face) |
2334 | (point-max))) | |
8a30a619 | 2335 | (setq choice (buffer-substring-no-properties beg end))))) |
73e2025f RS |
2336 | (let ((owindow (selected-window))) |
2337 | (select-window (posn-window (event-start event))) | |
874a2cbd RS |
2338 | (if (and (one-window-p t 'selected-frame) |
2339 | (window-dedicated-p (selected-window))) | |
2340 | ;; This is a special buffer's frame | |
2341 | (iconify-frame (selected-frame)) | |
2342 | (or (window-dedicated-p (selected-window)) | |
2343 | (bury-buffer))) | |
73e2025f | 2344 | (select-window owindow)) |
02680e9b | 2345 | (choose-completion-string choice buffer base-size))) |
f936ae06 | 2346 | \f |
07a78410 RS |
2347 | ;; Font selection. |
2348 | ||
0eb9fef3 RS |
2349 | (defun font-menu-add-default () |
2350 | (let* ((default (cdr (assq 'font (frame-parameters (selected-frame))))) | |
2351 | (font-alist x-fixed-font-alist) | |
0d94f5ca | 2352 | (elt (or (assoc "Misc" font-alist) (nth 1 font-alist)))) |
0eb9fef3 RS |
2353 | (if (assoc "Default" elt) |
2354 | (delete (assoc "Default" elt) elt)) | |
2355 | (setcdr elt | |
6b8e486e | 2356 | (cons (list "Default" default) |
0eb9fef3 RS |
2357 | (cdr elt))))) |
2358 | ||
07a78410 | 2359 | (defvar x-fixed-font-alist |
d2b532fe | 2360 | '("Font Menu" |
07a78410 | 2361 | ("Misc" |
19d973e8 RS |
2362 | ;; For these, we specify the pixel height and width. |
2363 | ("fixed" "fixed") | |
2364 | ("6x10" "-misc-fixed-medium-r-normal--10-*-*-*-c-60-iso8859-1" "6x10") | |
2365 | ("6x12" | |
2366 | "-misc-fixed-medium-r-semicondensed--12-*-*-*-c-60-iso8859-1" "6x12") | |
2367 | ("6x13" | |
2368 | "-misc-fixed-medium-r-semicondensed--13-*-*-*-c-60-iso8859-1" "6x13") | |
2369 | ("7x13" "-misc-fixed-medium-r-normal--13-*-*-*-c-70-iso8859-1" "7x13") | |
2370 | ("7x14" "-misc-fixed-medium-r-normal--14-*-*-*-c-70-iso8859-1" "7x14") | |
2371 | ("8x13" "-misc-fixed-medium-r-normal--13-*-*-*-c-80-iso8859-1" "8x13") | |
2372 | ("9x15" "-misc-fixed-medium-r-normal--15-*-*-*-c-90-iso8859-1" "9x15") | |
2373 | ("10x20" "-misc-fixed-medium-r-normal--20-*-*-*-c-100-iso8859-1" "10x20") | |
2374 | ("11x18" "-misc-fixed-medium-r-normal--18-*-*-*-c-110-iso8859-1" "11x18") | |
2375 | ("12x24" "-misc-fixed-medium-r-normal--24-*-*-*-c-120-iso8859-1" "12x24") | |
fa21fdec | 2376 | ("") |
f29c3695 RS |
2377 | ("clean 5x8" |
2378 | "-schumacher-clean-medium-r-normal--8-*-*-*-c-50-iso8859-1") | |
2379 | ("clean 6x8" | |
2380 | "-schumacher-clean-medium-r-normal--8-*-*-*-c-60-iso8859-1") | |
19d973e8 RS |
2381 | ("clean 8x8" |
2382 | "-schumacher-clean-medium-r-normal--8-*-*-*-c-80-iso8859-1") | |
2383 | ("clean 8x10" | |
2384 | "-schumacher-clean-medium-r-normal--10-*-*-*-c-80-iso8859-1") | |
2385 | ("clean 8x14" | |
2386 | "-schumacher-clean-medium-r-normal--14-*-*-*-c-80-iso8859-1") | |
2387 | ("clean 8x16" | |
2388 | "-schumacher-clean-medium-r-normal--16-*-*-*-c-80-iso8859-1") | |
fa21fdec | 2389 | ("") |
29a3028d | 2390 | ("sony 8x16" "-sony-fixed-medium-r-normal--16-*-*-*-c-80-iso8859-1") |
ad0d18af SM |
2391 | ;; We don't seem to have these; who knows what they are. |
2392 | ;; ("fg-18" "fg-18") | |
2393 | ;; ("fg-25" "fg-25") | |
29a3028d DL |
2394 | ("lucidasanstypewriter-12" "-b&h-lucidatypewriter-medium-r-normal-sans-*-120-*-*-*-*-iso8859-1") |
2395 | ("lucidasanstypewriter-bold-14" "-b&h-lucidatypewriter-bold-r-normal-sans-*-140-*-*-*-*-iso8859-1") | |
2396 | ("lucidasanstypewriter-bold-24" | |
2397 | "-b&h-lucidatypewriter-bold-r-normal-sans-*-240-*-*-*-*-iso8859-1") | |
ad0d18af SM |
2398 | ;; ("lucidatypewriter-bold-r-24" "-b&h-lucidatypewriter-bold-r-normal-sans-24-240-75-75-m-140-iso8859-1") |
2399 | ;; ("fixed-medium-20" "-misc-fixed-medium-*-*-*-20-*-*-*-*-*-*-*") | |
29a3028d | 2400 | ) |
07a78410 | 2401 | ("Courier" |
19d973e8 | 2402 | ;; For these, we specify the point height. |
82c048a9 RS |
2403 | ("8" "-adobe-courier-medium-r-normal--*-80-*-*-m-*-iso8859-1") |
2404 | ("10" "-adobe-courier-medium-r-normal--*-100-*-*-m-*-iso8859-1") | |
2405 | ("12" "-adobe-courier-medium-r-normal--*-120-*-*-m-*-iso8859-1") | |
2406 | ("14" "-adobe-courier-medium-r-normal--*-140-*-*-m-*-iso8859-1") | |
2407 | ("18" "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1") | |
2408 | ("24" "-adobe-courier-medium-r-normal--*-240-*-*-m-*-iso8859-1") | |
2409 | ("8 bold" "-adobe-courier-bold-r-normal--*-80-*-*-m-*-iso8859-1") | |
2410 | ("10 bold" "-adobe-courier-bold-r-normal--*-100-*-*-m-*-iso8859-1") | |
2411 | ("12 bold" "-adobe-courier-bold-r-normal--*-120-*-*-m-*-iso8859-1") | |
2412 | ("14 bold" "-adobe-courier-bold-r-normal--*-140-*-*-m-*-iso8859-1") | |
2413 | ("18 bold" "-adobe-courier-bold-r-normal--*-180-*-*-m-*-iso8859-1") | |
2414 | ("24 bold" "-adobe-courier-bold-r-normal--*-240-*-*-m-*-iso8859-1") | |
2415 | ("8 slant" "-adobe-courier-medium-o-normal--*-80-*-*-m-*-iso8859-1") | |
2416 | ("10 slant" "-adobe-courier-medium-o-normal--*-100-*-*-m-*-iso8859-1") | |
2417 | ("12 slant" "-adobe-courier-medium-o-normal--*-120-*-*-m-*-iso8859-1") | |
2418 | ("14 slant" "-adobe-courier-medium-o-normal--*-140-*-*-m-*-iso8859-1") | |
2419 | ("18 slant" "-adobe-courier-medium-o-normal--*-180-*-*-m-*-iso8859-1") | |
2420 | ("24 slant" "-adobe-courier-medium-o-normal--*-240-*-*-m-*-iso8859-1") | |
2421 | ("8 bold slant" "-adobe-courier-bold-o-normal--*-80-*-*-m-*-iso8859-1") | |
2422 | ("10 bold slant" "-adobe-courier-bold-o-normal--*-100-*-*-m-*-iso8859-1") | |
2423 | ("12 bold slant" "-adobe-courier-bold-o-normal--*-120-*-*-m-*-iso8859-1") | |
2424 | ("14 bold slant" "-adobe-courier-bold-o-normal--*-140-*-*-m-*-iso8859-1") | |
2425 | ("18 bold slant" "-adobe-courier-bold-o-normal--*-180-*-*-m-*-iso8859-1") | |
2426 | ("24 bold slant" "-adobe-courier-bold-o-normal--*-240-*-*-m-*-iso8859-1")) | |
07a78410 RS |
2427 | ) |
2428 | "X fonts suitable for use in Emacs.") | |
2429 | ||
1900a92b | 2430 | (defun mouse-set-font (&rest fonts) |
624c972d | 2431 | "Select an Emacs font from a list of known good fonts and fontsets." |
07a78410 | 2432 | (interactive |
8eb1dc02 RS |
2433 | (progn (unless (display-multi-font-p) |
2434 | (error "Cannot change fonts on this display")) | |
2435 | (x-popup-menu | |
91c51412 LT |
2436 | (if (listp last-nonmenu-event) |
2437 | last-nonmenu-event | |
2438 | (list '(0 0) (selected-window))) | |
8eb1dc02 RS |
2439 | ;; Append list of fontsets currently defined. |
2440 | (append x-fixed-font-alist (list (generate-fontset-menu)))))) | |
df4de8c6 KH |
2441 | (if fonts |
2442 | (let (font) | |
2443 | (while fonts | |
2444 | (condition-case nil | |
2445 | (progn | |
3fadec1a | 2446 | (set-default-font (car fonts)) |
df4de8c6 KH |
2447 | (setq font (car fonts)) |
2448 | (setq fonts nil)) | |
3fadec1a RS |
2449 | (error |
2450 | (setq fonts (cdr fonts))))) | |
df4de8c6 | 2451 | (if (null font) |
8eb1dc02 | 2452 | (error "Font not found"))))) |
cc0a8174 JB |
2453 | \f |
2454 | ;;; Bindings for mouse commands. | |
2455 | ||
fcfc3c63 | 2456 | (define-key global-map [down-mouse-1] 'mouse-drag-region) |
dbc4e1c1 | 2457 | (global-set-key [mouse-1] 'mouse-set-point) |
dbc4e1c1 | 2458 | (global-set-key [drag-mouse-1] 'mouse-set-region) |
fcfc3c63 | 2459 | |
e37de120 RS |
2460 | ;; These are tested for in mouse-drag-region. |
2461 | (global-set-key [double-mouse-1] 'mouse-set-point) | |
2462 | (global-set-key [triple-mouse-1] 'mouse-set-point) | |
2463 | ||
76693d12 KS |
2464 | ;; Clicking on the fringes causes hscrolling: |
2465 | (global-set-key [left-fringe mouse-1] 'mouse-set-point) | |
2466 | (global-set-key [right-fringe mouse-1] 'mouse-set-point) | |
2467 | ||
dbc4e1c1 | 2468 | (global-set-key [mouse-2] 'mouse-yank-at-click) |
3e9323d6 | 2469 | ;; Allow yanking also when the corresponding cursor is "in the fringe". |
d97c13b2 | 2470 | (global-set-key [right-fringe mouse-2] 'mouse-yank-at-click) |
84e42e60 | 2471 | (global-set-key [left-fringe mouse-2] 'mouse-yank-at-click) |
dbc4e1c1 | 2472 | (global-set-key [mouse-3] 'mouse-save-then-kill) |
84e42e60 EZ |
2473 | (global-set-key [right-fringe mouse-3] 'mouse-save-then-kill) |
2474 | (global-set-key [left-fringe mouse-3] 'mouse-save-then-kill) | |
8b34e79d | 2475 | |
dbc4e1c1 JB |
2476 | ;; By binding these to down-going events, we let the user use the up-going |
2477 | ;; event to make the selection, saving a click. | |
08a1c178 RS |
2478 | (global-set-key [C-down-mouse-1] 'mouse-buffer-menu) |
2479 | (if (not (eq system-type 'ms-dos)) | |
2480 | (global-set-key [S-down-mouse-1] 'mouse-set-font)) | |
eef805d7 | 2481 | ;; C-down-mouse-2 is bound in facemenu.el. |
0b2b62ff SM |
2482 | (global-set-key [C-down-mouse-3] |
2483 | '(menu-item "Menu Bar" ignore | |
2484 | :filter (lambda (_) | |
2485 | (if (zerop (or (frame-parameter nil 'menu-bar-lines) 0)) | |
2486 | (mouse-menu-bar-map) | |
2487 | (mouse-menu-major-mode-map))))) | |
95132d1c | 2488 | |
07a78410 | 2489 | |
8b34e79d RS |
2490 | ;; Replaced with dragging mouse-1 |
2491 | ;; (global-set-key [S-mouse-1] 'mouse-set-mark) | |
947da0c4 | 2492 | |
06a8c9f8 EZ |
2493 | ;; Binding mouse-1 to mouse-select-window when on mode-, header-, or |
2494 | ;; vertical-line prevents Emacs from signaling an error when the mouse | |
2495 | ;; button is released after dragging these lines, on non-toolkit | |
2496 | ;; versions. | |
3c2dd2c0 | 2497 | (global-set-key [mode-line mouse-1] 'mouse-select-window) |
544e7e73 RS |
2498 | (global-set-key [mode-line drag-mouse-1] 'mouse-select-window) |
2499 | (global-set-key [mode-line down-mouse-1] 'mouse-drag-mode-line) | |
b0d22e20 | 2500 | (global-set-key [header-line down-mouse-1] 'mouse-drag-header-line) |
06a8c9f8 | 2501 | (global-set-key [header-line mouse-1] 'mouse-select-window) |
3c2dd2c0 | 2502 | (global-set-key [mode-line mouse-2] 'mouse-delete-other-windows) |
dbc4e1c1 | 2503 | (global-set-key [mode-line mouse-3] 'mouse-delete-window) |
3c2dd2c0 | 2504 | (global-set-key [mode-line C-mouse-2] 'mouse-split-window-horizontally) |
9926ab64 | 2505 | (global-set-key [vertical-scroll-bar C-mouse-2] 'mouse-split-window-vertically) |
b6522df6 | 2506 | (global-set-key [vertical-line C-mouse-2] 'mouse-split-window-vertically) |
08a1c178 RS |
2507 | (global-set-key [vertical-line down-mouse-1] 'mouse-drag-vertical-line) |
2508 | (global-set-key [vertical-line mouse-1] 'mouse-select-window) | |
49116ac0 JB |
2509 | |
2510 | (provide 'mouse) | |
2511 | ||
2fe85227 DL |
2512 | ;; This file contains the functionality of the old mldrag.el. |
2513 | (defalias 'mldrag-drag-mode-line 'mouse-drag-mode-line) | |
2514 | (defalias 'mldrag-drag-vertical-line 'mouse-drag-vertical-line) | |
342a1e7b SM |
2515 | (make-obsolete 'mldrag-drag-mode-line 'mouse-drag-mode-line "21.1") |
2516 | (make-obsolete 'mldrag-drag-vertical-line 'mouse-drag-vertical-line "21.1") | |
2fe85227 DL |
2517 | (provide 'mldrag) |
2518 | ||
f002506f | 2519 | ;; arch-tag: 9a710ce1-914a-4923-9b81-697f7bf82ab3 |
6594deb0 | 2520 | ;;; mouse.el ends here |