Mercurial > hg > xemacs-beta
annotate lisp/term/bg-mouse.el @ 5940:c608d4b0b75e cygwin64 tip
rescue lost branch from 64bit.backup
author | Henry Thompson <ht@markup.co.uk> |
---|---|
date | Thu, 16 Dec 2021 18:48:58 +0000 |
parents | b9167d522a9a |
children |
rev | line source |
---|---|
0 | 1 ;;; bg-mouse.el --- GNU Emacs code for BBN Bitgraph mouse. |
2 | |
3 ;; Copyright (C) Free Software Foundation, Inc. Oct 1985. | |
4 | |
5 ;; Author: John Robinson <jr@bbn-unix.arpa> | |
6 ;; Stephen Gildea <gildea@bbn.com> | |
7 ;; Maintainer: FSF | |
8 ;; Keywords: hardware | |
9 | |
5291
85bd42a1e544
More permission consistency.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
772
diff
changeset
|
10 ;; This file is part of XEmacs. |
0 | 11 |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
772
diff
changeset
|
12 ;; XEmacs is free software: you can redistribute it and/or modify it |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
772
diff
changeset
|
13 ;; under the terms of the GNU General Public License as published by the |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
772
diff
changeset
|
14 ;; Free Software Foundation, either version 3 of the License, or (at your |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
772
diff
changeset
|
15 ;; option) any later version. |
0 | 16 |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
772
diff
changeset
|
17 ;; XEmacs is distributed in the hope that it will be useful, but WITHOUT |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
772
diff
changeset
|
18 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
772
diff
changeset
|
19 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
772
diff
changeset
|
20 ;; for more details. |
0 | 21 |
22 ;; You should have received a copy of the GNU General Public License | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
772
diff
changeset
|
23 ;; along with XEmacs. If not, see <http://www.gnu.org/licenses/>. |
0 | 24 |
25 ;;; Code: | |
26 | |
772 | 27 ;;; #### utterly broken. I've put in hacks so we don't get byte-comp |
28 ;;; warnings, but this shit should go NOW. --ben | |
29 | |
0 | 30 ;;; Original version by John Robinson (jr@bbn-unix.arpa, bbncca!jr), Oct 1985 |
31 ;;; Modularized and enhanced by gildea@bbn.com Nov 1987 | |
32 ;;; Time stamp <89/03/21 14:27:08 gildea> | |
33 | |
34 ;;; User customization option: | |
35 | |
36 (defvar bg-mouse-fast-select-window nil | |
37 "*Non-nil for mouse hits to select new window, then execute; else just select.") | |
38 | |
39 ;;; These numbers are summed to make the index into the mouse-map. | |
40 ;;; The low three bits correspond to what the mouse actually sends. | |
41 (defconst bg-button-r 1) | |
42 (defconst bg-button-m 2) | |
43 (defconst bg-button-c 2) | |
44 (defconst bg-button-l 4) | |
45 (defconst bg-in-modeline 8) | |
46 (defconst bg-in-scrollbar 16) | |
47 (defconst bg-in-minibuf 24) | |
48 | |
49 ;;; semicolon screws up indenting, so use this instead | |
50 (defconst semicolon ?\;) | |
51 | |
52 ;;; Defuns: | |
53 | |
772 | 54 ;; #### bunch of crap. |
55 (globally-declare-boundp 'mouse-map) | |
56 | |
57 (defun bg-window-edges (&optional win) | |
58 (error "not implemented") | |
59 (window-pixel-edges win)) | |
60 | |
0 | 61 (defun bg-mouse-report (prefix-arg) |
62 "Read, parse, and execute a BBN BitGraph mouse click. | |
63 | |
64 L-- move point | These apply for mouse click in a window. | |
65 --R set mark | If bg-mouse-fast-select-window is nil, | |
66 L-R kill region | these commands on a nonselected window | |
67 -C- move point and yank | just select that window. | |
68 LC- yank-pop | | |
69 -CR or LCR undo | \"Scroll bar\" is right-hand window column. | |
70 | |
71 on modeline: on \"scroll bar\": in minibuffer: | |
72 L-- scroll-up line to top execute-extended-command | |
73 --R scroll-down line to bottom eval-expression | |
74 -C- proportional goto-char line to middle suspend-emacs | |
75 | |
76 To reinitialize the mouse if the terminal is reset, type ESC : RET" | |
77 (interactive "P") | |
772 | 78 (declare (special bg-mouse-x bg-mouse-y bg-cursor-window)) |
0 | 79 (bg-get-tty-num semicolon) |
80 (let* | |
81 ((screen-mouse-x (min (1- (frame-width)) ;don't hit column 86! | |
82 (/ (bg-get-tty-num semicolon) 9))) | |
83 (screen-mouse-y (- (1- (frame-height)) ;assume default font size. | |
444 | 84 (/ (bg-get-tty-num semicolon) 16))) |
0 | 85 (bg-mouse-buttons (% (bg-get-tty-num ?c) 8)) |
86 (bg-mouse-window (bg-window-from-x-y screen-mouse-x screen-mouse-y)) | |
87 (bg-cursor-window (selected-window)) | |
772 | 88 (edges (bg-window-edges bg-mouse-window)) |
89 (minibuf-p (= screen-mouse-y (1- (frame-height)))) | |
0 | 90 (in-modeline-p (and (not minibuf-p) |
91 (= screen-mouse-y (1- (nth 3 edges))))) | |
92 (in-scrollbar-p (and (not minibuf-p) (not in-modeline-p) | |
93 (>= screen-mouse-x (1- (nth 2 edges))))) | |
94 (same-window-p (eq bg-mouse-window bg-cursor-window)) | |
95 (in-minibuf-p (and minibuf-p | |
96 (not bg-mouse-window))) ;minibuf must be inactive | |
97 (bg-mode-bits (+ (if in-minibuf-p bg-in-minibuf 0) | |
98 (if in-modeline-p bg-in-modeline 0) | |
99 (if in-scrollbar-p bg-in-scrollbar 0))) | |
100 (bg-command | |
101 (lookup-key mouse-map | |
102 (char-to-string (+ bg-mode-bits bg-mouse-buttons)))) | |
103 (bg-mouse-x (- screen-mouse-x (nth 0 edges))) | |
104 (bg-mouse-y (- screen-mouse-y (nth 1 edges)))) | |
105 (cond ((or in-modeline-p in-scrollbar-p) | |
106 (select-window bg-mouse-window) | |
107 (bg-command-execute bg-command) | |
108 (select-window bg-cursor-window)) | |
109 ((or same-window-p in-minibuf-p) | |
110 (bg-command-execute bg-command)) | |
111 (t ;in another window | |
112 (select-window bg-mouse-window) | |
113 (if bg-mouse-fast-select-window | |
114 (bg-command-execute bg-command))) | |
115 ))) | |
116 | |
117 | |
118 ;;; Library of commands: | |
119 | |
120 (defun bg-set-point () | |
121 "Move point to location of BitGraph mouse." | |
122 (interactive) | |
772 | 123 (declare (special bg-mouse-x bg-mouse-y)) |
0 | 124 (bg-move-point-to-x-y bg-mouse-x bg-mouse-y) |
125 (setq this-command 'next-line) ;make subsequent line moves work | |
126 (setq temporary-goal-column bg-mouse-x)) | |
127 | |
128 (defun bg-set-mark () | |
129 "Set mark at location of BitGraph mouse." | |
130 (interactive) | |
772 | 131 (declare (special bg-mouse-x bg-mouse-y)) |
0 | 132 (push-mark) |
133 (bg-move-point-to-x-y bg-mouse-x bg-mouse-y) | |
134 (exchange-point-and-mark)) | |
135 | |
136 (defun bg-yank () | |
137 "Move point to location of BitGraph mouse and yank." | |
138 (interactive "*") | |
772 | 139 (declare (special bg-mouse-x bg-mouse-y)) |
0 | 140 (bg-move-point-to-x-y bg-mouse-x bg-mouse-y) |
141 (setq this-command 'yank) | |
142 (yank)) | |
143 | |
144 (defun yank-pop-1 () | |
145 (interactive "*") | |
146 (yank-pop 1)) | |
147 | |
148 (defun bg-yank-or-pop () | |
149 "Move point to location of BitGraph mouse and yank. If last command | |
150 was a yank, do a yank-pop." | |
151 (interactive "*") | |
152 (if (eql last-command 'yank) | |
153 (yank-pop 1) | |
154 (bg-yank))) | |
155 | |
156 ;;; In 18.51, Emacs Lisp doesn't provide most-positive-fixnum | |
157 (defconst bg-most-positive-fixnum 8388607) | |
158 | |
159 (defun bg-move-by-percentage () | |
160 "Go to location in buffer that is the same percentage of the way | |
161 through the buffer as the BitGraph mouse's X position in the window." | |
162 (interactive) | |
772 | 163 (declare (special bg-mouse-x bg-mouse-y)) |
0 | 164 ;; check carefully for overflow in intermediate calculations |
165 (goto-char | |
166 (cond ((zerop bg-mouse-x) | |
167 0) | |
168 ((< (buffer-size) (/ bg-most-positive-fixnum bg-mouse-x)) | |
169 ;; no danger of overflow: compute it exactly | |
170 (/ (* bg-mouse-x (buffer-size)) | |
171 (1- (window-width)))) | |
172 (t | |
173 ;; overflow possible: approximate | |
174 (* (/ (buffer-size) (1- (window-width))) | |
175 bg-mouse-x)))) | |
176 (beginning-of-line) | |
177 (what-cursor-position)) | |
178 | |
179 (defun bg-mouse-line-to-top () | |
180 "Scroll the line pointed to by the BitGraph mouse to the top of the window." | |
181 (interactive) | |
772 | 182 (declare (special bg-mouse-x bg-mouse-y)) |
0 | 183 (scroll-up bg-mouse-y)) |
184 | |
185 (defun bg-mouse-line-to-center () | |
444 | 186 "Scroll the line pointed to by the BitGraph mouse to the center |
187 of the window." | |
0 | 188 (interactive) |
772 | 189 (declare (special bg-mouse-x bg-mouse-y)) |
0 | 190 (scroll-up (/ (+ 2 bg-mouse-y bg-mouse-y (- (window-height))) 2))) |
191 | |
192 (defun bg-mouse-line-to-bottom () | |
193 "Scroll the line pointed to by the mouse to the bottom of the window." | |
194 (interactive) | |
772 | 195 (declare (special bg-mouse-x bg-mouse-y)) |
0 | 196 (scroll-up (+ bg-mouse-y (- 2 (window-height))))) |
197 | |
198 (defun bg-kill-region () | |
199 (interactive "*") | |
200 (kill-region (region-beginning) (region-end))) | |
201 | |
202 (defun bg-insert-moused-sexp () | |
203 "Insert a copy of the word (actually sexp) that the mouse is pointing at. | |
204 Sexp is inserted into the buffer at point (where the text cursor is)." | |
205 (interactive) | |
772 | 206 (declare (special bg-mouse-x bg-mouse-y bg-cursor-window)) |
0 | 207 (let ((moused-text |
208 (save-excursion | |
209 (bg-move-point-to-x-y bg-mouse-x bg-mouse-y) | |
210 (if (looking-at "\\s)") | |
211 (forward-char 1) | |
212 (forward-sexp 1)) | |
213 (buffer-substring (save-excursion (backward-sexp 1) (point)) | |
214 (point))))) | |
215 (select-window bg-cursor-window) | |
216 (delete-horizontal-space) | |
217 (cond | |
218 ((bolp) | |
219 (indent-according-to-mode)) | |
220 ;; In Lisp assume double-quote is closing; in Text assume opening. | |
221 ;; Why? Because it does the right thing most often. | |
446 | 222 ((save-excursion (backward-char 1) |
0 | 223 (and (not (looking-at "\\s\"")) |
224 (looking-at "[`'\"\\]\\|\\s("))) | |
225 nil) | |
226 (t | |
227 (insert-string " "))) | |
228 (insert-string moused-text) | |
229 (or (eolp) | |
230 (looking-at "\\s.\\|\\s)") | |
231 (and (looking-at "'") (looking-at "\\sw")) ;hack for text mode | |
232 (save-excursion (insert-string " "))))) | |
233 | |
234 ;;; Utility functions: | |
235 | |
236 (defun bg-get-tty-num (term-char) | |
237 "Read from terminal until TERM-CHAR is read, and return intervening number. | |
238 If non-numeric not matching TERM-CHAR, reprogram the mouse and signal an error." | |
239 (let | |
240 ((num 0) | |
241 (char (- (read-char) 48))) | |
242 (while (and (>= char 0) | |
243 (<= char 9)) | |
244 (setq num (+ (* num 10) char)) | |
245 (setq char (- (read-char) 48))) | |
246 (or (eq term-char (+ char 48)) | |
247 (progn | |
248 (bg-program-mouse) | |
249 (error | |
250 "Invalid data format in bg-mouse command: mouse reinitialized."))) | |
251 num)) | |
252 | |
253 ;;; Note that this fails in the minibuf because move-to-column doesn't | |
254 ;;; allow for the width of the prompt. | |
255 (defun bg-move-point-to-x-y (x y) | |
256 "Position cursor in window coordinates. | |
257 X and Y are 0-based character positions in the window." | |
258 (move-to-window-line y) | |
259 ;; if not on a wrapped line, zero-column will be 0 | |
260 (let ((zero-column (current-column)) | |
261 (scroll-offset (window-hscroll))) | |
262 ;; scrolling takes up column 0 to display the $ | |
263 (if (> scroll-offset 0) | |
264 (setq scroll-offset (1- scroll-offset))) | |
265 (move-to-column (+ zero-column scroll-offset x)) | |
266 )) | |
267 | |
268 ;;; Returns the window that screen position (x, y) is in or nil if none, | |
269 ;;; meaning we are in the echo area with a non-active minibuffer. | |
270 ;;; If coordinates-in-window-p were not in an X-windows-specific file | |
271 ;;; we could use that. In Emacs 19 can even use locate-window-from-coordinates | |
272 (defun bg-window-from-x-y (x y) | |
273 "Find window corresponding to screen coordinates. | |
274 X and Y are 0-based character positions on the screen." | |
772 | 275 (let ((edges (bg-window-edges)) |
0 | 276 (window nil)) |
277 (while (and (not (eq window (selected-window))) | |
278 (or (< y (nth 1 edges)) | |
279 (>= y (nth 3 edges)) | |
280 (< x (nth 0 edges)) | |
281 (>= x (nth 2 edges)))) | |
282 (setq window (next-window window)) | |
772 | 283 (setq edges (bg-window-edges window))) |
0 | 284 (cond ((eq window (selected-window)) |
285 nil) ;we've looped: not found | |
286 ((not window) | |
287 (selected-window)) ;just starting: current window | |
288 (t | |
289 window)) | |
290 )) | |
291 | |
292 (defun bg-command-execute (bg-command) | |
293 (if (commandp bg-command) | |
294 (command-execute bg-command) | |
295 (ding))) | |
296 | |
297 (defun bg-program-mouse () | |
298 (send-string-to-terminal "\e:0;7;;;360;512;9;16;9;16c")) | |
299 | |
300 ;;; Note that the doc string for mouse-map (as defined in subr.el) | |
301 ;;; says it is for the X-window mouse. This is wrong; that keymap | |
302 ;;; should be used for your mouse no matter what terminal you have. | |
303 | |
304 (or (keymapp mouse-map) | |
305 (setq mouse-map (make-keymap))) | |
306 | |
307 (defun bind-bg-mouse-click (click-code function) | |
308 "Bind bg-mouse CLICK-CODE to run FUNCTION." | |
309 (define-key mouse-map (char-to-string click-code) function)) | |
310 | |
444 | 311 (bind-bg-mouse-click bg-button-l 'bg-set-point) |
0 | 312 (bind-bg-mouse-click bg-button-m 'bg-yank) |
313 (bind-bg-mouse-click bg-button-r 'bg-set-mark) | |
314 (bind-bg-mouse-click (+ bg-button-l bg-button-m) 'yank-pop-1) | |
315 (bind-bg-mouse-click (+ bg-button-l bg-button-r) 'bg-kill-region) | |
316 (bind-bg-mouse-click (+ bg-button-m bg-button-r) 'undo) | |
317 (bind-bg-mouse-click (+ bg-button-l bg-button-m bg-button-r) 'undo) | |
318 (bind-bg-mouse-click (+ bg-in-modeline bg-button-l) 'scroll-up) | |
319 (bind-bg-mouse-click (+ bg-in-modeline bg-button-m) 'bg-move-by-percentage) | |
320 (bind-bg-mouse-click (+ bg-in-modeline bg-button-r) 'scroll-down) | |
321 (bind-bg-mouse-click (+ bg-in-scrollbar bg-button-l) 'bg-mouse-line-to-top) | |
322 (bind-bg-mouse-click (+ bg-in-scrollbar bg-button-m) 'bg-mouse-line-to-center) | |
323 (bind-bg-mouse-click (+ bg-in-scrollbar bg-button-r) 'bg-mouse-line-to-bottom) | |
324 (bind-bg-mouse-click (+ bg-in-minibuf bg-button-l) 'execute-extended-command) | |
325 (bind-bg-mouse-click (+ bg-in-minibuf bg-button-m) 'suspend-emacs) | |
326 (bind-bg-mouse-click (+ bg-in-minibuf bg-button-r) 'eval-expression) | |
327 | |
328 (provide 'bg-mouse) | |
329 | |
330 ;;; bg-mouse.el ends here |