1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3 ;; File: sup-mouse.el ;;
4 ;; Author: Wolfgang Rupprecht ;;
5 ;; Created: Fri Nov 21 19:22:22 1986 ;;
6 ;; Contents: supdup mouse support for lisp machines ;;
8 ;; (from code originally written by John Robinson@bbn for the bitgraph) ;;
11 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13 ;; GNU Emacs code for lambda/supdup mouse
14 ;; Copyright (C) Free Software Foundation 1985, 1986
16 ;; This file is part of GNU Emacs.
18 ;; GNU Emacs is free software; you can redistribute it and/or modify
19 ;; it under the terms of the GNU General Public License as published by
20 ;; the Free Software Foundation; either version 1, or (at your option)
23 ;; GNU Emacs is distributed in the hope that it will be useful,
24 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
25 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 ;; GNU General Public License for more details.
28 ;; You should have received a copy of the GNU General Public License
29 ;; along with GNU Emacs; see the file COPYING. If not, write to
30 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
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- (screen-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 screen coordinates.
194 X and Y are 0-based character positions on the screen."
195 (let ((edges (window-edges))
197 (while (and (not (eq window (selected-window)))
198 (or (< y (nth 1 edges))
201 (>= x (nth 2 edges))))
202 (setq window (next-window window))
203 (setq edges (window-edges window))
205 (or window (selected-window))