Mercurial > emacs
comparison lisp/avoid.el @ 5745:01628c0b2646
Doc fix.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Wed, 02 Feb 1994 20:43:50 +0000 |
parents | 78323ca35d6f |
children | b8026de94b3a |
comparison
equal
deleted
inserted
replaced
5744:c870cde64544 | 5745:01628c0b2646 |
---|---|
1 ;;; avoid.el -- make mouse pointer stay out of the way of editing. | 1 ;;; avoid.el -- make mouse pointer stay out of the way of editing. |
2 | 2 |
3 ;;; Copyright (C) 1993 Free Software Foundation, Inc. | 3 ;;; Copyright (C) 1993, 1994 Free Software Foundation, Inc. |
4 | 4 |
5 ;; Author: Boris Goldowsky <boris@cs.rochester.edu> | 5 ;; Author: Boris Goldowsky <boris@cs.rochester.edu> |
6 ;; Keywords: mouse | 6 ;; Keywords: mouse |
7 ;; Version: 1.10 | 7 ;; Version: 1.10 |
8 | 8 |
34 ;;; (cond (window-system | 34 ;;; (cond (window-system |
35 ;;; (require 'avoid) | 35 ;;; (require 'avoid) |
36 ;;; (mouse-avoidance-mode 'cat-and-mouse))) | 36 ;;; (mouse-avoidance-mode 'cat-and-mouse))) |
37 ;;; | 37 ;;; |
38 ;;; The 'animate can be 'jump or 'banish or 'protean if you prefer. | 38 ;;; The 'animate can be 'jump or 'banish or 'protean if you prefer. |
39 ;;; See the documentation for function `mouse-avoidance-mode' for | |
40 ;;; details of the different modes. | |
39 ;;; | 41 ;;; |
40 ;;; For added silliness, make the animatee animate... | 42 ;;; For added silliness, make the animatee animate... |
41 ;;; put something similar to the following into your .emacs: | 43 ;;; put something similar to the following into your .emacs: |
42 ;;; | 44 ;;; |
43 ;;; (cond (window-system | 45 ;;; (cond (window-system |
50 ;;; For completely random pointer shape, replace the setq above with: | 52 ;;; For completely random pointer shape, replace the setq above with: |
51 ;;; (setq x-pointer-shape (mouse-avoidance-random-shape)) | 53 ;;; (setq x-pointer-shape (mouse-avoidance-random-shape)) |
52 ;;; | 54 ;;; |
53 ;;; Bugs & Warnings: | 55 ;;; Bugs & Warnings: |
54 ;;; | 56 ;;; |
55 ;;; - THIS CODE IS FOR USE WITH FSF EMACS 19.21 or later. | 57 ;;; - Due to a bug in (mouse-position), this code can cause emacs |
56 ;;; It can cause earlier versions of emacs to crash, due to a bug in the | 58 ;;; 19.22 to crash when deleting a frame if the mouse has not moved |
57 ;;; mouse code. | 59 ;;; since creating the frame. Versions earlier than 19.21 will |
60 ;;; crash more easily; this program should not be used with them. | |
58 ;;; | 61 ;;; |
59 ;;; - Using this code does slow emacs down. "banish" mode shouldn't | 62 ;;; - Using this code does slow emacs down. "banish" mode shouldn't |
60 ;;; ever be too bad though, and on my workstation even "animate" doesn't | 63 ;;; ever be too bad though, and on my workstation even "animate" doesn't |
61 ;;; seem to have a noticable effect. | 64 ;;; seem to have a noticable effect. |
62 ;;; | 65 ;;; |
135 (let ((i 0.0) | 138 (let ((i 0.0) |
136 (color (cdr (assoc 'mouse-color (frame-parameters))))) | 139 (color (cdr (assoc 'mouse-color (frame-parameters))))) |
137 (while (<= i 1) | 140 (while (<= i 1) |
138 (set-mouse-position | 141 (set-mouse-position |
139 (car cur) | 142 (car cur) |
140 (mod (+ (car (cdr cur)) (round (* i deltax))) (window-width)) | 143 (mod (+ (car (cdr cur)) (round (* i deltax))) (frame-width)) |
141 (mod (+ (cdr (cdr cur)) (round (* i deltay))) (window-height))) | 144 (mod (+ (cdr (cdr cur)) (round (* i deltay))) (frame-height))) |
142 (setq i (+ i (/ 1.0 mouse-avoidance-nudge-dist))) | 145 (setq i (+ i (/ 1.0 mouse-avoidance-nudge-dist))) |
143 (if (eq mouse-avoidance-mode 'proteus) | 146 (if (eq mouse-avoidance-mode 'proteus) |
144 (progn | 147 (progn |
145 (setq x-pointer-shape (mouse-avoidance-random-shape)) | 148 (setq x-pointer-shape (mouse-avoidance-random-shape)) |
146 (set-mouse-color color))) | 149 (set-mouse-color color))) |
168 (nth (random mouse-avoidance-n-pointer-shapes) | 171 (nth (random mouse-avoidance-n-pointer-shapes) |
169 mouse-avoidance-pointer-shapes)) | 172 mouse-avoidance-pointer-shapes)) |
170 | 173 |
171 (defun mouse-avoidance-simple-hook () | 174 (defun mouse-avoidance-simple-hook () |
172 (if (and (mouse-avoidance-keyboard-command (this-command-keys))) | 175 (if (and (mouse-avoidance-keyboard-command (this-command-keys))) |
173 (mouse-avoidance-banish-mouse))) | 176 (progn |
177 (raise-frame (selected-frame)) | |
178 (mouse-avoidance-banish-mouse)))) | |
174 | 179 |
175 (defun mouse-avoidance-fancy-hook () | 180 (defun mouse-avoidance-fancy-hook () |
176 (if (and (mouse-avoidance-keyboard-command (this-command-keys)) | 181 (if (and (mouse-avoidance-keyboard-command (this-command-keys)) |
177 (mouse-avoidance-too-close-p)) | 182 (mouse-avoidance-too-close-p)) |
178 (mouse-avoidance-nudge-mouse))) | 183 (let ((old-pos (mouse-position))) |
184 (mouse-avoidance-nudge-mouse) | |
185 (if (not (eq (selected-frame) (car old-pos))) | |
186 (apply 'set-mouse-position old-pos))))) | |
179 | 187 |
180 (defun mouse-avoidance-keyboard-command (key) | 188 (defun mouse-avoidance-keyboard-command (key) |
181 "Return t if the KEYSEQENCE is composed of keyboard events only. | 189 "Return t if the KEYSEQENCE is composed of keyboard events only. |
182 Returns nil if there are any lists in the key sequence." | 190 Returns nil if there are any lists in the key sequence." |
183 (cond ((null key) nil) ; Null event seems to be | 191 (cond ((null key) nil) ; Null event seems to be |
193 t)))) | 201 t)))) |
194 | 202 |
195 (defun mouse-avoidance-mode (&optional mode) | 203 (defun mouse-avoidance-mode (&optional mode) |
196 "Set cursor avoidance mode to MODE. | 204 "Set cursor avoidance mode to MODE. |
197 MODE should be one of the symbols `banish', `jump', `animate', | 205 MODE should be one of the symbols `banish', `jump', `animate', |
198 `cat-and-mouse', or `none'. `Animate' is the same as `cat-and-mouse'. | 206 `cat-and-mouse', `proteus', or `none'. |
199 If MODE is nil, toggle mouse avoidance. Positive numbers and | 207 |
200 symbols other than the above are treated as equivalent to `banish'; | 208 If MODE is nil, toggle mouse avoidance between `none' and `banish' |
201 negative numbers and `-' are equivalent to `none'." | 209 modes. Positive numbers and symbols other than the above are treated |
210 as equivalent to `banish'; negative numbers and `-' are equivalent to `none'. | |
211 | |
212 Effects of the different modes: | |
213 * BANISH: Move the mouse to the upper-right corner on any keypress. | |
214 Also raises the frame. | |
215 * JUMP: If the cursor gets too close to the mouse, displace the mouse | |
216 a random distance & direction. If this would put it in another, | |
217 overlapping frame, it is put back \(until the next keypress). | |
218 * ANIMATE: As `jump', but shows steps along the way for illusion of motion. | |
219 * CAT-AND-MOUSE: Same as `animate'. | |
220 * PROTEUS: As `animate', but changes the shape of the mouse pointer too. | |
221 | |
222 \(see `mouse-avoidance-threshhold' for definition of \"too close\", | |
223 and `mouse-avoidance-nudge-dist' and `mouse-avoidance-nudge-var' for | |
224 definition of \"random distance\".)" | |
202 (interactive | 225 (interactive |
203 (list (intern (completing-read | 226 (list (intern (completing-read |
204 "Select cursor avoidance technique (SPACE for list): " | 227 "Select cursor avoidance technique (SPACE for list): " |
205 '(("banish") ("jump") ("animate") ("cat-and-mouse") | 228 '(("banish") ("jump") ("animate") ("cat-and-mouse") |
206 ("proteus") ("none")) | 229 ("proteus") ("none")) |