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