* dired.el (dired-get-marked-files): Doc fix.
[emacs.git] / lisp / obsolete / sup-mouse.el
blob682b7d73fa4e3e204a3035227825c0055612ec4a
1 ;;; sup-mouse.el --- supdup mouse support for lisp machines
3 ;; Copyright (C) 1985-1986, 2001-2014 Free Software Foundation, Inc.
5 ;; Author: Wolfgang Rupprecht
6 ;; Maintainer: emacs-devel@gnu.org
7 ;; Created: 21 Nov 1986
8 ;; Keywords: hardware
9 ;; Obsolete-since: 24.4
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/>.
28 ;;; Commentary:
30 ;;; Code:
32 ;;; User customization option:
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)
40 (defconst mouse-left 0)
41 (defconst mouse-center 1)
42 (defconst mouse-right 2)
44 (defconst mouse-2left 4)
45 (defconst mouse-2center 5)
46 (defconst mouse-2right 6)
48 (defconst mouse-3left 8)
49 (defconst mouse-3center 9)
50 (defconst mouse-3right 10)
52 ;;; Defuns:
54 (defun sup-mouse-report ()
55 "This function is called directly by the mouse, it parses and
56 executes the mouse commands.
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 |
67 on mode line on \"scroll bar\" in minibuffer
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"
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))
81 (in-minibuf-p (eq y (1- (frame-height))))
82 (same-window-p (and (not in-minibuf-p) (eq window old-window)))
83 (in-mode-line-p (eq y (1- (nth 3 edges))))
84 (in-scrollbar-p (>= x (1- (nth 2 edges)))))
85 (setq x (- x (nth 0 edges)))
86 (setq y (- y (nth 1 edges)))
88 ; (error "mouse-hit %d %d %d" buttons x y) ;;;; debug
90 (cond (in-mode-line-p
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)
108 ((= buttons mouse-right)
109 (+ y (- 2 (window-height))))
110 ((= buttons mouse-center)
111 (/ (+ 2 y y (- (window-height))) 2))
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)
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))
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)
155 (describe-function 'sup-mouse-report)); silly self help
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))
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))
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)
195 (defun sup-pos-to-window (x y)
196 "Find window corresponding to frame coordinates.
197 X and Y are 0-based character positions on the frame."
198 (get-window-with-predicate (lambda (w)
199 (coordinates-in-window-p (cons x y) w))))
201 (provide 'sup-mouse)
203 ;;; sup-mouse.el ends here