(etc): Delete *.orig and *.rej.
[emacs.git] / lisp / mouse.el
blob98711f4e767deabb2a4ced3ec41f47b91d6e8808
1 ;;; mouse.el --- window system-independent mouse support
3 ;; Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
5 ;; Maintainer: FSF
6 ;; Keywords: hardware
8 ;; This file is part of GNU Emacs.
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.
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.
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.
24 ;;; Commentary:
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.
30 ;; The code is rather X-dependent.
32 ;;; Code:
34 ;;; Utility functions.
36 ;;; Indent track-mouse like progn.
37 (put 'track-mouse 'lisp-indent-function 0)
39 (defvar mouse-yank-at-point nil
40 "*If non-nil, mouse yank commands yank at point instead of at click.")
42 ;; Provide a mode-specific menu on a mouse button.
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)))))
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))))
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))))
104 ;; Commands that operate on windows.
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))
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))))
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)))
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)))
145 (defun mouse-delete-other-windows ()
146 "Delete all window except the one you click on."
147 (interactive "@")
148 (delete-other-windows))
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))))))
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))))))
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)
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)
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.
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)))))))))
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)
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.
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)))))))))
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)))))
379 (defvar mouse-last-region-beg nil)
380 (defvar mouse-last-region-end nil)
381 (defvar mouse-last-region-tick nil)
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))))
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)))
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)))
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.")
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.")
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))))
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)
479 (defvar mouse-selection-click-count 0)
481 (defvar mouse-selection-click-count-buffer nil)
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)
525 (setq end (event-end event)
526 end-point (posn-point end))
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))))
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)))))
586 ;; Commands to handle xterm-style multiple clicks.
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)))
605 (while (and (not (eobp)) (= (following-char) char))
606 (forward-char 1))))))
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))))))
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))))
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))))
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))))
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)))))
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))
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))
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.
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)
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))
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.
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)))))))
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)
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)
872 (defvar mouse-secondary-click-count 0)
874 ;; A marker which records the specified first end for a secondary selection.
875 ;; May be nil.
876 (defvar mouse-secondary-start nil)
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)))))))
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))
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))))
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)))
958 (if (eq (car-safe event) 'switch-frame)
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))))))
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)))))))))
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)))))))))
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)))
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.
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))
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.
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)))))))
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 ((menu
1162 (list "Buffer Menu"
1163 (cons "Select Buffer"
1164 (let ((tail (buffer-list))
1165 (maxbuf 0)
1166 head)
1167 (while tail
1168 (or (eq ?\ (aref (buffer-name (car tail)) 0))
1169 (setq maxbuf
1170 (max maxbuf
1171 (length (buffer-name (car tail))))))
1172 (setq tail (cdr tail)))
1173 (setq tail (buffer-list))
1174 (while tail
1175 (let ((elt (car tail)))
1176 (if (not (string-match "^ "
1177 (buffer-name elt)))
1178 (setq head
1179 (cons
1180 (cons
1181 (format
1182 (format "%%%ds %%s%%s %%s" maxbuf)
1183 (buffer-name elt)
1184 (if (buffer-modified-p elt) "*" " ")
1185 (save-excursion
1186 (set-buffer elt)
1187 (if buffer-read-only "%" " "))
1188 (or (buffer-file-name elt)
1189 (save-excursion
1190 (set-buffer elt)
1191 (if list-buffers-directory
1192 (expand-file-name
1193 list-buffers-directory)))
1194 ""))
1195 elt)
1196 head))))
1197 (setq tail (cdr tail)))
1198 (reverse head))))))
1199 (let ((buf (x-popup-menu event menu))
1200 (window (posn-window (event-start event))))
1201 (if buf
1202 (progn
1203 (or (framep window) (select-window window))
1204 (switch-to-buffer buf))))))
1206 ;;; These need to be rewritten for the new scroll bar implementation.
1208 ;;;!! ;; Commands for the scroll bar.
1209 ;;;!!
1210 ;;;!! (defun mouse-scroll-down (click)
1211 ;;;!! (interactive "@e")
1212 ;;;!! (scroll-down (1+ (cdr (mouse-coords click)))))
1213 ;;;!!
1214 ;;;!! (defun mouse-scroll-up (click)
1215 ;;;!! (interactive "@e")
1216 ;;;!! (scroll-up (1+ (cdr (mouse-coords click)))))
1217 ;;;!!
1218 ;;;!! (defun mouse-scroll-down-full ()
1219 ;;;!! (interactive "@")
1220 ;;;!! (scroll-down nil))
1221 ;;;!!
1222 ;;;!! (defun mouse-scroll-up-full ()
1223 ;;;!! (interactive "@")
1224 ;;;!! (scroll-up nil))
1225 ;;;!!
1226 ;;;!! (defun mouse-scroll-move-cursor (click)
1227 ;;;!! (interactive "@e")
1228 ;;;!! (move-to-window-line (1+ (cdr (mouse-coords click)))))
1229 ;;;!!
1230 ;;;!! (defun mouse-scroll-absolute (event)
1231 ;;;!! (interactive "@e")
1232 ;;;!! (let* ((pos (car event))
1233 ;;;!! (position (car pos))
1234 ;;;!! (length (car (cdr pos))))
1235 ;;;!! (if (<= length 0) (setq length 1))
1236 ;;;!! (let* ((scale-factor (max 1 (/ length (/ 8000000 (buffer-size)))))
1237 ;;;!! (newpos (* (/ (* (/ (buffer-size) scale-factor)
1238 ;;;!! position)
1239 ;;;!! length)
1240 ;;;!! scale-factor)))
1241 ;;;!! (goto-char newpos)
1242 ;;;!! (recenter '(4)))))
1243 ;;;!!
1244 ;;;!! (defun mouse-scroll-left (click)
1245 ;;;!! (interactive "@e")
1246 ;;;!! (scroll-left (1+ (car (mouse-coords click)))))
1247 ;;;!!
1248 ;;;!! (defun mouse-scroll-right (click)
1249 ;;;!! (interactive "@e")
1250 ;;;!! (scroll-right (1+ (car (mouse-coords click)))))
1251 ;;;!!
1252 ;;;!! (defun mouse-scroll-left-full ()
1253 ;;;!! (interactive "@")
1254 ;;;!! (scroll-left nil))
1255 ;;;!!
1256 ;;;!! (defun mouse-scroll-right-full ()
1257 ;;;!! (interactive "@")
1258 ;;;!! (scroll-right nil))
1259 ;;;!!
1260 ;;;!! (defun mouse-scroll-move-cursor-horizontally (click)
1261 ;;;!! (interactive "@e")
1262 ;;;!! (move-to-column (1+ (car (mouse-coords click)))))
1263 ;;;!!
1264 ;;;!! (defun mouse-scroll-absolute-horizontally (event)
1265 ;;;!! (interactive "@e")
1266 ;;;!! (let* ((pos (car event))
1267 ;;;!! (position (car pos))
1268 ;;;!! (length (car (cdr pos))))
1269 ;;;!! (set-window-hscroll (selected-window) 33)))
1270 ;;;!!
1271 ;;;!! (global-set-key [scroll-bar mouse-1] 'mouse-scroll-up)
1272 ;;;!! (global-set-key [scroll-bar mouse-2] 'mouse-scroll-absolute)
1273 ;;;!! (global-set-key [scroll-bar mouse-3] 'mouse-scroll-down)
1274 ;;;!!
1275 ;;;!! (global-set-key [vertical-slider mouse-1] 'mouse-scroll-move-cursor)
1276 ;;;!! (global-set-key [vertical-slider mouse-2] 'mouse-scroll-move-cursor)
1277 ;;;!! (global-set-key [vertical-slider mouse-3] 'mouse-scroll-move-cursor)
1278 ;;;!!
1279 ;;;!! (global-set-key [thumbup mouse-1] 'mouse-scroll-up-full)
1280 ;;;!! (global-set-key [thumbup mouse-2] 'mouse-scroll-up-full)
1281 ;;;!! (global-set-key [thumbup mouse-3] 'mouse-scroll-up-full)
1282 ;;;!!
1283 ;;;!! (global-set-key [thumbdown mouse-1] 'mouse-scroll-down-full)
1284 ;;;!! (global-set-key [thumbdown mouse-2] 'mouse-scroll-down-full)
1285 ;;;!! (global-set-key [thumbdown mouse-3] 'mouse-scroll-down-full)
1286 ;;;!!
1287 ;;;!! (global-set-key [horizontal-scroll-bar mouse-1] 'mouse-scroll-left)
1288 ;;;!! (global-set-key [horizontal-scroll-bar mouse-2]
1289 ;;;!! 'mouse-scroll-absolute-horizontally)
1290 ;;;!! (global-set-key [horizontal-scroll-bar mouse-3] 'mouse-scroll-right)
1291 ;;;!!
1292 ;;;!! (global-set-key [horizontal-slider mouse-1]
1293 ;;;!! 'mouse-scroll-move-cursor-horizontally)
1294 ;;;!! (global-set-key [horizontal-slider mouse-2]
1295 ;;;!! 'mouse-scroll-move-cursor-horizontally)
1296 ;;;!! (global-set-key [horizontal-slider mouse-3]
1297 ;;;!! 'mouse-scroll-move-cursor-horizontally)
1298 ;;;!!
1299 ;;;!! (global-set-key [thumbleft mouse-1] 'mouse-scroll-left-full)
1300 ;;;!! (global-set-key [thumbleft mouse-2] 'mouse-scroll-left-full)
1301 ;;;!! (global-set-key [thumbleft mouse-3] 'mouse-scroll-left-full)
1302 ;;;!!
1303 ;;;!! (global-set-key [thumbright mouse-1] 'mouse-scroll-right-full)
1304 ;;;!! (global-set-key [thumbright mouse-2] 'mouse-scroll-right-full)
1305 ;;;!! (global-set-key [thumbright mouse-3] 'mouse-scroll-right-full)
1306 ;;;!!
1307 ;;;!! (global-set-key [horizontal-scroll-bar S-mouse-2]
1308 ;;;!! 'mouse-split-window-horizontally)
1309 ;;;!! (global-set-key [mode-line S-mouse-2]
1310 ;;;!! 'mouse-split-window-horizontally)
1311 ;;;!! (global-set-key [vertical-scroll-bar S-mouse-2]
1312 ;;;!! 'mouse-split-window)
1314 ;;;!! ;;;;
1315 ;;;!! ;;;; Here are experimental things being tested. Mouse events
1316 ;;;!! ;;;; are of the form:
1317 ;;;!! ;;;; ((x y) window screen-part key-sequence timestamp)
1318 ;;;!! ;;
1319 ;;;!! ;;;;
1320 ;;;!! ;;;; Dynamically track mouse coordinates
1321 ;;;!! ;;;;
1322 ;;;!! ;;
1323 ;;;!! ;;(defun track-mouse (event)
1324 ;;;!! ;; "Track the coordinates, absolute and relative, of the mouse."
1325 ;;;!! ;; (interactive "@e")
1326 ;;;!! ;; (while mouse-grabbed
1327 ;;;!! ;; (let* ((pos (read-mouse-position (selected-screen)))
1328 ;;;!! ;; (abs-x (car pos))
1329 ;;;!! ;; (abs-y (cdr pos))
1330 ;;;!! ;; (relative-coordinate (coordinates-in-window-p
1331 ;;;!! ;; (list (car pos) (cdr pos))
1332 ;;;!! ;; (selected-window))))
1333 ;;;!! ;; (if (consp relative-coordinate)
1334 ;;;!! ;; (message "mouse: [%d %d], (%d %d)" abs-x abs-y
1335 ;;;!! ;; (car relative-coordinate)
1336 ;;;!! ;; (car (cdr relative-coordinate)))
1337 ;;;!! ;; (message "mouse: [%d %d]" abs-x abs-y)))))
1338 ;;;!!
1339 ;;;!! ;;
1340 ;;;!! ;; Dynamically put a box around the line indicated by point
1341 ;;;!! ;;
1342 ;;;!! ;;
1343 ;;;!! ;;(require 'backquote)
1344 ;;;!! ;;
1345 ;;;!! ;;(defun mouse-select-buffer-line (event)
1346 ;;;!! ;; (interactive "@e")
1347 ;;;!! ;; (let ((relative-coordinate
1348 ;;;!! ;; (coordinates-in-window-p (car event) (selected-window)))
1349 ;;;!! ;; (abs-y (car (cdr (car event)))))
1350 ;;;!! ;; (if (consp relative-coordinate)
1351 ;;;!! ;; (progn
1352 ;;;!! ;; (save-excursion
1353 ;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
1354 ;;;!! ;; (x-draw-rectangle
1355 ;;;!! ;; (selected-screen)
1356 ;;;!! ;; abs-y 0
1357 ;;;!! ;; (save-excursion
1358 ;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
1359 ;;;!! ;; (end-of-line)
1360 ;;;!! ;; (push-mark nil t)
1361 ;;;!! ;; (beginning-of-line)
1362 ;;;!! ;; (- (region-end) (region-beginning))) 1))
1363 ;;;!! ;; (sit-for 1)
1364 ;;;!! ;; (x-erase-rectangle (selected-screen))))))
1365 ;;;!! ;;
1366 ;;;!! ;;(defvar last-line-drawn nil)
1367 ;;;!! ;;(defvar begin-delim "[^ \t]")
1368 ;;;!! ;;(defvar end-delim "[^ \t]")
1369 ;;;!! ;;
1370 ;;;!! ;;(defun mouse-boxing (event)
1371 ;;;!! ;; (interactive "@e")
1372 ;;;!! ;; (save-excursion
1373 ;;;!! ;; (let ((screen (selected-screen)))
1374 ;;;!! ;; (while (= (x-mouse-events) 0)
1375 ;;;!! ;; (let* ((pos (read-mouse-position screen))
1376 ;;;!! ;; (abs-x (car pos))
1377 ;;;!! ;; (abs-y (cdr pos))
1378 ;;;!! ;; (relative-coordinate
1379 ;;;!! ;; (coordinates-in-window-p (` ((, abs-x) (, abs-y)))
1380 ;;;!! ;; (selected-window)))
1381 ;;;!! ;; (begin-reg nil)
1382 ;;;!! ;; (end-reg nil)
1383 ;;;!! ;; (end-column nil)
1384 ;;;!! ;; (begin-column nil))
1385 ;;;!! ;; (if (and (consp relative-coordinate)
1386 ;;;!! ;; (or (not last-line-drawn)
1387 ;;;!! ;; (not (= last-line-drawn abs-y))))
1388 ;;;!! ;; (progn
1389 ;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
1390 ;;;!! ;; (if (= (following-char) 10)
1391 ;;;!! ;; ()
1392 ;;;!! ;; (progn
1393 ;;;!! ;; (setq begin-reg (1- (re-search-forward end-delim)))
1394 ;;;!! ;; (setq begin-column (1- (current-column)))
1395 ;;;!! ;; (end-of-line)
1396 ;;;!! ;; (setq end-reg (1+ (re-search-backward begin-delim)))
1397 ;;;!! ;; (setq end-column (1+ (current-column)))
1398 ;;;!! ;; (message "%s" (buffer-substring begin-reg end-reg))
1399 ;;;!! ;; (x-draw-rectangle screen
1400 ;;;!! ;; (setq last-line-drawn abs-y)
1401 ;;;!! ;; begin-column
1402 ;;;!! ;; (- end-column begin-column) 1))))))))))
1403 ;;;!! ;;
1404 ;;;!! ;;(defun mouse-erase-box ()
1405 ;;;!! ;; (interactive)
1406 ;;;!! ;; (if last-line-drawn
1407 ;;;!! ;; (progn
1408 ;;;!! ;; (x-erase-rectangle (selected-screen))
1409 ;;;!! ;; (setq last-line-drawn nil))))
1410 ;;;!!
1411 ;;;!! ;;; (defun test-x-rectangle ()
1412 ;;;!! ;;; (use-local-mouse-map (setq rectangle-test-map (make-sparse-keymap)))
1413 ;;;!! ;;; (define-key rectangle-test-map mouse-motion-button-left 'mouse-boxing)
1414 ;;;!! ;;; (define-key rectangle-test-map mouse-button-left-up 'mouse-erase-box))
1415 ;;;!!
1416 ;;;!! ;;
1417 ;;;!! ;; Here is how to do double clicking in lisp. About to change.
1418 ;;;!! ;;
1419 ;;;!!
1420 ;;;!! (defvar double-start nil)
1421 ;;;!! (defconst double-click-interval 300
1422 ;;;!! "Max ticks between clicks")
1423 ;;;!!
1424 ;;;!! (defun double-down (event)
1425 ;;;!! (interactive "@e")
1426 ;;;!! (if double-start
1427 ;;;!! (let ((interval (- (nth 4 event) double-start)))
1428 ;;;!! (if (< interval double-click-interval)
1429 ;;;!! (progn
1430 ;;;!! (backward-up-list 1)
1431 ;;;!! ;; (message "Interval %d" interval)
1432 ;;;!! (sleep-for 1)))
1433 ;;;!! (setq double-start nil))
1434 ;;;!! (setq double-start (nth 4 event))))
1435 ;;;!!
1436 ;;;!! (defun double-up (event)
1437 ;;;!! (interactive "@e")
1438 ;;;!! (and double-start
1439 ;;;!! (> (- (nth 4 event ) double-start) double-click-interval)
1440 ;;;!! (setq double-start nil)))
1441 ;;;!!
1442 ;;;!! ;;; (defun x-test-doubleclick ()
1443 ;;;!! ;;; (use-local-mouse-map (setq doubleclick-test-map (make-sparse-keymap)))
1444 ;;;!! ;;; (define-key doubleclick-test-map mouse-button-left 'double-down)
1445 ;;;!! ;;; (define-key doubleclick-test-map mouse-button-left-up 'double-up))
1446 ;;;!!
1447 ;;;!! ;;
1448 ;;;!! ;; This scrolls while button is depressed. Use preferable in scroll bar.
1449 ;;;!! ;;
1450 ;;;!!
1451 ;;;!! (defvar scrolled-lines 0)
1452 ;;;!! (defconst scroll-speed 1)
1453 ;;;!!
1454 ;;;!! (defun incr-scroll-down (event)
1455 ;;;!! (interactive "@e")
1456 ;;;!! (setq scrolled-lines 0)
1457 ;;;!! (incremental-scroll scroll-speed))
1458 ;;;!!
1459 ;;;!! (defun incr-scroll-up (event)
1460 ;;;!! (interactive "@e")
1461 ;;;!! (setq scrolled-lines 0)
1462 ;;;!! (incremental-scroll (- scroll-speed)))
1463 ;;;!!
1464 ;;;!! (defun incremental-scroll (n)
1465 ;;;!! (while (= (x-mouse-events) 0)
1466 ;;;!! (setq scrolled-lines (1+ (* scroll-speed scrolled-lines)))
1467 ;;;!! (scroll-down n)
1468 ;;;!! (sit-for 300 t)))
1469 ;;;!!
1470 ;;;!! (defun incr-scroll-stop (event)
1471 ;;;!! (interactive "@e")
1472 ;;;!! (message "Scrolled %d lines" scrolled-lines)
1473 ;;;!! (setq scrolled-lines 0)
1474 ;;;!! (sleep-for 1))
1475 ;;;!!
1476 ;;;!! ;;; (defun x-testing-scroll ()
1477 ;;;!! ;;; (let ((scrolling-map (function mouse-vertical-scroll-bar-prefix)))
1478 ;;;!! ;;; (define-key scrolling-map mouse-button-left 'incr-scroll-down)
1479 ;;;!! ;;; (define-key scrolling-map mouse-button-right 'incr-scroll-up)
1480 ;;;!! ;;; (define-key scrolling-map mouse-button-left-up 'incr-scroll-stop)
1481 ;;;!! ;;; (define-key scrolling-map mouse-button-right-up 'incr-scroll-stop)))
1482 ;;;!!
1483 ;;;!! ;;
1484 ;;;!! ;; Some playthings suitable for picture mode? They need work.
1485 ;;;!! ;;
1486 ;;;!!
1487 ;;;!! (defun mouse-kill-rectangle (event)
1488 ;;;!! "Kill the rectangle between point and the mouse cursor."
1489 ;;;!! (interactive "@e")
1490 ;;;!! (let ((point-save (point)))
1491 ;;;!! (save-excursion
1492 ;;;!! (mouse-set-point event)
1493 ;;;!! (push-mark nil t)
1494 ;;;!! (if (> point-save (point))
1495 ;;;!! (kill-rectangle (point) point-save)
1496 ;;;!! (kill-rectangle point-save (point))))))
1497 ;;;!!
1498 ;;;!! (defun mouse-open-rectangle (event)
1499 ;;;!! "Kill the rectangle between point and the mouse cursor."
1500 ;;;!! (interactive "@e")
1501 ;;;!! (let ((point-save (point)))
1502 ;;;!! (save-excursion
1503 ;;;!! (mouse-set-point event)
1504 ;;;!! (push-mark nil t)
1505 ;;;!! (if (> point-save (point))
1506 ;;;!! (open-rectangle (point) point-save)
1507 ;;;!! (open-rectangle point-save (point))))))
1508 ;;;!!
1509 ;;;!! ;; Must be a better way to do this.
1510 ;;;!!
1511 ;;;!! (defun mouse-multiple-insert (n char)
1512 ;;;!! (while (> n 0)
1513 ;;;!! (insert char)
1514 ;;;!! (setq n (1- n))))
1515 ;;;!!
1516 ;;;!! ;; What this could do is not finalize until button was released.
1517 ;;;!!
1518 ;;;!! (defun mouse-move-text (event)
1519 ;;;!! "Move text from point to cursor position, inserting spaces."
1520 ;;;!! (interactive "@e")
1521 ;;;!! (let* ((relative-coordinate
1522 ;;;!! (coordinates-in-window-p (car event) (selected-window))))
1523 ;;;!! (if (consp relative-coordinate)
1524 ;;;!! (cond ((> (current-column) (car relative-coordinate))
1525 ;;;!! (delete-char
1526 ;;;!! (- (car relative-coordinate) (current-column))))
1527 ;;;!! ((< (current-column) (car relative-coordinate))
1528 ;;;!! (mouse-multiple-insert
1529 ;;;!! (- (car relative-coordinate) (current-column)) " "))
1530 ;;;!! ((= (current-column) (car relative-coordinate)) (ding))))))
1532 ;; Choose a completion with the mouse.
1534 (defun mouse-choose-completion (event)
1535 "Click on an alternative in the `*Completions*' buffer to choose it."
1536 (interactive "e")
1537 ;; Give temporary modes such as isearch a chance to turn off.
1538 (run-hooks 'mouse-leave-buffer-hook)
1539 (let ((buffer (window-buffer))
1540 choice
1541 base-size)
1542 (save-excursion
1543 (set-buffer (window-buffer (posn-window (event-start event))))
1544 (if completion-reference-buffer
1545 (setq buffer completion-reference-buffer))
1546 (setq base-size completion-base-size)
1547 (save-excursion
1548 (goto-char (posn-point (event-start event)))
1549 (let (beg end)
1550 (if (and (not (eobp)) (get-text-property (point) 'mouse-face))
1551 (setq end (point) beg (1+ (point))))
1552 (if (null beg)
1553 (error "No completion here"))
1554 (setq beg (previous-single-property-change beg 'mouse-face))
1555 (setq end (or (next-single-property-change end 'mouse-face)
1556 (point-max)))
1557 (setq choice (buffer-substring beg end)))))
1558 (let ((owindow (selected-window)))
1559 (select-window (posn-window (event-start event)))
1560 (if (and (one-window-p t 'selected-frame)
1561 (window-dedicated-p (selected-window)))
1562 ;; This is a special buffer's frame
1563 (iconify-frame (selected-frame))
1564 (or (window-dedicated-p (selected-window))
1565 (bury-buffer)))
1566 (select-window owindow))
1567 (choose-completion-string choice buffer base-size)))
1569 ;; Font selection.
1571 (defun font-menu-add-default ()
1572 (let* ((default (cdr (assq 'font (frame-parameters (selected-frame)))))
1573 (font-alist x-fixed-font-alist)
1574 (elt (or (assoc "Misc" font-alist) (nth 1 font-alist))))
1575 (if (assoc "Default" elt)
1576 (delete (assoc "Default" elt) elt))
1577 (setcdr elt
1578 (cons (list "Default"
1579 (cdr (assq 'font (frame-parameters (selected-frame)))))
1580 (cdr elt)))))
1582 (defvar x-fixed-font-alist
1583 '("Font menu"
1584 ("Misc"
1585 ;; For these, we specify the pixel height and width.
1586 ("fixed" "fixed")
1587 ("6x10" "-misc-fixed-medium-r-normal--10-*-*-*-c-60-iso8859-1" "6x10")
1588 ("6x12"
1589 "-misc-fixed-medium-r-semicondensed--12-*-*-*-c-60-iso8859-1" "6x12")
1590 ("6x13"
1591 "-misc-fixed-medium-r-semicondensed--13-*-*-*-c-60-iso8859-1" "6x13")
1592 ("7x13" "-misc-fixed-medium-r-normal--13-*-*-*-c-70-iso8859-1" "7x13")
1593 ("7x14" "-misc-fixed-medium-r-normal--14-*-*-*-c-70-iso8859-1" "7x14")
1594 ("8x13" "-misc-fixed-medium-r-normal--13-*-*-*-c-80-iso8859-1" "8x13")
1595 ("9x15" "-misc-fixed-medium-r-normal--15-*-*-*-c-90-iso8859-1" "9x15")
1596 ("10x20" "-misc-fixed-medium-r-normal--20-*-*-*-c-100-iso8859-1" "10x20")
1597 ("11x18" "-misc-fixed-medium-r-normal--18-*-*-*-c-110-iso8859-1" "11x18")
1598 ("12x24" "-misc-fixed-medium-r-normal--24-*-*-*-c-120-iso8859-1" "12x24")
1599 ("")
1600 ("clean 5x8"
1601 "-schumacher-clean-medium-r-normal--8-*-*-*-c-50-iso8859-1")
1602 ("clean 6x8"
1603 "-schumacher-clean-medium-r-normal--8-*-*-*-c-60-iso8859-1")
1604 ("clean 8x8"
1605 "-schumacher-clean-medium-r-normal--8-*-*-*-c-80-iso8859-1")
1606 ("clean 8x10"
1607 "-schumacher-clean-medium-r-normal--10-*-*-*-c-80-iso8859-1")
1608 ("clean 8x14"
1609 "-schumacher-clean-medium-r-normal--14-*-*-*-c-80-iso8859-1")
1610 ("clean 8x16"
1611 "-schumacher-clean-medium-r-normal--16-*-*-*-c-80-iso8859-1")
1612 ("")
1613 ("sony 8x16" "-sony-fixed-medium-r-normal--16-*-*-*-c-80-iso8859-1"))
1614 ;;; We don't seem to have these; who knows what they are.
1615 ;;; ("fg-18" "fg-18")
1616 ;;; ("fg-25" "fg-25")
1617 ;;; ("lucidasanstypewriter-12" "lucidasanstypewriter-12")
1618 ;;; ("lucidasanstypewriter-bold-14" "lucidasanstypewriter-bold-14")
1619 ;;; ("lucidasanstypewriter-bold-24" "lucidasanstypewriter-bold-24")
1620 ;;; ("lucidatypewriter-bold-r-24" "-b&h-lucidatypewriter-bold-r-normal-sans-24-240-75-75-m-140-iso8859-1")
1621 ;;; ("fixed-medium-20" "-misc-fixed-medium-*-*-*-20-*-*-*-*-*-*-*")
1622 ("Courier"
1623 ;; For these, we specify the point height.
1624 ("8" "-adobe-courier-medium-r-normal--*-80-*-*-m-*-iso8859-1")
1625 ("10" "-adobe-courier-medium-r-normal--*-100-*-*-m-*-iso8859-1")
1626 ("12" "-adobe-courier-medium-r-normal--*-120-*-*-m-*-iso8859-1")
1627 ("14" "-adobe-courier-medium-r-normal--*-140-*-*-m-*-iso8859-1")
1628 ("18" "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1")
1629 ("24" "-adobe-courier-medium-r-normal--*-240-*-*-m-*-iso8859-1")
1630 ("8 bold" "-adobe-courier-bold-r-normal--*-80-*-*-m-*-iso8859-1")
1631 ("10 bold" "-adobe-courier-bold-r-normal--*-100-*-*-m-*-iso8859-1")
1632 ("12 bold" "-adobe-courier-bold-r-normal--*-120-*-*-m-*-iso8859-1")
1633 ("14 bold" "-adobe-courier-bold-r-normal--*-140-*-*-m-*-iso8859-1")
1634 ("18 bold" "-adobe-courier-bold-r-normal--*-180-*-*-m-*-iso8859-1")
1635 ("24 bold" "-adobe-courier-bold-r-normal--*-240-*-*-m-*-iso8859-1")
1636 ("8 slant" "-adobe-courier-medium-o-normal--*-80-*-*-m-*-iso8859-1")
1637 ("10 slant" "-adobe-courier-medium-o-normal--*-100-*-*-m-*-iso8859-1")
1638 ("12 slant" "-adobe-courier-medium-o-normal--*-120-*-*-m-*-iso8859-1")
1639 ("14 slant" "-adobe-courier-medium-o-normal--*-140-*-*-m-*-iso8859-1")
1640 ("18 slant" "-adobe-courier-medium-o-normal--*-180-*-*-m-*-iso8859-1")
1641 ("24 slant" "-adobe-courier-medium-o-normal--*-240-*-*-m-*-iso8859-1")
1642 ("8 bold slant" "-adobe-courier-bold-o-normal--*-80-*-*-m-*-iso8859-1")
1643 ("10 bold slant" "-adobe-courier-bold-o-normal--*-100-*-*-m-*-iso8859-1")
1644 ("12 bold slant" "-adobe-courier-bold-o-normal--*-120-*-*-m-*-iso8859-1")
1645 ("14 bold slant" "-adobe-courier-bold-o-normal--*-140-*-*-m-*-iso8859-1")
1646 ("18 bold slant" "-adobe-courier-bold-o-normal--*-180-*-*-m-*-iso8859-1")
1647 ("24 bold slant" "-adobe-courier-bold-o-normal--*-240-*-*-m-*-iso8859-1"))
1649 "X fonts suitable for use in Emacs.")
1651 (defun mouse-set-font (&rest fonts)
1652 "Select an emacs font from a list of known good fonts"
1653 (interactive
1654 (x-popup-menu last-nonmenu-event x-fixed-font-alist))
1655 (if fonts
1656 (let (font)
1657 (while fonts
1658 (condition-case nil
1659 (progn
1660 (set-default-font (car fonts))
1661 (setq font (car fonts))
1662 (setq fonts nil))
1663 (error
1664 (setq fonts (cdr fonts)))))
1665 (if (null font)
1666 (error "Font not found")))))
1668 ;;; Bindings for mouse commands.
1670 (define-key global-map [down-mouse-1] 'mouse-drag-region)
1671 (global-set-key [mouse-1] 'mouse-set-point)
1672 (global-set-key [drag-mouse-1] 'mouse-set-region)
1674 ;; These are tested for in mouse-drag-region.
1675 (global-set-key [double-mouse-1] 'mouse-set-point)
1676 (global-set-key [triple-mouse-1] 'mouse-set-point)
1678 (global-set-key [mouse-2] 'mouse-yank-at-click)
1679 (global-set-key [mouse-3] 'mouse-save-then-kill)
1681 ;; By binding these to down-going events, we let the user use the up-going
1682 ;; event to make the selection, saving a click.
1683 (global-set-key [C-down-mouse-1] 'mouse-buffer-menu)
1684 (if (not (eq system-type 'ms-dos))
1685 (global-set-key [S-down-mouse-1] 'mouse-set-font))
1686 ;; C-down-mouse-2 is bound in facemenu.el.
1687 (global-set-key [C-down-mouse-3] 'mouse-major-mode-menu)
1690 ;; Replaced with dragging mouse-1
1691 ;; (global-set-key [S-mouse-1] 'mouse-set-mark)
1693 (global-set-key [mode-line mouse-1] 'mouse-select-window)
1694 (global-set-key [mode-line drag-mouse-1] 'mouse-select-window)
1695 (global-set-key [mode-line down-mouse-1] 'mouse-drag-mode-line)
1696 (global-set-key [mode-line mouse-2] 'mouse-delete-other-windows)
1697 (global-set-key [mode-line mouse-3] 'mouse-delete-window)
1698 (global-set-key [mode-line C-mouse-2] 'mouse-split-window-horizontally)
1699 (global-set-key [vertical-scroll-bar C-mouse-2] 'mouse-split-window-vertically)
1700 (global-set-key [vertical-line C-mouse-2] 'mouse-split-window-vertically)
1701 (global-set-key [vertical-line down-mouse-1] 'mouse-drag-vertical-line)
1702 (global-set-key [vertical-line mouse-1] 'mouse-select-window)
1704 (provide 'mouse)
1706 ;;; mouse.el ends here