annotate lisp/modes/strokes.el @ 157:6b37e6ddd302 r20-3b5

Import from CVS: tag r20-3b5
author cvs
date Mon, 13 Aug 2007 09:40:41 +0200
parents 25f70ba0133c
children 6075d714658b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1 ;;; strokes.el Sat May 24 14:18:08 1997
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
2
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
3 ;; Copyright (C) 1997 Free Software Foundation, Inc.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
4
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
5 ;; Author: David Bakhash <cadet@mit.edu>
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
6 ;; Maintainer: David Bakhash <cadet@mit.edu>
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
7 ;; Version: 2.3-beta
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
8 ;; Created: 12 April 1997
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
9 ;; Keywords: lisp, mouse, extensions
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
10
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
11 ;; This file is part of XEmacs.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
12
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
13 ;; XEmacs is free software; you can redistribute it and/or modify it
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
14 ;; under the terms of the GNU General Public License as published by
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
15 ;; the Free Software Foundation; either version 2 of the License, or
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
16 ;; (at your option) any later version.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
17
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
18 ;; XEmacs program is distributed in the hope that it will be useful,
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
21 ;; General Public License for more details.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
22
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
23 ;; You should have received a copy of the GNU General Public License
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
24 ;; along with XEmacs; see the file COPYING. If not, write to the Free
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
25 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
26 ;; 02111-1307, USA.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
27
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
28 ;;; Synched up with: Not in FSF.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
29
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
30 ;;; Commentary:
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
31
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
32 ;; This package is written for for XEmacs v19.14 and up.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
33 ;; This is the strokes package. It is intended to allow the user to
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
34 ;; control XEmacs by means of mouse strokes. Once strokes is loaded, you
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
35 ;; can always get help be invoking `strokes-help':
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
36
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
37 ;; > M-x strokes-help
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
38
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
39 ;; and you can learn how to use the package. A mouse stroke, for now,
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
40 ;; can be defined as holding the middle button, for instance, and then
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
41 ;; moving the mouse in whatever pattern you wish, which you have set
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
42 ;; XEmacs to understand as mapping to a given command. For example, you
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
43 ;; may wish the have a mouse stroke that looks like a capital `C' which
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
44 ;; means `copy-region-as-kill'. Treat strokes just like you do key
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
45 ;; bindings. For example, XEmacs sets key bindings globally with the
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
46 ;; `global-set-key' command. Likewise, you can do
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
47
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
48 ;; > M-x global-set-stroke
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
49
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
50 ;; to interactively program in a stroke. It would be wise to set the
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
51 ;; first one to this very command, so that from then on, you invoke
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
52 ;; `global-set-stroke' with a stroke. likewise, there may eventually
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
53 ;; be a `local-set-stroke' command, also analogous to `local-set-key'.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
54
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
55 ;; You can always unset the last stroke definition with the command
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
56
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
57 ;; > M-x strokes-unset-last-stroke
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
58
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
59 ;; and the last stroke that was added to `strokes-global-map' will be
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
60 ;; removed.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
61
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
62 ;; Other analogies between strokes and key bindings are as follows:
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
63
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
64 ;; 1) To describe a stroke binding, you can type
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
65
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
66 ;; > M-x describe-stroke
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
67
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
68 ;; analogous to `describe-key'. It's also wise to have a stroke,
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
69 ;; like an `h', for help, or a `?', mapped to `describe-stroke'.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
70
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
71 ;; 2) stroke bindings are set internally through the lisp function
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
72 ;; `define-stroke', similar to the `define-key' function. some
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
73 ;; examples for a 3x3 stroke grid would be
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
74
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
75 ;; (define-stroke c-mode-stroke-map
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
76 ;; '((0 . 0) (1 . 1) (2 . 2))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
77 ;; 'kill-region)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
78 ;; (define-stroke strokes-global-map
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
79 ;; '((0 . 0) (0 . 1) (0 . 2) (1 . 2) (2 . 2))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
80 ;; 'list-buffers)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
81
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
82 ;; however, if you would probably just have the user enter in the
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
83 ;; stroke interactively and then set the stroke to whatever he/she
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
84 ;; entered. The lisp function to interactively read a stroke is
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
85 ;; `strokes-read-stroke'. This is especially helpful when you're
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
86 ;; on a fast computer that can handle a 9x9 stroke grid.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
87
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
88 ;; NOTE: only global stroke bindings are currently implemented,
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
89 ;; however mode- and buffer-local stroke bindings may eventually
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
90 ;; be implemented in a future version.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
91
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
92 ;; The important variables to be aware of for this package are listed
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
93 ;; below. They can all be altered through the customizing package via
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
94
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
95 ;; > M-x customize
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
96
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
97 ;; and customizing the group named `strokes'. You can also read
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
98 ;; documentation on the variables there.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
99
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
100 ;; `strokes-minimum-match-score' (determines the threshold of error that
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
101 ;; makes a stroke acceptable or unacceptable. If your strokes arn't
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
102 ;; matching, then you should raise this variable.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
103
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
104 ;; `strokes-grid-resolution' (determines the grid dimensions that you use
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
105 ;; when defining/reading strokes. The finer the grid your computer can
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
106 ;; handle, the more you can do, but even a 3x3 grid is pretty cool.)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
107 ;; The default value (7) should be fine for most decent computers.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
108 ;; NOTE: This variable should not be set to a number less than 3.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
109
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
110 ;; `strokes-display-strokes-buffer' will allow you to hide the strokes
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
111 ;; buffer when doing simple strokes. This is a speedup for slow
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
112 ;; computers as well as people who don't want to see their strokes.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
113
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
114 ;; If you find that your mouse is accelerating too fast, you can
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
115 ;; execute the UNIX X command to slow it down. A good possibility is
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
116
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
117 ;; % xset m 5/4 8
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
118
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
119 ;; which seems, heuristically, to work okay, without much disruption.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
120
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
121 ;; Whenever you load in the strokes package, you will be able to save
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
122 ;; what you've done upon exiting XEmacs. You can also do
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
123
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
124 ;; > M-x save-strokes
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
125
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
126 ;; and it will save your strokes in ~/.strokes, or you may wish to change
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
127 ;; this by setting the variable `strokes-file'.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
128
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
129 ;; Note that internally, all of the routines that are part of this
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
130 ;; package are able to deal with complex strokes, as they are a superset
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
131 ;; of simple strokes. However, the default of this package will map
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
132 ;; mouse button2 to the command `strokes-do-stroke', and NOT
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
133 ;; `strokes-do-complex-stroke'. If you wish to use complex strokes, you
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
134 ;; will have to override this key mapping. Complex strokes are terminated
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
135 ;; with mouse button3. The strokes package will not interfere with
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
136 ;; `mouse-yank', but you may want to examine how this is done (see the
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
137 ;; variable `strokes-click-command')
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
138
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
139 ;; To get strokes to work as part of your your setup, then you'll have
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
140 ;; put the strokes package in your load-path (preferably byte-compiled)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
141 ;; and then add the following to your .xemacs-options file (or wherever
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
142 ;; you put XEmacs-specific startup preferences):
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
143
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
144 ;;(and (fboundp 'device-on-window-system-p)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
145 ;; (device-on-window-system-p)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
146 ;; (require 'strokes))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
147
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
148 ;; Once loaded, you can start stroking. You can also toggle between
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
149 ;; strokes mode by simple typing
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
150
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
151 ;; > M-x strokes-mode
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
152
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
153 ;; I am now in the process of porting this package to emacs. I also hope
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
154 ;; that, with the help of others, this package will be useful in entering
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
155 ;; in pictographic-like language text using the mouse (i.e. Korean).
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
156 ;; Japanese and Chinese are a bit trickier, but I'm sure that with help
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
157 ;; it can be done. The next version will allow the user to enter strokes
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
158 ;; which "remove the pencil from the paper" so to speak, so one character
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
159 ;; can have multiple strokes.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
160
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
161 ;; Great thanks to Rob Ristroph for his generosity in letting me use his
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
162 ;; PC to develop this, Jason Johnson for his help in algorithms, Euna
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
163 ;; Kim for her help in Korean, and massive thanks to the helpful guys
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
164 ;; on the help instance on athena (zeno, jered, amu, gsstark, ghudson, etc)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
165 ;; Special thanks to Steve Baur and Hrvoje Niksic for all their help.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
166
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
167 ;; Tasks: (what I'm getting ready for future version)...
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
168 ;; 2) use 'strokes-read-complex-stroke for korean, etc.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
169 ;; 4) buffer-local 'strokes-local-map, and mode-stroke-maps would be nice
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
170 ;; 5) 'list-strokes (kinda important). What do people want?
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
171 ;; How about an optional docstring for each stroke so that a person
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
172 ;; can examine the strokes-file and actually make sense of it?
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
173 ;; (e.g. "This stroke is a pentagram")
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
174 ;; 6) add some hooks, like `strokes-read-stroke-hook'
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
175 ;; 7) See what people think of the factory settings. Should I change
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
176 ;; them? They're all pretty arbitrary in a way. I guess they
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
177 ;; should be minimal, but computers are getting lots faster, and
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
178 ;; if I choose the defaults too conservatively, then strokes will
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
179 ;; surely dissapoint some people on decent machines (until they
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
180 ;; figure out M-x customize). I need feedback.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
181 ;; Other: I always have the most beta version of strokes, so if you
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
182 ;; want it just let me know.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
183
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
184 ;;; Change Log:
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
185
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
186 ;; 1.3: provided user variable `strokes-use-strokes-buffer' to let users
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
187 ;; hide the strokes and strokes buffer when entering simple strokes.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
188 ;; 1.3: cleaned up most leaks.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
189 ;; 1.3: with Jari Aalto's help, cleaned up overall program.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
190 ;; 1.3: added `strokes-help' for help on strokes
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
191 ;; 1.3: fixed 'strokes-load-hook bug
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
192 ;; 1.3: email address change: now <cadet@mit.edu>
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
193 ;; 1.3: added `strokes-report-bug' based on efs/dired's `dired-report-bug'
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
194 ;; 1.3: added more dialog-box queries for mouse-event stuff.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
195 ;; 1.4: allowed strokes to invoke kbd macros as well (thanks gsstark!)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
196 ;; 2.0: fixed up ordering of certain functions.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
197 ;; 2.0: fixed bug applying to strokes in dedicated and minibuffer windows.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
198 ;; 2.0: punted the C-h way of invoking strokes help routines.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
199 ;; 2.0: fixed `strokes-define-stroke' so it would error check against
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
200 ;; defining strokes that were too short (really clicks)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
201 ;; 2.0: added `strokes-toggle-strokes-buffer' interactive function
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
202 ;; 2.0: added `customize' support, thanks to patch from Hrvoje (thanks)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
203 ;; 2.1: strokes no longer forces `mouse-yank-at-point' to t on mouse-yank
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
204 ;; (i.e. `mouse-yank-at-point' is up to you again)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
205 ;; 2.1: toggling strokes-mode off and then back on no longer deletes
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
206 ;; the strokes that you programmed in but didn't save before
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
207 ;; toggling off strokes-mode.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
208 ;; 2.1: advised may functions for modes like VM and w3 so that they too
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
209 ;; can use strokes, while still mantaining old button2 functionality.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
210 ;; 2.1: with steve's help, got the autoload for `strokes-mode' and
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
211 ;; fixed up the package so loading it does not enable strokes
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
212 ;; until user calls `strokes-mode'.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
213 ;; 2.2: made sure that abbrev-mode was off in the ` *strokes*' buffer
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
214 ;; 2.2: added more dired advice for mouse permissions commands
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
215 ;; 2.2: added some checks to see if saving strokes is really necessary so
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
216 ;; the user doesn't get promped aimlessly.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
217 ;; 2.2: change the `strokes-lift' symbol to a keyword of value `:strokes-lift'
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
218 ;; for legibility. IF YOUR OLD STROKES DON'T WORK, THIS IS PROBABLY WHY.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
219 ;; 2.2: I might have to change this back to `'strokes-lift' because the keyword
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
220 ;; fails in emacs, though I don't know why.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
221 ;; 2.2: `strokes-describe-stroke' is nicer during recursive edits
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
222 ;; 2.2: provided `strokes-fill-stroke' to fill in empty spaces of strokes
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
223 ;; as an important step towards platform (speed) independence.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
224 ;; Because of this, I moved the global setting of `strokes-last-stroke'
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
225 ;; from `strokes-eliminate-consecutive-redundancies' to
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
226 ;; `strokes-fill-stroke' since the latter comes later in processing
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
227 ;; a user stroke.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
228 ;; 2.2: Finally changed the defaults, so now `strokes-grid-resolution' is 9
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
229 ;; and `strokes-minimum-match-score' is 1000 by default. This will surely
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
230 ;; mess some people up, but if so, just set it back w/ M-x customize.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
231 ;; 2.2: Fixed up the mechanism for updating the `strokes-window-configuration'.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
232 ;; Now it only uses one function (`strokes-update-window-configuration')
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
233 ;; which does it all, and much more efficiently (thanks RMS!).
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
234 ;; 2.2 Fixed up the appearance of the *strokes* buffer so that there are no
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
235 ;; ugly line truncations, and I got rid of the bug which would draw the stroke
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
236 ;; on the wrong line. I still wish that `event-closest-point' was smarter.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
237 ;; In fact, `event-closest-point' does *not* do what its name suggests.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
238 ;; 2.3 Added more to `strokes-update-window-configuration' so it goes to hell less often
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
239 ;; 2.3 `strokes-mode' no longer will undefine keys unless it's sure that the user had
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
240 ;; had them mapped to a strokes command.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
241 ;; 2.3 added more magic autoload statements so strokes work more smoothly.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
242 ;; similarly, I made strokes-mode turn itself on when the user defines a stroke
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
243 ;; (thanks Hrvoje).
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
244 ;; 2.3 Added "Strokes" to the modeline when strokes is on, and allow toggling strokes
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
245 ;; with mouse button2.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
246 ;; 2.3 Added `list-strokes', which is a really nice function which graphically lists
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
247 ;; all the strokes that the user has defined and their corresponding commands.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
248 ;; `list-strokes' will appropriately colorize the pixmaps to display some time info.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
249
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
250 ;;; Code:
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
251
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
252 ;;; Requirements and provisions...
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
253
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
254 (autoload 'reporter-submit-bug-report "reporter")
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
255 (autoload 'mail-position-on-field "sendmail")
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
256
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
257 ;;; Constants...
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
258
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
259 (defconst strokes-version "2.3-beta")
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
260
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
261 (defconst strokes-bug-address "cadet@mit.edu")
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
262
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
263 (defconst strokes-lift :strokes-lift
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
264 "Symbol representing a stroke lift event for complex strokes.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
265 Complex strokes are those which contain two or more simple strokes.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
266 This will be useful for when XEmacs understands Chinese.")
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
267
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
268 ;;; user variables...
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
269
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
270 (defgroup strokes nil
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
271 "Control Emacs through mouse strokes"
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
272 :group 'mouse)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
273
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
274 (defcustom strokes-modeline-string " Strokes"
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
275 "*Modeline identification when strokes are on \(default is \" Strokes\"\)."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
276 :type 'string
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
277 :group 'strokes)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
278
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
279 (defcustom strokes-character ?o
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
280 "*Character used when drawing strokes in the strokes buffer.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
281 \(The default is lower-case `o', which works okay\)."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
282 :type 'character
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
283 :group 'strokes)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
284
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
285 (defcustom strokes-minimum-match-score 1000
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
286 "*Minimum score for a stroke to be considered a possible match.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
287 Requiring a perfect match would set this variable to 0.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
288 The default value is 1000, but it's mostly dependent on how precisely
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
289 you manage to replicate your user-defined strokes. It also depends on
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
290 the value of `strokes-grid-resolution', since a higher grid resolution
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
291 will correspond to more sample points, and thus more distance
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
292 measurements. Usually, this is not a problem since you first set
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
293 `strokes-grid-resolution' based on what your computer seems to be able
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
294 to handle (though the defaults are usually more than sufficent), and
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
295 then you can set `strokes-minimum-match-score' to something that works
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
296 for you. The only purpose of this variable is to insure that if you
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
297 do a bogus stroke that really doesn't match any of the predefined
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
298 ones, then strokes should NOT pick the one that came closest."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
299 :type 'integer
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
300 :group 'strokes)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
301
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
302 (defcustom strokes-grid-resolution 9
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
303 "*Integer defining dimensions of the stroke grid.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
304 The grid is a square grid, where STROKES-GRID-RESOLUTION defaults to
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
305 `9', making a 9x9 grid whose coordinates go from (0 . 0) on the top
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
306 left to ((STROKES-GRID-RESOLUTION - 1) . (STROKES-GRID-RESOLUTION - 1))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
307 on the bottom right. The greater the resolution, the more intricate
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
308 your strokes can be.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
309 NOTE: This variable should be odd and MUST NOT be less than 3.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
310 WARNING: Changing the value of this variable will gravely affect the
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
311 strokes you have already programmed in. You should try to
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
312 figure out what it should be based on your needs and on how
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
313 quick the particular platform(s) you're operating on, and
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
314 only then start programming in your custom strokes."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
315 :type 'integer
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
316 :group 'strokes)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
317
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
318 (defcustom strokes-file "~/.strokes"
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
319 "*File containing saved strokes for stroke-mode (default is ~/.strokes)."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
320 :type 'file
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
321 :group 'strokes)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
322
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
323 (defcustom strokes-buffer-name " *strokes*"
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
324 "The buffer that the strokes take place in (default is ` *strokes*')."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
325 :type 'string
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
326 :group 'strokes)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
327
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
328 (defcustom strokes-use-strokes-buffer t
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
329 "*If non-nil, the strokes buffer is used and strokes are displayed.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
330 If nil, strokes will be read the same, however the user will not be
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
331 able to see the strokes. This be helpful for people who don't like
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
332 the delay in switching to the strokes buffer."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
333 :type 'boolean
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
334 :group 'strokes)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
335
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
336 (defcustom strokes-click-command 'mouse-yank
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
337 "*Command to execute when stroke is actually a `click' event.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
338 This is set to `mouse-yank' by default."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
339 :type 'function
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
340 :group 'strokes)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
341
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
342 ;;; internal variables...
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
343
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
344 ;;;###autoload
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
345 (defvar strokes-mode nil
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
346 "Non-nil when `strokes' is globally enabled")
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
347
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
348 (defvar strokes-window-configuration nil
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
349 "The special window configuration used when entering strokes.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
350 This is set properly in the function `strokes-update-window-configuration'.")
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
351
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
352 (defvar strokes-last-stroke nil
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
353 "Last stroke entered by the user.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
354 Its value gets set every time the function
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
355 `strokes-fill-stroke' gets called,
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
356 since that is the best time to set the variable")
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
357
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
358 (defvar strokes-global-map '()
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
359 "Association list of strokes and their definitions.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
360 Each entry is (STROKE . COMMAND) where STROKE is itself a list of
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
361 coordinates (X . Y) where X and Y are lists of positions on the
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
362 normalized stroke grid, with the top left at (0 . 0). COMMAND is the
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
363 corresponding interactive function")
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
364
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
365 (defvar strokes-load-hook nil
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
366 "Function or functions to be called when `strokes' is loaded.")
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
367
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
368 ;;; Macros...
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
369
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
370 (defsubst strokes-click-p (stroke)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
371 "Non-nil if STROKE is really click."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
372 (< (length stroke) 3))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
373
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
374 ;;; old, but worked pretty good (just in case)...
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
375 ;;(defmacro strokes-define-stroke (stroke-map stroke def)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
376 ;; "Add STROKE to STROKE-MAP alist with given command DEF"
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
377 ;; (list 'if (list '< (list 'length stroke) 3)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
378 ;; (list 'error
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
379 ;; "That's a click, not a stroke. See `strokes-click-command'")
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
380 ;; (list 'setq stroke-map (list 'cons (list 'cons stroke def)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
381 ;; (list 'remassoc stroke stroke-map)))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
382
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
383 (defmacro strokes-define-stroke (stroke-map stroke def)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
384 "Add STROKE to STROKE-MAP alist with given command DEF"
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
385 `(if (strokes-click-p ,stroke)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
386 (error "That's a click, not a stroke; see `strokes-click-command'")
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
387 (setq ,stroke-map (cons (cons ,stroke ,def)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
388 (remassoc ,stroke ,stroke-map)))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
389
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
390 (defalias 'define-stroke 'strokes-define-stroke)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
391
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
392 (defsubst strokes-square (x)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
393 "Returns the square of the number X"
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
394 (* x x))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
395
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
396 (defsubst strokes-distance-squared (p1 p2)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
397 "Gets the distance (squared) between to points P1 and P2.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
398 Each point is a cons cells (X . Y)"
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
399 (let ((x1 (car p1))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
400 (y1 (cdr p1))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
401 (x2 (car p2))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
402 (y2 (cdr p2)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
403 (+ (strokes-square (- x2 x1))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
404 (strokes-square (- y2 y1)))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
405
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
406 ;;; Advice for various functions...
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
407
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
408 ;; I'd originally wanted to write a macro that would just take in the
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
409 ;; generic functions which use mouse button2 in various modes. Most of
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
410 ;; them are identical in form: they take an event as the single argument
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
411 ;; and then do their thing. I tried writing a macro that looked
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
412 ;; something like this, but failed. Advice just ain't that easy. The
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
413 ;; one that bugged me the most was `Manual-follow-xref', because that had
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
414 ;; &rest arguments, and I didn't know how to work around it in defadvice.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
415 ;; However, I was able to fix up most of the important modes (i.e. the
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
416 ;; ones I use all the time). One `bug' in the program that I just can't
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
417 ;; seem to figure out is why I can only advise other button2 functions
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
418 ;; successfully when the variable `strokes-use-strokes-buffer' is nil. I
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
419 ;; did all the save-excursion/save-window-excursion stuff SPECIFICALLY so
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
420 ;; that using the strokes buffer or not would absolutely not affect any
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
421 ;; other part of the program. If someone can figure out how to make the
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
422 ;; following advices work w/ regardless of that variable
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
423 ;; `strokes-use-strokes-buffer', then that would be a great victory. If
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
424 ;; someone out there would be kind enough to make the commented code
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
425 ;; below work, I'd be grateful. By the way, I put the `protect' keywords
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
426 ;; there to insure that if a stroke went bad, then
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
427 ;; `strokes-click-command' would be set back. If this isn't necessary,
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
428 ;; then feel free to let me know.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
429
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
430 ;; For what follows, I really wanted something that would work like this:
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
431
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
432 ;;(strokes-fix-button2 'vm-mouse-button-2)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
433
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
434 ;; Or even better, I could have simply done something like:
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
435
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
436 ;;(mapcar 'strokes-fix-button2
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
437 ;; '(vm-mouse-button-2
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
438 ;; rmail-summary-mouse-goto-msg
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
439 ;; <rest of them>))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
440
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
441 ;;; With help from Hans (author of advice.el)...
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
442 (defmacro strokes-fix-button2-command (command)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
443 "Fix COMMAND so that it can also work with strokes.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
444 COMMAND must take one event argument.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
445 Example of how one might fix up a command that's bound to button2
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
446 and which is an interactive funcion of one event argument:
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
447
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
448 (strokes-fix-button2-command 'vm-mouse-button-2)"
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
449 (let ((command (eval command)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
450 `(progn
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
451 (defadvice ,command (around strokes-fix-button2 compile preactivate)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
452 ,(format "Fix %s to work with strokes." command)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
453 (if strokes-use-strokes-buffer
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
454 ;; then strokes is no good and we'll have to use the original
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
455 ad-do-it
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
456 ;; otherwise, we can make strokes work too...
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
457 (let ((strokes-click-command
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
458 ',(intern (format "ad-Orig-%s" command))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
459 (strokes-do-stroke (ad-get-arg 0))))))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
460
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
461 (strokes-fix-button2-command 'vm-mouse-button-2)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
462 (strokes-fix-button2-command 'rmail-summary-mouse-goto-msg)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
463 (strokes-fix-button2-command 'Buffer-menu-mouse-select)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
464 (strokes-fix-button2-command 'w3-widget-button-click)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
465 (strokes-fix-button2-command 'widget-image-button-press)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
466 (strokes-fix-button2-command 'Info-follow-clicked-node)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
467 (strokes-fix-button2-command 'compile-mouse-goto-error)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
468 (strokes-fix-button2-command 'gdbsrc-select-or-yank)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
469 (strokes-fix-button2-command 'hypropos-mouse-get-doc)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
470 (strokes-fix-button2-command 'gnus-mouse-pick-group)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
471 (strokes-fix-button2-command 'gnus-mouse-pick-article)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
472 (strokes-fix-button2-command 'gnus-article-push-button)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
473 (strokes-fix-button2-command 'dired-mouse-find-file)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
474 (strokes-fix-button2-command 'url-dired-find-file-mouse)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
475 (strokes-fix-button2-command 'dired-u-r-mouse-toggle)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
476 (strokes-fix-button2-command 'dired-u-w-mouse-toggle)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
477 (strokes-fix-button2-command 'dired-u-x-mouse-toggle)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
478 (strokes-fix-button2-command 'dired-g-r-mouse-toggle)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
479 (strokes-fix-button2-command 'dired-g-w-mouse-toggle)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
480 (strokes-fix-button2-command 'dired-g-x-mouse-toggle)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
481 (strokes-fix-button2-command 'dired-o-r-mouse-toggle)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
482 (strokes-fix-button2-command 'dired-o-w-mouse-toggle)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
483 (strokes-fix-button2-command 'isearch-yank-x-selection)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
484 (strokes-fix-button2-command 'occur-mode-mouse-goto)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
485
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
486 ;;; I can fix the customize widget button click, but then
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
487 ;;; people will get confused when they try to customize
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
488 ;;; strokes with the mouse and customize tells them that
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
489 ;;; `strokes-click-command' is mapped to `ad-Orig-widget-button-click'
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
490 ;;(strokes-fix-button2-command 'widget-button-click)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
491
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
492 ;;; without the advice, each advised function would look like...
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
493 ;;(defadvice vm-mouse-button-2 (around vm-strokes activate protect)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
494 ;; "Allow strokes to work in VM."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
495 ;; (if strokes-use-strokes-buffer
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
496 ;; ;; then strokes is no good and we'll have to use the original
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
497 ;; ad-do-it
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
498 ;; ;; otherwise, we can make strokes work too...
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
499 ;; (let ((strokes-click-command 'ad-Orig-vm-mouse-button-2))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
500 ;; (strokes-do-stroke (ad-get-arg 0)))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
501
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
502 ;;; Functions...
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
503
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
504 (defun strokes-lift-p (object)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
505 "Return non-nil if object is a stroke-lift"
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
506 (eq object strokes-lift))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
507
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
508 (defun strokes-unset-last-stroke ()
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
509 "Undo the last stroke definition."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
510 (interactive)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
511 (let ((command (cdar strokes-global-map)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
512 (if (y-or-n-p-maybe-dialog-box
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
513 (format "really delete last stroke definition, defined to `%s'? "
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
514 command))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
515 (progn
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
516 (setq strokes-global-map (cdr strokes-global-map))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
517 (message "That stroke has been deleted"))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
518 (message "Nothing done"))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
519
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
520 ;;;###autoload
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
521 (defun strokes-global-set-stroke (stroke command)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
522 "Interactively give STROKE the global binding as COMMAND.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
523 Operated just like `global-set-key', except for strokes.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
524 COMMAND is a symbol naming an interactively-callable function. STROKE
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
525 is a list of sampled positions on the stroke grid as described in the
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
526 documentation for the `strokes-define-stroke' function."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
527 (interactive
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
528 (list
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
529 (and (or strokes-mode (strokes-mode t))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
530 (strokes-read-complex-stroke
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
531 "Define a new stroke. Draw with button1 (or 2). End with button3..."))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
532 (read-command "command to map stroke to: ")))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
533 (strokes-define-stroke strokes-global-map stroke command))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
534
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
535 ;;;###autoload
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
536 (defalias 'global-set-stroke 'strokes-global-set-stroke)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
537
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
538 ;;(defun global-unset-stroke (stroke); FINISH THIS DEFUN!
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
539 ;; "delete all strokes matching STROKE from `strokes-global-map',
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
540 ;; letting the user input
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
541 ;; the stroke with the mouse"
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
542 ;; (interactive
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
543 ;; (list
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
544 ;; (strokes-read-stroke "Enter the stroke you want to delete...")))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
545 ;; (strokes-define-stroke 'strokes-global-map stroke command))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
546
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
547 (defun strokes-get-grid-position (stroke-extent position &optional grid-resolution)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
548 "Map POSITION to a new grid position based on its STROKE-EXTENT and GRID-RESOLUTION.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
549 STROKE-EXTENT as a list \(\(xmin . ymin\) \(xmax . ymax\)\).
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
550 If POSITION is a `strokes-lift', then it is itself returned.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
551 Optional GRID-RESOLUTION may be used in place of STROKES-GRID-RESOLUTION.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
552 The grid is a square whose dimesion is [0,GRID-RESOLUTION)."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
553 (cond ((consp position) ; actual pixel location
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
554 (let ((grid-resolution (or grid-resolution strokes-grid-resolution))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
555 (x (car position))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
556 (y (cdr position))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
557 (xmin (caar stroke-extent))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
558 (ymin (cdar stroke-extent))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
559 ;; the `1+' is there to insure that the
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
560 ;; formula evaluates correctly at the boundaries
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
561 (xmax (1+ (caadr stroke-extent)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
562 (ymax (1+ (cdadr stroke-extent))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
563 (cons (floor (* grid-resolution
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
564 (/ (float (- x xmin))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
565 (- xmax xmin))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
566 (floor (* grid-resolution
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
567 (/ (float (- y ymin))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
568 (- ymax ymin)))))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
569 ((strokes-lift-p position) ; stroke lift
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
570 strokes-lift)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
571
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
572 ;;(defun strokes-get-grid-position (stroke-extent pix-pos)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
573 ;; "Return the stroke-grid position for PIX-POS given the total STROKE-EXTENT.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
574 ;;STROKE-EXTENT as a list \(\(xmin . ymin\) \(xmax . ymax\)\) and a particular
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
575 ;;pixel position or `strokes-lift', find the corresponding grid position
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
576 ;;\(based on `strokes-grid-resolution'\) for the PIX-POS."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
577 ;; (cond ((consp pix-pos) ; actual pixel location
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
578 ;; (let ((x (car pix-pos))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
579 ;; (y (cdr pix-pos))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
580 ;; (xmin (caar stroke-extent))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
581 ;; (ymin (cdar stroke-extent))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
582 ;; ;; the `1+' is there to insure that the
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
583 ;; ;; formula evaluates correctly at the boundaries
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
584 ;; (xmax (1+ (caadr stroke-extent)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
585 ;; (ymax (1+ (cdadr stroke-extent))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
586 ;; (cons (floor (* strokes-grid-resolution
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
587 ;; (/ (float (- x xmin))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
588 ;; (- xmax xmin))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
589 ;; (floor (* strokes-grid-resolution
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
590 ;; (/ (float (- y ymin))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
591 ;; (- ymax ymin)))))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
592 ;; ((strokes-lift-p pix-pos) ; stroke lift
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
593 ;; strokes-lift)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
594
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
595 (defun strokes-get-stroke-extent (pixel-positions)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
596 "From a list of absolute PIXEL-POSITIONS, returns absolute spatial extent.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
597 The return value is a list ((xmin . ymin) (xmax . ymax))."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
598 (if pixel-positions
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
599 (let ((xmin (caar pixel-positions))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
600 (xmax (caar pixel-positions))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
601 (ymin (cdar pixel-positions))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
602 (ymax (cdar pixel-positions))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
603 (rest (cdr pixel-positions)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
604 (while rest
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
605 (if (consp (car rest))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
606 (let ((x (caar rest))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
607 (y (cdar rest)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
608 (if (< x xmin)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
609 (setq xmin x))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
610 (if (> x xmax)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
611 (setq xmax x))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
612 (if (< y ymin)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
613 (setq ymin y))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
614 (if (> y ymax)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
615 (setq ymax y))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
616 (setq rest (cdr rest)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
617 (let ((delta-x (- xmax xmin))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
618 (delta-y (- ymax ymin)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
619 (if (> delta-x delta-y)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
620 (setq ymin (- ymin
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
621 (/ (- delta-x delta-y)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
622 2))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
623 ymax (+ ymax
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
624 (/ (- delta-x delta-y)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
625 2)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
626 (setq xmin (- xmin
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
627 (/ (- delta-y delta-x)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
628 2))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
629 xmax (+ xmax
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
630 (/ (- delta-y delta-x)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
631 2))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
632 (list (cons xmin ymin)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
633 (cons xmax ymax))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
634 nil))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
635
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
636 (defun strokes-eliminate-consecutive-redundancies (entries)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
637 "Returns a list with no consecutive redundant entries."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
638 ;; defun a grande vitesse grace a Dave G.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
639 (loop for element on entries
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
640 if (not (equal (car element) (cadr element)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
641 collect (car element)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
642 ;; (loop for element on entries
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
643 ;; nconc (if (not (equal (car el) (cadr el)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
644 ;; (list (car el)))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
645 ;; yet another (orig) way of doing it...
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
646 ;; (if entries
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
647 ;; (let* ((current (car entries))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
648 ;; (rest (cdr entries))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
649 ;; (non-redundant-list (list current))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
650 ;; (next nil))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
651 ;; (while rest
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
652 ;; (setq next (car rest))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
653 ;; (if (equal current next)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
654 ;; (setq rest (cdr rest))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
655 ;; (setq non-redundant-list (cons next non-redundant-list)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
656 ;; current next
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
657 ;; rest (cdr rest))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
658 ;; (nreverse non-redundant-list))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
659 ;; nil))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
660
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
661 (defun strokes-renormalize-to-grid (positions &optional grid-resolution)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
662 "Map POSITIONS to a new grid whose dimensions are based on GRID-RESOLUTION.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
663 POSITIONS is a list of positions and stroke-lifts.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
664 Optional GRID-RESOLUTION may be used in place of STROKES-GRID-RESOLUTION.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
665 The grid is a square whose dimesion is [0,GRID-RESOLUTION)."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
666 (let ((stroke-extent (strokes-get-stroke-extent positions)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
667 (mapcar (function
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
668 (lambda (pos)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
669 (strokes-get-grid-position stroke-extent pos grid-resolution)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
670 positions)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
671
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
672 ;;(defun strokes-normalize-pixels-to-grid (pixel-positions)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
673 ;; "Map PIXEL-POSITIONS to the stroke grid.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
674 ;;PIXEL-POSITIONS is a list of pixel-positions and stroke-lifts. The
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
675 ;;normalized stroke grid is defined by the variable STROKES-GRID-RESOLUTION"
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
676 ;; (let ((stroke-extent (strokes-get-stroke-extent pixel-positions)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
677 ;; (mapcar (function
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
678 ;; (lambda (pix-pos)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
679 ;; (strokes-get-grid-position stroke-extent pix-pos)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
680 ;; pixel-positions)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
681
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
682 (defun strokes-fill-stroke (unfilled-stroke &optional force)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
683 "Fill in missing grid locations in the list of UNFILLED-STROKE.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
684 If FORCE is non-nil, then fill the stroke even if it's `stroke-click'.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
685 NOTE: This is where the global variable `strokes-last-stroke' is set."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
686 (setq strokes-last-stroke ; this is global
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
687 (if (and (strokes-click-p unfilled-stroke)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
688 (not force))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
689 unfilled-stroke
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
690 (loop for grid-locs on unfilled-stroke
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
691 nconc (let* ((current (car grid-locs))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
692 (current-is-a-point-p (consp current))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
693 (next (cadr grid-locs))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
694 (next-is-a-point-p (consp next))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
695 (both-are-points-p (and current-is-a-point-p
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
696 next-is-a-point-p))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
697 (x1 (and current-is-a-point-p
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
698 (car current)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
699 (y1 (and current-is-a-point-p
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
700 (cdr current)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
701 (x2 (and next-is-a-point-p
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
702 (car next)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
703 (y2 (and next-is-a-point-p
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
704 (cdr next)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
705 (delta-x (and both-are-points-p
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
706 (- x2 x1)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
707 (delta-y (and both-are-points-p
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
708 (- y2 y1)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
709 (slope (and both-are-points-p
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
710 (if (zerop delta-x)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
711 nil ; undefined vertical slope
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
712 (/ (float delta-y)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
713 delta-x)))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
714 (cond ((not both-are-points-p)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
715 (list current))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
716 ((null slope) ; undefinded vertical slope
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
717 (if (>= delta-y 0)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
718 (loop for y from y1 below y2
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
719 collect (cons x1 y))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
720 (loop for y from y1 above y2
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
721 collect (cons x1 y))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
722 ((zerop slope) ; (= y1 y2)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
723 (if (>= delta-x 0)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
724 (loop for x from x1 below x2
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
725 collect (cons x y1))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
726 (loop for x from x1 above x2
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
727 collect (cons x y1))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
728 ((>= (abs delta-x) (abs delta-y))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
729 (if (> delta-x 0)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
730 (loop for x from x1 below x2
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
731 collect (cons x
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
732 (+ y1
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
733 (round (* slope
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
734 (- x x1))))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
735 (loop for x from x1 above x2
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
736 collect (cons x
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
737 (+ y1
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
738 (round (* slope
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
739 (- x x1))))))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
740 (t ; (< (abs delta-x) (abs delta-y))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
741 (if (> delta-y 0)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
742 (loop for y from y1 below y2
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
743 collect (cons (+ x1
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
744 (round (/ (- y y1)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
745 slope)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
746 y))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
747 (loop for y from y1 above y2
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
748 collect (cons (+ x1
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
749 (round (/ (- y y1)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
750 slope)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
751 y))))))))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
752
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
753 (defun strokes-rate-stroke (stroke1 stroke2)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
754 "Rates STROKE1 with STROKE2 and returns a score based on a distance metric.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
755 Note: the rating is an error rating, and therefore, a return of 0
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
756 represents a perfect match. Also note that the order of stroke
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
757 arguments is order-independent for the algorithm used here."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
758 (if (and stroke1 stroke2)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
759 (let ((rest1 (cdr stroke1))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
760 (rest2 (cdr stroke2))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
761 (err (strokes-distance-squared (car stroke1)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
762 (car stroke2))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
763 (while (and rest1 rest2)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
764 (while (and (consp (car rest1))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
765 (consp (car rest2)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
766 (setq err (+ err
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
767 (strokes-distance-squared (car rest1)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
768 (car rest2)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
769 stroke1 rest1
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
770 stroke2 rest2
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
771 rest1 (cdr stroke1)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
772 rest2 (cdr stroke2)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
773 (cond ((and (strokes-lift-p (car rest1))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
774 (strokes-lift-p (car rest2)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
775 (setq rest1 (cdr rest1)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
776 rest2 (cdr rest2)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
777 ((strokes-lift-p (car rest2))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
778 (while (consp (car rest1))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
779 (setq err (+ err
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
780 (strokes-distance-squared (car rest1)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
781 (car stroke2)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
782 rest1 (cdr rest1))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
783 ((strokes-lift-p (car rest1))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
784 (while (consp (car rest2))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
785 (setq err (+ err
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
786 (strokes-distance-squared (car stroke1)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
787 (car rest2)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
788 rest2 (cdr rest2))))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
789 (if (null rest2)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
790 (while (consp (car rest1))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
791 (setq err (+ err
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
792 (strokes-distance-squared (car rest1)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
793 (car stroke2)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
794 rest1 (cdr rest1))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
795 (if (null rest1)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
796 (while (consp (car rest2))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
797 (setq err (+ err
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
798 (strokes-distance-squared (car stroke1)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
799 (car rest2)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
800 rest2 (cdr rest2))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
801 (if (or (strokes-lift-p (car rest1))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
802 (strokes-lift-p (car rest2)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
803 (setq err nil)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
804 err))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
805 nil))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
806
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
807 (defun strokes-match-stroke (stroke stroke-map)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
808 "Finds the best matching command of STROKE in STROKE-MAP.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
809 Returns the corresponding match as (COMMAND . SCORE)."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
810 (if (and stroke stroke-map)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
811 (let ((score (strokes-rate-stroke stroke (caar stroke-map)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
812 (command (cdar stroke-map))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
813 (map (cdr stroke-map)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
814 (while map
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
815 (let ((newscore (strokes-rate-stroke stroke (caar map))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
816 (if (or (and newscore score (< newscore score))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
817 (and newscore (null score)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
818 (setq score newscore
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
819 command (cdar map)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
820 (setq map (cdr map))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
821 (if score
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
822 (cons command score)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
823 nil))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
824 nil))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
825
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
826 ;;;###autoload
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
827 (defun strokes-read-stroke (&optional prompt event)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
828 "Read a simple stroke (interactively) and return the stroke.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
829 Optional PROMPT in minibuffer displays before and during stroke reading.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
830 This function will display the stroke interactively as it is being
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
831 entered in the strokes buffer if the variable
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
832 `strokes-use-strokes-buffer' is non-nil.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
833 Optional EVENT is currently not used, but hopefully will be soon."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
834 (save-excursion
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
835 (let ((pix-locs nil)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
836 (grid-locs nil)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
837 (event (or event (make-event))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
838 (if strokes-use-strokes-buffer
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
839 ;; switch to the strokes buffer and
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
840 ;; display the stroke as it's being read
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
841 (save-window-excursion
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
842 (set-window-configuration strokes-window-configuration)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
843 (if prompt
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
844 (progn
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
845 (setq event (next-event event prompt))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
846 (while (not (button-press-event-p event))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
847 (dispatch-event event)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
848 (setq event (next-event event)))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
849 (unwind-protect
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
850 (progn
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
851 (setq event (next-event event))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
852 (while (not (button-release-event-p event))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
853 (if (mouse-event-p event)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
854 (let ((point (event-closest-point event)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
855 (when point
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
856 (goto-char point)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
857 (subst-char-in-region point (1+ point) ?\ strokes-character))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
858 (setq pix-locs (cons (cons (event-x-pixel event)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
859 (event-y-pixel event))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
860 pix-locs))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
861 (setq event (next-event event))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
862 ;; protected
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
863 ;; clean up strokes buffer and then bury it.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
864 (subst-char-in-region (point-min) (point-max) strokes-character ?\ )
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
865 (goto-char (point-min))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
866 (bury-buffer)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
867 ;; Otherwise, don't use strokes buffer and read stroke silently
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
868 (if prompt
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
869 (progn
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
870 (setq event (next-event event prompt))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
871 (while (not (button-press-event-p event))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
872 (dispatch-event event)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
873 (setq event (next-event event)))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
874 (setq event (next-event))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
875 (while (not (button-release-event-p event))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
876 (if (mouse-event-p event)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
877 (setq pix-locs (cons (cons (event-x-pixel event)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
878 (event-y-pixel event))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
879 pix-locs)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
880 (setq event (next-event event))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
881 (setq grid-locs (strokes-renormalize-to-grid (nreverse pix-locs)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
882 (strokes-fill-stroke (strokes-eliminate-consecutive-redundancies grid-locs)))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
883
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
884 ;;;###autoload
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
885 (defun strokes-read-complex-stroke (&optional prompt event)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
886 "Read a complex stroke (interactively) and return the stroke.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
887 Optional PROMPT in minibuffer displays before and during stroke reading.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
888 Note that a complex stroke allows the user to pen-up and pen-down. This
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
889 is implemented by allowing the user to paint with button1 or button2 and
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
890 then complete the stroke with button3.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
891 Optional EVENT is currently not used, but hopefully will be soon."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
892 (save-excursion
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
893 (save-window-excursion
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
894 (set-window-configuration strokes-window-configuration)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
895 (let ((pix-locs nil)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
896 (grid-locs nil)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
897 (event (or event (next-event nil prompt))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
898 (if prompt
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
899 (while (not (button-press-event-p event))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
900 (dispatch-event event)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
901 (setq event (next-event event))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
902 (unwind-protect
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
903 (progn
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
904 (while (not (and (button-press-event-p event)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
905 (eq (event-button event) 3)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
906 (while (not (button-release-event-p event))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
907 (if (mouse-event-p event)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
908 (let ((point (event-closest-point event)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
909 (when point
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
910 (goto-char point)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
911 (subst-char-in-region point (1+ point) ?\ strokes-character))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
912 (setq pix-locs (cons (cons (event-x-pixel event)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
913 (event-y-pixel event))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
914 pix-locs))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
915 (setq event (next-event event prompt)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
916 (setq pix-locs (cons strokes-lift pix-locs))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
917 (while (not (button-press-event-p event))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
918 (dispatch-event event)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
919 (setq event (next-event event prompt))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
920 (setq pix-locs (nreverse (cdr pix-locs))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
921 grid-locs (strokes-renormalize-to-grid pix-locs))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
922 (strokes-fill-stroke
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
923 (strokes-eliminate-consecutive-redundancies grid-locs)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
924 ;; protected
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
925 (subst-char-in-region (point-min) (point-max) strokes-character ?\ )
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
926 (goto-char (point-min))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
927 (bury-buffer))))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
928
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
929 (defun strokes-execute-stroke (stroke)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
930 "Given STROKE, execute the command which corresponds to it.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
931 The command will be executed provided one exists for that stroke,
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
932 based on the variable `strokes-minimum-match-score'.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
933 If no stroke matches, nothing is done and return value is nil."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
934 (let* ((match (strokes-match-stroke stroke strokes-global-map))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
935 (command (car match))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
936 (score (cdr match)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
937 (cond ((strokes-click-p stroke)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
938 ;; This is the case of a `click' type event
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
939 (command-execute strokes-click-command))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
940 ((and match (<= score strokes-minimum-match-score))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
941 (message "%s" command)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
942 (command-execute command))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
943 ((null strokes-global-map)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
944 (if (file-exists-p strokes-file)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
945 (and (y-or-n-p-maybe-dialog-box
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
946 (format "No strokes loaded. Load `%s'? "
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
947 strokes-file))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
948 (strokes-load-user-strokes))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
949 (error "No strokes defined; use `global-set-stroke'")))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
950 (t
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
951 (error
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
952 "No stroke matches; see variable `strokes-minimum-match-score'")
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
953 nil))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
954
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
955 ;;;###autoload
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
956 (defun strokes-do-stroke (event)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
957 "Read a simple stroke from the user and then exectute its comand.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
958 This must be bound to a mouse event."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
959 (interactive "e")
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
960 (or strokes-mode (strokes-mode t))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
961 (strokes-execute-stroke (strokes-read-stroke nil event)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
962
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
963 ;;;###autoload
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
964 (defun strokes-do-complex-stroke (event)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
965 "Read a complex stroke from the user and then exectute its command.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
966 This must be bound to a mouse event."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
967 (interactive "e")
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
968 (or strokes-mode (strokes-mode t))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
969 (strokes-execute-stroke (strokes-read-complex-stroke nil event)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
970
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
971 ;;;###autoload
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
972 (defun strokes-describe-stroke (stroke)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
973 "Displays the command which STROKE maps to, reading STROKE interactively."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
974 (interactive
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
975 (list
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
976 (strokes-read-complex-stroke
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
977 "Enter stroke to describe; end with button3...")))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
978 (let* ((match (strokes-match-stroke stroke strokes-global-map))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
979 (command (or (and (strokes-click-p stroke)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
980 strokes-click-command)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
981 (car match)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
982 (score (cdr match)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
983 (if (or (and match
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
984 (<= score strokes-minimum-match-score))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
985 (and (strokes-click-p stroke)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
986 strokes-click-command))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
987 (message "That stroke maps to `%s'" command)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
988 (message "That stroke is undefined"))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
989 (sleep-for 1))) ; helpful for recursive edits
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
990
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
991 ;;;###autoload
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
992 (defalias 'describe-stroke 'strokes-describe-stroke)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
993
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
994 ;;;###autoload
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
995 (defun strokes-help ()
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
996 "Get instructional help on using the the `strokes' package."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
997 (interactive)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
998 (with-displaying-help-buffer
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
999 (function
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1000 (lambda ()
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1001 (save-excursion
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1002 (let ((helpdoc
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1003 "This is help for the strokes package.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1004
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1005 If you find something wrong with it, or feel that it can be improved
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1006 in some way, then please feel free to email me:
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1007
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1008 David Bakhash <cadet@mit.edu>
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1009
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1010 or just do
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1011
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1012 M-x strokes-report-bug
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1013
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1014 ------------------------------------------------------------
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1015
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1016 The strokes package allows you to define strokes (that you make with
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1017 the mouse or other pointer device) that XEmacs can interpret as
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1018 corresponding to commands, and then executes the commands. It does
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1019 character recognition, so you don't have to worry about getting it
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1020 right every time.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1021
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1022 Strokes are easy to program and fun to use. To start strokes going,
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1023 you'll want to put the following line in your .emacs file:
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1024
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1025 (and (fboundp 'device-on-window-system-p)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1026 (device-on-window-system-p)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1027 (require 'strokes))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1028
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1029 This will load strokes when and only when you start XEmacs on a window
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1030 system (i.e. that has a pointer (mouse) device, etc.).
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1031
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1032 To toggle strokes-mode, you just do
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1033
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1034 > M-x strokes-mode
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1035
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1036 When you're ready to start defining strokes, just use the command
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1037
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1038 > M-x global-set-stroke
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1039
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1040 You will see a ` *strokes*' buffer which is waiting for you to enter in
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1041 your stroke. When you enter in the stroke, you draw with button1 or
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1042 button2, and then end with button3. Next, you enter in the command
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1043 which will be executed when that stroke is invoked. Simple as that.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1044 For now, try to define a stroke to copy a region. This is a popular
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1045 edit command, so type
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1046
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1047 > M-x global-set-stroke
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1048
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1049 Then, in the ` *strokes*' buffer, draw the letter `C' (for `copy')
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1050 and then, when it asks you to enter the command to map that to, type
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1051
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1052 > copy-region-as-kill
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1053
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1054 That's about as hard as it gets.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1055 Remember: paint with button1 or button2 and then end with button3.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1056
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1057 If ever you want to know what a certain strokes maps to, then do
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1058
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1059 > M-x describe-stroke
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1060
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1061 and you can enter in any arbitrary stroke. Remember: The strokes
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1062 package lets you program in simple and complex (multi-lift) strokes.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1063 The only difference is how you *invoke* the two. You will most likely
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1064 use simple strokes, as complex strokes were developed for
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1065 Chinese/Japanese/Korean. So the middle mouse button (button2) will
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1066 invoke the command `strokes-do-stroke' in buffers where button2 doesn't
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1067 already have a meaning other than its original, which is `mouse-yank'.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1068 But don't worry: `mouse-yank' will still work with strokes (see the
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1069 variable `strokes-click-command').
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1070
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1071 If ever you define a stroke which you don't like, then you can unset
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1072 it with the command
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1073
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1074 > M-x strokes-unset-last-stroke
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1075
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1076 You can always get an idea of what your current strokes look like with
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1077 the command
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1078
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1079 > M-x list-strokes
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1080
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1081 Your strokes will be displayed in from most recent down, and the
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1082 beginning of each simple stroke will be marked by a color dot. Since
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1083 you may have several simple strokes in a complex stroke, the dot
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1084 colors are arranged in the rainbow color sequence, `ROYGBIV'.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1085
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1086 Your strokes are stored as you enter them. They get saved in a file
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1087 called ~/.strokes, along with other strokes configuration variables.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1088 You can change this location by setting the variable `strokes-file'.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1089 You will be prompted to save them when you exit XEmacs, or you can save
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1090 them with
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1091
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1092 > M-x save-strokes
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1093
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1094 Your strokes get loaded automatically when you enable `strokes-mode'.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1095 You can also load in your user-defined strokes with
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1096
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1097 > M-x load-user-strokes
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1098
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1099 A few more important things:
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1100
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1101 o The command `strokes-do-stroke' is also invoked with C-button2, so that you
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1102 can still enter a stroke in modes which use button2 for other things,
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1103 such as cross-referencing.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1104
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1105 o Complex strokes (i.e. `strokes-do-complex-stroke'), by default, use
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1106 Sh-button2.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1107
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1108 o Strokes are a bit computer-dependent in that they depend somewhat on
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1109 the speed of the computer you're working on. This means that you
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1110 may have to tweak some variables. You can read about them in the
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1111 commentary of `strokes.el'. Better to just use apropos and read their
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1112 docstrings. All variables/functions start with `strokes'. The one
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1113 variable which many people wanted to see was
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1114 `strokes-use-strokes-buffer' which allows the user to use strokes
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1115 silently--without displaying the strokes. All variables can be set
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1116 by customizing the group named `strokes' via the customization package:
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1117
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1118 > M-x customize
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1119
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1120 o A problem with strokes happens when you resize windows. If you
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1121 enlarge your XEmacs window a lot and realize that your strokes
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1122 buffer is not big enough, you may need to fix it with
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1123
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1124 > M-x strokes-update-window-configuration."))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1125 (princ helpdoc standard-output)))))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1126
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1127 (defun strokes-report-bug ()
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1128 "Submit a bug report for strokes."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1129 (interactive)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1130 (let ((reporter-prompt-for-summary-p t))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1131 (or (boundp 'reporter-version)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1132 (setq reporter-version
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1133 "Your version of reporter is obsolete. Please upgrade."))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1134 (reporter-submit-bug-report
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1135 strokes-bug-address "Strokes"
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1136 (cons
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1137 'strokes-version
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1138 (nconc
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1139 (mapcar
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1140 'intern
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1141 (sort
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1142 (let (completion-ignore-case)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1143 (all-completions "strokes-" obarray 'user-variable-p))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1144 'string-lessp))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1145 (list 'reporter-version)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1146 (function
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1147 (lambda ()
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1148 (save-excursion
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1149 (mail-position-on-field "subject")
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1150 (beginning-of-line)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1151 (skip-chars-forward "^:\n")
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1152 (if (looking-at ": Strokes;")
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1153 (progn
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1154 (goto-char (match-end 0))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1155 (delete-char -1)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1156 (insert " " strokes-version " bug:")))))))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1157
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1158 (defsubst strokes-fill-current-buffer-with-whitespace ()
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1159 "Erase the contents of the current buffer and fill it with whitespace"
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1160 (erase-buffer)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1161 (loop for i from 1 to (frame-height) do
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1162 (progn
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1163 (insert-char ?\ (1- (frame-width)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1164 (newline)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1165 (goto-char (point-min)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1166
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1167 (defun strokes-update-window-configuration ()
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1168 "Insure that `strokes-window-configuration' is up-to-date."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1169 (interactive)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1170 (let ((current-window (selected-window)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1171 (cond ((or (window-minibuffer-p current-window)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1172 (window-dedicated-p current-window))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1173 ;; don't try to update strokes window configuration
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1174 ;; if window is dedicated or a minibuffer
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1175 nil)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1176 ((or (interactive-p)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1177 (not (buffer-live-p (get-buffer strokes-buffer-name)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1178 (null strokes-window-configuration))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1179 ;; create `strokes-window-configuration' from scratch...
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1180 (save-excursion
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1181 (save-window-excursion
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1182 (get-buffer-create strokes-buffer-name)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1183 (set-window-buffer current-window strokes-buffer-name)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1184 (delete-other-windows)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1185 (fundamental-mode)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1186 (auto-save-mode 0)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1187 (if (featurep 'font-lock)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1188 (font-lock-mode 0))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1189 (abbrev-mode 0)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1190 (buffer-disable-undo (current-buffer))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1191 (setq truncate-lines nil)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1192 (strokes-fill-current-buffer-with-whitespace)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1193 (setq strokes-window-configuration (current-window-configuration))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1194 (bury-buffer))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1195 (t ; `strokes buffer' still exists...
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1196 ;; update the strokes-window-configuration for this specific frame...
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1197 (save-excursion
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1198 (save-window-excursion
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1199 (set-window-buffer current-window strokes-buffer-name)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1200 (delete-other-windows)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1201 (strokes-fill-current-buffer-with-whitespace)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1202 (setq strokes-window-configuration (current-window-configuration))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1203 (bury-buffer)))))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1204
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1205 ;;;###autoload
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1206 (defun strokes-load-user-strokes ()
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1207 "Load user-defined strokes from file named by `strokes-file'."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1208 (interactive)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1209 (cond ((and (file-exists-p strokes-file)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1210 (file-readable-p strokes-file))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1211 (load-file strokes-file))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1212 ((interactive-p)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1213 (error "Trouble loading user-defined strokes; nothing done"))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1214 (t
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1215 (message "No user-defined strokes, sorry"))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1216
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1217 ;;;###autoload
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1218 (defalias 'load-user-strokes 'strokes-load-user-strokes)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1219
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1220 (defun strokes-prompt-user-save-strokes ()
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1221 "Save user-defined strokes to file named by `strokes-file'."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1222 (interactive)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1223 (save-excursion
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1224 (let ((current strokes-global-map))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1225 (unwind-protect
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1226 (progn
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1227 (setq strokes-global-map nil)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1228 (strokes-load-user-strokes)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1229 (if (and (not (equal current strokes-global-map))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1230 (or (interactive-p)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1231 (yes-or-no-p-maybe-dialog-box "save your strokes? ")))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1232 (progn
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1233 (require 'pp) ; pretty-print variables
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1234 (message "Saving strokes in %s..." strokes-file)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1235 (get-buffer-create "*saved-strokes*")
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1236 (set-buffer "*saved-strokes*")
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1237 (erase-buffer)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1238 (emacs-lisp-mode)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1239 (goto-char (point-min))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1240 (insert-string
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1241 ";; -*- Syntax: Emacs-Lisp; Mode: emacs-lisp -*-\n")
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1242 (insert-string (format ";;; saved strokes for %s, as of %s\n\n"
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1243 (user-full-name)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1244 (format-time-string "%B %e, %Y" nil)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1245 (message "Saving strokes in %s..." strokes-file)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1246 (insert-string (format "(setq strokes-global-map '%s)"
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1247 (pp current)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1248 (message "Saving strokes in %s..." strokes-file)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1249 (indent-region (point-min) (point-max) nil)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1250 (write-region (point-min)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1251 (point-max)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1252 strokes-file))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1253 (message "(no changes need to be saved)")))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1254 ;; protected
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1255 (if (get-buffer "*saved-strokes*")
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1256 (kill-buffer (get-buffer "*saved-strokes*")))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1257 (setq strokes-global-map current)))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1258
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1259 (defalias 'save-strokes 'strokes-prompt-user-save-strokes)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1260
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1261 (defun strokes-toggle-strokes-buffer (&optional arg)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1262 "Toggle the use of the strokes buffer.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1263 In other words, toggle the variabe `strokes-use-strokes-buffer'.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1264 With ARG, use strokes buffer if and only if ARG is positive or true.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1265 Returns value of `strokes-use-strokes-buffer'."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1266 (interactive "P")
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1267 (setq strokes-use-strokes-buffer
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1268 (if arg (> (prefix-numeric-value arg) 0)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1269 (not strokes-use-strokes-buffer))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1270
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1271 (defun strokes-xpm-for-stroke (stroke &optional bufname)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1272 "Create an xpm pixmap for the given stroke in buffer `*strokes-xpm*'.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1273 Optional BUFNAME to name something else.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1274 The pixmap will contain time information via rainbow dot colors
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1275 where each individual strokes begins."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1276 (save-excursion
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1277 (let ((buf (get-buffer-create (or bufname "*strokes-xpm*")))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1278 (stroke (strokes-eliminate-consecutive-redundancies
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1279 (strokes-fill-stroke
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1280 (strokes-renormalize-to-grid stroke 31))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1281 (lift-flag t)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1282 (rainbow-chars (list ?R ?O ?Y ?G ?B ?P)) ; ROYGBIV w/o indigo
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1283 (header (format "/* XPM */
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1284 static char * stroke_xpm[] = {
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1285 /* width height ncolors cpp [x_hot y_hot] */
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1286 \"33 33 9 1 26 23\",
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1287 /* colors */
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1288 \" c #FFFFFFFFFFFF\",
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1289 \"* s iconColor1 m black c black\",
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1290 \"R c #FFFF00000000\",
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1291 \"O c #FFFF80000000\",
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1292 \"Y c #FFFFFFFF0000\",
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1293 \"G c #0000FFFF0000\",
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1294 \"B c #00000000FFFF\",
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1295 \"P c #FFFF0000FFFF\",
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1296 \". c #45458B8B0000\",
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1297 /* pixels */")))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1298 (set-buffer buf)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1299 (erase-buffer)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1300 (insert header)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1301 (loop repeat 33 do
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1302 (newline)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1303 (insert-char ?\")
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1304 (insert-char ?\ 33)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1305 (insert "\",")
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1306 finally (insert "}\n"))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1307 (loop for point in stroke
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1308 for x = (car-safe point)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1309 for y = (cdr-safe point) do
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1310 (cond ((consp point)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1311 ;; draw a point, and possibly a starting-point
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1312 (if lift-flag
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1313 ;; mark starting point with the appropriate color
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1314 (let ((char (or (car rainbow-chars) ?\.)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1315 (loop for i from 0 to 2 do
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1316 (loop for j from 0 to 2 do
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1317 (goto-line (+ 16 i y))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1318 (forward-char (+ 1 j x))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1319 (delete-char 1)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1320 (insert-char char)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1321 (setq rainbow-chars (cdr rainbow-chars)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1322 lift-flag nil))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1323 ;; Otherwise, just plot the point...
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1324 (goto-line (+ 17 y))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1325 (forward-char (+ 2 x))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1326 (subst-char-in-region (point) (1+ (point)) ?\ ?\*)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1327 ((strokes-lift-p point)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1328 ;; a lift--tell the loop to X out the next point...
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1329 (setq lift-flag t)))))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1330
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1331 ;;;###autoload
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1332 (defun strokes-list-strokes (&optional stroke-map)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1333 "Pop up a buffer containing a listing of all strokes defined in STROKE-MAP.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1334 If STROKE-MAP is not given, `strokes-global-map' will be used instead."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1335 (interactive)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1336 (push-window-configuration)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1337 (set-buffer (get-buffer-create "*Strokes List*"))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1338 (setq buffer-read-only nil)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1339 (erase-buffer)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1340 (insert
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1341 "Command Stroke\n"
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1342 "------- ------\n\n")
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1343 (loop for def in (or stroke-map strokes-global-map) do
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1344 (let ((stroke (car def))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1345 (command (cdr def)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1346 (strokes-xpm-for-stroke stroke " *strokes-xpm*")
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1347 (insert-char ?\ 60)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1348 (beginning-of-line)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1349 (insert (symbol-name command))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1350 (beginning-of-line)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1351 (forward-char 45)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1352 (make-annotation (make-glyph
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1353 (list
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1354 (vector 'xpm
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1355 :data (buffer-substring
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1356 (point-min " *strokes-xpm*")
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1357 (point-max " *strokes-xpm*")
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1358 " *strokes-xpm*"))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1359 [string :data "[Image]"]))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1360 (point) 'text)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1361 (newline 2)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1362 (view-buffer "*Strokes List*" t)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1363 (goto-char (point-min))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1364 ;; (define-key
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1365 ;; (current-local-map (get-buffer "*Strokes List*"))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1366 ;; [(q)]
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1367 ;; 'pop-window-configuration))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1368 )
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1369
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1370 ;;;###autoload
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1371 (defalias 'list-strokes 'strokes-list-strokes)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1372
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1373 ;;;###autoload
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1374 (defun strokes-mode (&optional arg)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1375 "Toggle strokes being enabled.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1376 With ARG, turn strokes on if and only if ARG is positive or true.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1377 Note that `strokes-mode' is a global mode. Think of it as a minor
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1378 mode in all buffers when activated.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1379 By default, strokes are invoked with mouse button-2. You can define
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1380 new strokes with
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1381
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1382 > M-x global-set-stroke"
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1383 (interactive "P")
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1384 (let ((on-p (if arg
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1385 (> (prefix-numeric-value arg) 0)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1386 (not strokes-mode))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1387 (cond ((not (device-on-window-system-p))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1388 (error "Can't use strokes without windows"))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1389 (on-p ; turn on strokes
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1390 (and (file-exists-p strokes-file)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1391 (null strokes-global-map)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1392 (strokes-load-user-strokes))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1393 (add-hook 'kill-emacs-hook
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1394 'strokes-prompt-user-save-strokes)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1395 (add-hook 'select-frame-hook
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1396 'strokes-update-window-configuration)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1397 (strokes-update-window-configuration)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1398 (define-key global-map [(button2)] 'strokes-do-stroke)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1399 (define-key global-map [(control button2)] 'strokes-do-stroke)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1400 (define-key global-map [(shift button2)]
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1401 'strokes-do-complex-stroke)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1402 (ad-activate-regexp "^strokes-") ; advise button2 commands
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1403 (setq strokes-mode t))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1404 (t ; turn off strokes
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1405 (if (get-buffer strokes-buffer-name)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1406 (kill-buffer (get-buffer strokes-buffer-name)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1407 (remove-hook 'select-frame-hook
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1408 'strokes-update-window-configuration)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1409 (if (string-match "^strokes-" (symbol-name (key-binding [(button2)])))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1410 (define-key global-map [(button2)] strokes-click-command))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1411 (if (string-match "^strokes-" (symbol-name (key-binding [(control button2)])))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1412 (global-unset-key [(control button2)]))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1413 (if (string-match "^strokes-" (symbol-name (key-binding [(shift button2)])))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1414 (global-unset-key [(shift button2)]))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1415 (ad-deactivate-regexp "^strokes-") ; unadvise strokes-button2 commands
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1416 (setq strokes-mode nil))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1417 (redraw-modeline))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1418
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1419 (add-minor-mode 'strokes-mode strokes-modeline-string nil nil 'strokes-mode)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1420
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1421 (provide 'strokes)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1422 (run-hooks 'strokes-load-hook)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1423
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1424 ;;; strokes.el ends here