Commit | Line | Data |
---|---|---|
e5167999 ER |
1 | ;;; sup-mouse.el --- supdup mouse support for lisp machines |
2 | ||
ba318903 | 3 | ;; Copyright (C) 1985-1986, 2001-2014 Free Software Foundation, Inc. |
58142744 | 4 | |
e5167999 ER |
5 | ;; Author: Wolfgang Rupprecht |
6 | ;; Maintainer: FSF | |
7 | ;; Created: 21 Nov 1986 | |
d7b4d18f | 8 | ;; Keywords: hardware |
27c8b6eb | 9 | ;; Obsolete-since: 24.4 |
e5167999 ER |
10 | |
11 | ;; (from code originally written by John Robinson@bbn for the bitgraph) | |
0d20f9a0 | 12 | |
0d20f9a0 JB |
13 | ;; This file is part of GNU Emacs. |
14 | ||
1fecc8fe | 15 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
0d20f9a0 | 16 | ;; it under the terms of the GNU General Public License as published by |
1fecc8fe GM |
17 | ;; the Free Software Foundation, either version 3 of the License, or |
18 | ;; (at your option) any later version. | |
0d20f9a0 JB |
19 | |
20 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
21 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
23 | ;; GNU General Public License for more details. | |
24 | ||
25 | ;; You should have received a copy of the GNU General Public License | |
1fecc8fe | 26 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
0d20f9a0 | 27 | |
55535639 PJ |
28 | ;;; Commentary: |
29 | ||
e5167999 ER |
30 | ;;; Code: |
31 | ||
0d20f9a0 JB |
32 | ;;; User customization option: |
33 | ||
53ef76c7 GM |
34 | (defcustom sup-mouse-fast-select-window nil |
35 | "Non-nil means mouse hits select new window, then execute. | |
36 | Otherwise just select." | |
37 | :type 'boolean | |
38 | :group 'mouse) | |
0d20f9a0 JB |
39 | |
40 | (defconst mouse-left 0) | |
41 | (defconst mouse-center 1) | |
42 | (defconst mouse-right 2) | |
43 | ||
44 | (defconst mouse-2left 4) | |
45 | (defconst mouse-2center 5) | |
46 | (defconst mouse-2right 6) | |
47 | ||
48 | (defconst mouse-3left 8) | |
49 | (defconst mouse-3center 9) | |
50 | (defconst mouse-3right 10) | |
51 | ||
52 | ;;; Defuns: | |
53 | ||
54 | (defun sup-mouse-report () | |
55 | "This function is called directly by the mouse, it parses and | |
56 | executes the mouse commands. | |
57 | ||
58 | L move point * |---- These apply for mouse click in a window. | |
59 | 2L delete word | | |
60 | 3L copy word | If sup-mouse-fast-select-window is nil, | |
61 | C move point and yank * | just selects that window. | |
62 | 2C yank pop | | |
63 | R set mark * | | |
64 | 2R delete region | | |
65 | 3R copy region | | |
66 | ||
37269466 | 67 | on mode line on \"scroll bar\" in minibuffer |
0d20f9a0 JB |
68 | L scroll-up line to top execute-extended-command |
69 | C proportional goto-char line to middle mouse-help | |
70 | R scroll-down line to bottom eval-expression" | |
db95369b | 71 | |
0d20f9a0 JB |
72 | (interactive) |
73 | (let* | |
74 | ;; expect a string of <esc>:<buttons>;<x-pos>;<y-pos>c | |
75 | ((buttons (sup-get-tty-num ?\;)) | |
76 | (x (sup-get-tty-num ?\;)) | |
77 | (y (sup-get-tty-num ?c)) | |
78 | (window (sup-pos-to-window x y)) | |
79 | (edges (window-edges window)) | |
80 | (old-window (selected-window)) | |
0cc89026 | 81 | (in-minibuf-p (eq y (1- (frame-height)))) |
0d20f9a0 | 82 | (same-window-p (and (not in-minibuf-p) (eq window old-window))) |
37269466 | 83 | (in-mode-line-p (eq y (1- (nth 3 edges)))) |
0d20f9a0 JB |
84 | (in-scrollbar-p (>= x (1- (nth 2 edges))))) |
85 | (setq x (- x (nth 0 edges))) | |
86 | (setq y (- y (nth 1 edges))) | |
87 | ||
88 | ; (error "mouse-hit %d %d %d" buttons x y) ;;;; debug | |
89 | ||
37269466 | 90 | (cond (in-mode-line-p |
0d20f9a0 JB |
91 | (select-window window) |
92 | (cond ((= buttons mouse-left) | |
93 | (scroll-up)) | |
94 | ((= buttons mouse-right) | |
95 | (scroll-down)) | |
96 | ((= buttons mouse-center) | |
97 | (goto-char (/ (* x | |
98 | (- (point-max) (point-min))) | |
99 | (1- (window-width)))) | |
100 | (beginning-of-line) | |
101 | (what-cursor-position))) | |
102 | (select-window old-window)) | |
103 | (in-scrollbar-p | |
104 | (select-window window) | |
105 | (scroll-up | |
106 | (cond ((= buttons mouse-left) | |
107 | y) | |
108 | ((= buttons mouse-right) | |
109 | (+ y (- 2 (window-height)))) | |
110 | ((= buttons mouse-center) | |
111 | (/ (+ 2 y y (- (window-height))) 2)) | |
112 | (t | |
113 | 0))) | |
114 | (select-window old-window)) | |
115 | (same-window-p | |
116 | (cond ((= buttons mouse-left) | |
117 | (sup-move-point-to-x-y x y)) | |
118 | ((= buttons mouse-2left) | |
119 | (sup-move-point-to-x-y x y) | |
120 | (kill-word 1)) | |
121 | ((= buttons mouse-3left) | |
122 | (sup-move-point-to-x-y x y) | |
123 | (save-excursion | |
124 | (copy-region-as-kill | |
125 | (point) (progn (forward-word 1) (point)))) | |
126 | (setq this-command 'yank) | |
127 | ) | |
128 | ((= buttons mouse-right) | |
129 | (push-mark) | |
130 | (sup-move-point-to-x-y x y) | |
131 | (exchange-point-and-mark)) | |
132 | ((= buttons mouse-2right) | |
133 | (push-mark) | |
134 | (sup-move-point-to-x-y x y) | |
135 | (kill-region (mark) (point))) | |
136 | ((= buttons mouse-3right) | |
137 | (push-mark) | |
138 | (sup-move-point-to-x-y x y) | |
139 | (copy-region-as-kill (mark) (point)) | |
140 | (setq this-command 'yank)) | |
141 | ((= buttons mouse-center) | |
142 | (sup-move-point-to-x-y x y) | |
143 | (setq this-command 'yank) | |
144 | (yank)) | |
145 | ((= buttons mouse-2center) | |
146 | (yank-pop 1)) | |
147 | ) | |
148 | ) | |
149 | (in-minibuf-p | |
150 | (cond ((= buttons mouse-right) | |
151 | (call-interactively 'eval-expression)) | |
152 | ((= buttons mouse-left) | |
153 | (call-interactively 'execute-extended-command)) | |
154 | ((= buttons mouse-center) | |
db95369b | 155 | (describe-function 'sup-mouse-report)); silly self help |
0d20f9a0 JB |
156 | )) |
157 | (t ;in another window | |
158 | (select-window window) | |
159 | (cond ((not sup-mouse-fast-select-window)) | |
160 | ((= buttons mouse-left) | |
161 | (sup-move-point-to-x-y x y)) | |
162 | ((= buttons mouse-right) | |
163 | (push-mark) | |
164 | (sup-move-point-to-x-y x y) | |
165 | (exchange-point-and-mark)) | |
166 | ((= buttons mouse-center) | |
167 | (sup-move-point-to-x-y x y) | |
168 | (setq this-command 'yank) | |
169 | (yank)) | |
170 | )) | |
171 | ))) | |
172 | \f | |
173 | ||
174 | (defun sup-get-tty-num (term-char) | |
175 | "Read from terminal until TERM-CHAR is read, and return intervening number. | |
176 | Upon non-numeric not matching TERM-CHAR signal an error." | |
177 | (let | |
178 | ((num 0) | |
179 | (char (read-char))) | |
180 | (while (and (>= char ?0) | |
181 | (<= char ?9)) | |
182 | (setq num (+ (* num 10) (- char ?0))) | |
183 | (setq char (read-char))) | |
184 | (or (eq term-char char) | |
185 | (error "Invalid data format in mouse command")) | |
186 | num)) | |
187 | ||
188 | (defun sup-move-point-to-x-y (x y) | |
189 | "Position cursor in window coordinates. | |
190 | X and Y are 0-based character positions in the window." | |
191 | (move-to-window-line y) | |
192 | (move-to-column x) | |
193 | ) | |
194 | ||
195 | (defun sup-pos-to-window (x y) | |
0cc89026 JB |
196 | "Find window corresponding to frame coordinates. |
197 | X and Y are 0-based character positions on the frame." | |
75377eba GM |
198 | (get-window-with-predicate (lambda (w) |
199 | (coordinates-in-window-p (cons x y) w)))) | |
c88ab9ce | 200 | |
27c8b6eb GM |
201 | (provide 'sup-mouse) |
202 | ||
c88ab9ce | 203 | ;;; sup-mouse.el ends here |