[MULTI_FRAME]: Increase PURESIZE to 220000.
[bpt/emacs.git] / lisp / mouse.el
CommitLineData
6594deb0 1;;; mouse.el --- window system-independent mouse support.
84176303 2
9a408b1d 3;;; Copyright (C) 1993 Free Software Foundation, Inc.
eea8d4ef 4
84176303 5;; Maintainer: FSF
84176303
ER
6;; Keywords: hardware
7
cc0a8174 8;;; This file is part of GNU Emacs.
72ea54a4 9
cc0a8174
JB
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
87ef29fd 12;;; the Free Software Foundation; either version 2, or (at your option)
cc0a8174 13;;; any later version.
72ea54a4 14
cc0a8174
JB
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.
72ea54a4 19
cc0a8174
JB
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.
72ea54a4 23
edbd2f74
ER
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
aae56ea7
ER
32;;; Code:
33
cc0a8174 34;;; Utility functions.
72ea54a4 35
cc0a8174
JB
36;;; Indent track-mouse like progn.
37(put 'track-mouse 'lisp-indent-function 0)
72ea54a4 38
cc0a8174
JB
39\f
40(defun mouse-delete-window (click)
947da0c4 41 "Delete the window you click on.
cc0a8174 42This must be bound to a mouse click."
ec558adc 43 (interactive "e")
b5370f03 44 (delete-window (posn-window (event-start click))))
cc0a8174 45
b0f3a26b
JB
46(defun mouse-tear-off-window (click)
47 "Delete the window clicked on, and create a new frame displaying its buffer."
48 (interactive "e")
49 (let* ((window (posn-window (event-start click)))
50 (buf (window-buffer window))
51 (frame (new-frame)))
52 (select-frame frame)
53 (switch-to-buffer buf)
54 (delete-window window)))
55
b5370f03 56(defun mouse-delete-other-windows ()
947da0c4 57 "Delete all window except the one you click on."
b5370f03 58 (interactive "@")
cc0a8174 59 (delete-other-windows))
72ea54a4 60
cc0a8174
JB
61(defun mouse-split-window-vertically (click)
62 "Select Emacs window mouse is on, then split it vertically in half.
63The window is split at the line clicked on.
64This command must be bound to a mouse click."
947da0c4 65 (interactive "@e")
b5370f03
JB
66 (let ((start (event-start click)))
67 (select-window (posn-window start))
3f26b32a
RS
68 (let ((new-height (if (eq (posn-point start) 'vertical-scroll-bar)
69 (scroll-bar-scale (posn-col-row start)
70 (1- (window-height)))
71 (1+ (cdr (posn-col-row (event-end click))))))
5ba2dc3f
JB
72 (first-line window-min-height)
73 (last-line (- (window-height) window-min-height)))
74 (if (< last-line first-line)
75 (error "window too short to split")
76 (split-window-vertically
77 (min (max new-height first-line) last-line))))))
cc0a8174 78
947da0c4
RS
79(defun mouse-split-window-horizontally (click)
80 "Select Emacs window mouse is on, then split it horizontally in half.
81The window is split at the column clicked on.
82This command must be bound to a mouse click."
83 (interactive "@e")
5ba2dc3f
JB
84 (let ((start (event-start click)))
85 (select-window (posn-window start))
86 (let ((new-width (1+ (car (posn-col-row (event-end click)))))
87 (first-col window-min-width)
88 (last-col (- (window-width) window-min-width)))
89 (if (< last-col first-col)
90 (error "window too narrow to split")
91 (split-window-horizontally
92 (min (max new-width first-col) last-col))))))
947da0c4 93
2a5fa27b 94(defun mouse-set-point (event)
cc0a8174 95 "Move point to the position clicked on with the mouse.
2a5fa27b 96This should be bound to a mouse click event type."
ec558adc 97 (interactive "e")
2a5fa27b
RS
98 ;; Use event-end in case called from mouse-drag-region.
99 ;; If EVENT is a click, event-end and event-start give same value.
100 (let ((posn (event-end event)))
b80f1928
RS
101 (and (window-minibuffer-p (posn-window posn))
102 (not (minibuffer-window-active-p (posn-window posn)))
103 (error "Minibuffer window is not active"))
b5370f03
JB
104 (select-window (posn-window posn))
105 (if (numberp (posn-point posn))
106 (goto-char (posn-point posn)))))
cc0a8174 107
652ccd35 108(defun mouse-set-region (click)
e37de120 109 "Set the region to the text dragged over, and copy to kill ring.
2a5fa27b 110This should be bound to a mouse drag event."
652ccd35
RS
111 (interactive "e")
112 (let ((posn (event-start click))
113 (end (event-end click)))
114 (select-window (posn-window posn))
115 (if (numberp (posn-point posn))
116 (goto-char (posn-point posn)))
fcfc3c63
RS
117 ;; If mark is highlighted, no need to bounce the cursor.
118 (or (and transient-mark-mode
119 (eq (framep (selected-frame)) 'x))
120 (sit-for 1))
652ccd35 121 (push-mark)
1cc8a3f4 122 (set-mark (point))
652ccd35 123 (if (numberp (posn-point end))
e37de120
RS
124 (goto-char (posn-point end)))
125 ;; Don't set this-command to kill-region, so that a following
126 ;; C-w will not double the text in the kill ring.
127 (let (this-command)
128 (copy-region-as-kill (mark) (point)))))
652ccd35 129
600c6e3a
JB
130(defvar mouse-scroll-delay 0.25
131 "*The pause between scroll steps caused by mouse drags, in seconds.
132If you drag the mouse beyond the edge of a window, Emacs scrolls the
133window to bring the text beyond that edge into view, with a delay of
134this many seconds between scroll steps. Scrolling stops when you move
135the mouse back into the window, or release the button.
136This variable's value may be non-integral.
137Setting this to zero causes Emacs to scroll as fast as it can.")
138
139(defun mouse-scroll-subr (jump &optional overlay start)
140 "Scroll the selected window JUMP lines at a time, until new input arrives.
141If OVERLAY is an overlay, let it stretch from START to the far edge of
142the newly visible text.
143Upon exit, point is at the far edge of the newly visible text."
144 (while (progn
145 (goto-char (window-start))
146 (if (not (zerop (vertical-motion jump)))
147 (progn
148 (set-window-start (selected-window) (point))
149 (if (natnump jump)
150 (progn
151 (goto-char (window-end (selected-window)))
152 ;; window-end doesn't reflect the window's new
153 ;; start position until the next redisplay. Hurrah.
154 (vertical-motion (1- jump)))
155 (goto-char (window-start (selected-window))))
156 (if overlay
157 (move-overlay overlay start (point)))
158 (if (not (eobp))
159 (sit-for mouse-scroll-delay))))))
160 (point))
fcfc3c63 161
600c6e3a
JB
162(defvar mouse-drag-overlay (make-overlay 1 1))
163(overlay-put mouse-drag-overlay 'face 'region)
164
eb6ff46f
RS
165(defvar mouse-selection-click-count nil)
166
600c6e3a 167(defun mouse-drag-region (start-event)
bcd5aef1 168 "Set the region to the text that the mouse is dragged over.
78210c95
RS
169Highlight the drag area as you move the mouse.
170This must be bound to a button-down mouse event.
171In Transient Mark mode, the highlighting remains once you
172release the mouse button. Otherwise, it does not."
bcd5aef1 173 (interactive "e")
600c6e3a
JB
174 (let* ((start-posn (event-start start-event))
175 (start-point (posn-point start-posn))
176 (start-window (posn-window start-posn))
b846d039 177 (start-frame (window-frame start-window))
600c6e3a
JB
178 (bounds (window-edges start-window))
179 (top (nth 1 bounds))
180 (bottom (if (window-minibuffer-p start-window)
181 (nth 3 bounds)
182 ;; Don't count the mode line.
e37de120
RS
183 (1- (nth 3 bounds))))
184 (click-count (1- (event-click-count start-event))))
eb6ff46f 185 (setq mouse-selection-click-count click-count)
b80f1928 186 (mouse-set-point start-event)
e37de120
RS
187 (let ((range (mouse-start-end start-point start-point click-count)))
188 (move-overlay mouse-drag-overlay (car range) (nth 1 range)
189 (window-buffer start-window)))
f767385c 190 (deactivate-mark)
600c6e3a 191 (let (event end end-point)
bcd5aef1 192 (track-mouse
600c6e3a 193 (while (progn
b846d039
JB
194 (setq event (read-event))
195 (or (mouse-movement-p event)
196 (eq (car-safe event) 'switch-frame)))
197
198 (if (eq (car-safe event) 'switch-frame)
199 nil
200 (setq end (event-end event)
201 end-point (posn-point end))
202
203 (cond
204
205 ;; Ignore switch-frame events.
206 ((eq (car-safe event) 'switch-frame))
207
208 ;; Are we moving within the original window?
209 ((and (eq (posn-window end) start-window)
210 (integer-or-marker-p end-point))
211 (goto-char end-point)
e37de120
RS
212 (let ((range (mouse-start-end start-point (point) click-count)))
213 (move-overlay mouse-drag-overlay (car range) (nth 1 range))))
b846d039
JB
214
215 ;; Are we moving on a different window on the same frame?
216 ((and (windowp (posn-window end))
217 (eq (window-frame (posn-window end)) start-frame))
218 (let ((mouse-row
219 (+ (nth 1 (window-edges (posn-window end)))
220 (cdr (posn-col-row end)))))
221 (cond
222 ((< mouse-row top)
223 (mouse-scroll-subr
224 (- mouse-row top) mouse-drag-overlay start-point))
225 ((and (not (eobp))
226 (>= mouse-row bottom))
227 (mouse-scroll-subr (1+ (- mouse-row bottom))
228 mouse-drag-overlay start-point)))))
229
1e49aa29
RS
230 (t
231 (let ((mouse-y (cdr (cdr (mouse-position))))
232 (menu-bar-lines (or (cdr (assq 'menu-bar-lines
233 (frame-parameters)))
234 0)))
235
236 ;; Are we on the menu bar?
237 (and (integerp mouse-y) (< mouse-y menu-bar-lines)
238 (mouse-scroll-subr (- mouse-y menu-bar-lines)
239 mouse-drag-overlay start-point))))))))
b846d039 240
600c6e3a
JB
241 (if (and (eq (get (event-basic-type event) 'event-kind) 'mouse-click)
242 (eq (posn-window (event-end event)) start-window)
243 (numberp (posn-point (event-end event))))
e37de120
RS
244 (let ((fun (key-binding (vector (car event)))))
245 (if (memq fun '(mouse-set-region mouse-set-point))
246 (progn
247 (push-mark (overlay-start mouse-drag-overlay) t t)
248 (goto-char (overlay-end mouse-drag-overlay)))
249 (if (fboundp fun)
250 (funcall fun event)))))
600c6e3a 251 (delete-overlay mouse-drag-overlay))))
e37de120
RS
252\f
253;; Commands to handle xterm-style multiple clicks.
600c6e3a 254
e37de120
RS
255(defun mouse-skip-word (dir)
256 "Skip over word, over whitespace, or over identical punctuation.
257If DIR is positive skip forward; if negative, skip backward."
258 (let* ((char (following-char))
259 (syntax (char-to-string (char-syntax char))))
260 (if (or (string= syntax "w") (string= syntax " "))
261 (if (< dir 0)
262 (skip-syntax-backward syntax)
263 (skip-syntax-forward syntax))
264 (if (< dir 0)
265 (while (= (preceding-char) char)
266 (forward-char -1))
267 (while (= (following-char) char)
268 (forward-char 1))))))
269
270;; Return a list of region bounds based on START and END according to MODE.
271;; If MODE is 0 then set point to (min START END), mark to (max START END).
272;; If MODE is 1 then set point to start of word at (min START END),
273;; mark to end of word at (max START END).
274;; If MODE is 2 then do the same for lines.
eb6ff46f 275(defun mouse-start-end (start end mode)
e37de120
RS
276 (if (> start end)
277 (let ((temp start))
278 (setq start end
279 end temp)))
280 (cond ((= mode 0)
281 (list start end))
282 ((and (= mode 1)
283 (= start end)
284 (= (char-syntax (char-after start)) ?\())
285 (list start (save-excursion (forward-sexp 1) (point))))
286 ((and (= mode 1)
287 (= start end)
288 (= (char-syntax (char-after start)) ?\)))
289 (list (save-excursion
290 (goto-char (1+ start))
291 (backward-sexp 1))
292 (1+ start)))
293 ((= mode 1)
294 (list (save-excursion
295 (goto-char start)
296 (mouse-skip-word -1)
297 (point))
298 (save-excursion
299 (goto-char end)
300 (mouse-skip-word 1)
301 (point))))
302 ((= mode 2)
303 (list (save-excursion
304 (goto-char start)
305 (beginning-of-line 1)
306 (point))
307 (save-excursion
308 (goto-char end)
309 (forward-line 1)
310 (point))))))
e66feb07 311\f
3f26b32a
RS
312;; Subroutine: set the mark where CLICK happened,
313;; but don't do anything else.
314(defun mouse-set-mark-fast (click)
315 (let ((posn (event-start click)))
316 (select-window (posn-window posn))
317 (if (numberp (posn-point posn))
318 (push-mark (posn-point posn) t t))))
319
320;; Momentarily show where the mark is, if highlighting doesn't show it.
321(defun mouse-show-mark ()
322 (or transient-mark-mode
323 (save-excursion
324 (goto-char (mark t))
325 (sit-for 1))))
326
cc0a8174
JB
327(defun mouse-set-mark (click)
328 "Set mark at the position clicked on with the mouse.
329Display cursor at that position for a second.
330This must be bound to a mouse click."
ec558adc 331 (interactive "e")
72ea54a4
RS
332 (let ((point-save (point)))
333 (unwind-protect
cc0a8174 334 (progn (mouse-set-point click)
897897e3
RS
335 (push-mark nil t t)
336 (or transient-mark-mode
337 (sit-for 1)))
72ea54a4
RS
338 (goto-char point-save))))
339
cc0a8174
JB
340(defun mouse-kill (click)
341 "Kill the region between point and the mouse click.
342The text is saved in the kill ring, as with \\[kill-region]."
ec558adc 343 (interactive "e")
40a45a9f 344 (let ((click-posn (posn-point (event-start click))))
bd307392
JB
345 (if (numberp click-posn)
346 (kill-region (min (point) click-posn)
347 (max (point) click-posn)))))
72ea54a4 348
87ef29fd
JB
349(defun mouse-yank-at-click (click arg)
350 "Insert the last stretch of killed text at the position clicked on.
351Prefix arguments are interpreted as with \\[yank]."
ec558adc 352 (interactive "e\nP")
87ef29fd
JB
353 (mouse-set-point click)
354 (yank arg))
355
356(defun mouse-kill-ring-save (click)
cc0a8174
JB
357 "Copy the region between point and the mouse click in the kill ring.
358This does not delete the region; it acts like \\[kill-ring-save]."
ec558adc 359 (interactive "e")
3f26b32a
RS
360 (mouse-set-mark-fast click)
361 (kill-ring-save (point) (mark t))
362 (mouse-show-mark))
72ea54a4 363
dbc4e1c1
JB
364;;; This function used to delete the text between point and the mouse
365;;; whenever it was equal to the front of the kill ring, but some
366;;; people found that confusing.
367
368;;; A list (TEXT START END), describing the text and position of the last
369;;; invocation of mouse-save-then-kill.
370(defvar mouse-save-then-kill-posn nil)
371
eb6ff46f
RS
372(defun mouse-save-then-kill-delete-region ()
373 ;; Delete just one char, so in case buffer is being modified
374 ;; for the first time, the undo list records that fact.
375 (delete-region (point)
376 (+ (point) (if (> (mark) (point)) 1 -1)))
377 ;; Now delete the rest of the specified region,
378 ;; but don't record it.
379 (let ((buffer-undo-list t))
380 (delete-region (point) (mark)))
381 (if (not (eq buffer-undo-list t))
382 (let ((tail buffer-undo-list))
383 ;; Search back in buffer-undo-list for the string
384 ;; that came from the first delete-region.
385 (while (and tail (not (stringp (car (car tail)))))
386 (setq tail (cdr tail)))
387 ;; Replace it with an entry for the entire deleted text.
388 (and tail
389 (setcar tail (cons (car kill-ring) (point)))))))
390
947da0c4 391(defun mouse-save-then-kill (click)
40a45a9f
RS
392 "Save text to point in kill ring; the second time, kill the text.
393If the text between point and the mouse is the same as what's
394at the front of the kill ring, this deletes the text.
395Otherwise, it adds the text to the kill ring, like \\[kill-ring-save],
eb6ff46f
RS
396which prepares for a second click to delete the text.
397
398If you have selected words or lines, this command extends the
399selection through the word or line clicked on. If you do this
400again in a different position, it extends the selection again.
401If you do this twice in the same position, the selection is killed."
947da0c4 402 (interactive "e")
3f26b32a
RS
403 (let ((click-posn (posn-point (event-start click)))
404 ;; Don't let a subsequent kill command append to this one:
405 ;; prevent setting this-command to kill-region.
406 (this-command this-command))
eb6ff46f
RS
407 (if (> mouse-selection-click-count 0)
408 (if (not (and (eq last-command 'mouse-save-then-kill)
409 (equal click-posn
410 (car (cdr-safe (cdr-safe mouse-save-then-kill-posn))))))
411 (let* ((obeg (min (point) (mark t)))
412 (oend (max (point) (mark t)))
413 (beg (min obeg click-posn))
414 (end (if (< click-posn obeg) oend click-posn))
415 (range
416 (mouse-start-end beg end mouse-selection-click-count))
417 (nbeg (if (= beg obeg) obeg (car range)))
418 (nend (if (= end oend) oend (nth 1 range))))
419 (setq mouse-save-then-kill-posn
420 (list (car kill-ring) (point) click-posn))
421 (set-mark nbeg)
422 (goto-char nend)
423 ;; We have already put the old region in the kill ring.
424 ;; Replace it with the extended region.
425 ;; (It would be annoying to make a separate entry.)
426 (setcar kill-ring (buffer-substring (point) (mark t)))
427 (mouse-show-mark))
428 ;; If we click this button again without moving it,
429 ;; that time kill.
430 (mouse-save-then-kill-delete-region))
431 (if (and (eq last-command 'mouse-save-then-kill)
432 mouse-save-then-kill-posn
433 (eq (car mouse-save-then-kill-posn) (car kill-ring))
434 (equal (cdr mouse-save-then-kill-posn) (list (point) click-posn)))
435 ;; If this is the second time we've called
436 ;; mouse-save-then-kill, delete the text from the buffer.
437 (mouse-save-then-kill-delete-region)
438 ;; Otherwise, save this region.
439 (mouse-set-mark-fast click)
440 (kill-ring-save (point) (mark t))
441 (mouse-show-mark)
442 (setq mouse-save-then-kill-posn
443 (list (car kill-ring) (point) click-posn))))))
e66feb07
RS
444\f
445(global-set-key [M-mouse-1] 'mouse-start-secondary)
446(global-set-key [M-drag-mouse-1] 'mouse-set-secondary)
447(global-set-key [M-down-mouse-1] 'mouse-drag-secondary)
448(global-set-key [M-mouse-3] 'mouse-secondary-save-then-kill)
449(global-set-key [M-mouse-2] 'mouse-kill-secondary)
450
451;; An overlay which records the current secondary selection
452;; or else is deleted when there is no secondary selection.
453;; May be nil.
454(defvar mouse-secondary-overlay nil)
455
456;; A marker which records the specified first end for a secondary selection.
457;; May be nil.
458(defvar mouse-secondary-start nil)
459
460(defun mouse-start-secondary (click)
461 "Set one end of the secondary selection to the position clicked on.
462Use \\[mouse-secondary-save-then-kill] to set the other end
463and complete the secondary selection."
464 (interactive "e")
465 (let ((posn (event-start click)))
230aaa73
RS
466 (save-excursion
467 (set-buffer (window-buffer (posn-window posn)))
468 ;; Cancel any preexisting secondary selection.
469 (if mouse-secondary-overlay
470 (delete-overlay mouse-secondary-overlay))
471 (if (numberp (posn-point posn))
472 (progn
473 (or mouse-secondary-start
474 (setq mouse-secondary-start (make-marker)))
475 (move-marker mouse-secondary-start (posn-point posn)))))))
e66feb07
RS
476
477(defun mouse-set-secondary (click)
478 "Set the secondary selection to the text that the mouse is dragged over.
479This must be bound to a mouse drag event."
480 (interactive "e")
481 (let ((posn (event-start click))
482 beg
483 (end (event-end click)))
230aaa73
RS
484 (save-excursion
485 (set-buffer (window-buffer (posn-window posn)))
486 (if (numberp (posn-point posn))
487 (setq beg (posn-point posn)))
488 (if mouse-secondary-overlay
489 (move-overlay mouse-secondary-overlay beg (posn-point end))
490 (setq mouse-secondary-overlay (make-overlay beg (posn-point end))))
491 (overlay-put mouse-secondary-overlay 'face 'secondary-selection))))
947da0c4 492
e66feb07
RS
493(defun mouse-drag-secondary (click)
494 "Set the secondary selection to the text that the mouse is dragged over.
495This must be bound to a button-down mouse event."
496 (interactive "e")
497 (let ((posn (event-start click)))
230aaa73
RS
498 (save-window-excursion
499 (select-window (posn-window posn))
500 ;; Set point temporarily, so user sees where it is.
501 (save-excursion
502 (if (numberp (posn-point posn))
503 (goto-char (posn-point posn)))
504 (setq unread-command-events
505 (cons (read-event) unread-command-events))))))
e66feb07
RS
506
507(defun mouse-kill-secondary ()
508 "Kill the text in the secondary selection."
509 (interactive "*")
510 (kill-region (overlay-start mouse-secondary-overlay)
511 (overlay-end mouse-secondary-overlay))
512 (delete-overlay mouse-secondary-overlay)
513 (setq mouse-secondary-overlay nil))
514
515(defun mouse-secondary-save-then-kill (click)
516 "Save text to secondary start point in kill ring; if twice, kill it.
517If the text between secondary start point and the mouse is the same as what's
518at the front of the kill ring, this deletes the text.
519Otherwise, it adds the text to the kill ring, like \\[kill-ring-save],
520which prepares for a second click to delete the text."
521 (interactive "e")
522 (let ((click-posn (posn-point (event-start click)))
523 (start (+ 0 mouse-secondary-start))
524 ;; Don't let a subsequent kill command append to this one:
525 ;; prevent setting this-command to kill-region.
526 (this-command this-command))
527 (if (and (eq last-command 'mouse-secondary-save-then-kill)
528 mouse-save-then-kill-posn
529 (eq (car mouse-save-then-kill-posn) (car kill-ring))
530 (equal (cdr mouse-save-then-kill-posn)
531 (list start click-posn)))
532 ;; If this is the second time we've called
533 ;; mouse-save-then-kill, delete the text from the buffer.
534 (progn
535 (let ((buffer-undo-list t))
536 (delete-overlay mouse-secondary-overlay)
537 (delete-region start click-posn))
538 ;; Make the undo list by hand so it is shared.
539 (if (not (eq buffer-undo-list t))
540 (setq buffer-undo-list
367ee8f4 541 (cons (cons (car kill-ring) (marker-position start))
e66feb07
RS
542 buffer-undo-list))))
543 ;; Otherwise, save this region.
230aaa73
RS
544 (save-excursion
545 (set-buffer (window-buffer (posn-window (event-start click))))
546 (kill-ring-save start click-posn)
547 (if mouse-secondary-overlay
548 (move-overlay mouse-secondary-overlay start click-posn)
549 (setq mouse-secondary-overlay (make-overlay start click-posn)))
550 (overlay-put mouse-secondary-overlay 'face 'secondary-selection)
551 (setq mouse-save-then-kill-posn
552 (list (car kill-ring) start click-posn))))))
e66feb07 553\f
8b34e79d 554(defun mouse-buffer-menu (event)
2d82f7b9
RS
555 "Pop up a menu of buffers for selection with the mouse.
556This switches buffers in the window that you clicked on,
557and selects that window."
ec558adc 558 (interactive "e")
8b34e79d
RS
559 (let ((menu
560 (list "Buffer Menu"
561 (cons "Select Buffer"
562 (let ((tail (buffer-list))
af2a85fe 563 (maxbuf 0)
8b34e79d 564 head)
af2a85fe
RS
565 (while tail
566 (or (eq ?\ (aref (buffer-name (car tail)) 0))
567 (setq maxbuf
568 (max maxbuf
569 (length (buffer-name (car tail))))))
570 (setq tail (cdr tail)))
571 (setq tail (buffer-list))
8b34e79d
RS
572 (while tail
573 (let ((elt (car tail)))
574 (if (not (string-match "^ "
575 (buffer-name elt)))
576 (setq head (cons
577 (cons
578 (format
af2a85fe
RS
579 (format "%%%ds %%s%%s %%s"
580 maxbuf)
8b34e79d 581 (buffer-name elt)
af2a85fe
RS
582 (if (buffer-modified-p elt)
583 "*" " ")
584 (save-excursion
585 (set-buffer elt)
586 (if buffer-read-only "%" " "))
8b34e79d
RS
587 (or (buffer-file-name elt) ""))
588 elt)
589 head))))
590 (setq tail (cdr tail)))
591 (reverse head))))))
2d82f7b9
RS
592 (let ((buf (x-popup-menu event menu))
593 (window (posn-window (event-start event))))
594 (if buf
595 (progn
c0bb9f3b 596 (or (framep window) (select-window window))
2d82f7b9 597 (switch-to-buffer buf))))))
72ea54a4 598\f
5ba2dc3f 599;;; These need to be rewritten for the new scroll bar implementation.
dbc4e1c1
JB
600
601;;;!! ;; Commands for the scroll bar.
602;;;!!
603;;;!! (defun mouse-scroll-down (click)
604;;;!! (interactive "@e")
605;;;!! (scroll-down (1+ (cdr (mouse-coords click)))))
606;;;!!
607;;;!! (defun mouse-scroll-up (click)
608;;;!! (interactive "@e")
609;;;!! (scroll-up (1+ (cdr (mouse-coords click)))))
610;;;!!
611;;;!! (defun mouse-scroll-down-full ()
612;;;!! (interactive "@")
613;;;!! (scroll-down nil))
614;;;!!
615;;;!! (defun mouse-scroll-up-full ()
616;;;!! (interactive "@")
617;;;!! (scroll-up nil))
618;;;!!
619;;;!! (defun mouse-scroll-move-cursor (click)
620;;;!! (interactive "@e")
621;;;!! (move-to-window-line (1+ (cdr (mouse-coords click)))))
622;;;!!
623;;;!! (defun mouse-scroll-absolute (event)
624;;;!! (interactive "@e")
625;;;!! (let* ((pos (car event))
626;;;!! (position (car pos))
627;;;!! (length (car (cdr pos))))
628;;;!! (if (<= length 0) (setq length 1))
629;;;!! (let* ((scale-factor (max 1 (/ length (/ 8000000 (buffer-size)))))
630;;;!! (newpos (* (/ (* (/ (buffer-size) scale-factor)
631;;;!! position)
632;;;!! length)
633;;;!! scale-factor)))
634;;;!! (goto-char newpos)
635;;;!! (recenter '(4)))))
636;;;!!
637;;;!! (defun mouse-scroll-left (click)
638;;;!! (interactive "@e")
639;;;!! (scroll-left (1+ (car (mouse-coords click)))))
640;;;!!
641;;;!! (defun mouse-scroll-right (click)
642;;;!! (interactive "@e")
643;;;!! (scroll-right (1+ (car (mouse-coords click)))))
644;;;!!
645;;;!! (defun mouse-scroll-left-full ()
646;;;!! (interactive "@")
647;;;!! (scroll-left nil))
648;;;!!
649;;;!! (defun mouse-scroll-right-full ()
650;;;!! (interactive "@")
651;;;!! (scroll-right nil))
652;;;!!
653;;;!! (defun mouse-scroll-move-cursor-horizontally (click)
654;;;!! (interactive "@e")
655;;;!! (move-to-column (1+ (car (mouse-coords click)))))
656;;;!!
657;;;!! (defun mouse-scroll-absolute-horizontally (event)
658;;;!! (interactive "@e")
659;;;!! (let* ((pos (car event))
660;;;!! (position (car pos))
661;;;!! (length (car (cdr pos))))
662;;;!! (set-window-hscroll (selected-window) 33)))
663;;;!!
664;;;!! (global-set-key [scroll-bar mouse-1] 'mouse-scroll-up)
665;;;!! (global-set-key [scroll-bar mouse-2] 'mouse-scroll-absolute)
666;;;!! (global-set-key [scroll-bar mouse-3] 'mouse-scroll-down)
667;;;!!
668;;;!! (global-set-key [vertical-slider mouse-1] 'mouse-scroll-move-cursor)
669;;;!! (global-set-key [vertical-slider mouse-2] 'mouse-scroll-move-cursor)
670;;;!! (global-set-key [vertical-slider mouse-3] 'mouse-scroll-move-cursor)
671;;;!!
672;;;!! (global-set-key [thumbup mouse-1] 'mouse-scroll-up-full)
673;;;!! (global-set-key [thumbup mouse-2] 'mouse-scroll-up-full)
674;;;!! (global-set-key [thumbup mouse-3] 'mouse-scroll-up-full)
675;;;!!
676;;;!! (global-set-key [thumbdown mouse-1] 'mouse-scroll-down-full)
677;;;!! (global-set-key [thumbdown mouse-2] 'mouse-scroll-down-full)
678;;;!! (global-set-key [thumbdown mouse-3] 'mouse-scroll-down-full)
679;;;!!
680;;;!! (global-set-key [horizontal-scroll-bar mouse-1] 'mouse-scroll-left)
681;;;!! (global-set-key [horizontal-scroll-bar mouse-2]
682;;;!! 'mouse-scroll-absolute-horizontally)
683;;;!! (global-set-key [horizontal-scroll-bar mouse-3] 'mouse-scroll-right)
684;;;!!
685;;;!! (global-set-key [horizontal-slider mouse-1]
686;;;!! 'mouse-scroll-move-cursor-horizontally)
687;;;!! (global-set-key [horizontal-slider mouse-2]
688;;;!! 'mouse-scroll-move-cursor-horizontally)
689;;;!! (global-set-key [horizontal-slider mouse-3]
690;;;!! 'mouse-scroll-move-cursor-horizontally)
691;;;!!
692;;;!! (global-set-key [thumbleft mouse-1] 'mouse-scroll-left-full)
693;;;!! (global-set-key [thumbleft mouse-2] 'mouse-scroll-left-full)
694;;;!! (global-set-key [thumbleft mouse-3] 'mouse-scroll-left-full)
695;;;!!
696;;;!! (global-set-key [thumbright mouse-1] 'mouse-scroll-right-full)
697;;;!! (global-set-key [thumbright mouse-2] 'mouse-scroll-right-full)
698;;;!! (global-set-key [thumbright mouse-3] 'mouse-scroll-right-full)
699;;;!!
700;;;!! (global-set-key [horizontal-scroll-bar S-mouse-2]
701;;;!! 'mouse-split-window-horizontally)
702;;;!! (global-set-key [mode-line S-mouse-2]
703;;;!! 'mouse-split-window-horizontally)
704;;;!! (global-set-key [vertical-scroll-bar S-mouse-2]
705;;;!! 'mouse-split-window)
6b2154de 706\f
dbc4e1c1
JB
707;;;!! ;;;;
708;;;!! ;;;; Here are experimental things being tested. Mouse events
709;;;!! ;;;; are of the form:
710;;;!! ;;;; ((x y) window screen-part key-sequence timestamp)
711;;;!! ;;
712;;;!! ;;;;
713;;;!! ;;;; Dynamically track mouse coordinates
714;;;!! ;;;;
715;;;!! ;;
716;;;!! ;;(defun track-mouse (event)
717;;;!! ;; "Track the coordinates, absolute and relative, of the mouse."
718;;;!! ;; (interactive "@e")
719;;;!! ;; (while mouse-grabbed
720;;;!! ;; (let* ((pos (read-mouse-position (selected-screen)))
721;;;!! ;; (abs-x (car pos))
722;;;!! ;; (abs-y (cdr pos))
723;;;!! ;; (relative-coordinate (coordinates-in-window-p
724;;;!! ;; (list (car pos) (cdr pos))
725;;;!! ;; (selected-window))))
726;;;!! ;; (if (consp relative-coordinate)
727;;;!! ;; (message "mouse: [%d %d], (%d %d)" abs-x abs-y
728;;;!! ;; (car relative-coordinate)
729;;;!! ;; (car (cdr relative-coordinate)))
730;;;!! ;; (message "mouse: [%d %d]" abs-x abs-y)))))
731;;;!!
732;;;!! ;;
733;;;!! ;; Dynamically put a box around the line indicated by point
734;;;!! ;;
735;;;!! ;;
736;;;!! ;;(require 'backquote)
737;;;!! ;;
738;;;!! ;;(defun mouse-select-buffer-line (event)
739;;;!! ;; (interactive "@e")
740;;;!! ;; (let ((relative-coordinate
741;;;!! ;; (coordinates-in-window-p (car event) (selected-window)))
742;;;!! ;; (abs-y (car (cdr (car event)))))
743;;;!! ;; (if (consp relative-coordinate)
744;;;!! ;; (progn
745;;;!! ;; (save-excursion
746;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
747;;;!! ;; (x-draw-rectangle
748;;;!! ;; (selected-screen)
749;;;!! ;; abs-y 0
750;;;!! ;; (save-excursion
751;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
752;;;!! ;; (end-of-line)
753;;;!! ;; (push-mark nil t)
754;;;!! ;; (beginning-of-line)
755;;;!! ;; (- (region-end) (region-beginning))) 1))
756;;;!! ;; (sit-for 1)
757;;;!! ;; (x-erase-rectangle (selected-screen))))))
758;;;!! ;;
759;;;!! ;;(defvar last-line-drawn nil)
760;;;!! ;;(defvar begin-delim "[^ \t]")
761;;;!! ;;(defvar end-delim "[^ \t]")
762;;;!! ;;
763;;;!! ;;(defun mouse-boxing (event)
764;;;!! ;; (interactive "@e")
765;;;!! ;; (save-excursion
766;;;!! ;; (let ((screen (selected-screen)))
767;;;!! ;; (while (= (x-mouse-events) 0)
768;;;!! ;; (let* ((pos (read-mouse-position screen))
769;;;!! ;; (abs-x (car pos))
770;;;!! ;; (abs-y (cdr pos))
771;;;!! ;; (relative-coordinate
772;;;!! ;; (coordinates-in-window-p (` ((, abs-x) (, abs-y)))
773;;;!! ;; (selected-window)))
774;;;!! ;; (begin-reg nil)
775;;;!! ;; (end-reg nil)
776;;;!! ;; (end-column nil)
777;;;!! ;; (begin-column nil))
778;;;!! ;; (if (and (consp relative-coordinate)
779;;;!! ;; (or (not last-line-drawn)
780;;;!! ;; (not (= last-line-drawn abs-y))))
781;;;!! ;; (progn
782;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
783;;;!! ;; (if (= (following-char) 10)
784;;;!! ;; ()
785;;;!! ;; (progn
786;;;!! ;; (setq begin-reg (1- (re-search-forward end-delim)))
787;;;!! ;; (setq begin-column (1- (current-column)))
788;;;!! ;; (end-of-line)
789;;;!! ;; (setq end-reg (1+ (re-search-backward begin-delim)))
790;;;!! ;; (setq end-column (1+ (current-column)))
791;;;!! ;; (message "%s" (buffer-substring begin-reg end-reg))
792;;;!! ;; (x-draw-rectangle screen
793;;;!! ;; (setq last-line-drawn abs-y)
794;;;!! ;; begin-column
795;;;!! ;; (- end-column begin-column) 1))))))))))
796;;;!! ;;
797;;;!! ;;(defun mouse-erase-box ()
798;;;!! ;; (interactive)
799;;;!! ;; (if last-line-drawn
800;;;!! ;; (progn
801;;;!! ;; (x-erase-rectangle (selected-screen))
802;;;!! ;; (setq last-line-drawn nil))))
803;;;!!
804;;;!! ;;; (defun test-x-rectangle ()
805;;;!! ;;; (use-local-mouse-map (setq rectangle-test-map (make-sparse-keymap)))
806;;;!! ;;; (define-key rectangle-test-map mouse-motion-button-left 'mouse-boxing)
807;;;!! ;;; (define-key rectangle-test-map mouse-button-left-up 'mouse-erase-box))
808;;;!!
809;;;!! ;;
810;;;!! ;; Here is how to do double clicking in lisp. About to change.
811;;;!! ;;
812;;;!!
813;;;!! (defvar double-start nil)
814;;;!! (defconst double-click-interval 300
815;;;!! "Max ticks between clicks")
816;;;!!
817;;;!! (defun double-down (event)
818;;;!! (interactive "@e")
819;;;!! (if double-start
820;;;!! (let ((interval (- (nth 4 event) double-start)))
821;;;!! (if (< interval double-click-interval)
822;;;!! (progn
823;;;!! (backward-up-list 1)
824;;;!! ;; (message "Interval %d" interval)
825;;;!! (sleep-for 1)))
826;;;!! (setq double-start nil))
827;;;!! (setq double-start (nth 4 event))))
828;;;!!
829;;;!! (defun double-up (event)
830;;;!! (interactive "@e")
831;;;!! (and double-start
832;;;!! (> (- (nth 4 event ) double-start) double-click-interval)
833;;;!! (setq double-start nil)))
834;;;!!
835;;;!! ;;; (defun x-test-doubleclick ()
836;;;!! ;;; (use-local-mouse-map (setq doubleclick-test-map (make-sparse-keymap)))
837;;;!! ;;; (define-key doubleclick-test-map mouse-button-left 'double-down)
838;;;!! ;;; (define-key doubleclick-test-map mouse-button-left-up 'double-up))
839;;;!!
840;;;!! ;;
5ba2dc3f 841;;;!! ;; This scrolls while button is depressed. Use preferable in scroll bar.
dbc4e1c1
JB
842;;;!! ;;
843;;;!!
844;;;!! (defvar scrolled-lines 0)
845;;;!! (defconst scroll-speed 1)
846;;;!!
847;;;!! (defun incr-scroll-down (event)
848;;;!! (interactive "@e")
849;;;!! (setq scrolled-lines 0)
850;;;!! (incremental-scroll scroll-speed))
851;;;!!
852;;;!! (defun incr-scroll-up (event)
853;;;!! (interactive "@e")
854;;;!! (setq scrolled-lines 0)
855;;;!! (incremental-scroll (- scroll-speed)))
856;;;!!
857;;;!! (defun incremental-scroll (n)
858;;;!! (while (= (x-mouse-events) 0)
859;;;!! (setq scrolled-lines (1+ (* scroll-speed scrolled-lines)))
860;;;!! (scroll-down n)
861;;;!! (sit-for 300 t)))
862;;;!!
863;;;!! (defun incr-scroll-stop (event)
864;;;!! (interactive "@e")
865;;;!! (message "Scrolled %d lines" scrolled-lines)
866;;;!! (setq scrolled-lines 0)
867;;;!! (sleep-for 1))
868;;;!!
869;;;!! ;;; (defun x-testing-scroll ()
870;;;!! ;;; (let ((scrolling-map (function mouse-vertical-scroll-bar-prefix)))
871;;;!! ;;; (define-key scrolling-map mouse-button-left 'incr-scroll-down)
872;;;!! ;;; (define-key scrolling-map mouse-button-right 'incr-scroll-up)
873;;;!! ;;; (define-key scrolling-map mouse-button-left-up 'incr-scroll-stop)
874;;;!! ;;; (define-key scrolling-map mouse-button-right-up 'incr-scroll-stop)))
875;;;!!
876;;;!! ;;
877;;;!! ;; Some playthings suitable for picture mode? They need work.
878;;;!! ;;
879;;;!!
880;;;!! (defun mouse-kill-rectangle (event)
881;;;!! "Kill the rectangle between point and the mouse cursor."
882;;;!! (interactive "@e")
883;;;!! (let ((point-save (point)))
884;;;!! (save-excursion
885;;;!! (mouse-set-point event)
886;;;!! (push-mark nil t)
887;;;!! (if (> point-save (point))
888;;;!! (kill-rectangle (point) point-save)
889;;;!! (kill-rectangle point-save (point))))))
890;;;!!
891;;;!! (defun mouse-open-rectangle (event)
892;;;!! "Kill the rectangle between point and the mouse cursor."
893;;;!! (interactive "@e")
894;;;!! (let ((point-save (point)))
895;;;!! (save-excursion
896;;;!! (mouse-set-point event)
897;;;!! (push-mark nil t)
898;;;!! (if (> point-save (point))
899;;;!! (open-rectangle (point) point-save)
900;;;!! (open-rectangle point-save (point))))))
901;;;!!
902;;;!! ;; Must be a better way to do this.
903;;;!!
904;;;!! (defun mouse-multiple-insert (n char)
905;;;!! (while (> n 0)
906;;;!! (insert char)
907;;;!! (setq n (1- n))))
908;;;!!
909;;;!! ;; What this could do is not finalize until button was released.
910;;;!!
911;;;!! (defun mouse-move-text (event)
912;;;!! "Move text from point to cursor position, inserting spaces."
913;;;!! (interactive "@e")
914;;;!! (let* ((relative-coordinate
915;;;!! (coordinates-in-window-p (car event) (selected-window))))
916;;;!! (if (consp relative-coordinate)
917;;;!! (cond ((> (current-column) (car relative-coordinate))
918;;;!! (delete-char
919;;;!! (- (car relative-coordinate) (current-column))))
920;;;!! ((< (current-column) (car relative-coordinate))
921;;;!! (mouse-multiple-insert
922;;;!! (- (car relative-coordinate) (current-column)) " "))
923;;;!! ((= (current-column) (car relative-coordinate)) (ding))))))
07a78410 924\f
f936ae06
RS
925;; Choose a completion with the mouse.
926
927(defun mouse-choose-completion (event)
49e61c42 928 "Click on an alternative in the `*Completions*' buffer to choose it."
f936ae06
RS
929 (interactive "e")
930 (let (choice)
931 (save-excursion
932 (set-buffer (window-buffer (posn-window (event-start event))))
933 (save-excursion
934 (goto-char (posn-point (event-start event)))
935 (skip-chars-backward "^ \t\n")
936 (let ((beg (point)))
937 (skip-chars-forward "^ \t\n")
938 (setq choice (buffer-substring beg (point))))))
324710ca
RS
939 (set-buffer (window-buffer (minibuffer-window)))
940 (goto-char (max (point-min) (- (point-max) (length choice))))
941 (while (and (not (eobp))
942 (let ((tail (buffer-substring (point) (point-max))))
943 (not (string= tail (substring choice 0 (length tail))))))
944 (forward-char 1))
945 (insert choice)
946 (delete-region (point) (point-max))
947 (minibuffer-complete-and-exit)))
f936ae06 948\f
07a78410
RS
949;; Font selection.
950
0eb9fef3
RS
951(defun font-menu-add-default ()
952 (let* ((default (cdr (assq 'font (frame-parameters (selected-frame)))))
953 (font-alist x-fixed-font-alist)
0d94f5ca 954 (elt (or (assoc "Misc" font-alist) (nth 1 font-alist))))
0eb9fef3
RS
955 (if (assoc "Default" elt)
956 (delete (assoc "Default" elt) elt))
957 (setcdr elt
3d64d15b 958 (cons (list "Default"
0eb9fef3
RS
959 (cdr (assq 'font (frame-parameters (selected-frame)))))
960 (cdr elt)))))
961
07a78410
RS
962(defvar x-fixed-font-alist
963 '("Font menu"
964 ("Misc"
fa21fdec
RS
965 ("6x10" "-misc-fixed-medium-r-semicondensed--10-110-75-75-c-60-*-1")
966 ("6x12" "-misc-fixed-medium-r-semicondensed--12-110-75-75-c-60-*-1")
967 ("6x13" "-misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-*-1")
968 ("lucida 13"
969 "-b&h-lucidatypewriter-medium-r-normal-sans-0-0-0-0-m-0-*-1")
970 ("7x13" "-misc-fixed-medium-r-normal--13-120-75-75-c-70-*-1")
971 ("7x14" "-misc-fixed-medium-r-normal--14-130-75-75-c-70-*-1")
972 ("9x15" "-misc-fixed-medium-r-normal--15-140-*-*-c-*-*-1")
973 ("")
974 ("clean 8x8" "-schumacher-clean-medium-r-normal--*-80-*-*-c-*-*-1")
975 ("clean 8x14" "-schumacher-clean-medium-r-normal--*-140-*-*-c-*-*-1")
976 ("clean 8x10" "-schumacher-clean-medium-r-normal--*-100-*-*-c-*-*-1")
977 ("clean 8x16" "-schumacher-clean-medium-r-normal--*-160-*-*-c-*-*-1")
978 ("")
979 ("sony 8x16" "-sony-fixed-medium-r-normal--16-120-100-100-c-80-*-1")
980 ("")
07a78410 981 ("fixed" "fixed")
07a78410
RS
982 ("10x20" "10x20")
983 ("11x18" "11x18")
984 ("12x24" "12x24"))
985;;; We don't seem to have these; who knows what they are.
986;;; ("fg-18" "fg-18")
987;;; ("fg-25" "fg-25")
988;;; ("lucidasanstypewriter-12" "lucidasanstypewriter-12")
989;;; ("lucidasanstypewriter-bold-14" "lucidasanstypewriter-bold-14")
990;;; ("lucidasanstypewriter-bold-24" "lucidasanstypewriter-bold-24")
991;;; ("lucidatypewriter-bold-r-24" "-b&h-lucidatypewriter-bold-r-normal-sans-24-240-75-75-m-140-iso8859-1")
992;;; ("fixed-medium-20" "-misc-fixed-medium-*-*-*-20-*-*-*-*-*-*-*")
993 ("Courier"
82c048a9
RS
994 ("8" "-adobe-courier-medium-r-normal--*-80-*-*-m-*-iso8859-1")
995 ("10" "-adobe-courier-medium-r-normal--*-100-*-*-m-*-iso8859-1")
996 ("12" "-adobe-courier-medium-r-normal--*-120-*-*-m-*-iso8859-1")
997 ("14" "-adobe-courier-medium-r-normal--*-140-*-*-m-*-iso8859-1")
998 ("18" "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1")
999 ("24" "-adobe-courier-medium-r-normal--*-240-*-*-m-*-iso8859-1")
1000 ("8 bold" "-adobe-courier-bold-r-normal--*-80-*-*-m-*-iso8859-1")
1001 ("10 bold" "-adobe-courier-bold-r-normal--*-100-*-*-m-*-iso8859-1")
1002 ("12 bold" "-adobe-courier-bold-r-normal--*-120-*-*-m-*-iso8859-1")
1003 ("14 bold" "-adobe-courier-bold-r-normal--*-140-*-*-m-*-iso8859-1")
1004 ("18 bold" "-adobe-courier-bold-r-normal--*-180-*-*-m-*-iso8859-1")
1005 ("24 bold" "-adobe-courier-bold-r-normal--*-240-*-*-m-*-iso8859-1")
1006 ("8 slant" "-adobe-courier-medium-o-normal--*-80-*-*-m-*-iso8859-1")
1007 ("10 slant" "-adobe-courier-medium-o-normal--*-100-*-*-m-*-iso8859-1")
1008 ("12 slant" "-adobe-courier-medium-o-normal--*-120-*-*-m-*-iso8859-1")
1009 ("14 slant" "-adobe-courier-medium-o-normal--*-140-*-*-m-*-iso8859-1")
1010 ("18 slant" "-adobe-courier-medium-o-normal--*-180-*-*-m-*-iso8859-1")
1011 ("24 slant" "-adobe-courier-medium-o-normal--*-240-*-*-m-*-iso8859-1")
1012 ("8 bold slant" "-adobe-courier-bold-o-normal--*-80-*-*-m-*-iso8859-1")
1013 ("10 bold slant" "-adobe-courier-bold-o-normal--*-100-*-*-m-*-iso8859-1")
1014 ("12 bold slant" "-adobe-courier-bold-o-normal--*-120-*-*-m-*-iso8859-1")
1015 ("14 bold slant" "-adobe-courier-bold-o-normal--*-140-*-*-m-*-iso8859-1")
1016 ("18 bold slant" "-adobe-courier-bold-o-normal--*-180-*-*-m-*-iso8859-1")
1017 ("24 bold slant" "-adobe-courier-bold-o-normal--*-240-*-*-m-*-iso8859-1"))
07a78410
RS
1018 )
1019 "X fonts suitable for use in Emacs.")
1020
dbc4e1c1 1021(defun mouse-set-font (&optional font)
07a78410
RS
1022 "Select an emacs font from a list of known good fonts"
1023 (interactive
1024 (x-popup-menu last-nonmenu-event x-fixed-font-alist))
dbc4e1c1 1025 (if font
26d86f19
RS
1026 (progn (modify-frame-parameters (selected-frame)
1027 (list (cons 'font font)))
1028 ;; Update some standard faces too.
1029 (set-face-font 'bold nil (selected-frame))
1030 (make-face-bold 'bold (selected-frame) t)
1031 (set-face-font 'italic nil (selected-frame))
1032 (make-face-italic 'italic (selected-frame) t)
1033 (set-face-font 'bold-italic nil (selected-frame))
1034 (make-face-bold-italic 'bold-italic (selected-frame) t))))
cc0a8174
JB
1035\f
1036;;; Bindings for mouse commands.
1037
fcfc3c63 1038(define-key global-map [down-mouse-1] 'mouse-drag-region)
dbc4e1c1 1039(global-set-key [mouse-1] 'mouse-set-point)
dbc4e1c1 1040(global-set-key [drag-mouse-1] 'mouse-set-region)
fcfc3c63 1041
e37de120
RS
1042;; These are tested for in mouse-drag-region.
1043(global-set-key [double-mouse-1] 'mouse-set-point)
1044(global-set-key [triple-mouse-1] 'mouse-set-point)
1045
dbc4e1c1
JB
1046(global-set-key [mouse-2] 'mouse-yank-at-click)
1047(global-set-key [mouse-3] 'mouse-save-then-kill)
8b34e79d 1048
dbc4e1c1
JB
1049;; By binding these to down-going events, we let the user use the up-going
1050;; event to make the selection, saving a click.
1051(global-set-key [C-down-mouse-1] 'mouse-buffer-menu)
1052(global-set-key [C-down-mouse-3] 'mouse-set-font)
07a78410 1053
8b34e79d
RS
1054;; Replaced with dragging mouse-1
1055;; (global-set-key [S-mouse-1] 'mouse-set-mark)
947da0c4 1056
dbc4e1c1
JB
1057(global-set-key [mode-line mouse-1] 'mouse-delete-other-windows)
1058(global-set-key [mode-line mouse-3] 'mouse-delete-window)
1059(global-set-key [mode-line S-mouse-2] 'mouse-split-window-horizontally)
8b34e79d 1060\f
6b2154de
RS
1061;; Define the mouse help menu tree.
1062
8b34e79d 1063(defvar help-menu-map '(keymap "Help"))
dbc4e1c1
JB
1064(global-set-key [C-down-mouse-2] help-menu-map)
1065
1066(defvar help-apropos-map (make-sparse-keymap "Is there a command that..."))
1067(defvar help-keys-map (make-sparse-keymap "Key Commands <==> Functions"))
1068(defvar help-manual-map (make-sparse-keymap "Manual and tutorial"))
1069(defvar help-misc-map (make-sparse-keymap "Odds and ends"))
1070(defvar help-modes-map (make-sparse-keymap "Modes"))
1071(defvar help-admin-map (make-sparse-keymap "Administrivia"))
8b34e79d 1072
e7691e9c 1073(define-key help-menu-map [apropos]
6ec3899e 1074 (cons "@Is there a command that..." help-apropos-map))
e7691e9c 1075(define-key help-menu-map [keys]
6ec3899e 1076 (cons "@Key Commands <==> Functions" help-keys-map))
e7691e9c 1077(define-key help-menu-map [manuals]
6ec3899e 1078 (cons "@Manual and tutorial" help-manual-map))
e7691e9c 1079(define-key help-menu-map [misc]
6ec3899e 1080 (cons "@Odds and ends" help-misc-map))
e7691e9c 1081(define-key help-menu-map [modes]
6ec3899e 1082 (cons "@Modes" help-modes-map))
e7691e9c 1083(define-key help-menu-map [admin]
6ec3899e 1084 (cons "@Administrivia" help-admin-map))
8b34e79d
RS
1085
1086(define-key help-apropos-map "c" '("Command Apropos" . command-apropos))
1087(define-key help-apropos-map "a" '("Apropos" . apropos))
1088
1089(define-key help-keys-map "b"
1090 '("List all keystroke commands" . describe-bindings))
1091(define-key help-keys-map "c"
1092 '("Describe key briefly" . describe-key-briefly))
1093(define-key help-keys-map "k"
1094 '("Describe key verbose" . describe-key))
1095(define-key help-keys-map "f"
1096 '("Describe Lisp function" . describe-function))
1097(define-key help-keys-map "w"
1098 '("Where is this command" . where-is))
1099
1100(define-key help-manual-map "i" '("Info system" . info))
1101(define-key help-manual-map "t"
1102 '("Invoke Emacs tutorial" . help-with-tutorial))
1103
1104(define-key help-misc-map "l" '("Last 100 Keystrokes" . view-lossage))
1105(define-key help-misc-map "s" '("Describe syntax table" . describe-syntax))
1106
1107(define-key help-modes-map "m"
1108 '("Describe current major mode" . describe-mode))
1109(define-key help-modes-map "b"
1110 '("List all keystroke commands" . describe-bindings))
1111
1112(define-key help-admin-map "n"
8b213da7 1113 '("View Emacs news" . view-emacs-news))
8b34e79d 1114(define-key help-admin-map "l"
8b213da7 1115 '("View Emacs copying conditions" . describe-copying))
8b34e79d
RS
1116(define-key help-admin-map "d"
1117 '("Describe distribution" . describe-distribution))
1118(define-key help-admin-map "w"
1119 '("Describe (non)warranty" . describe-no-warranty))
49116ac0
JB
1120
1121(provide 'mouse)
1122
6594deb0 1123;;; mouse.el ends here