Mercurial > emacs
annotate lisp/xt-mouse.el @ 76563:68ddc580d34e
*** empty log message ***
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Mon, 19 Mar 2007 05:42:21 +0000 |
parents | e3694f1cb928 |
children | ee5fbf83e732 b8d9a391daf3 95d0cdf160ea |
rev | line source |
---|---|
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
38178
diff
changeset
|
1 ;;; xt-mouse.el --- support the mouse when emacs run in an xterm |
14169 | 2 |
64762
41bb365f41c4
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64091
diff
changeset
|
3 ;; Copyright (C) 1994, 2000, 2001, 2002, 2003, |
75347 | 4 ;; 2004, 2005, 2006, 2007 Free Software Foundation, Inc. |
13163 | 5 |
17982 | 6 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk> |
13163 | 7 ;; Keywords: mouse, terminals |
8 | |
14169 | 9 ;; This file is part of GNU Emacs. |
10 | |
11 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
13163 | 12 ;; it under the terms of the GNU General Public License as published by |
13 ;; the Free Software Foundation; either version 2, or (at your option) | |
14 ;; any later version. | |
14169 | 15 |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
13163 | 17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
14169 | 20 |
13163 | 21 ;; You should have received a copy of the GNU General Public License |
14169 | 22 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
64091 | 23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
24 ;; Boston, MA 02110-1301, USA. | |
13163 | 25 |
27803 | 26 ;;; Commentary: |
13163 | 27 |
59594
7ce4342aac7f
(xterm-mouse-event): Set new optional fourth arg in
Nick Roberts <nickrob@snap.net.nz>
parents:
59531
diff
changeset
|
28 ;; Enable mouse support when running inside an xterm. |
13163 | 29 |
30 ;; This is actually useful when you are running X11 locally, but is | |
31 ;; working on remote machine over a modem line or through a gateway. | |
32 | |
33 ;; It works by translating xterm escape codes into generic emacs mouse | |
34 ;; events so it should work with any package that uses the mouse. | |
35 | |
14750 | 36 ;; You don't have to turn off xterm mode to use the normal xterm mouse |
37 ;; functionality, it is still available by holding down the SHIFT key | |
38 ;; when you press the mouse button. | |
39 | |
13163 | 40 ;;; Todo: |
41 | |
42 ;; Support multi-click -- somehow. | |
43 | |
27803 | 44 ;;; Code: |
13163 | 45 |
46 (define-key function-key-map "\e[M" 'xterm-mouse-translate) | |
47 | |
13920
3a5b5eeba5b5
(xterm-mouse-translate, xterm-mouse-event):
Richard M. Stallman <rms@gnu.org>
parents:
13500
diff
changeset
|
48 (defvar xterm-mouse-last) |
3a5b5eeba5b5
(xterm-mouse-translate, xterm-mouse-event):
Richard M. Stallman <rms@gnu.org>
parents:
13500
diff
changeset
|
49 |
59497
255a31569c3f
(xterm-mouse-translate, xterm-mouse-event): Enable
Nick Roberts <nickrob@snap.net.nz>
parents:
58875
diff
changeset
|
50 ;; Mouse events symbols must have an 'event-kind property with |
255a31569c3f
(xterm-mouse-translate, xterm-mouse-event): Enable
Nick Roberts <nickrob@snap.net.nz>
parents:
58875
diff
changeset
|
51 ;; the value 'mouse-click. |
255a31569c3f
(xterm-mouse-translate, xterm-mouse-event): Enable
Nick Roberts <nickrob@snap.net.nz>
parents:
58875
diff
changeset
|
52 (dolist (event-type '(mouse-1 mouse-2 mouse-3)) |
255a31569c3f
(xterm-mouse-translate, xterm-mouse-event): Enable
Nick Roberts <nickrob@snap.net.nz>
parents:
58875
diff
changeset
|
53 (put event-type 'event-kind 'mouse-click)) |
255a31569c3f
(xterm-mouse-translate, xterm-mouse-event): Enable
Nick Roberts <nickrob@snap.net.nz>
parents:
58875
diff
changeset
|
54 |
13163 | 55 (defun xterm-mouse-translate (event) |
27803 | 56 "Read a click and release event from XTerm." |
13163 | 57 (save-excursion |
58 (save-window-excursion | |
59 (deactivate-mark) | |
13920
3a5b5eeba5b5
(xterm-mouse-translate, xterm-mouse-event):
Richard M. Stallman <rms@gnu.org>
parents:
13500
diff
changeset
|
60 (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
|
61 (down (xterm-mouse-event)) |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
62 (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
|
63 (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
|
64 (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
|
65 (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
|
66 (vector down-where down-command) |
38563
75f49513b989
(xterm-mouse-event): Recognize control sequences
Gerd Moellmann <gerd@gnu.org>
parents:
38436
diff
changeset
|
67 (vector down-command)))) |
75f49513b989
(xterm-mouse-event): Recognize control sequences
Gerd Moellmann <gerd@gnu.org>
parents:
38436
diff
changeset
|
68 (is-click (string-match "^mouse" (symbol-name (car down))))) |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
46836
diff
changeset
|
69 |
38563
75f49513b989
(xterm-mouse-event): Recognize control sequences
Gerd Moellmann <gerd@gnu.org>
parents:
38436
diff
changeset
|
70 (unless is-click |
75f49513b989
(xterm-mouse-event): Recognize control sequences
Gerd Moellmann <gerd@gnu.org>
parents:
38436
diff
changeset
|
71 (unless (and (eq (read-char) ?\e) |
75f49513b989
(xterm-mouse-event): Recognize control sequences
Gerd Moellmann <gerd@gnu.org>
parents:
38436
diff
changeset
|
72 (eq (read-char) ?\[) |
75f49513b989
(xterm-mouse-event): Recognize control sequences
Gerd Moellmann <gerd@gnu.org>
parents:
38436
diff
changeset
|
73 (eq (read-char) ?M)) |
75f49513b989
(xterm-mouse-event): Recognize control sequences
Gerd Moellmann <gerd@gnu.org>
parents:
38436
diff
changeset
|
74 (error "Unexpected escape sequence from XTerm"))) |
75f49513b989
(xterm-mouse-event): Recognize control sequences
Gerd Moellmann <gerd@gnu.org>
parents:
38436
diff
changeset
|
75 |
75f49513b989
(xterm-mouse-event): Recognize control sequences
Gerd Moellmann <gerd@gnu.org>
parents:
38436
diff
changeset
|
76 (let* ((click (if is-click down (xterm-mouse-event))) |
13500
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
77 (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
|
78 (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
|
79 (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
|
80 (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
|
81 (if (and (symbolp click-where) |
59497
255a31569c3f
(xterm-mouse-translate, xterm-mouse-event): Enable
Nick Roberts <nickrob@snap.net.nz>
parents:
58875
diff
changeset
|
82 (consp click-where)) |
13500
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
83 (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
|
84 (vector click)) |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
85 (setq unread-command-events |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
86 (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
|
87 (list click) |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
88 (list |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
89 ;; 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
|
90 (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
|
91 ;; Generate a drag event. |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
92 (if (symbolp down-where) |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
93 0 |
27803 | 94 (list (intern (format "drag-mouse-%d" |
95 (+ 1 xterm-mouse-last))) | |
59497
255a31569c3f
(xterm-mouse-translate, xterm-mouse-event): Enable
Nick Roberts <nickrob@snap.net.nz>
parents:
58875
diff
changeset
|
96 down-data click-data))))) |
13500
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
97 (if (and (symbolp down-where) |
59497
255a31569c3f
(xterm-mouse-translate, xterm-mouse-event): Enable
Nick Roberts <nickrob@snap.net.nz>
parents:
58875
diff
changeset
|
98 (consp down-where)) |
13500
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
99 (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
|
100 (vector down)))))))) |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
101 |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
102 (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
|
103 "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
|
104 |
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
105 (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
|
106 "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
|
107 |
23823
d60ff4432412
(xterm-mouse-mode): Pacify the byte compiler.
Markus Rost <rost@math.uni-bielefeld.de>
parents:
21270
diff
changeset
|
108 ;; Indicator for the xterm-mouse mode. |
d60ff4432412
(xterm-mouse-mode): Pacify the byte compiler.
Markus Rost <rost@math.uni-bielefeld.de>
parents:
21270
diff
changeset
|
109 |
27803 | 110 (defun xterm-mouse-position-function (pos) |
111 "Bound to `mouse-position-function' in XTerm mouse mode." | |
112 (setcdr pos (cons xterm-mouse-x xterm-mouse-y)) | |
113 pos) | |
13163 | 114 |
50478
4c84e707a287
(xterm-mouse-event-read): New function.
Francesco Potortì <pot@gnu.org>
parents:
49597
diff
changeset
|
115 ;; read xterm sequences above ascii 127 (#x7f) |
4c84e707a287
(xterm-mouse-event-read): New function.
Francesco Potortì <pot@gnu.org>
parents:
49597
diff
changeset
|
116 (defun xterm-mouse-event-read () |
4c84e707a287
(xterm-mouse-event-read): New function.
Francesco Potortì <pot@gnu.org>
parents:
49597
diff
changeset
|
117 (let ((c (read-char))) |
4c84e707a287
(xterm-mouse-event-read): New function.
Francesco Potortì <pot@gnu.org>
parents:
49597
diff
changeset
|
118 (if (< c 0) |
4c84e707a287
(xterm-mouse-event-read): New function.
Francesco Potortì <pot@gnu.org>
parents:
49597
diff
changeset
|
119 (+ c #x8000000 128) |
4c84e707a287
(xterm-mouse-event-read): New function.
Francesco Potortì <pot@gnu.org>
parents:
49597
diff
changeset
|
120 c))) |
4c84e707a287
(xterm-mouse-event-read): New function.
Francesco Potortì <pot@gnu.org>
parents:
49597
diff
changeset
|
121 |
13163 | 122 (defun xterm-mouse-event () |
27803 | 123 "Convert XTerm mouse event to Emacs mouse event." |
50478
4c84e707a287
(xterm-mouse-event-read): New function.
Francesco Potortì <pot@gnu.org>
parents:
49597
diff
changeset
|
124 (let* ((type (- (xterm-mouse-event-read) #o40)) |
4c84e707a287
(xterm-mouse-event-read): New function.
Francesco Potortì <pot@gnu.org>
parents:
49597
diff
changeset
|
125 (x (- (xterm-mouse-event-read) #o40 1)) |
4c84e707a287
(xterm-mouse-event-read): New function.
Francesco Potortì <pot@gnu.org>
parents:
49597
diff
changeset
|
126 (y (- (xterm-mouse-event-read) #o40 1)) |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
46836
diff
changeset
|
127 (mouse (intern |
38563
75f49513b989
(xterm-mouse-event): Recognize control sequences
Gerd Moellmann <gerd@gnu.org>
parents:
38436
diff
changeset
|
128 ;; For buttons > 3, the release-event looks |
75f49513b989
(xterm-mouse-event): Recognize control sequences
Gerd Moellmann <gerd@gnu.org>
parents:
38436
diff
changeset
|
129 ;; differently (see xc/programs/xterm/button.c, |
75f49513b989
(xterm-mouse-event): Recognize control sequences
Gerd Moellmann <gerd@gnu.org>
parents:
38436
diff
changeset
|
130 ;; function EditorButton), and there seems to come in |
75f49513b989
(xterm-mouse-event): Recognize control sequences
Gerd Moellmann <gerd@gnu.org>
parents:
38436
diff
changeset
|
131 ;; a release-event only, no down-event. |
75f49513b989
(xterm-mouse-event): Recognize control sequences
Gerd Moellmann <gerd@gnu.org>
parents:
38436
diff
changeset
|
132 (cond ((>= type 64) |
75f49513b989
(xterm-mouse-event): Recognize control sequences
Gerd Moellmann <gerd@gnu.org>
parents:
38436
diff
changeset
|
133 (format "mouse-%d" (- type 60))) |
75f49513b989
(xterm-mouse-event): Recognize control sequences
Gerd Moellmann <gerd@gnu.org>
parents:
38436
diff
changeset
|
134 ((= type 3) |
75f49513b989
(xterm-mouse-event): Recognize control sequences
Gerd Moellmann <gerd@gnu.org>
parents:
38436
diff
changeset
|
135 (format "mouse-%d" (+ 1 xterm-mouse-last))) |
75f49513b989
(xterm-mouse-event): Recognize control sequences
Gerd Moellmann <gerd@gnu.org>
parents:
38436
diff
changeset
|
136 (t |
75f49513b989
(xterm-mouse-event): Recognize control sequences
Gerd Moellmann <gerd@gnu.org>
parents:
38436
diff
changeset
|
137 (setq xterm-mouse-last type) |
59497
255a31569c3f
(xterm-mouse-translate, xterm-mouse-event): Enable
Nick Roberts <nickrob@snap.net.nz>
parents:
58875
diff
changeset
|
138 (format "down-mouse-%d" (+ 1 type)))))) |
59531
0b4694a3c513
(xterm-mouse-event): Compute window co-ordinates
Nick Roberts <nickrob@snap.net.nz>
parents:
59497
diff
changeset
|
139 (w (window-at x y)) |
0b4694a3c513
(xterm-mouse-event): Compute window co-ordinates
Nick Roberts <nickrob@snap.net.nz>
parents:
59497
diff
changeset
|
140 (ltrb (window-edges w)) |
0b4694a3c513
(xterm-mouse-event): Compute window co-ordinates
Nick Roberts <nickrob@snap.net.nz>
parents:
59497
diff
changeset
|
141 (left (nth 0 ltrb)) |
0b4694a3c513
(xterm-mouse-event): Compute window co-ordinates
Nick Roberts <nickrob@snap.net.nz>
parents:
59497
diff
changeset
|
142 (top (nth 1 ltrb))) |
0b4694a3c513
(xterm-mouse-event): Compute window co-ordinates
Nick Roberts <nickrob@snap.net.nz>
parents:
59497
diff
changeset
|
143 |
13500
5de4c8a3f702
(global-map): Removed bindings of down events to ignore.
Richard M. Stallman <rms@gnu.org>
parents:
13163
diff
changeset
|
144 (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
|
145 xterm-mouse-y y) |
67176
c1b362058986
(xterm-mouse-event): Set last-input-event so
Nick Roberts <nickrob@snap.net.nz>
parents:
64762
diff
changeset
|
146 (setq |
c1b362058986
(xterm-mouse-event): Set last-input-event so
Nick Roberts <nickrob@snap.net.nz>
parents:
64762
diff
changeset
|
147 last-input-event |
c1b362058986
(xterm-mouse-event): Set last-input-event so
Nick Roberts <nickrob@snap.net.nz>
parents:
64762
diff
changeset
|
148 (if w |
c1b362058986
(xterm-mouse-event): Set last-input-event so
Nick Roberts <nickrob@snap.net.nz>
parents:
64762
diff
changeset
|
149 (list mouse (posn-at-x-y (- x left) (- y top) w t)) |
c1b362058986
(xterm-mouse-event): Set last-input-event so
Nick Roberts <nickrob@snap.net.nz>
parents:
64762
diff
changeset
|
150 (list mouse |
c1b362058986
(xterm-mouse-event): Set last-input-event so
Nick Roberts <nickrob@snap.net.nz>
parents:
64762
diff
changeset
|
151 (append (list nil 'menu-bar) (nthcdr 2 (posn-at-x-y x y w t)))))))) |
13163 | 152 |
153 ;;;###autoload | |
44520
53a8da1bdd13
(xterm-mouse-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41814
diff
changeset
|
154 (define-minor-mode xterm-mouse-mode |
13163 | 155 "Toggle XTerm mouse mode. |
156 With prefix arg, turn XTerm mouse mode on iff arg is positive. | |
157 | |
61255
321e7372c394
(xterm-mouse-mode): Add explicit Custom group (mouse). Doc fix.
Luc Teirlinck <teirllm@auburn.edu>
parents:
59594
diff
changeset
|
158 Turn it on to use Emacs mouse commands, and off to use xterm mouse commands. |
61513
a53097b105b0
(xterm-mouse-mode): Provide correct standard value for Custom. No
Luc Teirlinck <teirllm@auburn.edu>
parents:
61255
diff
changeset
|
159 This works in terminal emulators compatible with xterm. It only |
a53097b105b0
(xterm-mouse-mode): Provide correct standard value for Custom. No
Luc Teirlinck <teirllm@auburn.edu>
parents:
61255
diff
changeset
|
160 works for simple uses of the mouse. Basically, only non-modified |
a53097b105b0
(xterm-mouse-mode): Provide correct standard value for Custom. No
Luc Teirlinck <teirllm@auburn.edu>
parents:
61255
diff
changeset
|
161 single clicks are supported. When turned on, the normal xterm |
a53097b105b0
(xterm-mouse-mode): Provide correct standard value for Custom. No
Luc Teirlinck <teirllm@auburn.edu>
parents:
61255
diff
changeset
|
162 mouse functionality for such clicks is still available by holding |
a53097b105b0
(xterm-mouse-mode): Provide correct standard value for Custom. No
Luc Teirlinck <teirllm@auburn.edu>
parents:
61255
diff
changeset
|
163 down the SHIFT key while pressing the mouse button." |
a53097b105b0
(xterm-mouse-mode): Provide correct standard value for Custom. No
Luc Teirlinck <teirllm@auburn.edu>
parents:
61255
diff
changeset
|
164 :global t :group 'mouse |
44520
53a8da1bdd13
(xterm-mouse-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41814
diff
changeset
|
165 (if xterm-mouse-mode |
53a8da1bdd13
(xterm-mouse-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41814
diff
changeset
|
166 ;; Turn it on |
53a8da1bdd13
(xterm-mouse-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41814
diff
changeset
|
167 (unless window-system |
53a8da1bdd13
(xterm-mouse-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41814
diff
changeset
|
168 (setq mouse-position-function #'xterm-mouse-position-function) |
53a8da1bdd13
(xterm-mouse-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41814
diff
changeset
|
169 (turn-on-xterm-mouse-tracking)) |
53a8da1bdd13
(xterm-mouse-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41814
diff
changeset
|
170 ;; Turn it off |
53a8da1bdd13
(xterm-mouse-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41814
diff
changeset
|
171 (turn-off-xterm-mouse-tracking 'force) |
53a8da1bdd13
(xterm-mouse-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41814
diff
changeset
|
172 (setq mouse-position-function nil))) |
13163 | 173 |
174 (defun turn-on-xterm-mouse-tracking () | |
27803 | 175 "Enable Emacs mouse tracking in xterm." |
13163 | 176 (if xterm-mouse-mode |
177 (send-string-to-terminal "\e[?1000h"))) | |
178 | |
44520
53a8da1bdd13
(xterm-mouse-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41814
diff
changeset
|
179 (defun turn-off-xterm-mouse-tracking (&optional force) |
41814
42c496dc0b7d
(turn-off-xterm-mouse-tracking): Doc fix.
Andreas Schwab <schwab@suse.de>
parents:
38563
diff
changeset
|
180 "Disable Emacs mouse tracking in xterm." |
44520
53a8da1bdd13
(xterm-mouse-mode): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41814
diff
changeset
|
181 (if (or force xterm-mouse-mode) |
13163 | 182 (send-string-to-terminal "\e[?1000l"))) |
183 | |
184 ;; Restore normal mouse behaviour outside Emacs. | |
185 (add-hook 'suspend-hook 'turn-off-xterm-mouse-tracking) | |
186 (add-hook 'suspend-resume-hook 'turn-on-xterm-mouse-tracking) | |
187 (add-hook 'kill-emacs-hook 'turn-off-xterm-mouse-tracking) | |
188 | |
189 (provide 'xt-mouse) | |
190 | |
52401 | 191 ;;; arch-tag: 84962d4e-fae9-4c13-a9d7-ef4925a4ac03 |
13163 | 192 ;;; xt-mouse.el ends here |