]> code.delx.au - gnu-emacs/blob - lisp/mouse.el
(goto-address-url-face, goto-address-mail-face)
[gnu-emacs] / lisp / mouse.el
1 ;;; mouse.el --- window system-independent mouse support
2
3 ;; Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
4
5 ;; Maintainer: FSF
6 ;; Keywords: hardware
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;; This package provides various useful commands (including help
28 ;; system access) through the mouse. All this code assumes that mouse
29 ;; interpretation has been abstracted into Emacs input events.
30 ;;
31 ;; The code is rather X-dependent.
32
33 ;;; Code:
34
35 ;;; Utility functions.
36
37 ;;; Indent track-mouse like progn.
38 (put 'track-mouse 'lisp-indent-function 0)
39
40 (defvar mouse-yank-at-point nil
41 "*If non-nil, mouse yank commands yank at point instead of at click.")
42 \f
43 ;; Provide a mode-specific menu on a mouse button.
44
45 (defun mouse-major-mode-menu (event)
46 "Pop up a mode-specific menu of mouse commands."
47 ;; Switch to the window clicked on, because otherwise
48 ;; the mode's commands may not make sense.
49 (interactive "@e")
50 (let ((newmap (make-sparse-keymap))
51 (unread-command-events (list event)))
52 ;; Make a keymap in which our last command leads to a menu
53 (define-key newmap (vector (car event))
54 (nconc (make-sparse-keymap "Menu")
55 (mouse-major-mode-menu-1
56 (and (current-local-map)
57 (lookup-key (current-local-map) [menu-bar])))))
58 (mouse-major-mode-menu-compute-equiv-keys newmap)
59 ;; Make NEWMAP override the usual definition
60 ;; of the mouse button that got us here.
61 ;; Then read the user's menu choice.
62 (let* ((minor-mode-map-alist
63 (cons (cons t newmap) minor-mode-map-alist))
64 ;; read-key-sequence quits if the user aborts the menu.
65 ;; If that happens, do nothing silently.
66 (keyseq (condition-case nil
67 (read-key-sequence "")
68 (quit nil)))
69 (command (if keyseq (lookup-key newmap keyseq))))
70 (if command
71 (command-execute command)))))
72
73 ;; Compute and cache the equivalent keys in MENU and all its submenus.
74 (defun mouse-major-mode-menu-compute-equiv-keys (menu)
75 (and (eq (car menu) 'keymap)
76 (x-popup-menu nil menu))
77 (while menu
78 (and (consp (car menu))
79 (consp (cdr (car menu)))
80 (let ((tail (cdr (car menu))))
81 (while (and (consp tail)
82 (not (eq (car tail) 'keymap)))
83 (setq tail (cdr tail)))
84 (if (consp tail)
85 (mouse-major-mode-menu-compute-equiv-keys tail))))
86 (setq menu (cdr menu))))
87
88 ;; Given a mode's menu bar keymap,
89 ;; if it defines exactly one menu bar menu,
90 ;; return just that menu.
91 ;; Otherwise return a menu for all of them.
92 (defun mouse-major-mode-menu-1 (menubar)
93 (if menubar
94 (let ((tail menubar)
95 submap)
96 (while tail
97 (if (consp (car tail))
98 (if submap
99 (setq submap t)
100 (setq submap (cdr (car tail)))))
101 (setq tail (cdr tail)))
102 (if (eq submap t) menubar
103 submap))))
104 \f
105 ;; Commands that operate on windows.
106
107 (defun mouse-minibuffer-check (event)
108 (let ((w (posn-window (event-start event))))
109 (and (window-minibuffer-p w)
110 (not (minibuffer-window-active-p w))
111 (error "Minibuffer window is not active")))
112 ;; Give temporary modes such as isearch a chance to turn off.
113 (run-hooks 'mouse-leave-buffer-hook))
114
115 (defun mouse-delete-window (click)
116 "Delete the window you click on.
117 This must be bound to a mouse click."
118 (interactive "e")
119 (mouse-minibuffer-check click)
120 (delete-window (posn-window (event-start click))))
121
122 (defun mouse-select-window (click)
123 "Select the window clicked on; don't move point."
124 (interactive "e")
125 (mouse-minibuffer-check click)
126 (let ((oframe (selected-frame))
127 (frame (window-frame (posn-window (event-start click)))))
128 (select-window (posn-window (event-start click)))
129 (raise-frame frame)
130 (select-frame frame)
131 (or (eq frame oframe)
132 (set-mouse-position (selected-frame) (1- (frame-width)) 0))
133 (unfocus-frame)))
134
135 (defun mouse-tear-off-window (click)
136 "Delete the window clicked on, and create a new frame displaying its buffer."
137 (interactive "e")
138 (mouse-minibuffer-check click)
139 (let* ((window (posn-window (event-start click)))
140 (buf (window-buffer window))
141 (frame (make-frame)))
142 (select-frame frame)
143 (switch-to-buffer buf)
144 (delete-window window)))
145
146 (defun mouse-delete-other-windows ()
147 "Delete all window except the one you click on."
148 (interactive "@")
149 (delete-other-windows))
150
151 (defun mouse-split-window-vertically (click)
152 "Select Emacs window mouse is on, then split it vertically in half.
153 The window is split at the line clicked on.
154 This command must be bound to a mouse click."
155 (interactive "@e")
156 (mouse-minibuffer-check click)
157 (let ((start (event-start click)))
158 (select-window (posn-window start))
159 (let ((new-height (1+ (cdr (posn-col-row (event-end click)))))
160 (first-line window-min-height)
161 (last-line (- (window-height) window-min-height)))
162 (if (< last-line first-line)
163 (error "Window too short to split")
164 (split-window-vertically
165 (min (max new-height first-line) last-line))))))
166
167 (defun mouse-split-window-horizontally (click)
168 "Select Emacs window mouse is on, then split it horizontally in half.
169 The window is split at the column clicked on.
170 This command must be bound to a mouse click."
171 (interactive "@e")
172 (mouse-minibuffer-check click)
173 (let ((start (event-start click)))
174 (select-window (posn-window start))
175 (let ((new-width (1+ (car (posn-col-row (event-end click)))))
176 (first-col window-min-width)
177 (last-col (- (window-width) window-min-width)))
178 (if (< last-col first-col)
179 (error "Window too narrow to split")
180 (split-window-horizontally
181 (min (max new-width first-col) last-col))))))
182
183 (defun mouse-drag-mode-line (start-event)
184 "Change the height of a window by dragging on the mode line."
185 (interactive "e")
186 ;; Give temporary modes such as isearch a chance to turn off.
187 (run-hooks 'mouse-leave-buffer-hook)
188 (let ((done nil)
189 (echo-keystrokes 0)
190 (start-event-frame (window-frame (car (car (cdr start-event)))))
191 (start-event-window (car (car (cdr start-event))))
192 (start-nwindows (count-windows t))
193 (old-selected-window (selected-window))
194 should-enlarge-minibuffer
195 event mouse minibuffer y top bot edges wconfig params growth)
196 (setq params (frame-parameters))
197 (if (and (not (setq minibuffer (cdr (assq 'minibuffer params))))
198 (one-window-p t))
199 (error "Attempt to resize sole window"))
200 (track-mouse
201 (progn
202 ;; enlarge-window only works on the selected window, so
203 ;; we must select the window where the start event originated.
204 ;; unwind-protect will restore the old selected window later.
205 (select-window start-event-window)
206 ;; if this is the bottommost ordinary window, then to
207 ;; move its modeline the minibuffer must be enlarged.
208 (setq should-enlarge-minibuffer
209 (and minibuffer
210 (not (one-window-p t))
211 (= (nth 1 (window-edges minibuffer))
212 (nth 3 (window-edges)))))
213 ;; loop reading events and sampling the position of
214 ;; the mouse.
215 (while (not done)
216 (setq event (read-event)
217 mouse (mouse-position))
218 ;; do nothing if
219 ;; - there is a switch-frame event.
220 ;; - the mouse isn't in the frame that we started in
221 ;; - the mouse isn't in any Emacs frame
222 ;; drag if
223 ;; - there is a mouse-movement event
224 ;; - there is a scroll-bar-movement event
225 ;; (same as mouse movement for our purposes)
226 ;; quit if
227 ;; - there is a keyboard event or some other unknown event
228 ;; unknown event.
229 (cond ((integerp event)
230 (setq done t))
231 ((eq (car event) 'switch-frame)
232 nil)
233 ((not (memq (car event)
234 '(mouse-movement scroll-bar-movement)))
235 (if (consp event)
236 (setq unread-command-events
237 (cons event unread-command-events)))
238 (setq done t))
239 ((not (eq (car mouse) start-event-frame))
240 nil)
241 ((null (car (cdr mouse)))
242 nil)
243 (t
244 (setq y (cdr (cdr mouse))
245 edges (window-edges)
246 top (nth 1 edges)
247 bot (nth 3 edges))
248 ;; scale back a move that would make the
249 ;; window too short.
250 (cond ((< (- y top -1) window-min-height)
251 (setq y (+ top window-min-height -1))))
252 ;; compute size change needed
253 (setq growth (- y bot -1)
254 wconfig (current-window-configuration))
255 ;; grow/shrink minibuffer?
256 (if should-enlarge-minibuffer
257 (progn
258 ;; yes. briefly select minibuffer so
259 ;; enlarge-window will affect the
260 ;; correct window.
261 (select-window minibuffer)
262 ;; scale back shrinkage if it would
263 ;; make the minibuffer less than 1
264 ;; line tall.
265 (if (and (> growth 0)
266 (< (- (window-height minibuffer)
267 growth)
268 1))
269 (setq growth (1- (window-height minibuffer))))
270 (enlarge-window (- growth))
271 (select-window start-event-window))
272 ;; no. grow/shrink the selected window
273 (enlarge-window growth))
274 ;; if this window's growth caused another
275 ;; window to be deleted because it was too
276 ;; short, rescind the change.
277 ;;
278 ;; if size change caused space to be stolen
279 ;; from a window above this one, rescind the
280 ;; change, but only if we didn't grow/srhink
281 ;; the minibuffer. minibuffer size changes
282 ;; can cause all windows to shrink... no way
283 ;; around it.
284 (if (or (/= start-nwindows (count-windows t))
285 (and (not should-enlarge-minibuffer)
286 (/= top (nth 1 (window-edges)))))
287 (set-window-configuration wconfig)))))))))
288 \f
289 (defun mouse-drag-vertical-line (start-event)
290 "Change the width of a window by dragging on the vertical line."
291 (interactive "e")
292 ;; Give temporary modes such as isearch a chance to turn off.
293 (run-hooks 'mouse-leave-buffer-hook)
294 (let ((done nil)
295 (echo-keystrokes 0)
296 (start-event-frame (window-frame (car (car (cdr start-event)))))
297 (start-event-window (car (car (cdr start-event))))
298 (start-nwindows (count-windows t))
299 (old-selected-window (selected-window))
300 event mouse x left right edges wconfig growth)
301 (if (one-window-p t)
302 (error "Attempt to resize sole ordinary window"))
303 (if (= (nth 2 (window-edges start-event-window))
304 (frame-width start-event-frame))
305 (error "Attempt to drag rightmost scrollbar"))
306 (track-mouse
307 (progn
308 ;; enlarge-window only works on the selected window, so
309 ;; we must select the window where the start event originated.
310 ;; unwind-protect will restore the old selected window later.
311 (select-window start-event-window)
312 ;; loop reading events and sampling the position of
313 ;; the mouse.
314 (while (not done)
315 (setq event (read-event)
316 mouse (mouse-position))
317 ;; do nothing if
318 ;; - there is a switch-frame event.
319 ;; - the mouse isn't in the frame that we started in
320 ;; - the mouse isn't in any Emacs frame
321 ;; drag if
322 ;; - there is a mouse-movement event
323 ;; - there is a scroll-bar-movement event
324 ;; (same as mouse movement for our purposes)
325 ;; quit if
326 ;; - there is a keyboard event or some other unknown event
327 ;; unknown event.
328 (cond ((integerp event)
329 (setq done t))
330 ((eq (car event) 'switch-frame)
331 nil)
332 ((not (memq (car event)
333 '(mouse-movement scroll-bar-movement)))
334 (if (consp event)
335 (setq unread-command-events
336 (cons event unread-command-events)))
337 (setq done t))
338 ((not (eq (car mouse) start-event-frame))
339 nil)
340 ((null (car (cdr mouse)))
341 nil)
342 (t
343 (setq x (car (cdr mouse))
344 edges (window-edges)
345 left (nth 0 edges)
346 right (nth 2 edges))
347 ;; scale back a move that would make the
348 ;; window too thin.
349 (cond ((< (- x left -1) window-min-width)
350 (setq x (+ left window-min-width -1))))
351 ;; compute size change needed
352 (setq growth (- x right -1)
353 wconfig (current-window-configuration))
354 (enlarge-window growth t)
355 ;; if this window's growth caused another
356 ;; window to be deleted because it was too
357 ;; thin, rescind the change.
358 ;;
359 ;; if size change caused space to be stolen
360 ;; from a window to the left of this one,
361 ;; rescind the change.
362 (if (or (/= start-nwindows (count-windows t))
363 (/= left (nth 0 (window-edges))))
364 (set-window-configuration wconfig)))))))))
365 \f
366 (defun mouse-set-point (event)
367 "Move point to the position clicked on with the mouse.
368 This should be bound to a mouse click event type."
369 (interactive "e")
370 (mouse-minibuffer-check event)
371 ;; Use event-end in case called from mouse-drag-region.
372 ;; If EVENT is a click, event-end and event-start give same value.
373 (let ((posn (event-end event)))
374 (if (not (windowp (posn-window posn)))
375 (error "Cursor not in text area of window"))
376 (select-window (posn-window posn))
377 (if (numberp (posn-point posn))
378 (goto-char (posn-point posn)))))
379
380 (defvar mouse-last-region-beg nil)
381 (defvar mouse-last-region-end nil)
382 (defvar mouse-last-region-tick nil)
383
384 (defun mouse-region-match ()
385 "Return non-nil if there's an active region that was set with the mouse."
386 (and (mark t) mark-active
387 (eq mouse-last-region-beg (region-beginning))
388 (eq mouse-last-region-end (region-end))
389 (eq mouse-last-region-tick (buffer-modified-tick))))
390
391 (defun mouse-set-region (click)
392 "Set the region to the text dragged over, and copy to kill ring.
393 This should be bound to a mouse drag event."
394 (interactive "e")
395 (mouse-minibuffer-check click)
396 (let ((posn (event-start click))
397 (end (event-end click)))
398 (select-window (posn-window posn))
399 (if (numberp (posn-point posn))
400 (goto-char (posn-point posn)))
401 ;; If mark is highlighted, no need to bounce the cursor.
402 ;; On X, we highlight while dragging, thus once again no need to bounce.
403 (or transient-mark-mode
404 (eq (framep (selected-frame)) 'x)
405 (eq (framep (selected-frame)) 'pc)
406 (eq (framep (selected-frame)) 'win32)
407 (sit-for 1))
408 (push-mark)
409 (set-mark (point))
410 (if (numberp (posn-point end))
411 (goto-char (posn-point end)))
412 ;; Don't set this-command to kill-region, so that a following
413 ;; C-w will not double the text in the kill ring.
414 ;; Ignore last-command so we don't append to a preceding kill.
415 (let (this-command last-command)
416 (copy-region-as-kill (mark) (point)))
417 (mouse-set-region-1)))
418
419 (defun mouse-set-region-1 ()
420 (setq mouse-last-region-beg (region-beginning))
421 (setq mouse-last-region-end (region-end))
422 (setq mouse-last-region-tick (buffer-modified-tick)))
423
424 (defvar mouse-scroll-delay 0.25
425 "*The pause between scroll steps caused by mouse drags, in seconds.
426 If you drag the mouse beyond the edge of a window, Emacs scrolls the
427 window to bring the text beyond that edge into view, with a delay of
428 this many seconds between scroll steps. Scrolling stops when you move
429 the mouse back into the window, or release the button.
430 This variable's value may be non-integral.
431 Setting this to zero causes Emacs to scroll as fast as it can.")
432
433 (defvar mouse-scroll-min-lines 1
434 "*The minimum number of lines scrolled by dragging mouse out of window.
435 Moving the mouse out the top or bottom edge of the window begins
436 scrolling repeatedly. The number of lines scrolled per repetition
437 is normally equal to the number of lines beyond the window edge that
438 the mouse has moved. However, it always scrolls at least the number
439 of lines specified by this variable.")
440
441 (defun mouse-scroll-subr (window jump &optional overlay start)
442 "Scroll the window WINDOW, JUMP lines at a time, until new input arrives.
443 If OVERLAY is an overlay, let it stretch from START to the far edge of
444 the newly visible text.
445 Upon exit, point is at the far edge of the newly visible text."
446 (cond
447 ((and (> jump 0) (< jump mouse-scroll-min-lines))
448 (setq jump mouse-scroll-min-lines))
449 ((and (< jump 0) (< (- jump) mouse-scroll-min-lines))
450 (setq jump (- mouse-scroll-min-lines))))
451 (let ((opoint (point)))
452 (while (progn
453 (goto-char (window-start window))
454 (if (not (zerop (vertical-motion jump window)))
455 (progn
456 (set-window-start window (point))
457 (if (natnump jump)
458 (progn
459 (goto-char (window-end window))
460 ;; window-end doesn't reflect the window's new
461 ;; start position until the next redisplay. Hurrah.
462 (vertical-motion (1- jump) window))
463 (goto-char (window-start window)))
464 (if overlay
465 (move-overlay overlay start (point)))
466 ;; Now that we have scrolled WINDOW properly,
467 ;; put point back where it was for the redisplay
468 ;; so that we don't mess up the selected window.
469 (or (eq window (selected-window))
470 (goto-char opoint))
471 (sit-for mouse-scroll-delay)))))
472 (or (eq window (selected-window))
473 (goto-char opoint))))
474
475 ;; Create an overlay and immediately delete it, to get "overlay in no buffer".
476 (defvar mouse-drag-overlay (make-overlay 1 1))
477 (delete-overlay mouse-drag-overlay)
478 (overlay-put mouse-drag-overlay 'face 'region)
479
480 (defvar mouse-selection-click-count 0)
481
482 (defvar mouse-selection-click-count-buffer nil)
483
484 (defun mouse-drag-region (start-event)
485 "Set the region to the text that the mouse is dragged over.
486 Highlight the drag area as you move the mouse.
487 This must be bound to a button-down mouse event.
488 In Transient Mark mode, the highlighting remains as long as the mark
489 remains active. Otherwise, it remains until the next input event."
490 (interactive "e")
491 (mouse-minibuffer-check start-event)
492 (let* ((echo-keystrokes 0)
493 (start-posn (event-start start-event))
494 (start-point (posn-point start-posn))
495 (start-window (posn-window start-posn))
496 (start-frame (window-frame start-window))
497 (bounds (window-edges start-window))
498 (top (nth 1 bounds))
499 (bottom (if (window-minibuffer-p start-window)
500 (nth 3 bounds)
501 ;; Don't count the mode line.
502 (1- (nth 3 bounds))))
503 (click-count (1- (event-click-count start-event))))
504 (setq mouse-selection-click-count click-count)
505 (setq mouse-selection-click-count-buffer (current-buffer))
506 (mouse-set-point start-event)
507 ;; In case the down click is in the middle of some intangible text,
508 ;; use the end of that text, and put it in START-POINT.
509 (if (< (point) start-point)
510 (goto-char start-point))
511 (setq start-point (point))
512 (let ((range (mouse-start-end start-point start-point click-count)))
513 (move-overlay mouse-drag-overlay (car range) (nth 1 range)
514 (window-buffer start-window)))
515 (deactivate-mark)
516 ;; end-of-range is used only in the single-click case.
517 ;; It is the place where the drag has reached so far
518 ;; (but not outside the window where the drag started).
519 (let (event end end-point (end-of-range (point)))
520 (track-mouse
521 (while (progn
522 (setq event (read-event))
523 (or (mouse-movement-p event)
524 (eq (car-safe event) 'switch-frame)))
525 (if (eq (car-safe event) 'switch-frame)
526 nil
527 (setq end (event-end event)
528 end-point (posn-point end))
529
530 (cond
531 ;; Are we moving within the original window?
532 ((and (eq (posn-window end) start-window)
533 (integer-or-marker-p end-point))
534 ;; Go to START-POINT first, so that when we move to END-POINT,
535 ;; if it's in the middle of intangible text,
536 ;; point jumps in the direction away from START-POINT.
537 (goto-char start-point)
538 (goto-char end-point)
539 (if (zerop (% click-count 3))
540 (setq end-of-range (point)))
541 (let ((range (mouse-start-end start-point (point) click-count)))
542 (move-overlay mouse-drag-overlay (car range) (nth 1 range))))
543
544 (t
545 (let ((mouse-row (cdr (cdr (mouse-position)))))
546 (cond
547 ((null mouse-row))
548 ((< mouse-row top)
549 (mouse-scroll-subr start-window (- mouse-row top)
550 mouse-drag-overlay start-point)
551 ;; Without this, point tends to jump back to the starting
552 ;; position where the mouse button was pressed down.
553 (setq end-of-range (overlay-start mouse-drag-overlay)))
554 ((>= mouse-row bottom)
555 (mouse-scroll-subr start-window (1+ (- mouse-row bottom))
556 mouse-drag-overlay start-point)
557 (setq end-of-range (overlay-end mouse-drag-overlay))))))))))
558 (if (consp event)
559 (let ((fun (key-binding (vector (car event)))))
560 ;; Run the binding of the terminating up-event, if possible.
561 ;; In the case of a multiple click, it gives the wrong results,
562 ;; because it would fail to set up a region.
563 (if nil ;; (and (= (mod mouse-selection-click-count 3) 0) (fboundp fun))
564 ;; In this case, we can just let the up-event execute normally.
565 (let ((end (event-end event)))
566 ;; Set the position in the event before we replay it,
567 ;; because otherwise it may have a position in the wrong
568 ;; buffer.
569 (setcar (cdr end) end-of-range)
570 ;; Delete the overlay before calling the function,
571 ;; because delete-overlay increases buffer-modified-tick.
572 (delete-overlay mouse-drag-overlay)
573 (setq unread-command-events
574 (cons event unread-command-events)))
575 (if (not (= (overlay-start mouse-drag-overlay)
576 (overlay-end mouse-drag-overlay)))
577 (let* ((stop-point (posn-point (event-end event)))
578 ;; The end that comes from where we ended the drag.
579 ;; Point goes here.
580 (region-termination
581 (if (< stop-point start-point)
582 (overlay-start mouse-drag-overlay)
583 (overlay-end mouse-drag-overlay)))
584 ;; The end that comes from where we started the drag.
585 ;; Mark goes there.
586 (region-commencement
587 (- (+ (overlay-end mouse-drag-overlay)
588 (overlay-start mouse-drag-overlay))
589 region-termination))
590 last-command this-command)
591 (push-mark region-commencement t t)
592 (goto-char region-termination)
593 (copy-region-as-kill (point) (mark t))
594 (mouse-show-mark)
595 (mouse-set-region-1))
596 (goto-char (overlay-end mouse-drag-overlay))
597 (setq this-command 'mouse-set-point)
598 (delete-overlay mouse-drag-overlay))))
599 (delete-overlay mouse-drag-overlay)))))
600 \f
601 ;; Commands to handle xterm-style multiple clicks.
602
603 (defun mouse-skip-word (dir)
604 "Skip over word, over whitespace, or over identical punctuation.
605 If DIR is positive skip forward; if negative, skip backward."
606 (let* ((char (following-char))
607 (syntax (char-to-string (char-syntax char))))
608 (cond ((or (string= syntax "w") (string= syntax " "))
609 (if (< dir 0)
610 (skip-syntax-backward syntax)
611 (skip-syntax-forward syntax)))
612 ((string= syntax "_")
613 (if (< dir 0)
614 (skip-syntax-backward "w_")
615 (skip-syntax-forward "w_")))
616 ((< dir 0)
617 (while (and (not (bobp)) (= (preceding-char) char))
618 (forward-char -1)))
619 (t
620 (while (and (not (eobp)) (= (following-char) char))
621 (forward-char 1))))))
622
623 ;; Return a list of region bounds based on START and END according to MODE.
624 ;; If MODE is 0 then set point to (min START END), mark to (max START END).
625 ;; If MODE is 1 then set point to start of word at (min START END),
626 ;; mark to end of word at (max START END).
627 ;; If MODE is 2 then do the same for lines.
628 (defun mouse-start-end (start end mode)
629 (if (> start end)
630 (let ((temp start))
631 (setq start end
632 end temp)))
633 (setq mode (mod mode 3))
634 (cond ((= mode 0)
635 (list start end))
636 ((and (= mode 1)
637 (= start end)
638 (char-after start)
639 (= (char-syntax (char-after start)) ?\())
640 (list start
641 (save-excursion
642 (goto-char start)
643 (forward-sexp 1)
644 (point))))
645 ((and (= mode 1)
646 (= start end)
647 (char-after start)
648 (= (char-syntax (char-after start)) ?\)))
649 (list (save-excursion
650 (goto-char (1+ start))
651 (backward-sexp 1)
652 (point))
653 (1+ start)))
654 ((= mode 1)
655 (list (save-excursion
656 (goto-char start)
657 (mouse-skip-word -1)
658 (point))
659 (save-excursion
660 (goto-char end)
661 (mouse-skip-word 1)
662 (point))))
663 ((= mode 2)
664 (list (save-excursion
665 (goto-char start)
666 (beginning-of-line 1)
667 (point))
668 (save-excursion
669 (goto-char end)
670 (forward-line 1)
671 (point))))))
672 \f
673 ;; Subroutine: set the mark where CLICK happened,
674 ;; but don't do anything else.
675 (defun mouse-set-mark-fast (click)
676 (mouse-minibuffer-check click)
677 (let ((posn (event-start click)))
678 (select-window (posn-window posn))
679 (if (numberp (posn-point posn))
680 (push-mark (posn-point posn) t t))))
681
682 ;; Momentarily show where the mark is, if highlighting doesn't show it.
683 (defun mouse-show-mark ()
684 (or transient-mark-mode
685 (if window-system
686 (let ((inhibit-quit t)
687 (echo-keystrokes 0)
688 event events)
689 (move-overlay mouse-drag-overlay (point) (mark t))
690 (while (progn (setq event (read-event))
691 (setq events (append events (list event)))
692 (and (memq 'down (event-modifiers event))
693 (not (key-binding (apply 'vector events))))))
694 (setq unread-command-events
695 (nconc events unread-command-events))
696 (setq quit-flag nil)
697 (delete-overlay mouse-drag-overlay))
698 (save-excursion
699 (goto-char (mark t))
700 (sit-for 1)))))
701
702 (defun mouse-set-mark (click)
703 "Set mark at the position clicked on with the mouse.
704 Display cursor at that position for a second.
705 This must be bound to a mouse click."
706 (interactive "e")
707 (mouse-minibuffer-check click)
708 (select-window (posn-window (event-start click)))
709 ;; We don't use save-excursion because that preserves the mark too.
710 (let ((point-save (point)))
711 (unwind-protect
712 (progn (mouse-set-point click)
713 (push-mark nil t t)
714 (or transient-mark-mode
715 (sit-for 1)))
716 (goto-char point-save))))
717
718 (defun mouse-kill (click)
719 "Kill the region between point and the mouse click.
720 The text is saved in the kill ring, as with \\[kill-region]."
721 (interactive "e")
722 (mouse-minibuffer-check click)
723 (let* ((posn (event-start click))
724 (click-posn (posn-point posn)))
725 (select-window (posn-window posn))
726 (if (numberp click-posn)
727 (kill-region (min (point) click-posn)
728 (max (point) click-posn)))))
729
730 (defun mouse-yank-at-click (click arg)
731 "Insert the last stretch of killed text at the position clicked on.
732 Also move point to one end of the text thus inserted (normally the end).
733 Prefix arguments are interpreted as with \\[yank].
734 If `mouse-yank-at-point' is non-nil, insert at point
735 regardless of where you click."
736 (interactive "e\nP")
737 ;; Give temporary modes such as isearch a chance to turn off.
738 (run-hooks 'mouse-leave-buffer-hook)
739 (or mouse-yank-at-point (mouse-set-point click))
740 (setq this-command 'yank)
741 (setq mouse-selection-click-count 0)
742 (yank arg))
743
744 (defun mouse-kill-ring-save (click)
745 "Copy the region between point and the mouse click in the kill ring.
746 This does not delete the region; it acts like \\[kill-ring-save]."
747 (interactive "e")
748 (mouse-set-mark-fast click)
749 (let (this-command last-command)
750 (kill-ring-save (point) (mark t)))
751 (mouse-show-mark))
752
753 ;;; This function used to delete the text between point and the mouse
754 ;;; whenever it was equal to the front of the kill ring, but some
755 ;;; people found that confusing.
756
757 ;;; A list (TEXT START END), describing the text and position of the last
758 ;;; invocation of mouse-save-then-kill.
759 (defvar mouse-save-then-kill-posn nil)
760
761 (defun mouse-save-then-kill-delete-region (beg end)
762 ;; We must make our own undo boundaries
763 ;; because they happen automatically only for the current buffer.
764 (undo-boundary)
765 (if (or (= beg end) (eq buffer-undo-list t))
766 ;; If we have no undo list in this buffer,
767 ;; just delete.
768 (delete-region beg end)
769 ;; Delete, but make the undo-list entry share with the kill ring.
770 ;; First, delete just one char, so in case buffer is being modified
771 ;; for the first time, the undo list records that fact.
772 (let (before-change-function after-change-function
773 before-change-functions after-change-functions)
774 (delete-region beg
775 (+ beg (if (> end beg) 1 -1))))
776 (let ((buffer-undo-list buffer-undo-list))
777 ;; Undo that deletion--but don't change the undo list!
778 (let (before-change-function after-change-function
779 before-change-functions after-change-functions)
780 (primitive-undo 1 buffer-undo-list))
781 ;; Now delete the rest of the specified region,
782 ;; but don't record it.
783 (setq buffer-undo-list t)
784 (if (/= (length (car kill-ring)) (- (max end beg) (min end beg)))
785 (error "Lossage in mouse-save-then-kill-delete-region"))
786 (delete-region beg end))
787 (let ((tail buffer-undo-list))
788 ;; Search back in buffer-undo-list for the string
789 ;; that came from deleting one character.
790 (while (and tail (not (stringp (car (car tail)))))
791 (setq tail (cdr tail)))
792 ;; Replace it with an entry for the entire deleted text.
793 (and tail
794 (setcar tail (cons (car kill-ring) (min beg end))))))
795 (undo-boundary))
796
797 (defun mouse-save-then-kill (click)
798 "Save text to point in kill ring; the second time, kill the text.
799 If the text between point and the mouse is the same as what's
800 at the front of the kill ring, this deletes the text.
801 Otherwise, it adds the text to the kill ring, like \\[kill-ring-save],
802 which prepares for a second click to delete the text.
803
804 If you have selected words or lines, this command extends the
805 selection through the word or line clicked on. If you do this
806 again in a different position, it extends the selection again.
807 If you do this twice in the same position, the selection is killed."
808 (interactive "e")
809 (let ((before-scroll point-before-scroll))
810 (mouse-minibuffer-check click)
811 (let ((click-posn (posn-point (event-start click)))
812 ;; Don't let a subsequent kill command append to this one:
813 ;; prevent setting this-command to kill-region.
814 (this-command this-command))
815 (if (and (save-excursion
816 (set-buffer (window-buffer (posn-window (event-start click))))
817 (and (mark t) (> (mod mouse-selection-click-count 3) 0)
818 ;; Don't be fooled by a recent click in some other buffer.
819 (eq mouse-selection-click-count-buffer
820 (current-buffer)))))
821 (if (not (and (eq last-command 'mouse-save-then-kill)
822 (equal click-posn
823 (car (cdr-safe (cdr-safe mouse-save-then-kill-posn))))))
824 ;; Find both ends of the object selected by this click.
825 (let* ((range
826 (mouse-start-end click-posn click-posn
827 mouse-selection-click-count)))
828 ;; Move whichever end is closer to the click.
829 ;; That's what xterm does, and it seems reasonable.
830 (if (< (abs (- click-posn (mark t)))
831 (abs (- click-posn (point))))
832 (set-mark (car range))
833 (goto-char (nth 1 range)))
834 ;; We have already put the old region in the kill ring.
835 ;; Replace it with the extended region.
836 ;; (It would be annoying to make a separate entry.)
837 (kill-new (buffer-substring (point) (mark t)) t)
838 (mouse-set-region-1)
839 ;; Arrange for a repeated mouse-3 to kill this region.
840 (setq mouse-save-then-kill-posn
841 (list (car kill-ring) (point) click-posn))
842 (mouse-show-mark))
843 ;; If we click this button again without moving it,
844 ;; that time kill.
845 (mouse-save-then-kill-delete-region (mark) (point))
846 (setq mouse-selection-click-count 0)
847 (setq mouse-save-then-kill-posn nil))
848 (if (and (eq last-command 'mouse-save-then-kill)
849 mouse-save-then-kill-posn
850 (eq (car mouse-save-then-kill-posn) (car kill-ring))
851 (equal (cdr mouse-save-then-kill-posn) (list (point) click-posn)))
852 ;; If this is the second time we've called
853 ;; mouse-save-then-kill, delete the text from the buffer.
854 (progn
855 (mouse-save-then-kill-delete-region (point) (mark))
856 ;; After we kill, another click counts as "the first time".
857 (setq mouse-save-then-kill-posn nil))
858 ;; This is not a repetition.
859 ;; We are adjusting an old selection or creating a new one.
860 (if (or (and (eq last-command 'mouse-save-then-kill)
861 mouse-save-then-kill-posn)
862 (and mark-active transient-mark-mode)
863 (and (memq last-command
864 '(mouse-drag-region mouse-set-region))
865 (or mark-even-if-inactive
866 (not transient-mark-mode))))
867 ;; We have a selection or suitable region, so adjust it.
868 (let* ((posn (event-start click))
869 (new (posn-point posn)))
870 (select-window (posn-window posn))
871 (if (numberp new)
872 (progn
873 ;; Move whichever end of the region is closer to the click.
874 ;; That is what xterm does, and it seems reasonable.
875 (if (< (abs (- new (point))) (abs (- new (mark t))))
876 (goto-char new)
877 (set-mark new))
878 (setq deactivate-mark nil)))
879 (kill-new (buffer-substring (point) (mark t)) t)
880 (mouse-show-mark))
881 ;; Set the mark where point is, then move where clicked.
882 (mouse-set-mark-fast click)
883 (if before-scroll
884 (goto-char before-scroll))
885 (exchange-point-and-mark)
886 (kill-new (buffer-substring (point) (mark t)))
887 (if window-system
888 (mouse-show-mark)))
889 (mouse-set-region-1)
890 (setq mouse-save-then-kill-posn
891 (list (car kill-ring) (point) click-posn)))))))
892 \f
893 (global-set-key [M-mouse-1] 'mouse-start-secondary)
894 (global-set-key [M-drag-mouse-1] 'mouse-set-secondary)
895 (global-set-key [M-down-mouse-1] 'mouse-drag-secondary)
896 (global-set-key [M-mouse-3] 'mouse-secondary-save-then-kill)
897 (global-set-key [M-mouse-2] 'mouse-yank-secondary)
898
899 ;; An overlay which records the current secondary selection
900 ;; or else is deleted when there is no secondary selection.
901 ;; May be nil.
902 (defvar mouse-secondary-overlay nil)
903
904 (defvar mouse-secondary-click-count 0)
905
906 ;; A marker which records the specified first end for a secondary selection.
907 ;; May be nil.
908 (defvar mouse-secondary-start nil)
909
910 (defun mouse-start-secondary (click)
911 "Set one end of the secondary selection to the position clicked on.
912 Use \\[mouse-secondary-save-then-kill] to set the other end
913 and complete the secondary selection."
914 (interactive "e")
915 (mouse-minibuffer-check click)
916 (let ((posn (event-start click)))
917 (save-excursion
918 (set-buffer (window-buffer (posn-window posn)))
919 ;; Cancel any preexisting secondary selection.
920 (if mouse-secondary-overlay
921 (delete-overlay mouse-secondary-overlay))
922 (if (numberp (posn-point posn))
923 (progn
924 (or mouse-secondary-start
925 (setq mouse-secondary-start (make-marker)))
926 (move-marker mouse-secondary-start (posn-point posn)))))))
927
928 (defun mouse-set-secondary (click)
929 "Set the secondary selection to the text that the mouse is dragged over.
930 This must be bound to a mouse drag event."
931 (interactive "e")
932 (mouse-minibuffer-check click)
933 (let ((posn (event-start click))
934 beg
935 (end (event-end click)))
936 (save-excursion
937 (set-buffer (window-buffer (posn-window posn)))
938 (if (numberp (posn-point posn))
939 (setq beg (posn-point posn)))
940 (if mouse-secondary-overlay
941 (move-overlay mouse-secondary-overlay beg (posn-point end))
942 (setq mouse-secondary-overlay (make-overlay beg (posn-point end))))
943 (overlay-put mouse-secondary-overlay 'face 'secondary-selection))))
944
945 (defun mouse-drag-secondary (start-event)
946 "Set the secondary selection to the text that the mouse is dragged over.
947 Highlight the drag area as you move the mouse.
948 This must be bound to a button-down mouse event."
949 (interactive "e")
950 (mouse-minibuffer-check start-event)
951 (let* ((echo-keystrokes 0)
952 (start-posn (event-start start-event))
953 (start-point (posn-point start-posn))
954 (start-window (posn-window start-posn))
955 (start-frame (window-frame start-window))
956 (bounds (window-edges start-window))
957 (top (nth 1 bounds))
958 (bottom (if (window-minibuffer-p start-window)
959 (nth 3 bounds)
960 ;; Don't count the mode line.
961 (1- (nth 3 bounds))))
962 (click-count (1- (event-click-count start-event))))
963 (save-excursion
964 (set-buffer (window-buffer start-window))
965 (setq mouse-secondary-click-count click-count)
966 (or mouse-secondary-overlay
967 (setq mouse-secondary-overlay
968 (make-overlay (point) (point))))
969 (overlay-put mouse-secondary-overlay 'face 'secondary-selection)
970 (if (> (mod click-count 3) 0)
971 ;; Double or triple press: make an initial selection
972 ;; of one word or line.
973 (let ((range (mouse-start-end start-point start-point click-count)))
974 (set-marker mouse-secondary-start nil)
975 (move-overlay mouse-secondary-overlay 1 1
976 (window-buffer start-window))
977 (move-overlay mouse-secondary-overlay (car range) (nth 1 range)
978 (window-buffer start-window)))
979 ;; Single-press: cancel any preexisting secondary selection.
980 (or mouse-secondary-start
981 (setq mouse-secondary-start (make-marker)))
982 (set-marker mouse-secondary-start start-point)
983 (delete-overlay mouse-secondary-overlay))
984 (let (event end end-point)
985 (track-mouse
986 (while (progn
987 (setq event (read-event))
988 (or (mouse-movement-p event)
989 (eq (car-safe event) 'switch-frame)))
990
991 (if (eq (car-safe event) 'switch-frame)
992 nil
993 (setq end (event-end event)
994 end-point (posn-point end))
995 (cond
996 ;; Are we moving within the original window?
997 ((and (eq (posn-window end) start-window)
998 (integer-or-marker-p end-point))
999 (let ((range (mouse-start-end start-point end-point
1000 click-count)))
1001 (if (or (/= start-point end-point)
1002 (null (marker-position mouse-secondary-start)))
1003 (progn
1004 (set-marker mouse-secondary-start nil)
1005 (move-overlay mouse-secondary-overlay
1006 (car range) (nth 1 range))))))
1007 (t
1008 (let ((mouse-row (cdr (cdr (mouse-position)))))
1009 (cond
1010 ((null mouse-row))
1011 ((< mouse-row top)
1012 (mouse-scroll-subr start-window (- mouse-row top)
1013 mouse-secondary-overlay start-point))
1014 ((>= mouse-row bottom)
1015 (mouse-scroll-subr start-window (1+ (- mouse-row bottom))
1016 mouse-secondary-overlay start-point)))))))))
1017
1018 (if (consp event)
1019 ;;; (eq (get (event-basic-type event) 'event-kind) 'mouse-click)
1020 ;;; (eq (posn-window (event-end event)) start-window)
1021 ;;; (numberp (posn-point (event-end event)))
1022 (if (marker-position mouse-secondary-start)
1023 (save-window-excursion
1024 (delete-overlay mouse-secondary-overlay)
1025 (x-set-selection 'SECONDARY nil)
1026 (select-window start-window)
1027 (save-excursion
1028 (goto-char mouse-secondary-start)
1029 (sit-for 1)))
1030 (x-set-selection
1031 'SECONDARY
1032 (buffer-substring (overlay-start mouse-secondary-overlay)
1033 (overlay-end mouse-secondary-overlay)))))))))
1034
1035 (defun mouse-yank-secondary (click)
1036 "Insert the secondary selection at the position clicked on.
1037 Move point to the end of the inserted text.
1038 If `mouse-yank-at-point' is non-nil, insert at point
1039 regardless of where you click."
1040 (interactive "e")
1041 ;; Give temporary modes such as isearch a chance to turn off.
1042 (run-hooks 'mouse-leave-buffer-hook)
1043 (or mouse-yank-at-point (mouse-set-point click))
1044 (insert (x-get-selection 'SECONDARY)))
1045
1046 (defun mouse-kill-secondary ()
1047 "Kill the text in the secondary selection.
1048 This is intended more as a keyboard command than as a mouse command
1049 but it can work as either one.
1050
1051 The current buffer (in case of keyboard use), or the buffer clicked on,
1052 must be the one that the secondary selection is in. This requirement
1053 is to prevent accidents."
1054 (interactive)
1055 (let* ((keys (this-command-keys))
1056 (click (elt keys (1- (length keys)))))
1057 (or (eq (overlay-buffer mouse-secondary-overlay)
1058 (if (listp click)
1059 (window-buffer (posn-window (event-start click)))
1060 (current-buffer)))
1061 (error "Select or click on the buffer where the secondary selection is")))
1062 (let (this-command)
1063 (save-excursion
1064 (set-buffer (overlay-buffer mouse-secondary-overlay))
1065 (kill-region (overlay-start mouse-secondary-overlay)
1066 (overlay-end mouse-secondary-overlay))))
1067 (delete-overlay mouse-secondary-overlay)
1068 ;;; (x-set-selection 'SECONDARY nil)
1069 (setq mouse-secondary-overlay nil))
1070
1071 (defun mouse-secondary-save-then-kill (click)
1072 "Save text to point in kill ring; the second time, kill the text.
1073 You must use this in a buffer where you have recently done \\[mouse-start-secondary].
1074 If the text between where you did \\[mouse-start-secondary] and where
1075 you use this command matches the text at the front of the kill ring,
1076 this command deletes the text.
1077 Otherwise, it adds the text to the kill ring, like \\[kill-ring-save],
1078 which prepares for a second click with this command to delete the text.
1079
1080 If you have already made a secondary selection in that buffer,
1081 this command extends or retracts the selection to where you click.
1082 If you do this again in a different position, it extends or retracts
1083 again. If you do this twice in the same position, it kills the selection."
1084 (interactive "e")
1085 (mouse-minibuffer-check click)
1086 (let ((posn (event-start click))
1087 (click-posn (posn-point (event-start click)))
1088 ;; Don't let a subsequent kill command append to this one:
1089 ;; prevent setting this-command to kill-region.
1090 (this-command this-command))
1091 (or (eq (window-buffer (posn-window posn))
1092 (or (and mouse-secondary-overlay
1093 (overlay-buffer mouse-secondary-overlay))
1094 (if mouse-secondary-start
1095 (marker-buffer mouse-secondary-start))))
1096 (error "Wrong buffer"))
1097 (save-excursion
1098 (set-buffer (window-buffer (posn-window posn)))
1099 (if (> (mod mouse-secondary-click-count 3) 0)
1100 (if (not (and (eq last-command 'mouse-secondary-save-then-kill)
1101 (equal click-posn
1102 (car (cdr-safe (cdr-safe mouse-save-then-kill-posn))))))
1103 ;; Find both ends of the object selected by this click.
1104 (let* ((range
1105 (mouse-start-end click-posn click-posn
1106 mouse-secondary-click-count)))
1107 ;; Move whichever end is closer to the click.
1108 ;; That's what xterm does, and it seems reasonable.
1109 (if (< (abs (- click-posn (overlay-start mouse-secondary-overlay)))
1110 (abs (- click-posn (overlay-end mouse-secondary-overlay))))
1111 (move-overlay mouse-secondary-overlay (car range)
1112 (overlay-end mouse-secondary-overlay))
1113 (move-overlay mouse-secondary-overlay
1114 (overlay-start mouse-secondary-overlay)
1115 (nth 1 range)))
1116 ;; We have already put the old region in the kill ring.
1117 ;; Replace it with the extended region.
1118 ;; (It would be annoying to make a separate entry.)
1119 (kill-new (buffer-substring
1120 (overlay-start mouse-secondary-overlay)
1121 (overlay-end mouse-secondary-overlay)) t)
1122 ;; Arrange for a repeated mouse-3 to kill this region.
1123 (setq mouse-save-then-kill-posn
1124 (list (car kill-ring) (point) click-posn)))
1125 ;; If we click this button again without moving it,
1126 ;; that time kill.
1127 (progn
1128 (mouse-save-then-kill-delete-region
1129 (overlay-start mouse-secondary-overlay)
1130 (overlay-end mouse-secondary-overlay))
1131 (setq mouse-save-then-kill-posn nil)
1132 (setq mouse-secondary-click-count 0)
1133 (delete-overlay mouse-secondary-overlay)))
1134 (if (and (eq last-command 'mouse-secondary-save-then-kill)
1135 mouse-save-then-kill-posn
1136 (eq (car mouse-save-then-kill-posn) (car kill-ring))
1137 (equal (cdr mouse-save-then-kill-posn) (list (point) click-posn)))
1138 ;; If this is the second time we've called
1139 ;; mouse-secondary-save-then-kill, delete the text from the buffer.
1140 (progn
1141 (mouse-save-then-kill-delete-region
1142 (overlay-start mouse-secondary-overlay)
1143 (overlay-end mouse-secondary-overlay))
1144 (setq mouse-save-then-kill-posn nil)
1145 (delete-overlay mouse-secondary-overlay))
1146 (if (overlay-start mouse-secondary-overlay)
1147 ;; We have a selection, so adjust it.
1148 (progn
1149 (if (numberp click-posn)
1150 (progn
1151 ;; Move whichever end of the region is closer to the click.
1152 ;; That is what xterm does, and it seems reasonable.
1153 (if (< (abs (- click-posn (overlay-start mouse-secondary-overlay)))
1154 (abs (- click-posn (overlay-end mouse-secondary-overlay))))
1155 (move-overlay mouse-secondary-overlay click-posn
1156 (overlay-end mouse-secondary-overlay))
1157 (move-overlay mouse-secondary-overlay
1158 (overlay-start mouse-secondary-overlay)
1159 click-posn))
1160 (setq deactivate-mark nil)))
1161 (if (eq last-command 'mouse-secondary-save-then-kill)
1162 ;; If the front of the kill ring comes from
1163 ;; an immediately previous use of this command,
1164 ;; replace it with the extended region.
1165 ;; (It would be annoying to make a separate entry.)
1166 (kill-new (buffer-substring
1167 (overlay-start mouse-secondary-overlay)
1168 (overlay-end mouse-secondary-overlay)) t)
1169 (copy-region-as-kill (overlay-start mouse-secondary-overlay)
1170 (overlay-end mouse-secondary-overlay))))
1171 (if mouse-secondary-start
1172 ;; All we have is one end of a selection,
1173 ;; so put the other end here.
1174 (let ((start (+ 0 mouse-secondary-start)))
1175 (kill-ring-save start click-posn)
1176 (if mouse-secondary-overlay
1177 (move-overlay mouse-secondary-overlay start click-posn)
1178 (setq mouse-secondary-overlay (make-overlay start click-posn)))
1179 (overlay-put mouse-secondary-overlay 'face 'secondary-selection))))
1180 (setq mouse-save-then-kill-posn
1181 (list (car kill-ring) (point) click-posn))))
1182 (if (overlay-buffer mouse-secondary-overlay)
1183 (x-set-selection 'SECONDARY
1184 (buffer-substring
1185 (overlay-start mouse-secondary-overlay)
1186 (overlay-end mouse-secondary-overlay)))))))
1187 \f
1188 (defvar mouse-menu-buffer-maxlen 20
1189 "*Number of buffers in one pane (submenu) of the buffer menu.
1190 If we have lots of buffers, divide them into groups of
1191 `mouse-menu-buffer-maxlen' and make a pane (or submenu) for each one.")
1192
1193 (defun mouse-buffer-menu (event)
1194 "Pop up a menu of buffers for selection with the mouse.
1195 This switches buffers in the window that you clicked on,
1196 and selects that window."
1197 (interactive "e")
1198 (mouse-minibuffer-check event)
1199 (let* ((buffers
1200 ;; Make an alist of (MENU-ITEM . BUFFER).
1201 (let ((tail (buffer-list))
1202 (maxlen 0)
1203 head)
1204 (while tail
1205 (or (eq ?\ (aref (buffer-name (car tail)) 0))
1206 (setq maxlen
1207 (max maxlen
1208 (length (buffer-name (car tail))))))
1209 (setq tail (cdr tail)))
1210 (setq tail (buffer-list))
1211 (while tail
1212 (let ((elt (car tail)))
1213 (if (/= (aref (buffer-name elt) 0) ?\ )
1214 (setq head
1215 (cons
1216 (cons
1217 (format
1218 (format "%%%ds %%s%%s %%s" maxlen)
1219 (buffer-name elt)
1220 (if (buffer-modified-p elt) "*" " ")
1221 (save-excursion
1222 (set-buffer elt)
1223 (if buffer-read-only "%" " "))
1224 (or (buffer-file-name elt)
1225 (save-excursion
1226 (set-buffer elt)
1227 (if list-buffers-directory
1228 (expand-file-name
1229 list-buffers-directory)))
1230 ""))
1231 elt)
1232 head))))
1233 (setq tail (cdr tail)))
1234 ;; Compensate for the reversal that the above loop does.
1235 (nreverse head)))
1236 (menu
1237 ;; If we have lots of buffers, divide them into groups of 20
1238 ;; and make a pane (or submenu) for each one.
1239 (if (> (length buffers) (/ (* mouse-menu-buffer-maxlen 3) 2))
1240 (let ((buffers buffers) sublists next
1241 (i 1))
1242 (while buffers
1243 ;; Pull off the next mouse-menu-buffer-maxlen buffers
1244 ;; and make them the next element of sublist.
1245 (setq next (nthcdr mouse-menu-buffer-maxlen buffers))
1246 (if next
1247 (setcdr (nthcdr (1- mouse-menu-buffer-maxlen) buffers)
1248 nil))
1249 (setq sublists (cons (cons (format "Buffers %d" i) buffers)
1250 sublists))
1251 (setq i (1+ i))
1252 (setq buffers next))
1253 (cons "Buffer Menu" (nreverse sublists)))
1254 ;; Few buffers--put them all in one pane.
1255 (list "Buffer Menu" (cons "Select Buffer" buffers)))))
1256 (let ((buf (x-popup-menu event menu))
1257 (window (posn-window (event-start event))))
1258 (if buf
1259 (progn
1260 (or (framep window) (select-window window))
1261 (switch-to-buffer buf))))))
1262 \f
1263 ;;; These need to be rewritten for the new scroll bar implementation.
1264
1265 ;;;!! ;; Commands for the scroll bar.
1266 ;;;!!
1267 ;;;!! (defun mouse-scroll-down (click)
1268 ;;;!! (interactive "@e")
1269 ;;;!! (scroll-down (1+ (cdr (mouse-coords click)))))
1270 ;;;!!
1271 ;;;!! (defun mouse-scroll-up (click)
1272 ;;;!! (interactive "@e")
1273 ;;;!! (scroll-up (1+ (cdr (mouse-coords click)))))
1274 ;;;!!
1275 ;;;!! (defun mouse-scroll-down-full ()
1276 ;;;!! (interactive "@")
1277 ;;;!! (scroll-down nil))
1278 ;;;!!
1279 ;;;!! (defun mouse-scroll-up-full ()
1280 ;;;!! (interactive "@")
1281 ;;;!! (scroll-up nil))
1282 ;;;!!
1283 ;;;!! (defun mouse-scroll-move-cursor (click)
1284 ;;;!! (interactive "@e")
1285 ;;;!! (move-to-window-line (1+ (cdr (mouse-coords click)))))
1286 ;;;!!
1287 ;;;!! (defun mouse-scroll-absolute (event)
1288 ;;;!! (interactive "@e")
1289 ;;;!! (let* ((pos (car event))
1290 ;;;!! (position (car pos))
1291 ;;;!! (length (car (cdr pos))))
1292 ;;;!! (if (<= length 0) (setq length 1))
1293 ;;;!! (let* ((scale-factor (max 1 (/ length (/ 8000000 (buffer-size)))))
1294 ;;;!! (newpos (* (/ (* (/ (buffer-size) scale-factor)
1295 ;;;!! position)
1296 ;;;!! length)
1297 ;;;!! scale-factor)))
1298 ;;;!! (goto-char newpos)
1299 ;;;!! (recenter '(4)))))
1300 ;;;!!
1301 ;;;!! (defun mouse-scroll-left (click)
1302 ;;;!! (interactive "@e")
1303 ;;;!! (scroll-left (1+ (car (mouse-coords click)))))
1304 ;;;!!
1305 ;;;!! (defun mouse-scroll-right (click)
1306 ;;;!! (interactive "@e")
1307 ;;;!! (scroll-right (1+ (car (mouse-coords click)))))
1308 ;;;!!
1309 ;;;!! (defun mouse-scroll-left-full ()
1310 ;;;!! (interactive "@")
1311 ;;;!! (scroll-left nil))
1312 ;;;!!
1313 ;;;!! (defun mouse-scroll-right-full ()
1314 ;;;!! (interactive "@")
1315 ;;;!! (scroll-right nil))
1316 ;;;!!
1317 ;;;!! (defun mouse-scroll-move-cursor-horizontally (click)
1318 ;;;!! (interactive "@e")
1319 ;;;!! (move-to-column (1+ (car (mouse-coords click)))))
1320 ;;;!!
1321 ;;;!! (defun mouse-scroll-absolute-horizontally (event)
1322 ;;;!! (interactive "@e")
1323 ;;;!! (let* ((pos (car event))
1324 ;;;!! (position (car pos))
1325 ;;;!! (length (car (cdr pos))))
1326 ;;;!! (set-window-hscroll (selected-window) 33)))
1327 ;;;!!
1328 ;;;!! (global-set-key [scroll-bar mouse-1] 'mouse-scroll-up)
1329 ;;;!! (global-set-key [scroll-bar mouse-2] 'mouse-scroll-absolute)
1330 ;;;!! (global-set-key [scroll-bar mouse-3] 'mouse-scroll-down)
1331 ;;;!!
1332 ;;;!! (global-set-key [vertical-slider mouse-1] 'mouse-scroll-move-cursor)
1333 ;;;!! (global-set-key [vertical-slider mouse-2] 'mouse-scroll-move-cursor)
1334 ;;;!! (global-set-key [vertical-slider mouse-3] 'mouse-scroll-move-cursor)
1335 ;;;!!
1336 ;;;!! (global-set-key [thumbup mouse-1] 'mouse-scroll-up-full)
1337 ;;;!! (global-set-key [thumbup mouse-2] 'mouse-scroll-up-full)
1338 ;;;!! (global-set-key [thumbup mouse-3] 'mouse-scroll-up-full)
1339 ;;;!!
1340 ;;;!! (global-set-key [thumbdown mouse-1] 'mouse-scroll-down-full)
1341 ;;;!! (global-set-key [thumbdown mouse-2] 'mouse-scroll-down-full)
1342 ;;;!! (global-set-key [thumbdown mouse-3] 'mouse-scroll-down-full)
1343 ;;;!!
1344 ;;;!! (global-set-key [horizontal-scroll-bar mouse-1] 'mouse-scroll-left)
1345 ;;;!! (global-set-key [horizontal-scroll-bar mouse-2]
1346 ;;;!! 'mouse-scroll-absolute-horizontally)
1347 ;;;!! (global-set-key [horizontal-scroll-bar mouse-3] 'mouse-scroll-right)
1348 ;;;!!
1349 ;;;!! (global-set-key [horizontal-slider mouse-1]
1350 ;;;!! 'mouse-scroll-move-cursor-horizontally)
1351 ;;;!! (global-set-key [horizontal-slider mouse-2]
1352 ;;;!! 'mouse-scroll-move-cursor-horizontally)
1353 ;;;!! (global-set-key [horizontal-slider mouse-3]
1354 ;;;!! 'mouse-scroll-move-cursor-horizontally)
1355 ;;;!!
1356 ;;;!! (global-set-key [thumbleft mouse-1] 'mouse-scroll-left-full)
1357 ;;;!! (global-set-key [thumbleft mouse-2] 'mouse-scroll-left-full)
1358 ;;;!! (global-set-key [thumbleft mouse-3] 'mouse-scroll-left-full)
1359 ;;;!!
1360 ;;;!! (global-set-key [thumbright mouse-1] 'mouse-scroll-right-full)
1361 ;;;!! (global-set-key [thumbright mouse-2] 'mouse-scroll-right-full)
1362 ;;;!! (global-set-key [thumbright mouse-3] 'mouse-scroll-right-full)
1363 ;;;!!
1364 ;;;!! (global-set-key [horizontal-scroll-bar S-mouse-2]
1365 ;;;!! 'mouse-split-window-horizontally)
1366 ;;;!! (global-set-key [mode-line S-mouse-2]
1367 ;;;!! 'mouse-split-window-horizontally)
1368 ;;;!! (global-set-key [vertical-scroll-bar S-mouse-2]
1369 ;;;!! 'mouse-split-window)
1370 \f
1371 ;;;!! ;;;;
1372 ;;;!! ;;;; Here are experimental things being tested. Mouse events
1373 ;;;!! ;;;; are of the form:
1374 ;;;!! ;;;; ((x y) window screen-part key-sequence timestamp)
1375 ;;;!! ;;
1376 ;;;!! ;;;;
1377 ;;;!! ;;;; Dynamically track mouse coordinates
1378 ;;;!! ;;;;
1379 ;;;!! ;;
1380 ;;;!! ;;(defun track-mouse (event)
1381 ;;;!! ;; "Track the coordinates, absolute and relative, of the mouse."
1382 ;;;!! ;; (interactive "@e")
1383 ;;;!! ;; (while mouse-grabbed
1384 ;;;!! ;; (let* ((pos (read-mouse-position (selected-screen)))
1385 ;;;!! ;; (abs-x (car pos))
1386 ;;;!! ;; (abs-y (cdr pos))
1387 ;;;!! ;; (relative-coordinate (coordinates-in-window-p
1388 ;;;!! ;; (list (car pos) (cdr pos))
1389 ;;;!! ;; (selected-window))))
1390 ;;;!! ;; (if (consp relative-coordinate)
1391 ;;;!! ;; (message "mouse: [%d %d], (%d %d)" abs-x abs-y
1392 ;;;!! ;; (car relative-coordinate)
1393 ;;;!! ;; (car (cdr relative-coordinate)))
1394 ;;;!! ;; (message "mouse: [%d %d]" abs-x abs-y)))))
1395 ;;;!!
1396 ;;;!! ;;
1397 ;;;!! ;; Dynamically put a box around the line indicated by point
1398 ;;;!! ;;
1399 ;;;!! ;;
1400 ;;;!! ;;(require 'backquote)
1401 ;;;!! ;;
1402 ;;;!! ;;(defun mouse-select-buffer-line (event)
1403 ;;;!! ;; (interactive "@e")
1404 ;;;!! ;; (let ((relative-coordinate
1405 ;;;!! ;; (coordinates-in-window-p (car event) (selected-window)))
1406 ;;;!! ;; (abs-y (car (cdr (car event)))))
1407 ;;;!! ;; (if (consp relative-coordinate)
1408 ;;;!! ;; (progn
1409 ;;;!! ;; (save-excursion
1410 ;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
1411 ;;;!! ;; (x-draw-rectangle
1412 ;;;!! ;; (selected-screen)
1413 ;;;!! ;; abs-y 0
1414 ;;;!! ;; (save-excursion
1415 ;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
1416 ;;;!! ;; (end-of-line)
1417 ;;;!! ;; (push-mark nil t)
1418 ;;;!! ;; (beginning-of-line)
1419 ;;;!! ;; (- (region-end) (region-beginning))) 1))
1420 ;;;!! ;; (sit-for 1)
1421 ;;;!! ;; (x-erase-rectangle (selected-screen))))))
1422 ;;;!! ;;
1423 ;;;!! ;;(defvar last-line-drawn nil)
1424 ;;;!! ;;(defvar begin-delim "[^ \t]")
1425 ;;;!! ;;(defvar end-delim "[^ \t]")
1426 ;;;!! ;;
1427 ;;;!! ;;(defun mouse-boxing (event)
1428 ;;;!! ;; (interactive "@e")
1429 ;;;!! ;; (save-excursion
1430 ;;;!! ;; (let ((screen (selected-screen)))
1431 ;;;!! ;; (while (= (x-mouse-events) 0)
1432 ;;;!! ;; (let* ((pos (read-mouse-position screen))
1433 ;;;!! ;; (abs-x (car pos))
1434 ;;;!! ;; (abs-y (cdr pos))
1435 ;;;!! ;; (relative-coordinate
1436 ;;;!! ;; (coordinates-in-window-p (` ((, abs-x) (, abs-y)))
1437 ;;;!! ;; (selected-window)))
1438 ;;;!! ;; (begin-reg nil)
1439 ;;;!! ;; (end-reg nil)
1440 ;;;!! ;; (end-column nil)
1441 ;;;!! ;; (begin-column nil))
1442 ;;;!! ;; (if (and (consp relative-coordinate)
1443 ;;;!! ;; (or (not last-line-drawn)
1444 ;;;!! ;; (not (= last-line-drawn abs-y))))
1445 ;;;!! ;; (progn
1446 ;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
1447 ;;;!! ;; (if (= (following-char) 10)
1448 ;;;!! ;; ()
1449 ;;;!! ;; (progn
1450 ;;;!! ;; (setq begin-reg (1- (re-search-forward end-delim)))
1451 ;;;!! ;; (setq begin-column (1- (current-column)))
1452 ;;;!! ;; (end-of-line)
1453 ;;;!! ;; (setq end-reg (1+ (re-search-backward begin-delim)))
1454 ;;;!! ;; (setq end-column (1+ (current-column)))
1455 ;;;!! ;; (message "%s" (buffer-substring begin-reg end-reg))
1456 ;;;!! ;; (x-draw-rectangle screen
1457 ;;;!! ;; (setq last-line-drawn abs-y)
1458 ;;;!! ;; begin-column
1459 ;;;!! ;; (- end-column begin-column) 1))))))))))
1460 ;;;!! ;;
1461 ;;;!! ;;(defun mouse-erase-box ()
1462 ;;;!! ;; (interactive)
1463 ;;;!! ;; (if last-line-drawn
1464 ;;;!! ;; (progn
1465 ;;;!! ;; (x-erase-rectangle (selected-screen))
1466 ;;;!! ;; (setq last-line-drawn nil))))
1467 ;;;!!
1468 ;;;!! ;;; (defun test-x-rectangle ()
1469 ;;;!! ;;; (use-local-mouse-map (setq rectangle-test-map (make-sparse-keymap)))
1470 ;;;!! ;;; (define-key rectangle-test-map mouse-motion-button-left 'mouse-boxing)
1471 ;;;!! ;;; (define-key rectangle-test-map mouse-button-left-up 'mouse-erase-box))
1472 ;;;!!
1473 ;;;!! ;;
1474 ;;;!! ;; Here is how to do double clicking in lisp. About to change.
1475 ;;;!! ;;
1476 ;;;!!
1477 ;;;!! (defvar double-start nil)
1478 ;;;!! (defconst double-click-interval 300
1479 ;;;!! "Max ticks between clicks")
1480 ;;;!!
1481 ;;;!! (defun double-down (event)
1482 ;;;!! (interactive "@e")
1483 ;;;!! (if double-start
1484 ;;;!! (let ((interval (- (nth 4 event) double-start)))
1485 ;;;!! (if (< interval double-click-interval)
1486 ;;;!! (progn
1487 ;;;!! (backward-up-list 1)
1488 ;;;!! ;; (message "Interval %d" interval)
1489 ;;;!! (sleep-for 1)))
1490 ;;;!! (setq double-start nil))
1491 ;;;!! (setq double-start (nth 4 event))))
1492 ;;;!!
1493 ;;;!! (defun double-up (event)
1494 ;;;!! (interactive "@e")
1495 ;;;!! (and double-start
1496 ;;;!! (> (- (nth 4 event ) double-start) double-click-interval)
1497 ;;;!! (setq double-start nil)))
1498 ;;;!!
1499 ;;;!! ;;; (defun x-test-doubleclick ()
1500 ;;;!! ;;; (use-local-mouse-map (setq doubleclick-test-map (make-sparse-keymap)))
1501 ;;;!! ;;; (define-key doubleclick-test-map mouse-button-left 'double-down)
1502 ;;;!! ;;; (define-key doubleclick-test-map mouse-button-left-up 'double-up))
1503 ;;;!!
1504 ;;;!! ;;
1505 ;;;!! ;; This scrolls while button is depressed. Use preferable in scroll bar.
1506 ;;;!! ;;
1507 ;;;!!
1508 ;;;!! (defvar scrolled-lines 0)
1509 ;;;!! (defconst scroll-speed 1)
1510 ;;;!!
1511 ;;;!! (defun incr-scroll-down (event)
1512 ;;;!! (interactive "@e")
1513 ;;;!! (setq scrolled-lines 0)
1514 ;;;!! (incremental-scroll scroll-speed))
1515 ;;;!!
1516 ;;;!! (defun incr-scroll-up (event)
1517 ;;;!! (interactive "@e")
1518 ;;;!! (setq scrolled-lines 0)
1519 ;;;!! (incremental-scroll (- scroll-speed)))
1520 ;;;!!
1521 ;;;!! (defun incremental-scroll (n)
1522 ;;;!! (while (= (x-mouse-events) 0)
1523 ;;;!! (setq scrolled-lines (1+ (* scroll-speed scrolled-lines)))
1524 ;;;!! (scroll-down n)
1525 ;;;!! (sit-for 300 t)))
1526 ;;;!!
1527 ;;;!! (defun incr-scroll-stop (event)
1528 ;;;!! (interactive "@e")
1529 ;;;!! (message "Scrolled %d lines" scrolled-lines)
1530 ;;;!! (setq scrolled-lines 0)
1531 ;;;!! (sleep-for 1))
1532 ;;;!!
1533 ;;;!! ;;; (defun x-testing-scroll ()
1534 ;;;!! ;;; (let ((scrolling-map (function mouse-vertical-scroll-bar-prefix)))
1535 ;;;!! ;;; (define-key scrolling-map mouse-button-left 'incr-scroll-down)
1536 ;;;!! ;;; (define-key scrolling-map mouse-button-right 'incr-scroll-up)
1537 ;;;!! ;;; (define-key scrolling-map mouse-button-left-up 'incr-scroll-stop)
1538 ;;;!! ;;; (define-key scrolling-map mouse-button-right-up 'incr-scroll-stop)))
1539 ;;;!!
1540 ;;;!! ;;
1541 ;;;!! ;; Some playthings suitable for picture mode? They need work.
1542 ;;;!! ;;
1543 ;;;!!
1544 ;;;!! (defun mouse-kill-rectangle (event)
1545 ;;;!! "Kill the rectangle between point and the mouse cursor."
1546 ;;;!! (interactive "@e")
1547 ;;;!! (let ((point-save (point)))
1548 ;;;!! (save-excursion
1549 ;;;!! (mouse-set-point event)
1550 ;;;!! (push-mark nil t)
1551 ;;;!! (if (> point-save (point))
1552 ;;;!! (kill-rectangle (point) point-save)
1553 ;;;!! (kill-rectangle point-save (point))))))
1554 ;;;!!
1555 ;;;!! (defun mouse-open-rectangle (event)
1556 ;;;!! "Kill the rectangle between point and the mouse cursor."
1557 ;;;!! (interactive "@e")
1558 ;;;!! (let ((point-save (point)))
1559 ;;;!! (save-excursion
1560 ;;;!! (mouse-set-point event)
1561 ;;;!! (push-mark nil t)
1562 ;;;!! (if (> point-save (point))
1563 ;;;!! (open-rectangle (point) point-save)
1564 ;;;!! (open-rectangle point-save (point))))))
1565 ;;;!!
1566 ;;;!! ;; Must be a better way to do this.
1567 ;;;!!
1568 ;;;!! (defun mouse-multiple-insert (n char)
1569 ;;;!! (while (> n 0)
1570 ;;;!! (insert char)
1571 ;;;!! (setq n (1- n))))
1572 ;;;!!
1573 ;;;!! ;; What this could do is not finalize until button was released.
1574 ;;;!!
1575 ;;;!! (defun mouse-move-text (event)
1576 ;;;!! "Move text from point to cursor position, inserting spaces."
1577 ;;;!! (interactive "@e")
1578 ;;;!! (let* ((relative-coordinate
1579 ;;;!! (coordinates-in-window-p (car event) (selected-window))))
1580 ;;;!! (if (consp relative-coordinate)
1581 ;;;!! (cond ((> (current-column) (car relative-coordinate))
1582 ;;;!! (delete-char
1583 ;;;!! (- (car relative-coordinate) (current-column))))
1584 ;;;!! ((< (current-column) (car relative-coordinate))
1585 ;;;!! (mouse-multiple-insert
1586 ;;;!! (- (car relative-coordinate) (current-column)) " "))
1587 ;;;!! ((= (current-column) (car relative-coordinate)) (ding))))))
1588 \f
1589 ;; Choose a completion with the mouse.
1590
1591 (defun mouse-choose-completion (event)
1592 "Click on an alternative in the `*Completions*' buffer to choose it."
1593 (interactive "e")
1594 ;; Give temporary modes such as isearch a chance to turn off.
1595 (run-hooks 'mouse-leave-buffer-hook)
1596 (let ((buffer (window-buffer))
1597 choice
1598 base-size)
1599 (save-excursion
1600 (set-buffer (window-buffer (posn-window (event-start event))))
1601 (if completion-reference-buffer
1602 (setq buffer completion-reference-buffer))
1603 (setq base-size completion-base-size)
1604 (save-excursion
1605 (goto-char (posn-point (event-start event)))
1606 (let (beg end)
1607 (if (and (not (eobp)) (get-text-property (point) 'mouse-face))
1608 (setq end (point) beg (1+ (point))))
1609 (if (null beg)
1610 (error "No completion here"))
1611 (setq beg (previous-single-property-change beg 'mouse-face))
1612 (setq end (or (next-single-property-change end 'mouse-face)
1613 (point-max)))
1614 (setq choice (buffer-substring beg end)))))
1615 (let ((owindow (selected-window)))
1616 (select-window (posn-window (event-start event)))
1617 (if (and (one-window-p t 'selected-frame)
1618 (window-dedicated-p (selected-window)))
1619 ;; This is a special buffer's frame
1620 (iconify-frame (selected-frame))
1621 (or (window-dedicated-p (selected-window))
1622 (bury-buffer)))
1623 (select-window owindow))
1624 (choose-completion-string choice buffer base-size)))
1625 \f
1626 ;; Font selection.
1627
1628 (defun font-menu-add-default ()
1629 (let* ((default (cdr (assq 'font (frame-parameters (selected-frame)))))
1630 (font-alist x-fixed-font-alist)
1631 (elt (or (assoc "Misc" font-alist) (nth 1 font-alist))))
1632 (if (assoc "Default" elt)
1633 (delete (assoc "Default" elt) elt))
1634 (setcdr elt
1635 (cons (list "Default"
1636 (cdr (assq 'font (frame-parameters (selected-frame)))))
1637 (cdr elt)))))
1638
1639 (defvar x-fixed-font-alist
1640 '("Font menu"
1641 ("Misc"
1642 ;; For these, we specify the pixel height and width.
1643 ("fixed" "fixed")
1644 ("6x10" "-misc-fixed-medium-r-normal--10-*-*-*-c-60-iso8859-1" "6x10")
1645 ("6x12"
1646 "-misc-fixed-medium-r-semicondensed--12-*-*-*-c-60-iso8859-1" "6x12")
1647 ("6x13"
1648 "-misc-fixed-medium-r-semicondensed--13-*-*-*-c-60-iso8859-1" "6x13")
1649 ("7x13" "-misc-fixed-medium-r-normal--13-*-*-*-c-70-iso8859-1" "7x13")
1650 ("7x14" "-misc-fixed-medium-r-normal--14-*-*-*-c-70-iso8859-1" "7x14")
1651 ("8x13" "-misc-fixed-medium-r-normal--13-*-*-*-c-80-iso8859-1" "8x13")
1652 ("9x15" "-misc-fixed-medium-r-normal--15-*-*-*-c-90-iso8859-1" "9x15")
1653 ("10x20" "-misc-fixed-medium-r-normal--20-*-*-*-c-100-iso8859-1" "10x20")
1654 ("11x18" "-misc-fixed-medium-r-normal--18-*-*-*-c-110-iso8859-1" "11x18")
1655 ("12x24" "-misc-fixed-medium-r-normal--24-*-*-*-c-120-iso8859-1" "12x24")
1656 ("")
1657 ("clean 5x8"
1658 "-schumacher-clean-medium-r-normal--8-*-*-*-c-50-iso8859-1")
1659 ("clean 6x8"
1660 "-schumacher-clean-medium-r-normal--8-*-*-*-c-60-iso8859-1")
1661 ("clean 8x8"
1662 "-schumacher-clean-medium-r-normal--8-*-*-*-c-80-iso8859-1")
1663 ("clean 8x10"
1664 "-schumacher-clean-medium-r-normal--10-*-*-*-c-80-iso8859-1")
1665 ("clean 8x14"
1666 "-schumacher-clean-medium-r-normal--14-*-*-*-c-80-iso8859-1")
1667 ("clean 8x16"
1668 "-schumacher-clean-medium-r-normal--16-*-*-*-c-80-iso8859-1")
1669 ("")
1670 ("sony 8x16" "-sony-fixed-medium-r-normal--16-*-*-*-c-80-iso8859-1"))
1671 ;;; We don't seem to have these; who knows what they are.
1672 ;;; ("fg-18" "fg-18")
1673 ;;; ("fg-25" "fg-25")
1674 ;;; ("lucidasanstypewriter-12" "lucidasanstypewriter-12")
1675 ;;; ("lucidasanstypewriter-bold-14" "lucidasanstypewriter-bold-14")
1676 ;;; ("lucidasanstypewriter-bold-24" "lucidasanstypewriter-bold-24")
1677 ;;; ("lucidatypewriter-bold-r-24" "-b&h-lucidatypewriter-bold-r-normal-sans-24-240-75-75-m-140-iso8859-1")
1678 ;;; ("fixed-medium-20" "-misc-fixed-medium-*-*-*-20-*-*-*-*-*-*-*")
1679 ("Courier"
1680 ;; For these, we specify the point height.
1681 ("8" "-adobe-courier-medium-r-normal--*-80-*-*-m-*-iso8859-1")
1682 ("10" "-adobe-courier-medium-r-normal--*-100-*-*-m-*-iso8859-1")
1683 ("12" "-adobe-courier-medium-r-normal--*-120-*-*-m-*-iso8859-1")
1684 ("14" "-adobe-courier-medium-r-normal--*-140-*-*-m-*-iso8859-1")
1685 ("18" "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1")
1686 ("24" "-adobe-courier-medium-r-normal--*-240-*-*-m-*-iso8859-1")
1687 ("8 bold" "-adobe-courier-bold-r-normal--*-80-*-*-m-*-iso8859-1")
1688 ("10 bold" "-adobe-courier-bold-r-normal--*-100-*-*-m-*-iso8859-1")
1689 ("12 bold" "-adobe-courier-bold-r-normal--*-120-*-*-m-*-iso8859-1")
1690 ("14 bold" "-adobe-courier-bold-r-normal--*-140-*-*-m-*-iso8859-1")
1691 ("18 bold" "-adobe-courier-bold-r-normal--*-180-*-*-m-*-iso8859-1")
1692 ("24 bold" "-adobe-courier-bold-r-normal--*-240-*-*-m-*-iso8859-1")
1693 ("8 slant" "-adobe-courier-medium-o-normal--*-80-*-*-m-*-iso8859-1")
1694 ("10 slant" "-adobe-courier-medium-o-normal--*-100-*-*-m-*-iso8859-1")
1695 ("12 slant" "-adobe-courier-medium-o-normal--*-120-*-*-m-*-iso8859-1")
1696 ("14 slant" "-adobe-courier-medium-o-normal--*-140-*-*-m-*-iso8859-1")
1697 ("18 slant" "-adobe-courier-medium-o-normal--*-180-*-*-m-*-iso8859-1")
1698 ("24 slant" "-adobe-courier-medium-o-normal--*-240-*-*-m-*-iso8859-1")
1699 ("8 bold slant" "-adobe-courier-bold-o-normal--*-80-*-*-m-*-iso8859-1")
1700 ("10 bold slant" "-adobe-courier-bold-o-normal--*-100-*-*-m-*-iso8859-1")
1701 ("12 bold slant" "-adobe-courier-bold-o-normal--*-120-*-*-m-*-iso8859-1")
1702 ("14 bold slant" "-adobe-courier-bold-o-normal--*-140-*-*-m-*-iso8859-1")
1703 ("18 bold slant" "-adobe-courier-bold-o-normal--*-180-*-*-m-*-iso8859-1")
1704 ("24 bold slant" "-adobe-courier-bold-o-normal--*-240-*-*-m-*-iso8859-1"))
1705 )
1706 "X fonts suitable for use in Emacs.")
1707
1708 (defun mouse-set-font (&rest fonts)
1709 "Select an emacs font from a list of known good fonts"
1710 (interactive
1711 (x-popup-menu last-nonmenu-event x-fixed-font-alist))
1712 (if fonts
1713 (let (font)
1714 (while fonts
1715 (condition-case nil
1716 (progn
1717 (set-default-font (car fonts))
1718 (setq font (car fonts))
1719 (setq fonts nil))
1720 (error
1721 (setq fonts (cdr fonts)))))
1722 (if (null font)
1723 (error "Font not found")))))
1724 \f
1725 ;;; Bindings for mouse commands.
1726
1727 (define-key global-map [down-mouse-1] 'mouse-drag-region)
1728 (global-set-key [mouse-1] 'mouse-set-point)
1729 (global-set-key [drag-mouse-1] 'mouse-set-region)
1730
1731 ;; These are tested for in mouse-drag-region.
1732 (global-set-key [double-mouse-1] 'mouse-set-point)
1733 (global-set-key [triple-mouse-1] 'mouse-set-point)
1734
1735 (global-set-key [mouse-2] 'mouse-yank-at-click)
1736 (global-set-key [mouse-3] 'mouse-save-then-kill)
1737
1738 ;; By binding these to down-going events, we let the user use the up-going
1739 ;; event to make the selection, saving a click.
1740 (global-set-key [C-down-mouse-1] 'mouse-buffer-menu)
1741 (if (not (eq system-type 'ms-dos))
1742 (global-set-key [S-down-mouse-1] 'mouse-set-font))
1743 ;; C-down-mouse-2 is bound in facemenu.el.
1744 (global-set-key [C-down-mouse-3] 'mouse-major-mode-menu)
1745
1746
1747 ;; Replaced with dragging mouse-1
1748 ;; (global-set-key [S-mouse-1] 'mouse-set-mark)
1749
1750 (global-set-key [mode-line mouse-1] 'mouse-select-window)
1751 (global-set-key [mode-line drag-mouse-1] 'mouse-select-window)
1752 (global-set-key [mode-line down-mouse-1] 'mouse-drag-mode-line)
1753 (global-set-key [mode-line mouse-2] 'mouse-delete-other-windows)
1754 (global-set-key [mode-line mouse-3] 'mouse-delete-window)
1755 (global-set-key [mode-line C-mouse-2] 'mouse-split-window-horizontally)
1756 (global-set-key [vertical-scroll-bar C-mouse-2] 'mouse-split-window-vertically)
1757 (global-set-key [vertical-line C-mouse-2] 'mouse-split-window-vertically)
1758 (global-set-key [vertical-line down-mouse-1] 'mouse-drag-vertical-line)
1759 (global-set-key [vertical-line mouse-1] 'mouse-select-window)
1760
1761 (provide 'mouse)
1762
1763 ;;; mouse.el ends here