1 ;;; sup-mouse.el --- supdup mouse support for lisp machines
3 ;; Copyright (C) 1985, 1986, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
6 ;; Author: Wolfgang Rupprecht
8 ;; Created: 21 Nov 1986
11 ;; (from code originally written by John Robinson@bbn for the bitgraph)
13 ;; This file is part of GNU Emacs.
15 ;; GNU Emacs is free software: you can redistribute it and/or modify
16 ;; it under the terms of the GNU General Public License as published by
17 ;; the Free Software Foundation, either version 3 of the License, or
18 ;; (at your option) any later version.
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.
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
32 ;;; User customization option:
34 (defvar sup-mouse-fast-select-window nil
35 "*Non-nil for mouse hits to select new window, then execute; else just select.")
37 (defconst mouse-left
0)
38 (defconst mouse-center
1)
39 (defconst mouse-right
2)
41 (defconst mouse-2left
4)
42 (defconst mouse-2center
5)
43 (defconst mouse-2right
6)
45 (defconst mouse-3left
8)
46 (defconst mouse-3center
9)
47 (defconst mouse-3right
10)
51 (defun sup-mouse-report ()
52 "This function is called directly by the mouse, it parses and
53 executes the mouse commands.
55 L move point * |---- These apply for mouse click in a window.
57 3L copy word | If sup-mouse-fast-select-window is nil,
58 C move point and yank * | just selects that window.
64 on modeline on \"scroll bar\" in minibuffer
65 L scroll-up line to top execute-extended-command
66 C proportional goto-char line to middle mouse-help
67 R scroll-down line to bottom eval-expression"
71 ;; expect a string of <esc>:<buttons>;<x-pos>;<y-pos>c
72 ((buttons (sup-get-tty-num ?\
;))
73 (x (sup-get-tty-num ?\
;))
74 (y (sup-get-tty-num ?c
))
75 (window (sup-pos-to-window x y
))
76 (edges (window-edges window
))
77 (old-window (selected-window))
78 (in-minibuf-p (eq y
(1- (frame-height))))
79 (same-window-p (and (not in-minibuf-p
) (eq window old-window
)))
80 (in-modeline-p (eq y
(1- (nth 3 edges
))))
81 (in-scrollbar-p (>= x
(1- (nth 2 edges
)))))
82 (setq x
(- x
(nth 0 edges
)))
83 (setq y
(- y
(nth 1 edges
)))
85 ; (error "mouse-hit %d %d %d" buttons x y) ;;;; debug
88 (select-window window
)
89 (cond ((= buttons mouse-left
)
91 ((= buttons mouse-right
)
93 ((= buttons mouse-center
)
95 (- (point-max) (point-min)))
98 (what-cursor-position)))
99 (select-window old-window
))
101 (select-window window
)
103 (cond ((= buttons mouse-left
)
105 ((= buttons mouse-right
)
106 (+ y
(- 2 (window-height))))
107 ((= buttons mouse-center
)
108 (/ (+ 2 y y
(- (window-height))) 2))
111 (select-window old-window
))
113 (cond ((= buttons mouse-left
)
114 (sup-move-point-to-x-y x y
))
115 ((= buttons mouse-2left
)
116 (sup-move-point-to-x-y x y
)
118 ((= buttons mouse-3left
)
119 (sup-move-point-to-x-y x y
)
122 (point) (progn (forward-word 1) (point))))
123 (setq this-command
'yank
)
125 ((= buttons mouse-right
)
127 (sup-move-point-to-x-y x y
)
128 (exchange-point-and-mark))
129 ((= buttons mouse-2right
)
131 (sup-move-point-to-x-y x y
)
132 (kill-region (mark) (point)))
133 ((= buttons mouse-3right
)
135 (sup-move-point-to-x-y x y
)
136 (copy-region-as-kill (mark) (point))
137 (setq this-command
'yank
))
138 ((= buttons mouse-center
)
139 (sup-move-point-to-x-y x y
)
140 (setq this-command
'yank
)
142 ((= buttons mouse-2center
)
147 (cond ((= buttons mouse-right
)
148 (call-interactively 'eval-expression
))
149 ((= buttons mouse-left
)
150 (call-interactively 'execute-extended-command
))
151 ((= buttons mouse-center
)
152 (describe-function 'sup-mouse-report
)); silly self help
154 (t ;in another window
155 (select-window window
)
156 (cond ((not sup-mouse-fast-select-window
))
157 ((= buttons mouse-left
)
158 (sup-move-point-to-x-y x y
))
159 ((= buttons mouse-right
)
161 (sup-move-point-to-x-y x y
)
162 (exchange-point-and-mark))
163 ((= buttons mouse-center
)
164 (sup-move-point-to-x-y x y
)
165 (setq this-command
'yank
)
171 (defun sup-get-tty-num (term-char)
172 "Read from terminal until TERM-CHAR is read, and return intervening number.
173 Upon non-numeric not matching TERM-CHAR signal an error."
177 (while (and (>= char ?
0)
179 (setq num
(+ (* num
10) (- char ?
0)))
180 (setq char
(read-char)))
181 (or (eq term-char char
)
182 (error "Invalid data format in mouse command"))
185 (defun sup-move-point-to-x-y (x y
)
186 "Position cursor in window coordinates.
187 X and Y are 0-based character positions in the window."
188 (move-to-window-line y
)
192 (defun sup-pos-to-window (x y
)
193 "Find window corresponding to frame coordinates.
194 X and Y are 0-based character positions on the frame."
195 (get-window-with-predicate (lambda (w)
196 (coordinates-in-window-p (cons x y
) w
))))
198 ;; arch-tag: ec644ed4-cac4-43b8-b3db-cfe83e9098d7
199 ;;; sup-mouse.el ends here