]> code.delx.au - gnu-emacs/blob - lisp/mouse.el
(mouse-buffer-menu): If lots of buffers, group them into multiple panes.
[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
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 (eq (framep (selected-frame)) 'win32)
406 (sit-for 1))
407 (push-mark)
408 (set-mark (point))
409 (if (numberp (posn-point end))
410 (goto-char (posn-point end)))
411 ;; Don't set this-command to kill-region, so that a following
412 ;; C-w will not double the text in the kill ring.
413 ;; Ignore last-command so we don't append to a preceding kill.
414 (let (this-command last-command)
415 (copy-region-as-kill (mark) (point)))
416 (mouse-set-region-1)))
417
418 (defun mouse-set-region-1 ()
419 (setq mouse-last-region-beg (region-beginning))
420 (setq mouse-last-region-end (region-end))
421 (setq mouse-last-region-tick (buffer-modified-tick)))
422
423 (defvar mouse-scroll-delay 0.25
424 "*The pause between scroll steps caused by mouse drags, in seconds.
425 If you drag the mouse beyond the edge of a window, Emacs scrolls the
426 window to bring the text beyond that edge into view, with a delay of
427 this many seconds between scroll steps. Scrolling stops when you move
428 the mouse back into the window, or release the button.
429 This variable's value may be non-integral.
430 Setting this to zero causes Emacs to scroll as fast as it can.")
431
432 (defvar mouse-scroll-min-lines 1
433 "*The minimum number of lines scrolled by dragging mouse out of window.
434 Moving the mouse out the top or bottom edge of the window begins
435 scrolling repeatedly. The number of lines scrolled per repetition
436 is normally equal to the number of lines beyond the window edge that
437 the mouse has moved. However, it always scrolls at least the number
438 of lines specified by this variable.")
439
440 (defun mouse-scroll-subr (window jump &optional overlay start)
441 "Scroll the window WINDOW, JUMP lines at a time, until new input arrives.
442 If OVERLAY is an overlay, let it stretch from START to the far edge of
443 the newly visible text.
444 Upon exit, point is at the far edge of the newly visible text."
445 (cond
446 ((and (> jump 0) (< jump mouse-scroll-min-lines))
447 (setq jump mouse-scroll-min-lines))
448 ((and (< jump 0) (< (- jump) mouse-scroll-min-lines))
449 (setq jump (- mouse-scroll-min-lines))))
450 (let ((opoint (point)))
451 (while (progn
452 (goto-char (window-start window))
453 (if (not (zerop (vertical-motion jump window)))
454 (progn
455 (set-window-start window (point))
456 (if (natnump jump)
457 (progn
458 (goto-char (window-end window))
459 ;; window-end doesn't reflect the window's new
460 ;; start position until the next redisplay. Hurrah.
461 (vertical-motion (1- jump) window))
462 (goto-char (window-start window)))
463 (if overlay
464 (move-overlay overlay start (point)))
465 ;; Now that we have scrolled WINDOW properly,
466 ;; put point back where it was for the redisplay
467 ;; so that we don't mess up the selected window.
468 (or (eq window (selected-window))
469 (goto-char opoint))
470 (sit-for mouse-scroll-delay)))))
471 (or (eq window (selected-window))
472 (goto-char opoint))))
473
474 ;; Create an overlay and immediately delete it, to get "overlay in no buffer".
475 (defvar mouse-drag-overlay (make-overlay 1 1))
476 (delete-overlay mouse-drag-overlay)
477 (overlay-put mouse-drag-overlay 'face 'region)
478
479 (defvar mouse-selection-click-count 0)
480
481 (defvar mouse-selection-click-count-buffer nil)
482
483 (defun mouse-drag-region (start-event)
484 "Set the region to the text that the mouse is dragged over.
485 Highlight the drag area as you move the mouse.
486 This must be bound to a button-down mouse event.
487 In Transient Mark mode, the highlighting remains once you
488 release the mouse button. Otherwise, it does not."
489 (interactive "e")
490 (mouse-minibuffer-check start-event)
491 (let* ((start-posn (event-start start-event))
492 (start-point (posn-point start-posn))
493 (start-window (posn-window start-posn))
494 (start-frame (window-frame start-window))
495 (bounds (window-edges start-window))
496 (top (nth 1 bounds))
497 (bottom (if (window-minibuffer-p start-window)
498 (nth 3 bounds)
499 ;; Don't count the mode line.
500 (1- (nth 3 bounds))))
501 (click-count (1- (event-click-count start-event))))
502 (setq mouse-selection-click-count click-count)
503 (setq mouse-selection-click-count-buffer (current-buffer))
504 (mouse-set-point start-event)
505 ;; In case the down click is in the middle of some intangible text,
506 ;; use the end of that text, and put it in START-POINT.
507 (if (< (point) start-point)
508 (goto-char start-point))
509 (setq start-point (point))
510 (let ((range (mouse-start-end start-point start-point click-count)))
511 (move-overlay mouse-drag-overlay (car range) (nth 1 range)
512 (window-buffer start-window)))
513 (deactivate-mark)
514 ;; end-of-range is used only in the single-click case.
515 ;; It is the place where the drag has reached so far
516 ;; (but not outside the window where the drag started).
517 (let (event end end-point (end-of-range (point)))
518 (track-mouse
519 (while (progn
520 (setq event (read-event))
521 (or (mouse-movement-p event)
522 (eq (car-safe event) 'switch-frame)))
523 (if (eq (car-safe event) 'switch-frame)
524 nil
525 (setq end (event-end event)
526 end-point (posn-point end))
527
528 (cond
529 ;; Are we moving within the original window?
530 ((and (eq (posn-window end) start-window)
531 (integer-or-marker-p end-point))
532 ;; Go to START-POINT first, so that when we move to END-POINT,
533 ;; if it's in the middle of intangible text,
534 ;; point jumps in the direction away from START-POINT.
535 (goto-char start-point)
536 (goto-char end-point)
537 (if (zerop (% click-count 3))
538 (setq end-of-range (point)))
539 (let ((range (mouse-start-end start-point (point) click-count)))
540 (move-overlay mouse-drag-overlay (car range) (nth 1 range))))
541
542 (t
543 (let ((mouse-row (cdr (cdr (mouse-position)))))
544 (cond
545 ((null mouse-row))
546 ((< mouse-row top)
547 (mouse-scroll-subr start-window (- mouse-row top)
548 mouse-drag-overlay start-point)
549 ;; Without this, point tends to jump back to the starting
550 ;; position where the mouse button was pressed down.
551 (setq end-of-range (overlay-start mouse-drag-overlay)))
552 ((>= mouse-row bottom)
553 (mouse-scroll-subr start-window (1+ (- mouse-row bottom))
554 mouse-drag-overlay start-point)
555 (setq end-of-range (overlay-end mouse-drag-overlay))))))))))
556 (if (consp event)
557 (let ((fun (key-binding (vector (car event)))))
558 ;; Run the binding of the terminating up-event, if possible.
559 ;; In the case of a multiple click, it gives the wrong results,
560 ;; because it would fail to set up a region.
561 (if (and (= (mod mouse-selection-click-count 3) 0) (fboundp fun))
562 ;; In this case, we can just let the up-event execute normally.
563 (let ((end (event-end event)))
564 ;; Set the position in the event before we replay it,
565 ;; because otherwise it may have a position in the wrong
566 ;; buffer.
567 (setcar (cdr end) end-of-range)
568 ;; Delete the overlay before calling the function,
569 ;; because delete-overlay increases buffer-modified-tick.
570 (delete-overlay mouse-drag-overlay)
571 (setq unread-command-events
572 (cons event unread-command-events)))
573 (if (not (= (overlay-start mouse-drag-overlay)
574 (overlay-end mouse-drag-overlay)))
575 (let (last-command this-command)
576 (push-mark (overlay-start mouse-drag-overlay) t t)
577 (goto-char (overlay-end mouse-drag-overlay))
578 (delete-overlay mouse-drag-overlay)
579 (copy-region-as-kill (point) (mark t))
580 (mouse-set-region-1))
581 (goto-char (overlay-end mouse-drag-overlay))
582 (setq this-command 'mouse-set-point)
583 (delete-overlay mouse-drag-overlay))))
584 (delete-overlay mouse-drag-overlay)))))
585 \f
586 ;; Commands to handle xterm-style multiple clicks.
587
588 (defun mouse-skip-word (dir)
589 "Skip over word, over whitespace, or over identical punctuation.
590 If DIR is positive skip forward; if negative, skip backward."
591 (let* ((char (following-char))
592 (syntax (char-to-string (char-syntax char))))
593 (cond ((or (string= syntax "w") (string= syntax " "))
594 (if (< dir 0)
595 (skip-syntax-backward syntax)
596 (skip-syntax-forward syntax)))
597 ((string= syntax "_")
598 (if (< dir 0)
599 (skip-syntax-backward "w_")
600 (skip-syntax-forward "w_")))
601 ((< dir 0)
602 (while (and (not (bobp)) (= (preceding-char) char))
603 (forward-char -1)))
604 (t
605 (while (and (not (eobp)) (= (following-char) char))
606 (forward-char 1))))))
607
608 ;; Return a list of region bounds based on START and END according to MODE.
609 ;; If MODE is 0 then set point to (min START END), mark to (max START END).
610 ;; If MODE is 1 then set point to start of word at (min START END),
611 ;; mark to end of word at (max START END).
612 ;; If MODE is 2 then do the same for lines.
613 (defun mouse-start-end (start end mode)
614 (if (> start end)
615 (let ((temp start))
616 (setq start end
617 end temp)))
618 (setq mode (mod mode 3))
619 (cond ((= mode 0)
620 (list start end))
621 ((and (= mode 1)
622 (= start end)
623 (char-after start)
624 (= (char-syntax (char-after start)) ?\())
625 (list start
626 (save-excursion
627 (goto-char start)
628 (forward-sexp 1)
629 (point))))
630 ((and (= mode 1)
631 (= start end)
632 (char-after start)
633 (= (char-syntax (char-after start)) ?\)))
634 (list (save-excursion
635 (goto-char (1+ start))
636 (backward-sexp 1)
637 (point))
638 (1+ start)))
639 ((= mode 1)
640 (list (save-excursion
641 (goto-char start)
642 (mouse-skip-word -1)
643 (point))
644 (save-excursion
645 (goto-char end)
646 (mouse-skip-word 1)
647 (point))))
648 ((= mode 2)
649 (list (save-excursion
650 (goto-char start)
651 (beginning-of-line 1)
652 (point))
653 (save-excursion
654 (goto-char end)
655 (forward-line 1)
656 (point))))))
657 \f
658 ;; Subroutine: set the mark where CLICK happened,
659 ;; but don't do anything else.
660 (defun mouse-set-mark-fast (click)
661 (mouse-minibuffer-check click)
662 (let ((posn (event-start click)))
663 (select-window (posn-window posn))
664 (if (numberp (posn-point posn))
665 (push-mark (posn-point posn) t t))))
666
667 ;; Momentarily show where the mark is, if highlighting doesn't show it.
668 (defun mouse-show-mark ()
669 (or transient-mark-mode
670 (save-excursion
671 (goto-char (mark t))
672 (sit-for 1))))
673
674 (defun mouse-set-mark (click)
675 "Set mark at the position clicked on with the mouse.
676 Display cursor at that position for a second.
677 This must be bound to a mouse click."
678 (interactive "e")
679 (mouse-minibuffer-check click)
680 (select-window (posn-window (event-start click)))
681 ;; We don't use save-excursion because that preserves the mark too.
682 (let ((point-save (point)))
683 (unwind-protect
684 (progn (mouse-set-point click)
685 (push-mark nil t t)
686 (or transient-mark-mode
687 (sit-for 1)))
688 (goto-char point-save))))
689
690 (defun mouse-kill (click)
691 "Kill the region between point and the mouse click.
692 The text is saved in the kill ring, as with \\[kill-region]."
693 (interactive "e")
694 (mouse-minibuffer-check click)
695 (let* ((posn (event-start click))
696 (click-posn (posn-point posn)))
697 (select-window (posn-window posn))
698 (if (numberp click-posn)
699 (kill-region (min (point) click-posn)
700 (max (point) click-posn)))))
701
702 (defun mouse-yank-at-click (click arg)
703 "Insert the last stretch of killed text at the position clicked on.
704 Also move point to one end of the text thus inserted (normally the end).
705 Prefix arguments are interpreted as with \\[yank].
706 If `mouse-yank-at-point' is non-nil, insert at point
707 regardless of where you click."
708 (interactive "e\nP")
709 ;; Give temporary modes such as isearch a chance to turn off.
710 (run-hooks 'mouse-leave-buffer-hook)
711 (or mouse-yank-at-point (mouse-set-point click))
712 (setq this-command 'yank)
713 (setq mouse-selection-click-count 0)
714 (yank arg))
715
716 (defun mouse-kill-ring-save (click)
717 "Copy the region between point and the mouse click in the kill ring.
718 This does not delete the region; it acts like \\[kill-ring-save]."
719 (interactive "e")
720 (mouse-set-mark-fast click)
721 (let (this-command last-command)
722 (kill-ring-save (point) (mark t)))
723 (mouse-show-mark))
724
725 ;;; This function used to delete the text between point and the mouse
726 ;;; whenever it was equal to the front of the kill ring, but some
727 ;;; people found that confusing.
728
729 ;;; A list (TEXT START END), describing the text and position of the last
730 ;;; invocation of mouse-save-then-kill.
731 (defvar mouse-save-then-kill-posn nil)
732
733 (defun mouse-save-then-kill-delete-region (beg end)
734 ;; We must make our own undo boundaries
735 ;; because they happen automatically only for the current buffer.
736 (undo-boundary)
737 (if (or (= beg end) (eq buffer-undo-list t))
738 ;; If we have no undo list in this buffer,
739 ;; just delete.
740 (delete-region beg end)
741 ;; Delete, but make the undo-list entry share with the kill ring.
742 ;; First, delete just one char, so in case buffer is being modified
743 ;; for the first time, the undo list records that fact.
744 (let (before-change-function after-change-function
745 before-change-functions after-change-functions)
746 (delete-region beg
747 (+ beg (if (> end beg) 1 -1))))
748 (let ((buffer-undo-list buffer-undo-list))
749 ;; Undo that deletion--but don't change the undo list!
750 (let (before-change-function after-change-function
751 before-change-functions after-change-functions)
752 (primitive-undo 1 buffer-undo-list))
753 ;; Now delete the rest of the specified region,
754 ;; but don't record it.
755 (setq buffer-undo-list t)
756 (if (/= (length (car kill-ring)) (- (max end beg) (min end beg)))
757 (error "Lossage in mouse-save-then-kill-delete-region"))
758 (delete-region beg end))
759 (let ((tail buffer-undo-list))
760 ;; Search back in buffer-undo-list for the string
761 ;; that came from deleting one character.
762 (while (and tail (not (stringp (car (car tail)))))
763 (setq tail (cdr tail)))
764 ;; Replace it with an entry for the entire deleted text.
765 (and tail
766 (setcar tail (cons (car kill-ring) (min beg end))))))
767 (undo-boundary))
768
769 (defun mouse-save-then-kill (click)
770 "Save text to point in kill ring; the second time, kill the text.
771 If the text between point and the mouse is the same as what's
772 at the front of the kill ring, this deletes the text.
773 Otherwise, it adds the text to the kill ring, like \\[kill-ring-save],
774 which prepares for a second click to delete the text.
775
776 If you have selected words or lines, this command extends the
777 selection through the word or line clicked on. If you do this
778 again in a different position, it extends the selection again.
779 If you do this twice in the same position, the selection is killed."
780 (interactive "e")
781 (let ((before-scroll point-before-scroll))
782 (mouse-minibuffer-check click)
783 (let ((click-posn (posn-point (event-start click)))
784 ;; Don't let a subsequent kill command append to this one:
785 ;; prevent setting this-command to kill-region.
786 (this-command this-command))
787 (if (and (save-excursion
788 (set-buffer (window-buffer (posn-window (event-start click))))
789 (and (mark t) (> (mod mouse-selection-click-count 3) 0)
790 ;; Don't be fooled by a recent click in some other buffer.
791 (eq mouse-selection-click-count-buffer
792 (current-buffer)))))
793 (if (not (and (eq last-command 'mouse-save-then-kill)
794 (equal click-posn
795 (car (cdr-safe (cdr-safe mouse-save-then-kill-posn))))))
796 ;; Find both ends of the object selected by this click.
797 (let* ((range
798 (mouse-start-end click-posn click-posn
799 mouse-selection-click-count)))
800 ;; Move whichever end is closer to the click.
801 ;; That's what xterm does, and it seems reasonable.
802 (if (< (abs (- click-posn (mark t)))
803 (abs (- click-posn (point))))
804 (set-mark (car range))
805 (goto-char (nth 1 range)))
806 ;; We have already put the old region in the kill ring.
807 ;; Replace it with the extended region.
808 ;; (It would be annoying to make a separate entry.)
809 (kill-new (buffer-substring (point) (mark t)) t)
810 (mouse-set-region-1)
811 ;; Arrange for a repeated mouse-3 to kill this region.
812 (setq mouse-save-then-kill-posn
813 (list (car kill-ring) (point) click-posn))
814 (mouse-show-mark))
815 ;; If we click this button again without moving it,
816 ;; that time kill.
817 (mouse-save-then-kill-delete-region (mark) (point))
818 (setq mouse-selection-click-count 0)
819 (setq mouse-save-then-kill-posn nil))
820 (if (and (eq last-command 'mouse-save-then-kill)
821 mouse-save-then-kill-posn
822 (eq (car mouse-save-then-kill-posn) (car kill-ring))
823 (equal (cdr mouse-save-then-kill-posn) (list (point) click-posn)))
824 ;; If this is the second time we've called
825 ;; mouse-save-then-kill, delete the text from the buffer.
826 (progn
827 (mouse-save-then-kill-delete-region (point) (mark))
828 ;; After we kill, another click counts as "the first time".
829 (setq mouse-save-then-kill-posn nil))
830 (if (or (and (eq last-command 'mouse-save-then-kill)
831 mouse-save-then-kill-posn)
832 (and mark-active transient-mark-mode)
833 (and (memq last-command
834 '(mouse-drag-region mouse-set-region))
835 (or mark-even-if-inactive
836 (not transient-mark-mode))))
837 ;; We have a selection or suitable region, so adjust it.
838 (let* ((posn (event-start click))
839 (new (posn-point posn)))
840 (select-window (posn-window posn))
841 (if (numberp new)
842 (progn
843 ;; Move whichever end of the region is closer to the click.
844 ;; That is what xterm does, and it seems reasonable.
845 (if (< (abs (- new (point))) (abs (- new (mark t))))
846 (goto-char new)
847 (set-mark new))
848 (setq deactivate-mark nil)))
849 (kill-new (buffer-substring (point) (mark t)) t)
850 (mouse-show-mark))
851 ;; Set the mark where point is, then move where clicked.
852 (mouse-set-mark-fast click)
853 (if before-scroll
854 (goto-char before-scroll))
855 (exchange-point-and-mark)
856 (kill-new (buffer-substring (point) (mark t))))
857 (mouse-set-region-1)
858 (setq mouse-save-then-kill-posn
859 (list (car kill-ring) (point) click-posn)))))))
860 \f
861 (global-set-key [M-mouse-1] 'mouse-start-secondary)
862 (global-set-key [M-drag-mouse-1] 'mouse-set-secondary)
863 (global-set-key [M-down-mouse-1] 'mouse-drag-secondary)
864 (global-set-key [M-mouse-3] 'mouse-secondary-save-then-kill)
865 (global-set-key [M-mouse-2] 'mouse-yank-secondary)
866
867 ;; An overlay which records the current secondary selection
868 ;; or else is deleted when there is no secondary selection.
869 ;; May be nil.
870 (defvar mouse-secondary-overlay nil)
871
872 (defvar mouse-secondary-click-count 0)
873
874 ;; A marker which records the specified first end for a secondary selection.
875 ;; May be nil.
876 (defvar mouse-secondary-start nil)
877
878 (defun mouse-start-secondary (click)
879 "Set one end of the secondary selection to the position clicked on.
880 Use \\[mouse-secondary-save-then-kill] to set the other end
881 and complete the secondary selection."
882 (interactive "e")
883 (mouse-minibuffer-check click)
884 (let ((posn (event-start click)))
885 (save-excursion
886 (set-buffer (window-buffer (posn-window posn)))
887 ;; Cancel any preexisting secondary selection.
888 (if mouse-secondary-overlay
889 (delete-overlay mouse-secondary-overlay))
890 (if (numberp (posn-point posn))
891 (progn
892 (or mouse-secondary-start
893 (setq mouse-secondary-start (make-marker)))
894 (move-marker mouse-secondary-start (posn-point posn)))))))
895
896 (defun mouse-set-secondary (click)
897 "Set the secondary selection to the text that the mouse is dragged over.
898 This must be bound to a mouse drag event."
899 (interactive "e")
900 (mouse-minibuffer-check click)
901 (let ((posn (event-start click))
902 beg
903 (end (event-end click)))
904 (save-excursion
905 (set-buffer (window-buffer (posn-window posn)))
906 (if (numberp (posn-point posn))
907 (setq beg (posn-point posn)))
908 (if mouse-secondary-overlay
909 (move-overlay mouse-secondary-overlay beg (posn-point end))
910 (setq mouse-secondary-overlay (make-overlay beg (posn-point end))))
911 (overlay-put mouse-secondary-overlay 'face 'secondary-selection))))
912
913 (defun mouse-drag-secondary (start-event)
914 "Set the secondary selection to the text that the mouse is dragged over.
915 Highlight the drag area as you move the mouse.
916 This must be bound to a button-down mouse event."
917 (interactive "e")
918 (mouse-minibuffer-check start-event)
919 (let* ((start-posn (event-start start-event))
920 (start-point (posn-point start-posn))
921 (start-window (posn-window start-posn))
922 (start-frame (window-frame start-window))
923 (bounds (window-edges start-window))
924 (top (nth 1 bounds))
925 (bottom (if (window-minibuffer-p start-window)
926 (nth 3 bounds)
927 ;; Don't count the mode line.
928 (1- (nth 3 bounds))))
929 (click-count (1- (event-click-count start-event))))
930 (save-excursion
931 (set-buffer (window-buffer start-window))
932 (setq mouse-secondary-click-count click-count)
933 (or mouse-secondary-overlay
934 (setq mouse-secondary-overlay
935 (make-overlay (point) (point))))
936 (overlay-put mouse-secondary-overlay 'face 'secondary-selection)
937 (if (> (mod click-count 3) 0)
938 ;; Double or triple press: make an initial selection
939 ;; of one word or line.
940 (let ((range (mouse-start-end start-point start-point click-count)))
941 (set-marker mouse-secondary-start nil)
942 (move-overlay mouse-secondary-overlay 1 1
943 (window-buffer start-window))
944 (move-overlay mouse-secondary-overlay (car range) (nth 1 range)
945 (window-buffer start-window)))
946 ;; Single-press: cancel any preexisting secondary selection.
947 (or mouse-secondary-start
948 (setq mouse-secondary-start (make-marker)))
949 (set-marker mouse-secondary-start start-point)
950 (delete-overlay mouse-secondary-overlay))
951 (let (event end end-point)
952 (track-mouse
953 (while (progn
954 (setq event (read-event))
955 (or (mouse-movement-p event)
956 (eq (car-safe event) 'switch-frame)))
957
958 (if (eq (car-safe event) 'switch-frame)
959 nil
960 (setq end (event-end event)
961 end-point (posn-point end))
962 (cond
963 ;; Are we moving within the original window?
964 ((and (eq (posn-window end) start-window)
965 (integer-or-marker-p end-point))
966 (let ((range (mouse-start-end start-point end-point
967 click-count)))
968 (if (or (/= start-point end-point)
969 (null (marker-position mouse-secondary-start)))
970 (progn
971 (set-marker mouse-secondary-start nil)
972 (move-overlay mouse-secondary-overlay
973 (car range) (nth 1 range))))))
974 (t
975 (let ((mouse-row (cdr (cdr (mouse-position)))))
976 (cond
977 ((null mouse-row))
978 ((< mouse-row top)
979 (mouse-scroll-subr start-window (- mouse-row top)
980 mouse-secondary-overlay start-point))
981 ((>= mouse-row bottom)
982 (mouse-scroll-subr start-window (1+ (- mouse-row bottom))
983 mouse-secondary-overlay start-point)))))))))
984
985 (if (consp event)
986 ;;; (eq (get (event-basic-type event) 'event-kind) 'mouse-click)
987 ;;; (eq (posn-window (event-end event)) start-window)
988 ;;; (numberp (posn-point (event-end event)))
989 (if (marker-position mouse-secondary-start)
990 (save-window-excursion
991 (delete-overlay mouse-secondary-overlay)
992 (x-set-selection 'SECONDARY nil)
993 (select-window start-window)
994 (save-excursion
995 (goto-char mouse-secondary-start)
996 (sit-for 1)))
997 (x-set-selection
998 'SECONDARY
999 (buffer-substring (overlay-start mouse-secondary-overlay)
1000 (overlay-end mouse-secondary-overlay)))))))))
1001
1002 (defun mouse-yank-secondary (click)
1003 "Insert the secondary selection at the position clicked on.
1004 Move point to the end of the inserted text.
1005 If `mouse-yank-at-point' is non-nil, insert at point
1006 regardless of where you click."
1007 (interactive "e")
1008 ;; Give temporary modes such as isearch a chance to turn off.
1009 (run-hooks 'mouse-leave-buffer-hook)
1010 (or mouse-yank-at-point (mouse-set-point click))
1011 (insert (x-get-selection 'SECONDARY)))
1012
1013 (defun mouse-kill-secondary ()
1014 "Kill the text in the secondary selection.
1015 This is intended more as a keyboard command than as a mouse command
1016 but it can work as either one.
1017
1018 The current buffer (in case of keyboard use), or the buffer clicked on,
1019 must be the one that the secondary selection is in. This requirement
1020 is to prevent accidents."
1021 (interactive)
1022 (let* ((keys (this-command-keys))
1023 (click (elt keys (1- (length keys)))))
1024 (or (eq (overlay-buffer mouse-secondary-overlay)
1025 (if (listp click)
1026 (window-buffer (posn-window (event-start click)))
1027 (current-buffer)))
1028 (error "Select or click on the buffer where the secondary selection is")))
1029 (let (this-command)
1030 (save-excursion
1031 (set-buffer (overlay-buffer mouse-secondary-overlay))
1032 (kill-region (overlay-start mouse-secondary-overlay)
1033 (overlay-end mouse-secondary-overlay))))
1034 (delete-overlay mouse-secondary-overlay)
1035 ;;; (x-set-selection 'SECONDARY nil)
1036 (setq mouse-secondary-overlay nil))
1037
1038 (defun mouse-secondary-save-then-kill (click)
1039 "Save text to point in kill ring; the second time, kill the text.
1040 You must use this in a buffer where you have recently done \\[mouse-start-secondary].
1041 If the text between where you did \\[mouse-start-secondary] and where
1042 you use this command matches the text at the front of the kill ring,
1043 this command deletes the text.
1044 Otherwise, it adds the text to the kill ring, like \\[kill-ring-save],
1045 which prepares for a second click with this command to delete the text.
1046
1047 If you have already made a secondary selection in that buffer,
1048 this command extends or retracts the selection to where you click.
1049 If you do this again in a different position, it extends or retracts
1050 again. If you do this twice in the same position, it kills the selection."
1051 (interactive "e")
1052 (mouse-minibuffer-check click)
1053 (let ((posn (event-start click))
1054 (click-posn (posn-point (event-start click)))
1055 ;; Don't let a subsequent kill command append to this one:
1056 ;; prevent setting this-command to kill-region.
1057 (this-command this-command))
1058 (or (eq (window-buffer (posn-window posn))
1059 (or (and mouse-secondary-overlay
1060 (overlay-buffer mouse-secondary-overlay))
1061 (if mouse-secondary-start
1062 (marker-buffer mouse-secondary-start))))
1063 (error "Wrong buffer"))
1064 (save-excursion
1065 (set-buffer (window-buffer (posn-window posn)))
1066 (if (> (mod mouse-secondary-click-count 3) 0)
1067 (if (not (and (eq last-command 'mouse-secondary-save-then-kill)
1068 (equal click-posn
1069 (car (cdr-safe (cdr-safe mouse-save-then-kill-posn))))))
1070 ;; Find both ends of the object selected by this click.
1071 (let* ((range
1072 (mouse-start-end click-posn click-posn
1073 mouse-secondary-click-count)))
1074 ;; Move whichever end is closer to the click.
1075 ;; That's what xterm does, and it seems reasonable.
1076 (if (< (abs (- click-posn (overlay-start mouse-secondary-overlay)))
1077 (abs (- click-posn (overlay-end mouse-secondary-overlay))))
1078 (move-overlay mouse-secondary-overlay (car range)
1079 (overlay-end mouse-secondary-overlay))
1080 (move-overlay mouse-secondary-overlay
1081 (overlay-start mouse-secondary-overlay)
1082 (nth 1 range)))
1083 ;; We have already put the old region in the kill ring.
1084 ;; Replace it with the extended region.
1085 ;; (It would be annoying to make a separate entry.)
1086 (kill-new (buffer-substring
1087 (overlay-start mouse-secondary-overlay)
1088 (overlay-end mouse-secondary-overlay)) t)
1089 ;; Arrange for a repeated mouse-3 to kill this region.
1090 (setq mouse-save-then-kill-posn
1091 (list (car kill-ring) (point) click-posn)))
1092 ;; If we click this button again without moving it,
1093 ;; that time kill.
1094 (progn
1095 (mouse-save-then-kill-delete-region
1096 (overlay-start mouse-secondary-overlay)
1097 (overlay-end mouse-secondary-overlay))
1098 (setq mouse-save-then-kill-posn nil)
1099 (setq mouse-secondary-click-count 0)
1100 (delete-overlay mouse-secondary-overlay)))
1101 (if (and (eq last-command 'mouse-secondary-save-then-kill)
1102 mouse-save-then-kill-posn
1103 (eq (car mouse-save-then-kill-posn) (car kill-ring))
1104 (equal (cdr mouse-save-then-kill-posn) (list (point) click-posn)))
1105 ;; If this is the second time we've called
1106 ;; mouse-secondary-save-then-kill, delete the text from the buffer.
1107 (progn
1108 (mouse-save-then-kill-delete-region
1109 (overlay-start mouse-secondary-overlay)
1110 (overlay-end mouse-secondary-overlay))
1111 (setq mouse-save-then-kill-posn nil)
1112 (delete-overlay mouse-secondary-overlay))
1113 (if (overlay-start mouse-secondary-overlay)
1114 ;; We have a selection, so adjust it.
1115 (progn
1116 (if (numberp click-posn)
1117 (progn
1118 ;; Move whichever end of the region is closer to the click.
1119 ;; That is what xterm does, and it seems reasonable.
1120 (if (< (abs (- click-posn (overlay-start mouse-secondary-overlay)))
1121 (abs (- click-posn (overlay-end mouse-secondary-overlay))))
1122 (move-overlay mouse-secondary-overlay click-posn
1123 (overlay-end mouse-secondary-overlay))
1124 (move-overlay mouse-secondary-overlay
1125 (overlay-start mouse-secondary-overlay)
1126 click-posn))
1127 (setq deactivate-mark nil)))
1128 (if (eq last-command 'mouse-secondary-save-then-kill)
1129 ;; If the front of the kill ring comes from
1130 ;; an immediately previous use of this command,
1131 ;; replace it with the extended region.
1132 ;; (It would be annoying to make a separate entry.)
1133 (kill-new (buffer-substring
1134 (overlay-start mouse-secondary-overlay)
1135 (overlay-end mouse-secondary-overlay)) t)
1136 (copy-region-as-kill (overlay-start mouse-secondary-overlay)
1137 (overlay-end mouse-secondary-overlay))))
1138 (if mouse-secondary-start
1139 ;; All we have is one end of a selection,
1140 ;; so put the other end here.
1141 (let ((start (+ 0 mouse-secondary-start)))
1142 (kill-ring-save start click-posn)
1143 (if mouse-secondary-overlay
1144 (move-overlay mouse-secondary-overlay start click-posn)
1145 (setq mouse-secondary-overlay (make-overlay start click-posn)))
1146 (overlay-put mouse-secondary-overlay 'face 'secondary-selection))))
1147 (setq mouse-save-then-kill-posn
1148 (list (car kill-ring) (point) click-posn))))
1149 (if (overlay-buffer mouse-secondary-overlay)
1150 (x-set-selection 'SECONDARY
1151 (buffer-substring
1152 (overlay-start mouse-secondary-overlay)
1153 (overlay-end mouse-secondary-overlay)))))))
1154 \f
1155 (defun mouse-buffer-menu (event)
1156 "Pop up a menu of buffers for selection with the mouse.
1157 This switches buffers in the window that you clicked on,
1158 and selects that window."
1159 (interactive "e")
1160 (mouse-minibuffer-check event)
1161 (let* ((buffers
1162 ;; Make an alist of (MENU-ITEM . BUFFER).
1163 (let ((tail (buffer-list))
1164 (maxlen 0)
1165 head)
1166 (while tail
1167 (or (eq ?\ (aref (buffer-name (car tail)) 0))
1168 (setq maxlen
1169 (max maxlen
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" maxlen)
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 head))
1198 (menu
1199 ;; If we have lots of buffers, divide them into groups of 20
1200 ;; and make a pane (or submenu) for each one.
1201 (if (> (length buffers) 30)
1202 (let ((buffers (reverse buffers)) sublists next
1203 (i 1))
1204 (while buffers
1205 ;; Pull off the next 20 buffers
1206 ;; and make them the next element of sublist.
1207 (setq next (nthcdr 20 buffers))
1208 (if next
1209 (setcdr (nthcdr 19 buffers) nil))
1210 (setq sublists (cons (cons (format "Buffers %d" i) buffers)
1211 sublists))
1212 (setq i (1+ i))
1213 (setq buffers next))
1214 (cons "Buffer Menu" (nreverse sublists)))
1215 ;; Few buffers--put them all in one pane.
1216 (list "Buffer Menu" (cons "Select Buffer" buffers)))))
1217 (setq foo menu)
1218 (let ((buf (x-popup-menu event menu))
1219 (window (posn-window (event-start event))))
1220 (if buf
1221 (progn
1222 (or (framep window) (select-window window))
1223 (switch-to-buffer buf))))))
1224
1225 (defun mouse-buffer-menu-split (alist)
1226 \f
1227 ;;; These need to be rewritten for the new scroll bar implementation.
1228
1229 ;;;!! ;; Commands for the scroll bar.
1230 ;;;!!
1231 ;;;!! (defun mouse-scroll-down (click)
1232 ;;;!! (interactive "@e")
1233 ;;;!! (scroll-down (1+ (cdr (mouse-coords click)))))
1234 ;;;!!
1235 ;;;!! (defun mouse-scroll-up (click)
1236 ;;;!! (interactive "@e")
1237 ;;;!! (scroll-up (1+ (cdr (mouse-coords click)))))
1238 ;;;!!
1239 ;;;!! (defun mouse-scroll-down-full ()
1240 ;;;!! (interactive "@")
1241 ;;;!! (scroll-down nil))
1242 ;;;!!
1243 ;;;!! (defun mouse-scroll-up-full ()
1244 ;;;!! (interactive "@")
1245 ;;;!! (scroll-up nil))
1246 ;;;!!
1247 ;;;!! (defun mouse-scroll-move-cursor (click)
1248 ;;;!! (interactive "@e")
1249 ;;;!! (move-to-window-line (1+ (cdr (mouse-coords click)))))
1250 ;;;!!
1251 ;;;!! (defun mouse-scroll-absolute (event)
1252 ;;;!! (interactive "@e")
1253 ;;;!! (let* ((pos (car event))
1254 ;;;!! (position (car pos))
1255 ;;;!! (length (car (cdr pos))))
1256 ;;;!! (if (<= length 0) (setq length 1))
1257 ;;;!! (let* ((scale-factor (max 1 (/ length (/ 8000000 (buffer-size)))))
1258 ;;;!! (newpos (* (/ (* (/ (buffer-size) scale-factor)
1259 ;;;!! position)
1260 ;;;!! length)
1261 ;;;!! scale-factor)))
1262 ;;;!! (goto-char newpos)
1263 ;;;!! (recenter '(4)))))
1264 ;;;!!
1265 ;;;!! (defun mouse-scroll-left (click)
1266 ;;;!! (interactive "@e")
1267 ;;;!! (scroll-left (1+ (car (mouse-coords click)))))
1268 ;;;!!
1269 ;;;!! (defun mouse-scroll-right (click)
1270 ;;;!! (interactive "@e")
1271 ;;;!! (scroll-right (1+ (car (mouse-coords click)))))
1272 ;;;!!
1273 ;;;!! (defun mouse-scroll-left-full ()
1274 ;;;!! (interactive "@")
1275 ;;;!! (scroll-left nil))
1276 ;;;!!
1277 ;;;!! (defun mouse-scroll-right-full ()
1278 ;;;!! (interactive "@")
1279 ;;;!! (scroll-right nil))
1280 ;;;!!
1281 ;;;!! (defun mouse-scroll-move-cursor-horizontally (click)
1282 ;;;!! (interactive "@e")
1283 ;;;!! (move-to-column (1+ (car (mouse-coords click)))))
1284 ;;;!!
1285 ;;;!! (defun mouse-scroll-absolute-horizontally (event)
1286 ;;;!! (interactive "@e")
1287 ;;;!! (let* ((pos (car event))
1288 ;;;!! (position (car pos))
1289 ;;;!! (length (car (cdr pos))))
1290 ;;;!! (set-window-hscroll (selected-window) 33)))
1291 ;;;!!
1292 ;;;!! (global-set-key [scroll-bar mouse-1] 'mouse-scroll-up)
1293 ;;;!! (global-set-key [scroll-bar mouse-2] 'mouse-scroll-absolute)
1294 ;;;!! (global-set-key [scroll-bar mouse-3] 'mouse-scroll-down)
1295 ;;;!!
1296 ;;;!! (global-set-key [vertical-slider mouse-1] 'mouse-scroll-move-cursor)
1297 ;;;!! (global-set-key [vertical-slider mouse-2] 'mouse-scroll-move-cursor)
1298 ;;;!! (global-set-key [vertical-slider mouse-3] 'mouse-scroll-move-cursor)
1299 ;;;!!
1300 ;;;!! (global-set-key [thumbup mouse-1] 'mouse-scroll-up-full)
1301 ;;;!! (global-set-key [thumbup mouse-2] 'mouse-scroll-up-full)
1302 ;;;!! (global-set-key [thumbup mouse-3] 'mouse-scroll-up-full)
1303 ;;;!!
1304 ;;;!! (global-set-key [thumbdown mouse-1] 'mouse-scroll-down-full)
1305 ;;;!! (global-set-key [thumbdown mouse-2] 'mouse-scroll-down-full)
1306 ;;;!! (global-set-key [thumbdown mouse-3] 'mouse-scroll-down-full)
1307 ;;;!!
1308 ;;;!! (global-set-key [horizontal-scroll-bar mouse-1] 'mouse-scroll-left)
1309 ;;;!! (global-set-key [horizontal-scroll-bar mouse-2]
1310 ;;;!! 'mouse-scroll-absolute-horizontally)
1311 ;;;!! (global-set-key [horizontal-scroll-bar mouse-3] 'mouse-scroll-right)
1312 ;;;!!
1313 ;;;!! (global-set-key [horizontal-slider mouse-1]
1314 ;;;!! 'mouse-scroll-move-cursor-horizontally)
1315 ;;;!! (global-set-key [horizontal-slider mouse-2]
1316 ;;;!! 'mouse-scroll-move-cursor-horizontally)
1317 ;;;!! (global-set-key [horizontal-slider mouse-3]
1318 ;;;!! 'mouse-scroll-move-cursor-horizontally)
1319 ;;;!!
1320 ;;;!! (global-set-key [thumbleft mouse-1] 'mouse-scroll-left-full)
1321 ;;;!! (global-set-key [thumbleft mouse-2] 'mouse-scroll-left-full)
1322 ;;;!! (global-set-key [thumbleft mouse-3] 'mouse-scroll-left-full)
1323 ;;;!!
1324 ;;;!! (global-set-key [thumbright mouse-1] 'mouse-scroll-right-full)
1325 ;;;!! (global-set-key [thumbright mouse-2] 'mouse-scroll-right-full)
1326 ;;;!! (global-set-key [thumbright mouse-3] 'mouse-scroll-right-full)
1327 ;;;!!
1328 ;;;!! (global-set-key [horizontal-scroll-bar S-mouse-2]
1329 ;;;!! 'mouse-split-window-horizontally)
1330 ;;;!! (global-set-key [mode-line S-mouse-2]
1331 ;;;!! 'mouse-split-window-horizontally)
1332 ;;;!! (global-set-key [vertical-scroll-bar S-mouse-2]
1333 ;;;!! 'mouse-split-window)
1334 \f
1335 ;;;!! ;;;;
1336 ;;;!! ;;;; Here are experimental things being tested. Mouse events
1337 ;;;!! ;;;; are of the form:
1338 ;;;!! ;;;; ((x y) window screen-part key-sequence timestamp)
1339 ;;;!! ;;
1340 ;;;!! ;;;;
1341 ;;;!! ;;;; Dynamically track mouse coordinates
1342 ;;;!! ;;;;
1343 ;;;!! ;;
1344 ;;;!! ;;(defun track-mouse (event)
1345 ;;;!! ;; "Track the coordinates, absolute and relative, of the mouse."
1346 ;;;!! ;; (interactive "@e")
1347 ;;;!! ;; (while mouse-grabbed
1348 ;;;!! ;; (let* ((pos (read-mouse-position (selected-screen)))
1349 ;;;!! ;; (abs-x (car pos))
1350 ;;;!! ;; (abs-y (cdr pos))
1351 ;;;!! ;; (relative-coordinate (coordinates-in-window-p
1352 ;;;!! ;; (list (car pos) (cdr pos))
1353 ;;;!! ;; (selected-window))))
1354 ;;;!! ;; (if (consp relative-coordinate)
1355 ;;;!! ;; (message "mouse: [%d %d], (%d %d)" abs-x abs-y
1356 ;;;!! ;; (car relative-coordinate)
1357 ;;;!! ;; (car (cdr relative-coordinate)))
1358 ;;;!! ;; (message "mouse: [%d %d]" abs-x abs-y)))))
1359 ;;;!!
1360 ;;;!! ;;
1361 ;;;!! ;; Dynamically put a box around the line indicated by point
1362 ;;;!! ;;
1363 ;;;!! ;;
1364 ;;;!! ;;(require 'backquote)
1365 ;;;!! ;;
1366 ;;;!! ;;(defun mouse-select-buffer-line (event)
1367 ;;;!! ;; (interactive "@e")
1368 ;;;!! ;; (let ((relative-coordinate
1369 ;;;!! ;; (coordinates-in-window-p (car event) (selected-window)))
1370 ;;;!! ;; (abs-y (car (cdr (car event)))))
1371 ;;;!! ;; (if (consp relative-coordinate)
1372 ;;;!! ;; (progn
1373 ;;;!! ;; (save-excursion
1374 ;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
1375 ;;;!! ;; (x-draw-rectangle
1376 ;;;!! ;; (selected-screen)
1377 ;;;!! ;; abs-y 0
1378 ;;;!! ;; (save-excursion
1379 ;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
1380 ;;;!! ;; (end-of-line)
1381 ;;;!! ;; (push-mark nil t)
1382 ;;;!! ;; (beginning-of-line)
1383 ;;;!! ;; (- (region-end) (region-beginning))) 1))
1384 ;;;!! ;; (sit-for 1)
1385 ;;;!! ;; (x-erase-rectangle (selected-screen))))))
1386 ;;;!! ;;
1387 ;;;!! ;;(defvar last-line-drawn nil)
1388 ;;;!! ;;(defvar begin-delim "[^ \t]")
1389 ;;;!! ;;(defvar end-delim "[^ \t]")
1390 ;;;!! ;;
1391 ;;;!! ;;(defun mouse-boxing (event)
1392 ;;;!! ;; (interactive "@e")
1393 ;;;!! ;; (save-excursion
1394 ;;;!! ;; (let ((screen (selected-screen)))
1395 ;;;!! ;; (while (= (x-mouse-events) 0)
1396 ;;;!! ;; (let* ((pos (read-mouse-position screen))
1397 ;;;!! ;; (abs-x (car pos))
1398 ;;;!! ;; (abs-y (cdr pos))
1399 ;;;!! ;; (relative-coordinate
1400 ;;;!! ;; (coordinates-in-window-p (` ((, abs-x) (, abs-y)))
1401 ;;;!! ;; (selected-window)))
1402 ;;;!! ;; (begin-reg nil)
1403 ;;;!! ;; (end-reg nil)
1404 ;;;!! ;; (end-column nil)
1405 ;;;!! ;; (begin-column nil))
1406 ;;;!! ;; (if (and (consp relative-coordinate)
1407 ;;;!! ;; (or (not last-line-drawn)
1408 ;;;!! ;; (not (= last-line-drawn abs-y))))
1409 ;;;!! ;; (progn
1410 ;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
1411 ;;;!! ;; (if (= (following-char) 10)
1412 ;;;!! ;; ()
1413 ;;;!! ;; (progn
1414 ;;;!! ;; (setq begin-reg (1- (re-search-forward end-delim)))
1415 ;;;!! ;; (setq begin-column (1- (current-column)))
1416 ;;;!! ;; (end-of-line)
1417 ;;;!! ;; (setq end-reg (1+ (re-search-backward begin-delim)))
1418 ;;;!! ;; (setq end-column (1+ (current-column)))
1419 ;;;!! ;; (message "%s" (buffer-substring begin-reg end-reg))
1420 ;;;!! ;; (x-draw-rectangle screen
1421 ;;;!! ;; (setq last-line-drawn abs-y)
1422 ;;;!! ;; begin-column
1423 ;;;!! ;; (- end-column begin-column) 1))))))))))
1424 ;;;!! ;;
1425 ;;;!! ;;(defun mouse-erase-box ()
1426 ;;;!! ;; (interactive)
1427 ;;;!! ;; (if last-line-drawn
1428 ;;;!! ;; (progn
1429 ;;;!! ;; (x-erase-rectangle (selected-screen))
1430 ;;;!! ;; (setq last-line-drawn nil))))
1431 ;;;!!
1432 ;;;!! ;;; (defun test-x-rectangle ()
1433 ;;;!! ;;; (use-local-mouse-map (setq rectangle-test-map (make-sparse-keymap)))
1434 ;;;!! ;;; (define-key rectangle-test-map mouse-motion-button-left 'mouse-boxing)
1435 ;;;!! ;;; (define-key rectangle-test-map mouse-button-left-up 'mouse-erase-box))
1436 ;;;!!
1437 ;;;!! ;;
1438 ;;;!! ;; Here is how to do double clicking in lisp. About to change.
1439 ;;;!! ;;
1440 ;;;!!
1441 ;;;!! (defvar double-start nil)
1442 ;;;!! (defconst double-click-interval 300
1443 ;;;!! "Max ticks between clicks")
1444 ;;;!!
1445 ;;;!! (defun double-down (event)
1446 ;;;!! (interactive "@e")
1447 ;;;!! (if double-start
1448 ;;;!! (let ((interval (- (nth 4 event) double-start)))
1449 ;;;!! (if (< interval double-click-interval)
1450 ;;;!! (progn
1451 ;;;!! (backward-up-list 1)
1452 ;;;!! ;; (message "Interval %d" interval)
1453 ;;;!! (sleep-for 1)))
1454 ;;;!! (setq double-start nil))
1455 ;;;!! (setq double-start (nth 4 event))))
1456 ;;;!!
1457 ;;;!! (defun double-up (event)
1458 ;;;!! (interactive "@e")
1459 ;;;!! (and double-start
1460 ;;;!! (> (- (nth 4 event ) double-start) double-click-interval)
1461 ;;;!! (setq double-start nil)))
1462 ;;;!!
1463 ;;;!! ;;; (defun x-test-doubleclick ()
1464 ;;;!! ;;; (use-local-mouse-map (setq doubleclick-test-map (make-sparse-keymap)))
1465 ;;;!! ;;; (define-key doubleclick-test-map mouse-button-left 'double-down)
1466 ;;;!! ;;; (define-key doubleclick-test-map mouse-button-left-up 'double-up))
1467 ;;;!!
1468 ;;;!! ;;
1469 ;;;!! ;; This scrolls while button is depressed. Use preferable in scroll bar.
1470 ;;;!! ;;
1471 ;;;!!
1472 ;;;!! (defvar scrolled-lines 0)
1473 ;;;!! (defconst scroll-speed 1)
1474 ;;;!!
1475 ;;;!! (defun incr-scroll-down (event)
1476 ;;;!! (interactive "@e")
1477 ;;;!! (setq scrolled-lines 0)
1478 ;;;!! (incremental-scroll scroll-speed))
1479 ;;;!!
1480 ;;;!! (defun incr-scroll-up (event)
1481 ;;;!! (interactive "@e")
1482 ;;;!! (setq scrolled-lines 0)
1483 ;;;!! (incremental-scroll (- scroll-speed)))
1484 ;;;!!
1485 ;;;!! (defun incremental-scroll (n)
1486 ;;;!! (while (= (x-mouse-events) 0)
1487 ;;;!! (setq scrolled-lines (1+ (* scroll-speed scrolled-lines)))
1488 ;;;!! (scroll-down n)
1489 ;;;!! (sit-for 300 t)))
1490 ;;;!!
1491 ;;;!! (defun incr-scroll-stop (event)
1492 ;;;!! (interactive "@e")
1493 ;;;!! (message "Scrolled %d lines" scrolled-lines)
1494 ;;;!! (setq scrolled-lines 0)
1495 ;;;!! (sleep-for 1))
1496 ;;;!!
1497 ;;;!! ;;; (defun x-testing-scroll ()
1498 ;;;!! ;;; (let ((scrolling-map (function mouse-vertical-scroll-bar-prefix)))
1499 ;;;!! ;;; (define-key scrolling-map mouse-button-left 'incr-scroll-down)
1500 ;;;!! ;;; (define-key scrolling-map mouse-button-right 'incr-scroll-up)
1501 ;;;!! ;;; (define-key scrolling-map mouse-button-left-up 'incr-scroll-stop)
1502 ;;;!! ;;; (define-key scrolling-map mouse-button-right-up 'incr-scroll-stop)))
1503 ;;;!!
1504 ;;;!! ;;
1505 ;;;!! ;; Some playthings suitable for picture mode? They need work.
1506 ;;;!! ;;
1507 ;;;!!
1508 ;;;!! (defun mouse-kill-rectangle (event)
1509 ;;;!! "Kill the rectangle between point and the mouse cursor."
1510 ;;;!! (interactive "@e")
1511 ;;;!! (let ((point-save (point)))
1512 ;;;!! (save-excursion
1513 ;;;!! (mouse-set-point event)
1514 ;;;!! (push-mark nil t)
1515 ;;;!! (if (> point-save (point))
1516 ;;;!! (kill-rectangle (point) point-save)
1517 ;;;!! (kill-rectangle point-save (point))))))
1518 ;;;!!
1519 ;;;!! (defun mouse-open-rectangle (event)
1520 ;;;!! "Kill the rectangle between point and the mouse cursor."
1521 ;;;!! (interactive "@e")
1522 ;;;!! (let ((point-save (point)))
1523 ;;;!! (save-excursion
1524 ;;;!! (mouse-set-point event)
1525 ;;;!! (push-mark nil t)
1526 ;;;!! (if (> point-save (point))
1527 ;;;!! (open-rectangle (point) point-save)
1528 ;;;!! (open-rectangle point-save (point))))))
1529 ;;;!!
1530 ;;;!! ;; Must be a better way to do this.
1531 ;;;!!
1532 ;;;!! (defun mouse-multiple-insert (n char)
1533 ;;;!! (while (> n 0)
1534 ;;;!! (insert char)
1535 ;;;!! (setq n (1- n))))
1536 ;;;!!
1537 ;;;!! ;; What this could do is not finalize until button was released.
1538 ;;;!!
1539 ;;;!! (defun mouse-move-text (event)
1540 ;;;!! "Move text from point to cursor position, inserting spaces."
1541 ;;;!! (interactive "@e")
1542 ;;;!! (let* ((relative-coordinate
1543 ;;;!! (coordinates-in-window-p (car event) (selected-window))))
1544 ;;;!! (if (consp relative-coordinate)
1545 ;;;!! (cond ((> (current-column) (car relative-coordinate))
1546 ;;;!! (delete-char
1547 ;;;!! (- (car relative-coordinate) (current-column))))
1548 ;;;!! ((< (current-column) (car relative-coordinate))
1549 ;;;!! (mouse-multiple-insert
1550 ;;;!! (- (car relative-coordinate) (current-column)) " "))
1551 ;;;!! ((= (current-column) (car relative-coordinate)) (ding))))))
1552 \f
1553 ;; Choose a completion with the mouse.
1554
1555 (defun mouse-choose-completion (event)
1556 "Click on an alternative in the `*Completions*' buffer to choose it."
1557 (interactive "e")
1558 ;; Give temporary modes such as isearch a chance to turn off.
1559 (run-hooks 'mouse-leave-buffer-hook)
1560 (let ((buffer (window-buffer))
1561 choice
1562 base-size)
1563 (save-excursion
1564 (set-buffer (window-buffer (posn-window (event-start event))))
1565 (if completion-reference-buffer
1566 (setq buffer completion-reference-buffer))
1567 (setq base-size completion-base-size)
1568 (save-excursion
1569 (goto-char (posn-point (event-start event)))
1570 (let (beg end)
1571 (if (and (not (eobp)) (get-text-property (point) 'mouse-face))
1572 (setq end (point) beg (1+ (point))))
1573 (if (null beg)
1574 (error "No completion here"))
1575 (setq beg (previous-single-property-change beg 'mouse-face))
1576 (setq end (or (next-single-property-change end 'mouse-face)
1577 (point-max)))
1578 (setq choice (buffer-substring beg end)))))
1579 (let ((owindow (selected-window)))
1580 (select-window (posn-window (event-start event)))
1581 (if (and (one-window-p t 'selected-frame)
1582 (window-dedicated-p (selected-window)))
1583 ;; This is a special buffer's frame
1584 (iconify-frame (selected-frame))
1585 (or (window-dedicated-p (selected-window))
1586 (bury-buffer)))
1587 (select-window owindow))
1588 (choose-completion-string choice buffer base-size)))
1589 \f
1590 ;; Font selection.
1591
1592 (defun font-menu-add-default ()
1593 (let* ((default (cdr (assq 'font (frame-parameters (selected-frame)))))
1594 (font-alist x-fixed-font-alist)
1595 (elt (or (assoc "Misc" font-alist) (nth 1 font-alist))))
1596 (if (assoc "Default" elt)
1597 (delete (assoc "Default" elt) elt))
1598 (setcdr elt
1599 (cons (list "Default"
1600 (cdr (assq 'font (frame-parameters (selected-frame)))))
1601 (cdr elt)))))
1602
1603 (defvar x-fixed-font-alist
1604 '("Font menu"
1605 ("Misc"
1606 ;; For these, we specify the pixel height and width.
1607 ("fixed" "fixed")
1608 ("6x10" "-misc-fixed-medium-r-normal--10-*-*-*-c-60-iso8859-1" "6x10")
1609 ("6x12"
1610 "-misc-fixed-medium-r-semicondensed--12-*-*-*-c-60-iso8859-1" "6x12")
1611 ("6x13"
1612 "-misc-fixed-medium-r-semicondensed--13-*-*-*-c-60-iso8859-1" "6x13")
1613 ("7x13" "-misc-fixed-medium-r-normal--13-*-*-*-c-70-iso8859-1" "7x13")
1614 ("7x14" "-misc-fixed-medium-r-normal--14-*-*-*-c-70-iso8859-1" "7x14")
1615 ("8x13" "-misc-fixed-medium-r-normal--13-*-*-*-c-80-iso8859-1" "8x13")
1616 ("9x15" "-misc-fixed-medium-r-normal--15-*-*-*-c-90-iso8859-1" "9x15")
1617 ("10x20" "-misc-fixed-medium-r-normal--20-*-*-*-c-100-iso8859-1" "10x20")
1618 ("11x18" "-misc-fixed-medium-r-normal--18-*-*-*-c-110-iso8859-1" "11x18")
1619 ("12x24" "-misc-fixed-medium-r-normal--24-*-*-*-c-120-iso8859-1" "12x24")
1620 ("")
1621 ("clean 5x8"
1622 "-schumacher-clean-medium-r-normal--8-*-*-*-c-50-iso8859-1")
1623 ("clean 6x8"
1624 "-schumacher-clean-medium-r-normal--8-*-*-*-c-60-iso8859-1")
1625 ("clean 8x8"
1626 "-schumacher-clean-medium-r-normal--8-*-*-*-c-80-iso8859-1")
1627 ("clean 8x10"
1628 "-schumacher-clean-medium-r-normal--10-*-*-*-c-80-iso8859-1")
1629 ("clean 8x14"
1630 "-schumacher-clean-medium-r-normal--14-*-*-*-c-80-iso8859-1")
1631 ("clean 8x16"
1632 "-schumacher-clean-medium-r-normal--16-*-*-*-c-80-iso8859-1")
1633 ("")
1634 ("sony 8x16" "-sony-fixed-medium-r-normal--16-*-*-*-c-80-iso8859-1"))
1635 ;;; We don't seem to have these; who knows what they are.
1636 ;;; ("fg-18" "fg-18")
1637 ;;; ("fg-25" "fg-25")
1638 ;;; ("lucidasanstypewriter-12" "lucidasanstypewriter-12")
1639 ;;; ("lucidasanstypewriter-bold-14" "lucidasanstypewriter-bold-14")
1640 ;;; ("lucidasanstypewriter-bold-24" "lucidasanstypewriter-bold-24")
1641 ;;; ("lucidatypewriter-bold-r-24" "-b&h-lucidatypewriter-bold-r-normal-sans-24-240-75-75-m-140-iso8859-1")
1642 ;;; ("fixed-medium-20" "-misc-fixed-medium-*-*-*-20-*-*-*-*-*-*-*")
1643 ("Courier"
1644 ;; For these, we specify the point height.
1645 ("8" "-adobe-courier-medium-r-normal--*-80-*-*-m-*-iso8859-1")
1646 ("10" "-adobe-courier-medium-r-normal--*-100-*-*-m-*-iso8859-1")
1647 ("12" "-adobe-courier-medium-r-normal--*-120-*-*-m-*-iso8859-1")
1648 ("14" "-adobe-courier-medium-r-normal--*-140-*-*-m-*-iso8859-1")
1649 ("18" "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1")
1650 ("24" "-adobe-courier-medium-r-normal--*-240-*-*-m-*-iso8859-1")
1651 ("8 bold" "-adobe-courier-bold-r-normal--*-80-*-*-m-*-iso8859-1")
1652 ("10 bold" "-adobe-courier-bold-r-normal--*-100-*-*-m-*-iso8859-1")
1653 ("12 bold" "-adobe-courier-bold-r-normal--*-120-*-*-m-*-iso8859-1")
1654 ("14 bold" "-adobe-courier-bold-r-normal--*-140-*-*-m-*-iso8859-1")
1655 ("18 bold" "-adobe-courier-bold-r-normal--*-180-*-*-m-*-iso8859-1")
1656 ("24 bold" "-adobe-courier-bold-r-normal--*-240-*-*-m-*-iso8859-1")
1657 ("8 slant" "-adobe-courier-medium-o-normal--*-80-*-*-m-*-iso8859-1")
1658 ("10 slant" "-adobe-courier-medium-o-normal--*-100-*-*-m-*-iso8859-1")
1659 ("12 slant" "-adobe-courier-medium-o-normal--*-120-*-*-m-*-iso8859-1")
1660 ("14 slant" "-adobe-courier-medium-o-normal--*-140-*-*-m-*-iso8859-1")
1661 ("18 slant" "-adobe-courier-medium-o-normal--*-180-*-*-m-*-iso8859-1")
1662 ("24 slant" "-adobe-courier-medium-o-normal--*-240-*-*-m-*-iso8859-1")
1663 ("8 bold slant" "-adobe-courier-bold-o-normal--*-80-*-*-m-*-iso8859-1")
1664 ("10 bold slant" "-adobe-courier-bold-o-normal--*-100-*-*-m-*-iso8859-1")
1665 ("12 bold slant" "-adobe-courier-bold-o-normal--*-120-*-*-m-*-iso8859-1")
1666 ("14 bold slant" "-adobe-courier-bold-o-normal--*-140-*-*-m-*-iso8859-1")
1667 ("18 bold slant" "-adobe-courier-bold-o-normal--*-180-*-*-m-*-iso8859-1")
1668 ("24 bold slant" "-adobe-courier-bold-o-normal--*-240-*-*-m-*-iso8859-1"))
1669 )
1670 "X fonts suitable for use in Emacs.")
1671
1672 (defun mouse-set-font (&rest fonts)
1673 "Select an emacs font from a list of known good fonts"
1674 (interactive
1675 (x-popup-menu last-nonmenu-event x-fixed-font-alist))
1676 (if fonts
1677 (let (font)
1678 (while fonts
1679 (condition-case nil
1680 (progn
1681 (set-default-font (car fonts))
1682 (setq font (car fonts))
1683 (setq fonts nil))
1684 (error
1685 (setq fonts (cdr fonts)))))
1686 (if (null font)
1687 (error "Font not found")))))
1688 \f
1689 ;;; Bindings for mouse commands.
1690
1691 (define-key global-map [down-mouse-1] 'mouse-drag-region)
1692 (global-set-key [mouse-1] 'mouse-set-point)
1693 (global-set-key [drag-mouse-1] 'mouse-set-region)
1694
1695 ;; These are tested for in mouse-drag-region.
1696 (global-set-key [double-mouse-1] 'mouse-set-point)
1697 (global-set-key [triple-mouse-1] 'mouse-set-point)
1698
1699 (global-set-key [mouse-2] 'mouse-yank-at-click)
1700 (global-set-key [mouse-3] 'mouse-save-then-kill)
1701
1702 ;; By binding these to down-going events, we let the user use the up-going
1703 ;; event to make the selection, saving a click.
1704 (global-set-key [C-down-mouse-1] 'mouse-buffer-menu)
1705 (if (not (eq system-type 'ms-dos))
1706 (global-set-key [S-down-mouse-1] 'mouse-set-font))
1707 ;; C-down-mouse-2 is bound in facemenu.el.
1708 (global-set-key [C-down-mouse-3] 'mouse-major-mode-menu)
1709
1710
1711 ;; Replaced with dragging mouse-1
1712 ;; (global-set-key [S-mouse-1] 'mouse-set-mark)
1713
1714 (global-set-key [mode-line mouse-1] 'mouse-select-window)
1715 (global-set-key [mode-line drag-mouse-1] 'mouse-select-window)
1716 (global-set-key [mode-line down-mouse-1] 'mouse-drag-mode-line)
1717 (global-set-key [mode-line mouse-2] 'mouse-delete-other-windows)
1718 (global-set-key [mode-line mouse-3] 'mouse-delete-window)
1719 (global-set-key [mode-line C-mouse-2] 'mouse-split-window-horizontally)
1720 (global-set-key [vertical-scroll-bar C-mouse-2] 'mouse-split-window-vertically)
1721 (global-set-key [vertical-line C-mouse-2] 'mouse-split-window-vertically)
1722 (global-set-key [vertical-line down-mouse-1] 'mouse-drag-vertical-line)
1723 (global-set-key [vertical-line mouse-1] 'mouse-select-window)
1724
1725 (provide 'mouse)
1726
1727 ;;; mouse.el ends here