annotate lisp/avoid.el @ 6904:b264fb73cfe7

(gnus-uu-enter-interactive-file): Escape any special characters in file names. (gnus-uu-call-asynchronous, gnus-uu-treat-archive): Likewise. (gnus-uu-uustrip-article-as): Added more corrections of corrupt uucode. (gnus-uu-uustrip-article-as): Changed the algorithm for finding begin/body lines of encoded articles. (gnus-uu-check-correct-stripped-uucode): Handle extraneous empty lines in uuencoded postings. (gnus-uu-uustrip-article-as, gnus-uu-clean-up): Check before calling process-status. (gnus-uu-uuencode-and-post): Added possibly non-standard posting of uuencoded files. Doc fixes. (gnus-uu): New function is placeholder for docs. (gnus-uu-summary-next-subject): Do sit-for before gnus-summary-recenter.
author Richard M. Stallman <rms@gnu.org>
date Sat, 16 Apr 1994 00:02:28 +0000
parents b8026de94b3a
children 41b90d7dd228
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;;; avoid.el -- make mouse pointer stay out of the way of editing.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2
5745
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
3 ;;; Copyright (C) 1993, 1994 Free Software Foundation, Inc.
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 ;; Author: Boris Goldowsky <boris@cs.rochester.edu>
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; Keywords: mouse
5145
78323ca35d6f Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 5119
diff changeset
7 ;; Version: 1.10
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; any later version.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; GNU General Public License for more details.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 ;;; Commentary:
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 ;;;
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;;; For those who are annoyed by the mouse pointer obscuring text,
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;;; this mode moves the mouse pointer - either just a little out of
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;;; the way, or all the way to the corner of the frame.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;;; To use, load or evaluate this file and type M-x mouse-avoidance-mode .
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 ;;; To set up permanently, put this file on your load-path and put the
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 ;;; following in your .emacs:
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 ;;;
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 ;;; (cond (window-system
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 ;;; (require 'avoid)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 ;;; (mouse-avoidance-mode 'cat-and-mouse)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 ;;;
6106
b8026de94b3a Fix comment typos.
David J. MacKenzie <djm@gnu.org>
parents: 5745
diff changeset
38 ;;; The 'cat-and-mouse can be
b8026de94b3a Fix comment typos.
David J. MacKenzie <djm@gnu.org>
parents: 5745
diff changeset
39 ;;; 'banish or 'jump or 'animate or 'proteus if you prefer.
5745
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
40 ;;; See the documentation for function `mouse-avoidance-mode' for
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
41 ;;; details of the different modes.
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 ;;;
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 ;;; For added silliness, make the animatee animate...
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 ;;; put something similar to the following into your .emacs:
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 ;;;
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 ;;; (cond (window-system
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 ;;; (setq x-pointer-shape
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 ;;; (eval (nth (random 4)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 ;;; '(x-pointer-man x-pointer-spider
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 ;;; x-pointer-gobbler x-pointer-gumby))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 ;;; (set-mouse-color (cdr (assoc 'mouse-color (frame-parameters))))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 ;;;
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 ;;; For completely random pointer shape, replace the setq above with:
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 ;;; (setq x-pointer-shape (mouse-avoidance-random-shape))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 ;;;
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 ;;; Bugs & Warnings:
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 ;;;
5745
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
58 ;;; - Due to a bug in (mouse-position), this code can cause emacs
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
59 ;;; 19.22 to crash when deleting a frame if the mouse has not moved
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
60 ;;; since creating the frame. Versions earlier than 19.21 will
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
61 ;;; crash more easily; this program should not be used with them.
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 ;;;
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 ;;; - Using this code does slow emacs down. "banish" mode shouldn't
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 ;;; ever be too bad though, and on my workstation even "animate" doesn't
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 ;;; seem to have a noticable effect.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 ;;;
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 ;;; - There are some situations where it doesn't do what you expect,
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 ;;; notably when there are long wrapped lines in the buffer. Since
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 ;;; there is no low-level command for finding point's position
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 ;;; on the screen, it can fail to move the pointer when on such a line.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 ;;; Credits:
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 ;;; This code was helped by all those who contributed suggestions, fixes, and
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 ;;; additions:
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 ;;; Joe Harrington (and his advisor), for the original inspiration
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 ;;; Ken Manheimer, for dreaming up the Protean mode
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 ;;; Richard Stallman, for the awful cat-and-mouse pun, among other things
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 ;;; Mike Williams, Denis Howe, Bill Benedetto, Chris Moore, Don Morris,
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 ;;; Simon Marshall, and M.S. Ashton, for their feedback.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 ;;;
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 ;;; Code:
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 (provide 'avoid)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 (defvar mouse-avoidance-mode nil
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 "Value is t or a symbol if the mouse pointer should avoid the cursor.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 See function mouse-avoidance-mode for possible values. Changing this
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 variable is NOT the recommended way to change modes; use the function
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 instead.")
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 (defvar mouse-avoidance-nudge-dist 4
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 "*Average distance that mouse will be moved when approached by cursor.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 Only applies in mode-avoidance-modes `animate' and `jump'.")
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 (defvar mouse-avoidance-nudge-var 3
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 "*Variability of mouse-avoidance-nudge-dist (which see).")
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 (defvar mouse-avoidance-animation-delay .01
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 "Delay between animation steps, in seconds.")
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 (defvar mouse-avoidance-threshhold 5
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 "*Mouse-pointer's flight distance.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 If the cursor gets closer than this, the mouse pointer will move away.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 Only applies in mouse-avoidance-modes `animate' and `jump'.")
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 ;; Internal variables for mouse-avoidance-random-shape
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 (defvar mouse-avoidance-pointer-shapes nil)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 (defvar mouse-avoidance-n-pointer-shapes 0)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 ;;; Functions:
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 (defun mouse-avoidance-too-close-p ()
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 ;; Return t if mouse pointer and point cursor are too close.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 ;; Acceptable distance is defined by mouse-avoidance-threshhold.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 (let ((mouse (mouse-position)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 (and (car (cdr mouse))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 (< (abs (- (car (cdr mouse)) (current-column)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 mouse-avoidance-threshhold)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 (< (abs (- (cdr (cdr mouse))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 (+ (car (cdr (window-edges)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 (count-lines (window-start) (point)))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 mouse-avoidance-threshhold))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 (defun mouse-avoidance-banish-mouse ()
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 ;; Put the mouse pointer in the upper-right corner of the current frame.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 (set-mouse-position (selected-frame) (1- (frame-width)) 0))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 (defun mouse-avoidance-nudge-mouse ()
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 ;; Push the mouse a little way away, possibly animating the move
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 (let* ((cur (mouse-position))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 (deltax (* (+ mouse-avoidance-nudge-dist
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 (random mouse-avoidance-nudge-var))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 (if (zerop (random 2)) 1 -1)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 (deltay (* (+ mouse-avoidance-nudge-dist
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 (random mouse-avoidance-nudge-var))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 (if (zerop (random 2)) 1 -1))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 (if (or (eq mouse-avoidance-mode 'animate)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 (eq mouse-avoidance-mode 'proteus))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 (let ((i 0.0)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 (color (cdr (assoc 'mouse-color (frame-parameters)))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 (while (<= i 1)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 (set-mouse-position
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 (car cur)
5745
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
144 (mod (+ (car (cdr cur)) (round (* i deltax))) (frame-width))
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
145 (mod (+ (cdr (cdr cur)) (round (* i deltay))) (frame-height)))
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 (setq i (+ i (/ 1.0 mouse-avoidance-nudge-dist)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 (if (eq mouse-avoidance-mode 'proteus)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 (progn
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 (setq x-pointer-shape (mouse-avoidance-random-shape))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 (set-mouse-color color)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 (sit-for mouse-avoidance-animation-delay)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 (set-mouse-position
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 (car cur)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 (mod (+ (car (cdr cur)) deltax) (window-width))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 (mod (+ (cdr (cdr cur)) deltay) (window-height))))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 (defun mouse-avoidance-random-shape ()
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 "Return a random cursor shape.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 This assumes that any variable whose name begins with x-pointer- and
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 has an integer value is a valid cursor shape. You might want to
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 redefine this function to suit your own tastes."
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 (if (null mouse-avoidance-pointer-shapes)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 (progn
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 (setq mouse-avoidance-pointer-shapes
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 (mapcar '(lambda (x) (symbol-value (intern x)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 (all-completions "x-pointer-" obarray
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 '(lambda (x)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 (and (boundp x)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 (integerp (symbol-value x)))))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 (setq mouse-avoidance-n-pointer-shapes
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 (length mouse-avoidance-pointer-shapes))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 (nth (random mouse-avoidance-n-pointer-shapes)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 mouse-avoidance-pointer-shapes))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 (defun mouse-avoidance-simple-hook ()
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 (if (and (mouse-avoidance-keyboard-command (this-command-keys)))
5745
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
177 (progn
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
178 (raise-frame (selected-frame))
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
179 (mouse-avoidance-banish-mouse))))
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 (defun mouse-avoidance-fancy-hook ()
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 (if (and (mouse-avoidance-keyboard-command (this-command-keys))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 (mouse-avoidance-too-close-p))
5745
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
184 (let ((old-pos (mouse-position)))
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
185 (mouse-avoidance-nudge-mouse)
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
186 (if (not (eq (selected-frame) (car old-pos)))
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
187 (apply 'set-mouse-position old-pos)))))
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 (defun mouse-avoidance-keyboard-command (key)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 "Return t if the KEYSEQENCE is composed of keyboard events only.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 Returns nil if there are any lists in the key sequence."
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 (cond ((null key) nil) ; Null event seems to be
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 ; returned occasionally.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 ((not (vectorp key)) t) ; Strings are keyboard events.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 ((catch 'done
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (let ((i 0)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 (l (length key)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 (while (< i l)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 (if (listp (aref key i))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 (throw 'done nil))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 (setq i (1+ i))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 t))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 (defun mouse-avoidance-mode (&optional mode)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 "Set cursor avoidance mode to MODE.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 MODE should be one of the symbols `banish', `jump', `animate',
5745
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
207 `cat-and-mouse', `proteus', or `none'.
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
208
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
209 If MODE is nil, toggle mouse avoidance between `none' and `banish'
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
210 modes. Positive numbers and symbols other than the above are treated
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
211 as equivalent to `banish'; negative numbers and `-' are equivalent to `none'.
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
212
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
213 Effects of the different modes:
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
214 * BANISH: Move the mouse to the upper-right corner on any keypress.
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
215 Also raises the frame.
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
216 * JUMP: If the cursor gets too close to the mouse, displace the mouse
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
217 a random distance & direction. If this would put it in another,
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
218 overlapping frame, it is put back \(until the next keypress).
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
219 * ANIMATE: As `jump', but shows steps along the way for illusion of motion.
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
220 * CAT-AND-MOUSE: Same as `animate'.
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
221 * PROTEUS: As `animate', but changes the shape of the mouse pointer too.
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
222
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
223 \(see `mouse-avoidance-threshhold' for definition of \"too close\",
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
224 and `mouse-avoidance-nudge-dist' and `mouse-avoidance-nudge-var' for
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
225 definition of \"random distance\".)"
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 (interactive
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 (list (intern (completing-read
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 "Select cursor avoidance technique (SPACE for list): "
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 '(("banish") ("jump") ("animate") ("cat-and-mouse")
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 ("proteus") ("none"))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 nil t))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 (if (eq mode 'cat-and-mouse)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 (setq mode 'animate))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 (setq post-command-hook
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 (delete 'mouse-avoidance-simple-hook (append post-command-hook nil)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 (setq post-command-hook
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 (delete 'mouse-avoidance-fancy-hook (append post-command-hook nil)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 (cond ((eq mode 'none)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 (setq mouse-avoidance-mode nil))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 ((or (eq mode 'jump)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 (eq mode 'animate)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 (eq mode 'proteus))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 (add-hook 'post-command-hook 'mouse-avoidance-fancy-hook)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 (setq mouse-avoidance-mode mode))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 ((or (eq mode 'banish)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 (eq mode t)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 (and (null mode) (null mouse-avoidance-mode))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 (and mode (> (prefix-numeric-value mode) 0)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 (add-hook 'post-command-hook 'mouse-avoidance-simple-hook)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 (setq mouse-avoidance-mode 'banish))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 (t (setq mouse-avoidance-mode nil))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 (or (assq 'mouse-avoidance-mode minor-mode-alist)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 (setq minor-mode-alist (cons '(mouse-avoidance-mode " Avoid")
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 minor-mode-alist)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 ;;; End of avoid.el
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258