Mercurial > emacs
annotate lisp/xt-mouse.el @ 14142:c9cb9dbb2d40
(vc-follow-symlinks): New variable.
(vc-find-file-hook): Use it.
author | André Spiegel <spiegel@gnu.org> |
---|---|
date | Wed, 10 Jan 1996 15:27:49 +0000 |
parents | 3a5b5eeba5b5 |
children | 83f275dcd93a |
rev | line source |
---|---|
13163 | 1 ;;; xt-mouse.el --- Support the mouse when emacs run in an xterm. |
2 ;; Copyright (C) 1994 Free Software Foundation | |
3 | |
4 ;; Author: Per Abrahamsen <abraham@iesd.auc.dk> | |
5 ;; Keywords: mouse, terminals | |
6 | |
7 ;; This program is free software; you can redistribute it and/or modify | |
8 ;; it under the terms of the GNU General Public License as published by | |
9 ;; the Free Software Foundation; either version 2, or (at your option) | |
10 ;; any later version. | |
11 ;; | |
12 ;; This program is distributed in the hope that it will be useful, | |
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 ;; GNU General Public License for more details. | |
16 ;; | |
17 ;; You should have received a copy of the GNU General Public License | |
18 ;; along with this program; if not, write to the Free Software | |
19 ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
20 | |
21 ;;; Comments: | |
22 | |
23 ;; Enable mouse support when running inside an xterm. | |
24 | |
25 ;; This is actually useful when you are running X11 locally, but is | |
26 ;; working on remote machine over a modem line or through a gateway. | |
27 | |
28 ;; It works by translating xterm escape codes into generic emacs mouse | |
29 ;; events so it should work with any package that uses the mouse. | |
30 | |
31 ;;; Todo: | |
32 | |
33 ;; Support multi-click -- somehow. | |
34 | |
35 ;; Clicking on the mode-line does not work, although it should. | |
36 | |
37 ;;; Code: | |
38 | |
39 (define-key function-key-map "\e[M" 'xterm-mouse-translate) | |
40 | |
13920
3a5b5eeba5b5
(xterm-mouse-translate, xterm-mouse-event):
Richard M. Stallman <rms@gnu.org>
parents:
13500
diff
changeset
|
41 (defvar xterm-mouse-last) |
3a5b5eeba5b5
(xterm-mouse-translate, xterm-mouse-event):
Richard M. Stallman <rms@gnu.org>
parents:
13500
diff
changeset
|
42 |
13163 | 43 (defun xterm-mouse-translate (event) |
44 ;; Read a click and release event from XTerm. | |
45 (save-excursion | |
46 (save-window-excursion | |
47 (deactivate-mark) | |
13920
3a5b5eeba5b5
(xterm-mouse-translate, xterm-mouse-event):
Richard M. Stallman <rms@gnu.org>
parents:
13500
diff
changeset
|
48 (let* ((xterm-mouse-last) |
13500
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
49 (down (xterm-mouse-event)) |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
50 (down-command (nth 0 down)) |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
51 (down-data (nth 1 down)) |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
52 (down-where (nth 1 down-data)) |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
53 (down-binding (key-binding (if (symbolp down-where) |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
54 (vector down-where down-command) |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
55 (vector down-command))))) |
13163 | 56 (or (and (eq (read-char) ?\e) |
57 (eq (read-char) ?\[) | |
58 (eq (read-char) ?M)) | |
59 (error "Unexpected escape sequence from XTerm")) | |
13500
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
60 (let* ((click (xterm-mouse-event)) |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
61 (click-command (nth 0 click)) |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
62 (click-data (nth 1 click)) |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
63 (click-where (nth 1 click-data))) |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
64 (if (memq down-binding '(nil ignore)) |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
65 (if (and (symbolp click-where) |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
66 (not (eq 'menu-bar click-where))) |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
67 (vector (list click-where click-data) click) |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
68 (vector click)) |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
69 (setq unread-command-events |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
70 (if (eq down-where click-where) |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
71 (list click) |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
72 (list |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
73 ;; Cheat `mouse-drag-region' with move event. |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
74 (list 'mouse-movement click-data) |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
75 ;; Generate a drag event. |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
76 (if (symbolp down-where) |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
77 0 |
13920
3a5b5eeba5b5
(xterm-mouse-translate, xterm-mouse-event):
Richard M. Stallman <rms@gnu.org>
parents:
13500
diff
changeset
|
78 (list (intern (concat "drag-mouse-" (+ 1 xterm-mouse-last))) |
13500
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
79 down-data click-data)) |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
80 ))) |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
81 (if (and (symbolp down-where) |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
82 (not (eq 'menu-bar down-where))) |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
83 (vector (list down-where down-data) down) |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
84 (vector down)))))))) |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
85 |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
86 (defvar xterm-mouse-x 0 |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
87 "Position of last xterm mouse event relative to the frame.") |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
88 |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
89 (defvar xterm-mouse-y 0 |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
90 "Position of last xterm mouse event relative to the frame.") |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
91 |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
92 (defadvice mouse-position (around xterm-mouse activate) |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
93 "Use last key from xterm-mouse-mode if available." |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
94 (let ((answer ad-do-it)) |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
95 (setq ad-return-value |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
96 (if xterm-mouse-mode |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
97 (cons (car answer) (cons xterm-mouse-x xterm-mouse-y)) |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
98 answer)))) |
13163 | 99 |
100 (defun xterm-mouse-event () | |
101 ;; Convert XTerm mouse event to Emacs mouse event. | |
102 (let* ((type (- (read-char) ? )) | |
103 (x (- (read-char) ? 1)) | |
104 (y (- (read-char) ? 1)) | |
105 (point (cons x y)) | |
106 (window (window-at x y)) | |
13500
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
107 (where (if window |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
108 (coordinates-in-window-p point window) |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
109 'menu-bar)) |
13163 | 110 (pos (if (consp where) |
111 (progn | |
112 (select-window window) | |
113 (goto-char (window-start window)) | |
114 (move-to-window-line (cdr where)) | |
115 (move-to-column (+ (car where) (current-column) | |
116 (max 0 (1- (window-hscroll))))) | |
117 (point)) | |
118 where)) | |
119 (mouse (intern (if (eq type 3) | |
13920
3a5b5eeba5b5
(xterm-mouse-translate, xterm-mouse-event):
Richard M. Stallman <rms@gnu.org>
parents:
13500
diff
changeset
|
120 (concat "mouse-" (+ 1 xterm-mouse-last)) |
3a5b5eeba5b5
(xterm-mouse-translate, xterm-mouse-event):
Richard M. Stallman <rms@gnu.org>
parents:
13500
diff
changeset
|
121 (setq xterm-mouse-last type) |
13163 | 122 (concat "down-mouse-" (+ 1 type)))))) |
13500
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
123 (setq xterm-mouse-x x |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
124 xterm-mouse-y y) |
13163 | 125 (list mouse |
126 (list window pos point | |
127 (/ (nth 2 (current-time)) 1000))))) | |
128 | |
129 ;; Indicator for the xterm-mouse mode. | |
130 (defvar xterm-mouse-mode nil) | |
131 | |
132 (or (assq 'xterm-mouse-mode minor-mode-alist) | |
133 (setq minor-mode-alist | |
134 (cons '(xterm-mouse-mode (" Mouse")) minor-mode-alist))) | |
135 | |
136 ;;;###autoload | |
137 (defun xterm-mouse-mode (arg) | |
138 "Toggle XTerm mouse mode. | |
139 With prefix arg, turn XTerm mouse mode on iff arg is positive. | |
140 | |
141 Turn it on to use emacs mouse commands, and off to use xterm mouse commands." | |
142 (interactive "P") | |
143 (if (or (and (null arg) xterm-mouse-mode) | |
144 (<= (prefix-numeric-value arg) 0)) | |
145 ;; Turn it off | |
146 (if xterm-mouse-mode | |
147 (progn | |
148 (turn-off-xterm-mouse-tracking) | |
149 (setq xterm-mouse-mode nil) | |
150 (set-buffer-modified-p (buffer-modified-p)))) | |
151 ;;Turn it on | |
152 (if xterm-mouse-mode | |
153 () | |
154 (setq xterm-mouse-mode t) | |
155 (turn-on-xterm-mouse-tracking) | |
156 (set-buffer-modified-p (buffer-modified-p))))) | |
157 | |
158 (defun turn-on-xterm-mouse-tracking () | |
159 ;; Enable emacs mouse tracking in xterm. | |
160 (if xterm-mouse-mode | |
161 (send-string-to-terminal "\e[?1000h"))) | |
162 | |
163 (defun turn-off-xterm-mouse-tracking () | |
164 ;; Disable disable emacs mouse tracking in xterm. | |
165 (if xterm-mouse-mode | |
166 (send-string-to-terminal "\e[?1000l"))) | |
167 | |
168 ;; Restore normal mouse behaviour outside Emacs. | |
169 (add-hook 'suspend-hook 'turn-off-xterm-mouse-tracking) | |
170 (add-hook 'suspend-resume-hook 'turn-on-xterm-mouse-tracking) | |
171 (add-hook 'kill-emacs-hook 'turn-off-xterm-mouse-tracking) | |
172 | |
173 (provide 'xt-mouse) | |
174 | |
175 ;;; xt-mouse.el ends here |