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