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