1 ;;; sup-mouse.el --- supdup mouse support for lisp machines
3 ;; Copyright (C) 1985-1986, 2001-2011 Free Software Foundation, Inc.
5 ;; Author: Wolfgang Rupprecht
7 ;; Created: 21 Nov 1986
10 ;; (from code originally written by John Robinson@bbn for the bitgraph)
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software: you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation, either version 3 of the License, or
17 ;; (at your option) any later version.
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
31 ;;; User customization option:
33 (defcustom sup-mouse-fast-select-window nil
34 "Non-nil means mouse hits select new window, then execute.
35 Otherwise just select."
39 (defconst mouse-left
0)
40 (defconst mouse-center
1)
41 (defconst mouse-right
2)
43 (defconst mouse-2left
4)
44 (defconst mouse-2center
5)
45 (defconst mouse-2right
6)
47 (defconst mouse-3left
8)
48 (defconst mouse-3center
9)
49 (defconst mouse-3right
10)
53 (defun sup-mouse-report ()
54 "This function is called directly by the mouse, it parses and
55 executes the mouse commands.
57 L move point * |---- These apply for mouse click in a window.
59 3L copy word | If sup-mouse-fast-select-window is nil,
60 C move point and yank * | just selects that window.
66 on modeline on \"scroll bar\" in minibuffer
67 L scroll-up line to top execute-extended-command
68 C proportional goto-char line to middle mouse-help
69 R scroll-down line to bottom eval-expression"
73 ;; expect a string of <esc>:<buttons>;<x-pos>;<y-pos>c
74 ((buttons (sup-get-tty-num ?\
;))
75 (x (sup-get-tty-num ?\
;))
76 (y (sup-get-tty-num ?c
))
77 (window (sup-pos-to-window x y
))
78 (edges (window-edges window
))
79 (old-window (selected-window))
80 (in-minibuf-p (eq y
(1- (frame-height))))
81 (same-window-p (and (not in-minibuf-p
) (eq window old-window
)))
82 (in-modeline-p (eq y
(1- (nth 3 edges
))))
83 (in-scrollbar-p (>= x
(1- (nth 2 edges
)))))
84 (setq x
(- x
(nth 0 edges
)))
85 (setq y
(- y
(nth 1 edges
)))
87 ; (error "mouse-hit %d %d %d" buttons x y) ;;;; debug
90 (select-window window
)
91 (cond ((= buttons mouse-left
)
93 ((= buttons mouse-right
)
95 ((= buttons mouse-center
)
97 (- (point-max) (point-min)))
100 (what-cursor-position)))
101 (select-window old-window
))
103 (select-window window
)
105 (cond ((= buttons mouse-left
)
107 ((= buttons mouse-right
)
108 (+ y
(- 2 (window-height))))
109 ((= buttons mouse-center
)
110 (/ (+ 2 y y
(- (window-height))) 2))
113 (select-window old-window
))
115 (cond ((= buttons mouse-left
)
116 (sup-move-point-to-x-y x y
))
117 ((= buttons mouse-2left
)
118 (sup-move-point-to-x-y x y
)
120 ((= buttons mouse-3left
)
121 (sup-move-point-to-x-y x y
)
124 (point) (progn (forward-word 1) (point))))
125 (setq this-command
'yank
)
127 ((= buttons mouse-right
)
129 (sup-move-point-to-x-y x y
)
130 (exchange-point-and-mark))
131 ((= buttons mouse-2right
)
133 (sup-move-point-to-x-y x y
)
134 (kill-region (mark) (point)))
135 ((= buttons mouse-3right
)
137 (sup-move-point-to-x-y x y
)
138 (copy-region-as-kill (mark) (point))
139 (setq this-command
'yank
))
140 ((= buttons mouse-center
)
141 (sup-move-point-to-x-y x y
)
142 (setq this-command
'yank
)
144 ((= buttons mouse-2center
)
149 (cond ((= buttons mouse-right
)
150 (call-interactively 'eval-expression
))
151 ((= buttons mouse-left
)
152 (call-interactively 'execute-extended-command
))
153 ((= buttons mouse-center
)
154 (describe-function 'sup-mouse-report
)); silly self help
156 (t ;in another window
157 (select-window window
)
158 (cond ((not sup-mouse-fast-select-window
))
159 ((= buttons mouse-left
)
160 (sup-move-point-to-x-y x y
))
161 ((= buttons mouse-right
)
163 (sup-move-point-to-x-y x y
)
164 (exchange-point-and-mark))
165 ((= buttons mouse-center
)
166 (sup-move-point-to-x-y x y
)
167 (setq this-command
'yank
)
173 (defun sup-get-tty-num (term-char)
174 "Read from terminal until TERM-CHAR is read, and return intervening number.
175 Upon non-numeric not matching TERM-CHAR signal an error."
179 (while (and (>= char ?
0)
181 (setq num
(+ (* num
10) (- char ?
0)))
182 (setq char
(read-char)))
183 (or (eq term-char char
)
184 (error "Invalid data format in mouse command"))
187 (defun sup-move-point-to-x-y (x y
)
188 "Position cursor in window coordinates.
189 X and Y are 0-based character positions in the window."
190 (move-to-window-line y
)
194 (defun sup-pos-to-window (x y
)
195 "Find window corresponding to frame coordinates.
196 X and Y are 0-based character positions on the frame."
197 (get-window-with-predicate (lambda (w)
198 (coordinates-in-window-p (cons x y
) w
))))
200 ;;; sup-mouse.el ends here