|
177
|
1 ;;; strokes.el -- Control XEmacs through mouse strokes --
|
|
|
2 ;; Mon Jun 2 12:40:41 EDT 1997
|
|
153
|
3
|
|
|
4 ;; Copyright (C) 1997 Free Software Foundation, Inc.
|
|
|
5
|
|
|
6 ;; Author: David Bakhash <cadet@mit.edu>
|
|
|
7 ;; Maintainer: David Bakhash <cadet@mit.edu>
|
|
177
|
8 ;; Version: 2.3
|
|
153
|
9 ;; Created: 12 April 1997
|
|
|
10 ;; Keywords: lisp, mouse, extensions
|
|
|
11
|
|
|
12 ;; This file is part of XEmacs.
|
|
|
13
|
|
|
14 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
|
15 ;; under the terms of the GNU General Public License as published by
|
|
|
16 ;; the Free Software Foundation; either version 2 of the License, or
|
|
|
17 ;; (at your option) any later version.
|
|
|
18
|
|
|
19 ;; XEmacs program is distributed in the hope that it will be useful,
|
|
|
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
22 ;; General Public License for more details.
|
|
|
23
|
|
|
24 ;; You should have received a copy of the GNU General Public License
|
|
|
25 ;; along with XEmacs; see the file COPYING. If not, write to the Free
|
|
|
26 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
|
27 ;; 02111-1307, USA.
|
|
|
28
|
|
|
29 ;;; Synched up with: Not in FSF.
|
|
|
30
|
|
|
31 ;;; Commentary:
|
|
|
32
|
|
|
33 ;; This package is written for for XEmacs v19.14 and up.
|
|
|
34 ;; This is the strokes package. It is intended to allow the user to
|
|
|
35 ;; control XEmacs by means of mouse strokes. Once strokes is loaded, you
|
|
|
36 ;; can always get help be invoking `strokes-help':
|
|
|
37
|
|
|
38 ;; > M-x strokes-help
|
|
|
39
|
|
|
40 ;; and you can learn how to use the package. A mouse stroke, for now,
|
|
|
41 ;; can be defined as holding the middle button, for instance, and then
|
|
|
42 ;; moving the mouse in whatever pattern you wish, which you have set
|
|
|
43 ;; XEmacs to understand as mapping to a given command. For example, you
|
|
|
44 ;; may wish the have a mouse stroke that looks like a capital `C' which
|
|
|
45 ;; means `copy-region-as-kill'. Treat strokes just like you do key
|
|
|
46 ;; bindings. For example, XEmacs sets key bindings globally with the
|
|
|
47 ;; `global-set-key' command. Likewise, you can do
|
|
|
48
|
|
|
49 ;; > M-x global-set-stroke
|
|
|
50
|
|
|
51 ;; to interactively program in a stroke. It would be wise to set the
|
|
|
52 ;; first one to this very command, so that from then on, you invoke
|
|
|
53 ;; `global-set-stroke' with a stroke. likewise, there may eventually
|
|
|
54 ;; be a `local-set-stroke' command, also analogous to `local-set-key'.
|
|
|
55
|
|
|
56 ;; You can always unset the last stroke definition with the command
|
|
|
57
|
|
|
58 ;; > M-x strokes-unset-last-stroke
|
|
|
59
|
|
|
60 ;; and the last stroke that was added to `strokes-global-map' will be
|
|
|
61 ;; removed.
|
|
|
62
|
|
|
63 ;; Other analogies between strokes and key bindings are as follows:
|
|
|
64
|
|
|
65 ;; 1) To describe a stroke binding, you can type
|
|
|
66
|
|
|
67 ;; > M-x describe-stroke
|
|
|
68
|
|
|
69 ;; analogous to `describe-key'. It's also wise to have a stroke,
|
|
|
70 ;; like an `h', for help, or a `?', mapped to `describe-stroke'.
|
|
|
71
|
|
|
72 ;; 2) stroke bindings are set internally through the lisp function
|
|
|
73 ;; `define-stroke', similar to the `define-key' function. some
|
|
|
74 ;; examples for a 3x3 stroke grid would be
|
|
|
75
|
|
|
76 ;; (define-stroke c-mode-stroke-map
|
|
|
77 ;; '((0 . 0) (1 . 1) (2 . 2))
|
|
|
78 ;; 'kill-region)
|
|
|
79 ;; (define-stroke strokes-global-map
|
|
|
80 ;; '((0 . 0) (0 . 1) (0 . 2) (1 . 2) (2 . 2))
|
|
|
81 ;; 'list-buffers)
|
|
|
82
|
|
|
83 ;; however, if you would probably just have the user enter in the
|
|
|
84 ;; stroke interactively and then set the stroke to whatever he/she
|
|
|
85 ;; entered. The lisp function to interactively read a stroke is
|
|
|
86 ;; `strokes-read-stroke'. This is especially helpful when you're
|
|
|
87 ;; on a fast computer that can handle a 9x9 stroke grid.
|
|
|
88
|
|
|
89 ;; NOTE: only global stroke bindings are currently implemented,
|
|
|
90 ;; however mode- and buffer-local stroke bindings may eventually
|
|
|
91 ;; be implemented in a future version.
|
|
|
92
|
|
|
93 ;; The important variables to be aware of for this package are listed
|
|
|
94 ;; below. They can all be altered through the customizing package via
|
|
|
95
|
|
|
96 ;; > M-x customize
|
|
|
97
|
|
|
98 ;; and customizing the group named `strokes'. You can also read
|
|
|
99 ;; documentation on the variables there.
|
|
|
100
|
|
|
101 ;; `strokes-minimum-match-score' (determines the threshold of error that
|
|
|
102 ;; makes a stroke acceptable or unacceptable. If your strokes arn't
|
|
|
103 ;; matching, then you should raise this variable.
|
|
|
104
|
|
|
105 ;; `strokes-grid-resolution' (determines the grid dimensions that you use
|
|
|
106 ;; when defining/reading strokes. The finer the grid your computer can
|
|
|
107 ;; handle, the more you can do, but even a 3x3 grid is pretty cool.)
|
|
|
108 ;; The default value (7) should be fine for most decent computers.
|
|
|
109 ;; NOTE: This variable should not be set to a number less than 3.
|
|
|
110
|
|
|
111 ;; `strokes-display-strokes-buffer' will allow you to hide the strokes
|
|
|
112 ;; buffer when doing simple strokes. This is a speedup for slow
|
|
|
113 ;; computers as well as people who don't want to see their strokes.
|
|
|
114
|
|
|
115 ;; If you find that your mouse is accelerating too fast, you can
|
|
|
116 ;; execute the UNIX X command to slow it down. A good possibility is
|
|
|
117
|
|
|
118 ;; % xset m 5/4 8
|
|
|
119
|
|
|
120 ;; which seems, heuristically, to work okay, without much disruption.
|
|
|
121
|
|
|
122 ;; Whenever you load in the strokes package, you will be able to save
|
|
|
123 ;; what you've done upon exiting XEmacs. You can also do
|
|
|
124
|
|
|
125 ;; > M-x save-strokes
|
|
|
126
|
|
|
127 ;; and it will save your strokes in ~/.strokes, or you may wish to change
|
|
|
128 ;; this by setting the variable `strokes-file'.
|
|
|
129
|
|
|
130 ;; Note that internally, all of the routines that are part of this
|
|
|
131 ;; package are able to deal with complex strokes, as they are a superset
|
|
|
132 ;; of simple strokes. However, the default of this package will map
|
|
|
133 ;; mouse button2 to the command `strokes-do-stroke', and NOT
|
|
|
134 ;; `strokes-do-complex-stroke'. If you wish to use complex strokes, you
|
|
|
135 ;; will have to override this key mapping. Complex strokes are terminated
|
|
|
136 ;; with mouse button3. The strokes package will not interfere with
|
|
|
137 ;; `mouse-yank', but you may want to examine how this is done (see the
|
|
|
138 ;; variable `strokes-click-command')
|
|
|
139
|
|
|
140 ;; To get strokes to work as part of your your setup, then you'll have
|
|
|
141 ;; put the strokes package in your load-path (preferably byte-compiled)
|
|
|
142 ;; and then add the following to your .xemacs-options file (or wherever
|
|
|
143 ;; you put XEmacs-specific startup preferences):
|
|
|
144
|
|
|
145 ;;(and (fboundp 'device-on-window-system-p)
|
|
|
146 ;; (device-on-window-system-p)
|
|
|
147 ;; (require 'strokes))
|
|
|
148
|
|
|
149 ;; Once loaded, you can start stroking. You can also toggle between
|
|
|
150 ;; strokes mode by simple typing
|
|
|
151
|
|
|
152 ;; > M-x strokes-mode
|
|
|
153
|
|
|
154 ;; I am now in the process of porting this package to emacs. I also hope
|
|
|
155 ;; that, with the help of others, this package will be useful in entering
|
|
|
156 ;; in pictographic-like language text using the mouse (i.e. Korean).
|
|
|
157 ;; Japanese and Chinese are a bit trickier, but I'm sure that with help
|
|
|
158 ;; it can be done. The next version will allow the user to enter strokes
|
|
|
159 ;; which "remove the pencil from the paper" so to speak, so one character
|
|
|
160 ;; can have multiple strokes.
|
|
|
161
|
|
177
|
162 ;; You can read more about strokes at:
|
|
|
163
|
|
|
164 ;; http://www.mit.edu/people/cadet/strokes-help.html
|
|
|
165
|
|
|
166 ;; If you're interested in using strokes for writing English into XEmacs
|
|
|
167 ;; using strokes, then you'll want to read about it on the web page above
|
|
|
168 ;; or just download from http://www.mit.edu/people/cadet/strokes-abc.el,
|
|
|
169 ;; which is nothing but a file with some helper commands for inserting
|
|
|
170 ;; alphanumerics and punctuation.
|
|
|
171
|
|
153
|
172 ;; Great thanks to Rob Ristroph for his generosity in letting me use his
|
|
|
173 ;; PC to develop this, Jason Johnson for his help in algorithms, Euna
|
|
|
174 ;; Kim for her help in Korean, and massive thanks to the helpful guys
|
|
|
175 ;; on the help instance on athena (zeno, jered, amu, gsstark, ghudson, etc)
|
|
|
176 ;; Special thanks to Steve Baur and Hrvoje Niksic for all their help.
|
|
177
|
177 ;; And even more thanks to Dave Gillespie for all the elisp help--he
|
|
|
178 ;; is responsible for helping me use the cl macros at (near) max speed.
|
|
153
|
179
|
|
|
180 ;; Tasks: (what I'm getting ready for future version)...
|
|
|
181 ;; 2) use 'strokes-read-complex-stroke for korean, etc.
|
|
|
182 ;; 4) buffer-local 'strokes-local-map, and mode-stroke-maps would be nice
|
|
|
183 ;; 5) 'list-strokes (kinda important). What do people want?
|
|
|
184 ;; How about an optional docstring for each stroke so that a person
|
|
|
185 ;; can examine the strokes-file and actually make sense of it?
|
|
|
186 ;; (e.g. "This stroke is a pentagram")
|
|
|
187 ;; 6) add some hooks, like `strokes-read-stroke-hook'
|
|
|
188 ;; 7) See what people think of the factory settings. Should I change
|
|
|
189 ;; them? They're all pretty arbitrary in a way. I guess they
|
|
|
190 ;; should be minimal, but computers are getting lots faster, and
|
|
|
191 ;; if I choose the defaults too conservatively, then strokes will
|
|
|
192 ;; surely dissapoint some people on decent machines (until they
|
|
|
193 ;; figure out M-x customize). I need feedback.
|
|
|
194 ;; Other: I always have the most beta version of strokes, so if you
|
|
|
195 ;; want it just let me know.
|
|
|
196
|
|
|
197 ;;; Change Log:
|
|
|
198
|
|
|
199 ;; 1.3: provided user variable `strokes-use-strokes-buffer' to let users
|
|
|
200 ;; hide the strokes and strokes buffer when entering simple strokes.
|
|
|
201 ;; 1.3: cleaned up most leaks.
|
|
|
202 ;; 1.3: with Jari Aalto's help, cleaned up overall program.
|
|
|
203 ;; 1.3: added `strokes-help' for help on strokes
|
|
|
204 ;; 1.3: fixed 'strokes-load-hook bug
|
|
|
205 ;; 1.3: email address change: now <cadet@mit.edu>
|
|
|
206 ;; 1.3: added `strokes-report-bug' based on efs/dired's `dired-report-bug'
|
|
|
207 ;; 1.3: added more dialog-box queries for mouse-event stuff.
|
|
|
208 ;; 1.4: allowed strokes to invoke kbd macros as well (thanks gsstark!)
|
|
|
209 ;; 2.0: fixed up ordering of certain functions.
|
|
|
210 ;; 2.0: fixed bug applying to strokes in dedicated and minibuffer windows.
|
|
|
211 ;; 2.0: punted the C-h way of invoking strokes help routines.
|
|
|
212 ;; 2.0: fixed `strokes-define-stroke' so it would error check against
|
|
|
213 ;; defining strokes that were too short (really clicks)
|
|
|
214 ;; 2.0: added `strokes-toggle-strokes-buffer' interactive function
|
|
|
215 ;; 2.0: added `customize' support, thanks to patch from Hrvoje (thanks)
|
|
|
216 ;; 2.1: strokes no longer forces `mouse-yank-at-point' to t on mouse-yank
|
|
|
217 ;; (i.e. `mouse-yank-at-point' is up to you again)
|
|
|
218 ;; 2.1: toggling strokes-mode off and then back on no longer deletes
|
|
|
219 ;; the strokes that you programmed in but didn't save before
|
|
|
220 ;; toggling off strokes-mode.
|
|
|
221 ;; 2.1: advised may functions for modes like VM and w3 so that they too
|
|
|
222 ;; can use strokes, while still mantaining old button2 functionality.
|
|
|
223 ;; 2.1: with steve's help, got the autoload for `strokes-mode' and
|
|
|
224 ;; fixed up the package so loading it does not enable strokes
|
|
|
225 ;; until user calls `strokes-mode'.
|
|
|
226 ;; 2.2: made sure that abbrev-mode was off in the ` *strokes*' buffer
|
|
|
227 ;; 2.2: added more dired advice for mouse permissions commands
|
|
|
228 ;; 2.2: added some checks to see if saving strokes is really necessary so
|
|
|
229 ;; the user doesn't get promped aimlessly.
|
|
|
230 ;; 2.2: change the `strokes-lift' symbol to a keyword of value `:strokes-lift'
|
|
|
231 ;; for legibility. IF YOUR OLD STROKES DON'T WORK, THIS IS PROBABLY WHY.
|
|
|
232 ;; 2.2: I might have to change this back to `'strokes-lift' because the keyword
|
|
|
233 ;; fails in emacs, though I don't know why.
|
|
|
234 ;; 2.2: `strokes-describe-stroke' is nicer during recursive edits
|
|
|
235 ;; 2.2: provided `strokes-fill-stroke' to fill in empty spaces of strokes
|
|
|
236 ;; as an important step towards platform (speed) independence.
|
|
|
237 ;; Because of this, I moved the global setting of `strokes-last-stroke'
|
|
|
238 ;; from `strokes-eliminate-consecutive-redundancies' to
|
|
|
239 ;; `strokes-fill-stroke' since the latter comes later in processing
|
|
|
240 ;; a user stroke.
|
|
|
241 ;; 2.2: Finally changed the defaults, so now `strokes-grid-resolution' is 9
|
|
|
242 ;; and `strokes-minimum-match-score' is 1000 by default. This will surely
|
|
|
243 ;; mess some people up, but if so, just set it back w/ M-x customize.
|
|
|
244 ;; 2.2: Fixed up the mechanism for updating the `strokes-window-configuration'.
|
|
|
245 ;; Now it only uses one function (`strokes-update-window-configuration')
|
|
|
246 ;; which does it all, and much more efficiently (thanks RMS!).
|
|
|
247 ;; 2.2 Fixed up the appearance of the *strokes* buffer so that there are no
|
|
|
248 ;; ugly line truncations, and I got rid of the bug which would draw the stroke
|
|
|
249 ;; on the wrong line. I still wish that `event-closest-point' was smarter.
|
|
|
250 ;; In fact, `event-closest-point' does *not* do what its name suggests.
|
|
|
251 ;; 2.3 Added more to `strokes-update-window-configuration' so it goes to hell less often
|
|
|
252 ;; 2.3 `strokes-mode' no longer will undefine keys unless it's sure that the user had
|
|
|
253 ;; had them mapped to a strokes command.
|
|
|
254 ;; 2.3 added more magic autoload statements so strokes work more smoothly.
|
|
|
255 ;; similarly, I made strokes-mode turn itself on when the user defines a stroke
|
|
|
256 ;; (thanks Hrvoje).
|
|
|
257 ;; 2.3 Added "Strokes" to the modeline when strokes is on, and allow toggling strokes
|
|
|
258 ;; with mouse button2.
|
|
|
259 ;; 2.3 Added `list-strokes', which is a really nice function which graphically lists
|
|
|
260 ;; all the strokes that the user has defined and their corresponding commands.
|
|
|
261 ;; `list-strokes' will appropriately colorize the pixmaps to display some time info.
|
|
|
262
|
|
|
263 ;;; Code:
|
|
|
264
|
|
|
265 ;;; Requirements and provisions...
|
|
|
266
|
|
|
267 (autoload 'reporter-submit-bug-report "reporter")
|
|
|
268 (autoload 'mail-position-on-field "sendmail")
|
|
177
|
269 (eval-when-compile
|
|
|
270 (mapc 'require '(xpm-mode pp annotations reporter advice)))
|
|
153
|
271
|
|
|
272 ;;; Constants...
|
|
|
273
|
|
177
|
274 (defconst strokes-version "2.3")
|
|
153
|
275
|
|
|
276 (defconst strokes-bug-address "cadet@mit.edu")
|
|
|
277
|
|
|
278 (defconst strokes-lift :strokes-lift
|
|
|
279 "Symbol representing a stroke lift event for complex strokes.
|
|
|
280 Complex strokes are those which contain two or more simple strokes.
|
|
|
281 This will be useful for when XEmacs understands Chinese.")
|
|
|
282
|
|
177
|
283 (defconst strokes-xpm-header "/* XPM */
|
|
|
284 static char * stroke_xpm[] = {
|
|
|
285 /* width height ncolors cpp [x_hot y_hot] */
|
|
|
286 \"33 33 9 1 26 23\",
|
|
|
287 /* colors */
|
|
|
288 \" c #D9D9D9D9D9D9\",
|
|
|
289 \"* s iconColor1 m black c black\",
|
|
|
290 \"R c #FFFF00000000\",
|
|
|
291 \"O c #FFFF80000000\",
|
|
|
292 \"Y c #FFFFFFFF0000\",
|
|
|
293 \"G c #0000FFFF0000\",
|
|
|
294 \"B c #00000000FFFF\",
|
|
|
295 \"P c #FFFF0000FFFF\",
|
|
|
296 \". c #45458B8B0000\",
|
|
|
297 /* pixels */\n"
|
|
|
298 "The header to all xpm buffers created by strokes")
|
|
|
299
|
|
153
|
300 ;;; user variables...
|
|
|
301
|
|
|
302 (defgroup strokes nil
|
|
|
303 "Control Emacs through mouse strokes"
|
|
|
304 :group 'mouse)
|
|
|
305
|
|
|
306 (defcustom strokes-modeline-string " Strokes"
|
|
|
307 "*Modeline identification when strokes are on \(default is \" Strokes\"\)."
|
|
|
308 :type 'string
|
|
|
309 :group 'strokes)
|
|
|
310
|
|
|
311 (defcustom strokes-character ?o
|
|
|
312 "*Character used when drawing strokes in the strokes buffer.
|
|
|
313 \(The default is lower-case `o', which works okay\)."
|
|
|
314 :type 'character
|
|
|
315 :group 'strokes)
|
|
|
316
|
|
|
317 (defcustom strokes-minimum-match-score 1000
|
|
|
318 "*Minimum score for a stroke to be considered a possible match.
|
|
|
319 Requiring a perfect match would set this variable to 0.
|
|
|
320 The default value is 1000, but it's mostly dependent on how precisely
|
|
|
321 you manage to replicate your user-defined strokes. It also depends on
|
|
|
322 the value of `strokes-grid-resolution', since a higher grid resolution
|
|
|
323 will correspond to more sample points, and thus more distance
|
|
|
324 measurements. Usually, this is not a problem since you first set
|
|
|
325 `strokes-grid-resolution' based on what your computer seems to be able
|
|
|
326 to handle (though the defaults are usually more than sufficent), and
|
|
|
327 then you can set `strokes-minimum-match-score' to something that works
|
|
|
328 for you. The only purpose of this variable is to insure that if you
|
|
|
329 do a bogus stroke that really doesn't match any of the predefined
|
|
|
330 ones, then strokes should NOT pick the one that came closest."
|
|
|
331 :type 'integer
|
|
|
332 :group 'strokes)
|
|
|
333
|
|
|
334 (defcustom strokes-grid-resolution 9
|
|
|
335 "*Integer defining dimensions of the stroke grid.
|
|
|
336 The grid is a square grid, where STROKES-GRID-RESOLUTION defaults to
|
|
|
337 `9', making a 9x9 grid whose coordinates go from (0 . 0) on the top
|
|
|
338 left to ((STROKES-GRID-RESOLUTION - 1) . (STROKES-GRID-RESOLUTION - 1))
|
|
|
339 on the bottom right. The greater the resolution, the more intricate
|
|
|
340 your strokes can be.
|
|
|
341 NOTE: This variable should be odd and MUST NOT be less than 3.
|
|
|
342 WARNING: Changing the value of this variable will gravely affect the
|
|
|
343 strokes you have already programmed in. You should try to
|
|
|
344 figure out what it should be based on your needs and on how
|
|
|
345 quick the particular platform(s) you're operating on, and
|
|
|
346 only then start programming in your custom strokes."
|
|
|
347 :type 'integer
|
|
|
348 :group 'strokes)
|
|
|
349
|
|
|
350 (defcustom strokes-file "~/.strokes"
|
|
|
351 "*File containing saved strokes for stroke-mode (default is ~/.strokes)."
|
|
|
352 :type 'file
|
|
|
353 :group 'strokes)
|
|
|
354
|
|
|
355 (defcustom strokes-buffer-name " *strokes*"
|
|
|
356 "The buffer that the strokes take place in (default is ` *strokes*')."
|
|
|
357 :type 'string
|
|
|
358 :group 'strokes)
|
|
|
359
|
|
|
360 (defcustom strokes-use-strokes-buffer t
|
|
|
361 "*If non-nil, the strokes buffer is used and strokes are displayed.
|
|
|
362 If nil, strokes will be read the same, however the user will not be
|
|
|
363 able to see the strokes. This be helpful for people who don't like
|
|
|
364 the delay in switching to the strokes buffer."
|
|
|
365 :type 'boolean
|
|
|
366 :group 'strokes)
|
|
|
367
|
|
|
368 (defcustom strokes-click-command 'mouse-yank
|
|
|
369 "*Command to execute when stroke is actually a `click' event.
|
|
|
370 This is set to `mouse-yank' by default."
|
|
|
371 :type 'function
|
|
|
372 :group 'strokes)
|
|
|
373
|
|
|
374 ;;; internal variables...
|
|
|
375
|
|
|
376 ;;;###autoload
|
|
|
377 (defvar strokes-mode nil
|
|
|
378 "Non-nil when `strokes' is globally enabled")
|
|
|
379
|
|
|
380 (defvar strokes-window-configuration nil
|
|
|
381 "The special window configuration used when entering strokes.
|
|
|
382 This is set properly in the function `strokes-update-window-configuration'.")
|
|
|
383
|
|
|
384 (defvar strokes-last-stroke nil
|
|
|
385 "Last stroke entered by the user.
|
|
|
386 Its value gets set every time the function
|
|
|
387 `strokes-fill-stroke' gets called,
|
|
|
388 since that is the best time to set the variable")
|
|
|
389
|
|
|
390 (defvar strokes-global-map '()
|
|
|
391 "Association list of strokes and their definitions.
|
|
|
392 Each entry is (STROKE . COMMAND) where STROKE is itself a list of
|
|
|
393 coordinates (X . Y) where X and Y are lists of positions on the
|
|
|
394 normalized stroke grid, with the top left at (0 . 0). COMMAND is the
|
|
|
395 corresponding interactive function")
|
|
|
396
|
|
|
397 (defvar strokes-load-hook nil
|
|
|
398 "Function or functions to be called when `strokes' is loaded.")
|
|
|
399
|
|
177
|
400 (defvar edit-strokes-menu
|
|
|
401 '("Edit-Strokes"
|
|
|
402 ["Add stroke..." strokes-global-set-stroke t]
|
|
|
403 ["Delete stroke..." strokes-edit-delete-stroke t]
|
|
|
404 ["Change stroke" strokes-smaller t]
|
|
|
405 ["Change definition" strokes-larger t]
|
|
|
406 ["[Re]List Strokes chronologically" strokes-list-strokes t]
|
|
|
407 ["[Re]List Strokes alphabetically" strokes-list-strokes t]
|
|
|
408 ["Quit" strokes-edit-quit t]
|
|
|
409 ))
|
|
|
410
|
|
153
|
411 ;;; Macros...
|
|
|
412
|
|
|
413 (defsubst strokes-click-p (stroke)
|
|
|
414 "Non-nil if STROKE is really click."
|
|
|
415 (< (length stroke) 3))
|
|
|
416
|
|
|
417 ;;; old, but worked pretty good (just in case)...
|
|
|
418 ;;(defmacro strokes-define-stroke (stroke-map stroke def)
|
|
|
419 ;; "Add STROKE to STROKE-MAP alist with given command DEF"
|
|
|
420 ;; (list 'if (list '< (list 'length stroke) 3)
|
|
|
421 ;; (list 'error
|
|
|
422 ;; "That's a click, not a stroke. See `strokes-click-command'")
|
|
|
423 ;; (list 'setq stroke-map (list 'cons (list 'cons stroke def)
|
|
|
424 ;; (list 'remassoc stroke stroke-map)))))
|
|
|
425
|
|
|
426 (defmacro strokes-define-stroke (stroke-map stroke def)
|
|
|
427 "Add STROKE to STROKE-MAP alist with given command DEF"
|
|
|
428 `(if (strokes-click-p ,stroke)
|
|
|
429 (error "That's a click, not a stroke; see `strokes-click-command'")
|
|
|
430 (setq ,stroke-map (cons (cons ,stroke ,def)
|
|
|
431 (remassoc ,stroke ,stroke-map)))))
|
|
|
432
|
|
|
433 (defalias 'define-stroke 'strokes-define-stroke)
|
|
|
434
|
|
|
435 (defsubst strokes-square (x)
|
|
|
436 "Returns the square of the number X"
|
|
|
437 (* x x))
|
|
|
438
|
|
|
439 (defsubst strokes-distance-squared (p1 p2)
|
|
|
440 "Gets the distance (squared) between to points P1 and P2.
|
|
|
441 Each point is a cons cells (X . Y)"
|
|
|
442 (let ((x1 (car p1))
|
|
|
443 (y1 (cdr p1))
|
|
|
444 (x2 (car p2))
|
|
|
445 (y2 (cdr p2)))
|
|
|
446 (+ (strokes-square (- x2 x1))
|
|
|
447 (strokes-square (- y2 y1)))))
|
|
|
448
|
|
|
449 ;;; Advice for various functions...
|
|
|
450
|
|
|
451 ;; I'd originally wanted to write a macro that would just take in the
|
|
|
452 ;; generic functions which use mouse button2 in various modes. Most of
|
|
|
453 ;; them are identical in form: they take an event as the single argument
|
|
|
454 ;; and then do their thing. I tried writing a macro that looked
|
|
|
455 ;; something like this, but failed. Advice just ain't that easy. The
|
|
|
456 ;; one that bugged me the most was `Manual-follow-xref', because that had
|
|
|
457 ;; &rest arguments, and I didn't know how to work around it in defadvice.
|
|
|
458 ;; However, I was able to fix up most of the important modes (i.e. the
|
|
|
459 ;; ones I use all the time). One `bug' in the program that I just can't
|
|
|
460 ;; seem to figure out is why I can only advise other button2 functions
|
|
|
461 ;; successfully when the variable `strokes-use-strokes-buffer' is nil. I
|
|
|
462 ;; did all the save-excursion/save-window-excursion stuff SPECIFICALLY so
|
|
|
463 ;; that using the strokes buffer or not would absolutely not affect any
|
|
|
464 ;; other part of the program. If someone can figure out how to make the
|
|
|
465 ;; following advices work w/ regardless of that variable
|
|
|
466 ;; `strokes-use-strokes-buffer', then that would be a great victory. If
|
|
|
467 ;; someone out there would be kind enough to make the commented code
|
|
|
468 ;; below work, I'd be grateful. By the way, I put the `protect' keywords
|
|
|
469 ;; there to insure that if a stroke went bad, then
|
|
|
470 ;; `strokes-click-command' would be set back. If this isn't necessary,
|
|
|
471 ;; then feel free to let me know.
|
|
|
472
|
|
|
473 ;; For what follows, I really wanted something that would work like this:
|
|
|
474
|
|
|
475 ;;(strokes-fix-button2 'vm-mouse-button-2)
|
|
|
476
|
|
|
477 ;; Or even better, I could have simply done something like:
|
|
|
478
|
|
|
479 ;;(mapcar 'strokes-fix-button2
|
|
|
480 ;; '(vm-mouse-button-2
|
|
|
481 ;; rmail-summary-mouse-goto-msg
|
|
|
482 ;; <rest of them>))
|
|
|
483
|
|
|
484 ;;; With help from Hans (author of advice.el)...
|
|
|
485 (defmacro strokes-fix-button2-command (command)
|
|
|
486 "Fix COMMAND so that it can also work with strokes.
|
|
|
487 COMMAND must take one event argument.
|
|
|
488 Example of how one might fix up a command that's bound to button2
|
|
|
489 and which is an interactive funcion of one event argument:
|
|
|
490
|
|
|
491 (strokes-fix-button2-command 'vm-mouse-button-2)"
|
|
|
492 (let ((command (eval command)))
|
|
|
493 `(progn
|
|
|
494 (defadvice ,command (around strokes-fix-button2 compile preactivate)
|
|
|
495 ,(format "Fix %s to work with strokes." command)
|
|
|
496 (if strokes-use-strokes-buffer
|
|
|
497 ;; then strokes is no good and we'll have to use the original
|
|
|
498 ad-do-it
|
|
|
499 ;; otherwise, we can make strokes work too...
|
|
|
500 (let ((strokes-click-command
|
|
|
501 ',(intern (format "ad-Orig-%s" command))))
|
|
|
502 (strokes-do-stroke (ad-get-arg 0))))))))
|
|
|
503
|
|
|
504 (strokes-fix-button2-command 'vm-mouse-button-2)
|
|
|
505 (strokes-fix-button2-command 'rmail-summary-mouse-goto-msg)
|
|
|
506 (strokes-fix-button2-command 'Buffer-menu-mouse-select)
|
|
|
507 (strokes-fix-button2-command 'w3-widget-button-click)
|
|
|
508 (strokes-fix-button2-command 'widget-image-button-press)
|
|
|
509 (strokes-fix-button2-command 'Info-follow-clicked-node)
|
|
|
510 (strokes-fix-button2-command 'compile-mouse-goto-error)
|
|
|
511 (strokes-fix-button2-command 'gdbsrc-select-or-yank)
|
|
|
512 (strokes-fix-button2-command 'hypropos-mouse-get-doc)
|
|
|
513 (strokes-fix-button2-command 'gnus-mouse-pick-group)
|
|
|
514 (strokes-fix-button2-command 'gnus-mouse-pick-article)
|
|
|
515 (strokes-fix-button2-command 'gnus-article-push-button)
|
|
|
516 (strokes-fix-button2-command 'dired-mouse-find-file)
|
|
|
517 (strokes-fix-button2-command 'url-dired-find-file-mouse)
|
|
|
518 (strokes-fix-button2-command 'dired-u-r-mouse-toggle)
|
|
|
519 (strokes-fix-button2-command 'dired-u-w-mouse-toggle)
|
|
|
520 (strokes-fix-button2-command 'dired-u-x-mouse-toggle)
|
|
|
521 (strokes-fix-button2-command 'dired-g-r-mouse-toggle)
|
|
|
522 (strokes-fix-button2-command 'dired-g-w-mouse-toggle)
|
|
|
523 (strokes-fix-button2-command 'dired-g-x-mouse-toggle)
|
|
|
524 (strokes-fix-button2-command 'dired-o-r-mouse-toggle)
|
|
|
525 (strokes-fix-button2-command 'dired-o-w-mouse-toggle)
|
|
|
526 (strokes-fix-button2-command 'isearch-yank-x-selection)
|
|
|
527 (strokes-fix-button2-command 'occur-mode-mouse-goto)
|
|
177
|
528 (strokes-fix-button2-command 'cvs-mouse-find-file)
|
|
153
|
529
|
|
|
530 ;;; I can fix the customize widget button click, but then
|
|
|
531 ;;; people will get confused when they try to customize
|
|
|
532 ;;; strokes with the mouse and customize tells them that
|
|
|
533 ;;; `strokes-click-command' is mapped to `ad-Orig-widget-button-click'
|
|
|
534 ;;(strokes-fix-button2-command 'widget-button-click)
|
|
|
535
|
|
|
536 ;;; without the advice, each advised function would look like...
|
|
|
537 ;;(defadvice vm-mouse-button-2 (around vm-strokes activate protect)
|
|
|
538 ;; "Allow strokes to work in VM."
|
|
|
539 ;; (if strokes-use-strokes-buffer
|
|
|
540 ;; ;; then strokes is no good and we'll have to use the original
|
|
|
541 ;; ad-do-it
|
|
|
542 ;; ;; otherwise, we can make strokes work too...
|
|
|
543 ;; (let ((strokes-click-command 'ad-Orig-vm-mouse-button-2))
|
|
|
544 ;; (strokes-do-stroke (ad-get-arg 0)))))
|
|
|
545
|
|
|
546 ;;; Functions...
|
|
|
547
|
|
|
548 (defun strokes-lift-p (object)
|
|
|
549 "Return non-nil if object is a stroke-lift"
|
|
|
550 (eq object strokes-lift))
|
|
|
551
|
|
|
552 (defun strokes-unset-last-stroke ()
|
|
|
553 "Undo the last stroke definition."
|
|
|
554 (interactive)
|
|
|
555 (let ((command (cdar strokes-global-map)))
|
|
|
556 (if (y-or-n-p-maybe-dialog-box
|
|
|
557 (format "really delete last stroke definition, defined to `%s'? "
|
|
|
558 command))
|
|
|
559 (progn
|
|
|
560 (setq strokes-global-map (cdr strokes-global-map))
|
|
|
561 (message "That stroke has been deleted"))
|
|
|
562 (message "Nothing done"))))
|
|
|
563
|
|
|
564 ;;;###autoload
|
|
|
565 (defun strokes-global-set-stroke (stroke command)
|
|
|
566 "Interactively give STROKE the global binding as COMMAND.
|
|
|
567 Operated just like `global-set-key', except for strokes.
|
|
|
568 COMMAND is a symbol naming an interactively-callable function. STROKE
|
|
|
569 is a list of sampled positions on the stroke grid as described in the
|
|
|
570 documentation for the `strokes-define-stroke' function."
|
|
|
571 (interactive
|
|
|
572 (list
|
|
|
573 (and (or strokes-mode (strokes-mode t))
|
|
|
574 (strokes-read-complex-stroke
|
|
|
575 "Define a new stroke. Draw with button1 (or 2). End with button3..."))
|
|
|
576 (read-command "command to map stroke to: ")))
|
|
|
577 (strokes-define-stroke strokes-global-map stroke command))
|
|
|
578
|
|
|
579 ;;;###autoload
|
|
|
580 (defalias 'global-set-stroke 'strokes-global-set-stroke)
|
|
|
581
|
|
|
582 ;;(defun global-unset-stroke (stroke); FINISH THIS DEFUN!
|
|
|
583 ;; "delete all strokes matching STROKE from `strokes-global-map',
|
|
|
584 ;; letting the user input
|
|
|
585 ;; the stroke with the mouse"
|
|
|
586 ;; (interactive
|
|
|
587 ;; (list
|
|
|
588 ;; (strokes-read-stroke "Enter the stroke you want to delete...")))
|
|
|
589 ;; (strokes-define-stroke 'strokes-global-map stroke command))
|
|
|
590
|
|
|
591 (defun strokes-get-grid-position (stroke-extent position &optional grid-resolution)
|
|
|
592 "Map POSITION to a new grid position based on its STROKE-EXTENT and GRID-RESOLUTION.
|
|
|
593 STROKE-EXTENT as a list \(\(xmin . ymin\) \(xmax . ymax\)\).
|
|
|
594 If POSITION is a `strokes-lift', then it is itself returned.
|
|
|
595 Optional GRID-RESOLUTION may be used in place of STROKES-GRID-RESOLUTION.
|
|
|
596 The grid is a square whose dimesion is [0,GRID-RESOLUTION)."
|
|
|
597 (cond ((consp position) ; actual pixel location
|
|
|
598 (let ((grid-resolution (or grid-resolution strokes-grid-resolution))
|
|
|
599 (x (car position))
|
|
|
600 (y (cdr position))
|
|
|
601 (xmin (caar stroke-extent))
|
|
|
602 (ymin (cdar stroke-extent))
|
|
|
603 ;; the `1+' is there to insure that the
|
|
|
604 ;; formula evaluates correctly at the boundaries
|
|
|
605 (xmax (1+ (caadr stroke-extent)))
|
|
|
606 (ymax (1+ (cdadr stroke-extent))))
|
|
|
607 (cons (floor (* grid-resolution
|
|
|
608 (/ (float (- x xmin))
|
|
|
609 (- xmax xmin))))
|
|
|
610 (floor (* grid-resolution
|
|
|
611 (/ (float (- y ymin))
|
|
|
612 (- ymax ymin)))))))
|
|
|
613 ((strokes-lift-p position) ; stroke lift
|
|
|
614 strokes-lift)))
|
|
|
615
|
|
|
616 ;;(defun strokes-get-grid-position (stroke-extent pix-pos)
|
|
|
617 ;; "Return the stroke-grid position for PIX-POS given the total STROKE-EXTENT.
|
|
|
618 ;;STROKE-EXTENT as a list \(\(xmin . ymin\) \(xmax . ymax\)\) and a particular
|
|
|
619 ;;pixel position or `strokes-lift', find the corresponding grid position
|
|
|
620 ;;\(based on `strokes-grid-resolution'\) for the PIX-POS."
|
|
|
621 ;; (cond ((consp pix-pos) ; actual pixel location
|
|
|
622 ;; (let ((x (car pix-pos))
|
|
|
623 ;; (y (cdr pix-pos))
|
|
|
624 ;; (xmin (caar stroke-extent))
|
|
|
625 ;; (ymin (cdar stroke-extent))
|
|
|
626 ;; ;; the `1+' is there to insure that the
|
|
|
627 ;; ;; formula evaluates correctly at the boundaries
|
|
|
628 ;; (xmax (1+ (caadr stroke-extent)))
|
|
|
629 ;; (ymax (1+ (cdadr stroke-extent))))
|
|
|
630 ;; (cons (floor (* strokes-grid-resolution
|
|
|
631 ;; (/ (float (- x xmin))
|
|
|
632 ;; (- xmax xmin))))
|
|
|
633 ;; (floor (* strokes-grid-resolution
|
|
|
634 ;; (/ (float (- y ymin))
|
|
|
635 ;; (- ymax ymin)))))))
|
|
|
636 ;; ((strokes-lift-p pix-pos) ; stroke lift
|
|
|
637 ;; strokes-lift)))
|
|
|
638
|
|
|
639 (defun strokes-get-stroke-extent (pixel-positions)
|
|
|
640 "From a list of absolute PIXEL-POSITIONS, returns absolute spatial extent.
|
|
|
641 The return value is a list ((xmin . ymin) (xmax . ymax))."
|
|
|
642 (if pixel-positions
|
|
|
643 (let ((xmin (caar pixel-positions))
|
|
|
644 (xmax (caar pixel-positions))
|
|
|
645 (ymin (cdar pixel-positions))
|
|
|
646 (ymax (cdar pixel-positions))
|
|
|
647 (rest (cdr pixel-positions)))
|
|
|
648 (while rest
|
|
|
649 (if (consp (car rest))
|
|
|
650 (let ((x (caar rest))
|
|
|
651 (y (cdar rest)))
|
|
|
652 (if (< x xmin)
|
|
|
653 (setq xmin x))
|
|
|
654 (if (> x xmax)
|
|
|
655 (setq xmax x))
|
|
|
656 (if (< y ymin)
|
|
|
657 (setq ymin y))
|
|
|
658 (if (> y ymax)
|
|
|
659 (setq ymax y))))
|
|
|
660 (setq rest (cdr rest)))
|
|
|
661 (let ((delta-x (- xmax xmin))
|
|
|
662 (delta-y (- ymax ymin)))
|
|
|
663 (if (> delta-x delta-y)
|
|
|
664 (setq ymin (- ymin
|
|
|
665 (/ (- delta-x delta-y)
|
|
|
666 2))
|
|
|
667 ymax (+ ymax
|
|
|
668 (/ (- delta-x delta-y)
|
|
|
669 2)))
|
|
|
670 (setq xmin (- xmin
|
|
|
671 (/ (- delta-y delta-x)
|
|
|
672 2))
|
|
|
673 xmax (+ xmax
|
|
|
674 (/ (- delta-y delta-x)
|
|
|
675 2))))
|
|
|
676 (list (cons xmin ymin)
|
|
|
677 (cons xmax ymax))))
|
|
|
678 nil))
|
|
|
679
|
|
|
680 (defun strokes-eliminate-consecutive-redundancies (entries)
|
|
|
681 "Returns a list with no consecutive redundant entries."
|
|
|
682 ;; defun a grande vitesse grace a Dave G.
|
|
|
683 (loop for element on entries
|
|
177
|
684 if (not (equal (car element) (cadr element)))
|
|
153
|
685 collect (car element)))
|
|
|
686 ;; (loop for element on entries
|
|
177
|
687 ;; nconc (if (not (equal (car el) (cadr el)))
|
|
153
|
688 ;; (list (car el)))))
|
|
|
689 ;; yet another (orig) way of doing it...
|
|
|
690 ;; (if entries
|
|
|
691 ;; (let* ((current (car entries))
|
|
|
692 ;; (rest (cdr entries))
|
|
|
693 ;; (non-redundant-list (list current))
|
|
|
694 ;; (next nil))
|
|
|
695 ;; (while rest
|
|
|
696 ;; (setq next (car rest))
|
|
|
697 ;; (if (equal current next)
|
|
|
698 ;; (setq rest (cdr rest))
|
|
|
699 ;; (setq non-redundant-list (cons next non-redundant-list)
|
|
|
700 ;; current next
|
|
|
701 ;; rest (cdr rest))))
|
|
|
702 ;; (nreverse non-redundant-list))
|
|
|
703 ;; nil))
|
|
|
704
|
|
|
705 (defun strokes-renormalize-to-grid (positions &optional grid-resolution)
|
|
|
706 "Map POSITIONS to a new grid whose dimensions are based on GRID-RESOLUTION.
|
|
|
707 POSITIONS is a list of positions and stroke-lifts.
|
|
|
708 Optional GRID-RESOLUTION may be used in place of STROKES-GRID-RESOLUTION.
|
|
|
709 The grid is a square whose dimesion is [0,GRID-RESOLUTION)."
|
|
177
|
710 (or grid-resolution (setq grid-resolution strokes-grid-resolution))
|
|
153
|
711 (let ((stroke-extent (strokes-get-stroke-extent positions)))
|
|
|
712 (mapcar (function
|
|
|
713 (lambda (pos)
|
|
|
714 (strokes-get-grid-position stroke-extent pos grid-resolution)))
|
|
|
715 positions)))
|
|
|
716
|
|
|
717 ;;(defun strokes-normalize-pixels-to-grid (pixel-positions)
|
|
|
718 ;; "Map PIXEL-POSITIONS to the stroke grid.
|
|
|
719 ;;PIXEL-POSITIONS is a list of pixel-positions and stroke-lifts. The
|
|
|
720 ;;normalized stroke grid is defined by the variable STROKES-GRID-RESOLUTION"
|
|
|
721 ;; (let ((stroke-extent (strokes-get-stroke-extent pixel-positions)))
|
|
|
722 ;; (mapcar (function
|
|
|
723 ;; (lambda (pix-pos)
|
|
|
724 ;; (strokes-get-grid-position stroke-extent pix-pos)))
|
|
|
725 ;; pixel-positions)))
|
|
|
726
|
|
|
727 (defun strokes-fill-stroke (unfilled-stroke &optional force)
|
|
|
728 "Fill in missing grid locations in the list of UNFILLED-STROKE.
|
|
|
729 If FORCE is non-nil, then fill the stroke even if it's `stroke-click'.
|
|
|
730 NOTE: This is where the global variable `strokes-last-stroke' is set."
|
|
|
731 (setq strokes-last-stroke ; this is global
|
|
|
732 (if (and (strokes-click-p unfilled-stroke)
|
|
|
733 (not force))
|
|
|
734 unfilled-stroke
|
|
|
735 (loop for grid-locs on unfilled-stroke
|
|
|
736 nconc (let* ((current (car grid-locs))
|
|
|
737 (current-is-a-point-p (consp current))
|
|
|
738 (next (cadr grid-locs))
|
|
|
739 (next-is-a-point-p (consp next))
|
|
|
740 (both-are-points-p (and current-is-a-point-p
|
|
|
741 next-is-a-point-p))
|
|
|
742 (x1 (and current-is-a-point-p
|
|
|
743 (car current)))
|
|
|
744 (y1 (and current-is-a-point-p
|
|
|
745 (cdr current)))
|
|
|
746 (x2 (and next-is-a-point-p
|
|
|
747 (car next)))
|
|
|
748 (y2 (and next-is-a-point-p
|
|
|
749 (cdr next)))
|
|
|
750 (delta-x (and both-are-points-p
|
|
|
751 (- x2 x1)))
|
|
|
752 (delta-y (and both-are-points-p
|
|
|
753 (- y2 y1)))
|
|
|
754 (slope (and both-are-points-p
|
|
|
755 (if (zerop delta-x)
|
|
|
756 nil ; undefined vertical slope
|
|
|
757 (/ (float delta-y)
|
|
|
758 delta-x)))))
|
|
|
759 (cond ((not both-are-points-p)
|
|
|
760 (list current))
|
|
|
761 ((null slope) ; undefinded vertical slope
|
|
|
762 (if (>= delta-y 0)
|
|
|
763 (loop for y from y1 below y2
|
|
|
764 collect (cons x1 y))
|
|
|
765 (loop for y from y1 above y2
|
|
|
766 collect (cons x1 y))))
|
|
|
767 ((zerop slope) ; (= y1 y2)
|
|
|
768 (if (>= delta-x 0)
|
|
|
769 (loop for x from x1 below x2
|
|
|
770 collect (cons x y1))
|
|
|
771 (loop for x from x1 above x2
|
|
|
772 collect (cons x y1))))
|
|
|
773 ((>= (abs delta-x) (abs delta-y))
|
|
|
774 (if (> delta-x 0)
|
|
|
775 (loop for x from x1 below x2
|
|
|
776 collect (cons x
|
|
|
777 (+ y1
|
|
|
778 (round (* slope
|
|
|
779 (- x x1))))))
|
|
|
780 (loop for x from x1 above x2
|
|
|
781 collect (cons x
|
|
|
782 (+ y1
|
|
|
783 (round (* slope
|
|
|
784 (- x x1))))))))
|
|
|
785 (t ; (< (abs delta-x) (abs delta-y))
|
|
|
786 (if (> delta-y 0)
|
|
|
787 (loop for y from y1 below y2
|
|
|
788 collect (cons (+ x1
|
|
|
789 (round (/ (- y y1)
|
|
|
790 slope)))
|
|
|
791 y))
|
|
|
792 (loop for y from y1 above y2
|
|
|
793 collect (cons (+ x1
|
|
|
794 (round (/ (- y y1)
|
|
|
795 slope)))
|
|
|
796 y))))))))))
|
|
|
797
|
|
|
798 (defun strokes-rate-stroke (stroke1 stroke2)
|
|
|
799 "Rates STROKE1 with STROKE2 and returns a score based on a distance metric.
|
|
|
800 Note: the rating is an error rating, and therefore, a return of 0
|
|
|
801 represents a perfect match. Also note that the order of stroke
|
|
|
802 arguments is order-independent for the algorithm used here."
|
|
|
803 (if (and stroke1 stroke2)
|
|
|
804 (let ((rest1 (cdr stroke1))
|
|
|
805 (rest2 (cdr stroke2))
|
|
|
806 (err (strokes-distance-squared (car stroke1)
|
|
|
807 (car stroke2))))
|
|
|
808 (while (and rest1 rest2)
|
|
|
809 (while (and (consp (car rest1))
|
|
|
810 (consp (car rest2)))
|
|
|
811 (setq err (+ err
|
|
|
812 (strokes-distance-squared (car rest1)
|
|
|
813 (car rest2)))
|
|
|
814 stroke1 rest1
|
|
|
815 stroke2 rest2
|
|
|
816 rest1 (cdr stroke1)
|
|
|
817 rest2 (cdr stroke2)))
|
|
|
818 (cond ((and (strokes-lift-p (car rest1))
|
|
|
819 (strokes-lift-p (car rest2)))
|
|
|
820 (setq rest1 (cdr rest1)
|
|
|
821 rest2 (cdr rest2)))
|
|
|
822 ((strokes-lift-p (car rest2))
|
|
|
823 (while (consp (car rest1))
|
|
|
824 (setq err (+ err
|
|
|
825 (strokes-distance-squared (car rest1)
|
|
|
826 (car stroke2)))
|
|
|
827 rest1 (cdr rest1))))
|
|
|
828 ((strokes-lift-p (car rest1))
|
|
|
829 (while (consp (car rest2))
|
|
|
830 (setq err (+ err
|
|
|
831 (strokes-distance-squared (car stroke1)
|
|
|
832 (car rest2)))
|
|
|
833 rest2 (cdr rest2))))))
|
|
|
834 (if (null rest2)
|
|
|
835 (while (consp (car rest1))
|
|
|
836 (setq err (+ err
|
|
|
837 (strokes-distance-squared (car rest1)
|
|
|
838 (car stroke2)))
|
|
|
839 rest1 (cdr rest1))))
|
|
|
840 (if (null rest1)
|
|
|
841 (while (consp (car rest2))
|
|
|
842 (setq err (+ err
|
|
|
843 (strokes-distance-squared (car stroke1)
|
|
|
844 (car rest2)))
|
|
|
845 rest2 (cdr rest2))))
|
|
|
846 (if (or (strokes-lift-p (car rest1))
|
|
|
847 (strokes-lift-p (car rest2)))
|
|
|
848 (setq err nil)
|
|
|
849 err))
|
|
|
850 nil))
|
|
|
851
|
|
|
852 (defun strokes-match-stroke (stroke stroke-map)
|
|
|
853 "Finds the best matching command of STROKE in STROKE-MAP.
|
|
|
854 Returns the corresponding match as (COMMAND . SCORE)."
|
|
|
855 (if (and stroke stroke-map)
|
|
|
856 (let ((score (strokes-rate-stroke stroke (caar stroke-map)))
|
|
|
857 (command (cdar stroke-map))
|
|
|
858 (map (cdr stroke-map)))
|
|
|
859 (while map
|
|
|
860 (let ((newscore (strokes-rate-stroke stroke (caar map))))
|
|
|
861 (if (or (and newscore score (< newscore score))
|
|
|
862 (and newscore (null score)))
|
|
|
863 (setq score newscore
|
|
|
864 command (cdar map)))
|
|
|
865 (setq map (cdr map))))
|
|
|
866 (if score
|
|
|
867 (cons command score)
|
|
|
868 nil))
|
|
|
869 nil))
|
|
|
870
|
|
|
871 ;;;###autoload
|
|
|
872 (defun strokes-read-stroke (&optional prompt event)
|
|
|
873 "Read a simple stroke (interactively) and return the stroke.
|
|
|
874 Optional PROMPT in minibuffer displays before and during stroke reading.
|
|
|
875 This function will display the stroke interactively as it is being
|
|
|
876 entered in the strokes buffer if the variable
|
|
|
877 `strokes-use-strokes-buffer' is non-nil.
|
|
|
878 Optional EVENT is currently not used, but hopefully will be soon."
|
|
|
879 (save-excursion
|
|
|
880 (let ((pix-locs nil)
|
|
|
881 (grid-locs nil)
|
|
|
882 (event (or event (make-event))))
|
|
|
883 (if strokes-use-strokes-buffer
|
|
|
884 ;; switch to the strokes buffer and
|
|
|
885 ;; display the stroke as it's being read
|
|
|
886 (save-window-excursion
|
|
|
887 (set-window-configuration strokes-window-configuration)
|
|
|
888 (if prompt
|
|
|
889 (progn
|
|
|
890 (setq event (next-event event prompt))
|
|
|
891 (while (not (button-press-event-p event))
|
|
|
892 (dispatch-event event)
|
|
|
893 (setq event (next-event event)))))
|
|
|
894 (unwind-protect
|
|
|
895 (progn
|
|
|
896 (setq event (next-event event))
|
|
|
897 (while (not (button-release-event-p event))
|
|
|
898 (if (mouse-event-p event)
|
|
|
899 (let ((point (event-closest-point event)))
|
|
|
900 (when point
|
|
|
901 (goto-char point)
|
|
|
902 (subst-char-in-region point (1+ point) ?\ strokes-character))
|
|
177
|
903 (push (cons (event-x-pixel event)
|
|
|
904 (event-y-pixel event))
|
|
|
905 pix-locs)))
|
|
153
|
906 (setq event (next-event event))))
|
|
|
907 ;; protected
|
|
|
908 ;; clean up strokes buffer and then bury it.
|
|
177
|
909 (when (equal (buffer-name) strokes-buffer-name)
|
|
|
910 (subst-char-in-region (point-min) (point-max) strokes-character ?\ )
|
|
|
911 (goto-char (point-min))
|
|
|
912 (bury-buffer))))
|
|
153
|
913 ;; Otherwise, don't use strokes buffer and read stroke silently
|
|
|
914 (if prompt
|
|
|
915 (progn
|
|
|
916 (setq event (next-event event prompt))
|
|
|
917 (while (not (button-press-event-p event))
|
|
|
918 (dispatch-event event)
|
|
|
919 (setq event (next-event event)))))
|
|
|
920 (setq event (next-event))
|
|
|
921 (while (not (button-release-event-p event))
|
|
|
922 (if (mouse-event-p event)
|
|
177
|
923 (push (cons (event-x-pixel event)
|
|
|
924 (event-y-pixel event))
|
|
|
925 pix-locs))
|
|
153
|
926 (setq event (next-event event))))
|
|
|
927 (setq grid-locs (strokes-renormalize-to-grid (nreverse pix-locs)))
|
|
|
928 (strokes-fill-stroke (strokes-eliminate-consecutive-redundancies grid-locs)))))
|
|
|
929
|
|
|
930 ;;;###autoload
|
|
|
931 (defun strokes-read-complex-stroke (&optional prompt event)
|
|
|
932 "Read a complex stroke (interactively) and return the stroke.
|
|
|
933 Optional PROMPT in minibuffer displays before and during stroke reading.
|
|
|
934 Note that a complex stroke allows the user to pen-up and pen-down. This
|
|
|
935 is implemented by allowing the user to paint with button1 or button2 and
|
|
|
936 then complete the stroke with button3.
|
|
|
937 Optional EVENT is currently not used, but hopefully will be soon."
|
|
|
938 (save-excursion
|
|
|
939 (save-window-excursion
|
|
|
940 (set-window-configuration strokes-window-configuration)
|
|
|
941 (let ((pix-locs nil)
|
|
|
942 (grid-locs nil)
|
|
|
943 (event (or event (next-event nil prompt))))
|
|
|
944 (if prompt
|
|
|
945 (while (not (button-press-event-p event))
|
|
|
946 (dispatch-event event)
|
|
|
947 (setq event (next-event event))))
|
|
|
948 (unwind-protect
|
|
|
949 (progn
|
|
177
|
950 (setq event (next-event event prompt))
|
|
153
|
951 (while (not (and (button-press-event-p event)
|
|
|
952 (eq (event-button event) 3)))
|
|
|
953 (while (not (button-release-event-p event))
|
|
|
954 (if (mouse-event-p event)
|
|
|
955 (let ((point (event-closest-point event)))
|
|
|
956 (when point
|
|
|
957 (goto-char point)
|
|
|
958 (subst-char-in-region point (1+ point) ?\ strokes-character))
|
|
177
|
959 (push (cons (event-x-pixel event)
|
|
|
960 (event-y-pixel event))
|
|
|
961 pix-locs)))
|
|
153
|
962 (setq event (next-event event prompt)))
|
|
177
|
963 (push strokes-lift pix-locs)
|
|
153
|
964 (while (not (button-press-event-p event))
|
|
|
965 (dispatch-event event)
|
|
|
966 (setq event (next-event event prompt))))
|
|
|
967 (setq pix-locs (nreverse (cdr pix-locs))
|
|
|
968 grid-locs (strokes-renormalize-to-grid pix-locs))
|
|
|
969 (strokes-fill-stroke
|
|
|
970 (strokes-eliminate-consecutive-redundancies grid-locs)))
|
|
|
971 ;; protected
|
|
177
|
972 (when (equal (buffer-name) strokes-buffer-name)
|
|
|
973 (subst-char-in-region (point-min) (point-max) strokes-character ?\ )
|
|
|
974 (goto-char (point-min))
|
|
|
975 (bury-buffer)))))))
|
|
153
|
976
|
|
|
977 (defun strokes-execute-stroke (stroke)
|
|
|
978 "Given STROKE, execute the command which corresponds to it.
|
|
|
979 The command will be executed provided one exists for that stroke,
|
|
|
980 based on the variable `strokes-minimum-match-score'.
|
|
|
981 If no stroke matches, nothing is done and return value is nil."
|
|
|
982 (let* ((match (strokes-match-stroke stroke strokes-global-map))
|
|
|
983 (command (car match))
|
|
|
984 (score (cdr match)))
|
|
|
985 (cond ((strokes-click-p stroke)
|
|
|
986 ;; This is the case of a `click' type event
|
|
|
987 (command-execute strokes-click-command))
|
|
|
988 ((and match (<= score strokes-minimum-match-score))
|
|
|
989 (message "%s" command)
|
|
|
990 (command-execute command))
|
|
|
991 ((null strokes-global-map)
|
|
|
992 (if (file-exists-p strokes-file)
|
|
|
993 (and (y-or-n-p-maybe-dialog-box
|
|
|
994 (format "No strokes loaded. Load `%s'? "
|
|
|
995 strokes-file))
|
|
|
996 (strokes-load-user-strokes))
|
|
|
997 (error "No strokes defined; use `global-set-stroke'")))
|
|
|
998 (t
|
|
|
999 (error
|
|
|
1000 "No stroke matches; see variable `strokes-minimum-match-score'")
|
|
|
1001 nil))))
|
|
|
1002
|
|
|
1003 ;;;###autoload
|
|
|
1004 (defun strokes-do-stroke (event)
|
|
|
1005 "Read a simple stroke from the user and then exectute its comand.
|
|
|
1006 This must be bound to a mouse event."
|
|
|
1007 (interactive "e")
|
|
|
1008 (or strokes-mode (strokes-mode t))
|
|
|
1009 (strokes-execute-stroke (strokes-read-stroke nil event)))
|
|
|
1010
|
|
|
1011 ;;;###autoload
|
|
|
1012 (defun strokes-do-complex-stroke (event)
|
|
|
1013 "Read a complex stroke from the user and then exectute its command.
|
|
|
1014 This must be bound to a mouse event."
|
|
|
1015 (interactive "e")
|
|
|
1016 (or strokes-mode (strokes-mode t))
|
|
|
1017 (strokes-execute-stroke (strokes-read-complex-stroke nil event)))
|
|
|
1018
|
|
|
1019 ;;;###autoload
|
|
|
1020 (defun strokes-describe-stroke (stroke)
|
|
|
1021 "Displays the command which STROKE maps to, reading STROKE interactively."
|
|
|
1022 (interactive
|
|
|
1023 (list
|
|
|
1024 (strokes-read-complex-stroke
|
|
|
1025 "Enter stroke to describe; end with button3...")))
|
|
|
1026 (let* ((match (strokes-match-stroke stroke strokes-global-map))
|
|
|
1027 (command (or (and (strokes-click-p stroke)
|
|
|
1028 strokes-click-command)
|
|
|
1029 (car match)))
|
|
|
1030 (score (cdr match)))
|
|
|
1031 (if (or (and match
|
|
|
1032 (<= score strokes-minimum-match-score))
|
|
|
1033 (and (strokes-click-p stroke)
|
|
|
1034 strokes-click-command))
|
|
|
1035 (message "That stroke maps to `%s'" command)
|
|
|
1036 (message "That stroke is undefined"))
|
|
|
1037 (sleep-for 1))) ; helpful for recursive edits
|
|
|
1038
|
|
|
1039 ;;;###autoload
|
|
|
1040 (defalias 'describe-stroke 'strokes-describe-stroke)
|
|
|
1041
|
|
|
1042 ;;;###autoload
|
|
|
1043 (defun strokes-help ()
|
|
|
1044 "Get instructional help on using the the `strokes' package."
|
|
|
1045 (interactive)
|
|
|
1046 (with-displaying-help-buffer
|
|
|
1047 (function
|
|
|
1048 (lambda ()
|
|
|
1049 (save-excursion
|
|
|
1050 (let ((helpdoc
|
|
|
1051 "This is help for the strokes package.
|
|
|
1052
|
|
|
1053 If you find something wrong with it, or feel that it can be improved
|
|
|
1054 in some way, then please feel free to email me:
|
|
|
1055
|
|
|
1056 David Bakhash <cadet@mit.edu>
|
|
|
1057
|
|
|
1058 or just do
|
|
|
1059
|
|
|
1060 M-x strokes-report-bug
|
|
|
1061
|
|
|
1062 ------------------------------------------------------------
|
|
|
1063
|
|
|
1064 The strokes package allows you to define strokes (that you make with
|
|
|
1065 the mouse or other pointer device) that XEmacs can interpret as
|
|
|
1066 corresponding to commands, and then executes the commands. It does
|
|
|
1067 character recognition, so you don't have to worry about getting it
|
|
|
1068 right every time.
|
|
|
1069
|
|
|
1070 Strokes are easy to program and fun to use. To start strokes going,
|
|
|
1071 you'll want to put the following line in your .emacs file:
|
|
|
1072
|
|
|
1073 (and (fboundp 'device-on-window-system-p)
|
|
|
1074 (device-on-window-system-p)
|
|
|
1075 (require 'strokes))
|
|
|
1076
|
|
|
1077 This will load strokes when and only when you start XEmacs on a window
|
|
|
1078 system (i.e. that has a pointer (mouse) device, etc.).
|
|
|
1079
|
|
|
1080 To toggle strokes-mode, you just do
|
|
|
1081
|
|
|
1082 > M-x strokes-mode
|
|
|
1083
|
|
|
1084 When you're ready to start defining strokes, just use the command
|
|
|
1085
|
|
|
1086 > M-x global-set-stroke
|
|
|
1087
|
|
|
1088 You will see a ` *strokes*' buffer which is waiting for you to enter in
|
|
|
1089 your stroke. When you enter in the stroke, you draw with button1 or
|
|
|
1090 button2, and then end with button3. Next, you enter in the command
|
|
|
1091 which will be executed when that stroke is invoked. Simple as that.
|
|
|
1092 For now, try to define a stroke to copy a region. This is a popular
|
|
|
1093 edit command, so type
|
|
|
1094
|
|
|
1095 > M-x global-set-stroke
|
|
|
1096
|
|
|
1097 Then, in the ` *strokes*' buffer, draw the letter `C' (for `copy')
|
|
|
1098 and then, when it asks you to enter the command to map that to, type
|
|
|
1099
|
|
|
1100 > copy-region-as-kill
|
|
|
1101
|
|
|
1102 That's about as hard as it gets.
|
|
|
1103 Remember: paint with button1 or button2 and then end with button3.
|
|
|
1104
|
|
|
1105 If ever you want to know what a certain strokes maps to, then do
|
|
|
1106
|
|
|
1107 > M-x describe-stroke
|
|
|
1108
|
|
|
1109 and you can enter in any arbitrary stroke. Remember: The strokes
|
|
|
1110 package lets you program in simple and complex (multi-lift) strokes.
|
|
|
1111 The only difference is how you *invoke* the two. You will most likely
|
|
|
1112 use simple strokes, as complex strokes were developed for
|
|
|
1113 Chinese/Japanese/Korean. So the middle mouse button (button2) will
|
|
|
1114 invoke the command `strokes-do-stroke' in buffers where button2 doesn't
|
|
|
1115 already have a meaning other than its original, which is `mouse-yank'.
|
|
|
1116 But don't worry: `mouse-yank' will still work with strokes (see the
|
|
|
1117 variable `strokes-click-command').
|
|
|
1118
|
|
|
1119 If ever you define a stroke which you don't like, then you can unset
|
|
|
1120 it with the command
|
|
|
1121
|
|
|
1122 > M-x strokes-unset-last-stroke
|
|
|
1123
|
|
|
1124 You can always get an idea of what your current strokes look like with
|
|
|
1125 the command
|
|
|
1126
|
|
|
1127 > M-x list-strokes
|
|
|
1128
|
|
177
|
1129 Your strokes will be displayed in alphabetical order (based on command
|
|
|
1130 names) and the beginning of each simple stroke will be marked by a
|
|
|
1131 color dot. Since you may have several simple strokes in a complex
|
|
|
1132 stroke, the dot colors are arranged in the rainbow color sequence,
|
|
|
1133 `ROYGBIV'. If you want a listing of your strokes from most recent
|
|
|
1134 down, then use a prefix argument:
|
|
|
1135
|
|
|
1136 > C-u M-x list-strokes
|
|
153
|
1137
|
|
|
1138 Your strokes are stored as you enter them. They get saved in a file
|
|
|
1139 called ~/.strokes, along with other strokes configuration variables.
|
|
|
1140 You can change this location by setting the variable `strokes-file'.
|
|
|
1141 You will be prompted to save them when you exit XEmacs, or you can save
|
|
|
1142 them with
|
|
|
1143
|
|
|
1144 > M-x save-strokes
|
|
|
1145
|
|
|
1146 Your strokes get loaded automatically when you enable `strokes-mode'.
|
|
|
1147 You can also load in your user-defined strokes with
|
|
|
1148
|
|
|
1149 > M-x load-user-strokes
|
|
|
1150
|
|
|
1151 A few more important things:
|
|
|
1152
|
|
|
1153 o The command `strokes-do-stroke' is also invoked with C-button2, so that you
|
|
|
1154 can still enter a stroke in modes which use button2 for other things,
|
|
|
1155 such as cross-referencing.
|
|
|
1156
|
|
|
1157 o Complex strokes (i.e. `strokes-do-complex-stroke'), by default, use
|
|
|
1158 Sh-button2.
|
|
|
1159
|
|
|
1160 o Strokes are a bit computer-dependent in that they depend somewhat on
|
|
|
1161 the speed of the computer you're working on. This means that you
|
|
|
1162 may have to tweak some variables. You can read about them in the
|
|
|
1163 commentary of `strokes.el'. Better to just use apropos and read their
|
|
|
1164 docstrings. All variables/functions start with `strokes'. The one
|
|
|
1165 variable which many people wanted to see was
|
|
|
1166 `strokes-use-strokes-buffer' which allows the user to use strokes
|
|
|
1167 silently--without displaying the strokes. All variables can be set
|
|
|
1168 by customizing the group named `strokes' via the customization package:
|
|
|
1169
|
|
|
1170 > M-x customize
|
|
|
1171
|
|
|
1172 o A problem with strokes happens when you resize windows. If you
|
|
|
1173 enlarge your XEmacs window a lot and realize that your strokes
|
|
|
1174 buffer is not big enough, you may need to fix it with
|
|
|
1175
|
|
|
1176 > M-x strokes-update-window-configuration."))
|
|
|
1177 (princ helpdoc standard-output)))))))
|
|
|
1178
|
|
|
1179 (defun strokes-report-bug ()
|
|
|
1180 "Submit a bug report for strokes."
|
|
|
1181 (interactive)
|
|
|
1182 (let ((reporter-prompt-for-summary-p t))
|
|
|
1183 (or (boundp 'reporter-version)
|
|
|
1184 (setq reporter-version
|
|
|
1185 "Your version of reporter is obsolete. Please upgrade."))
|
|
|
1186 (reporter-submit-bug-report
|
|
|
1187 strokes-bug-address "Strokes"
|
|
|
1188 (cons
|
|
|
1189 'strokes-version
|
|
|
1190 (nconc
|
|
|
1191 (mapcar
|
|
|
1192 'intern
|
|
|
1193 (sort
|
|
|
1194 (let (completion-ignore-case)
|
|
|
1195 (all-completions "strokes-" obarray 'user-variable-p))
|
|
|
1196 'string-lessp))
|
|
|
1197 (list 'reporter-version)))
|
|
|
1198 (function
|
|
|
1199 (lambda ()
|
|
|
1200 (save-excursion
|
|
|
1201 (mail-position-on-field "subject")
|
|
|
1202 (beginning-of-line)
|
|
|
1203 (skip-chars-forward "^:\n")
|
|
|
1204 (if (looking-at ": Strokes;")
|
|
|
1205 (progn
|
|
|
1206 (goto-char (match-end 0))
|
|
|
1207 (delete-char -1)
|
|
|
1208 (insert " " strokes-version " bug:")))))))))
|
|
|
1209
|
|
|
1210 (defsubst strokes-fill-current-buffer-with-whitespace ()
|
|
|
1211 "Erase the contents of the current buffer and fill it with whitespace"
|
|
|
1212 (erase-buffer)
|
|
177
|
1213 (loop repeat (frame-height) do
|
|
|
1214 (insert-char ?\ (1- (frame-width)))
|
|
|
1215 (newline))
|
|
153
|
1216 (goto-char (point-min)))
|
|
|
1217
|
|
|
1218 (defun strokes-update-window-configuration ()
|
|
|
1219 "Insure that `strokes-window-configuration' is up-to-date."
|
|
|
1220 (interactive)
|
|
|
1221 (let ((current-window (selected-window)))
|
|
|
1222 (cond ((or (window-minibuffer-p current-window)
|
|
|
1223 (window-dedicated-p current-window))
|
|
|
1224 ;; don't try to update strokes window configuration
|
|
|
1225 ;; if window is dedicated or a minibuffer
|
|
|
1226 nil)
|
|
|
1227 ((or (interactive-p)
|
|
|
1228 (not (buffer-live-p (get-buffer strokes-buffer-name)))
|
|
|
1229 (null strokes-window-configuration))
|
|
|
1230 ;; create `strokes-window-configuration' from scratch...
|
|
|
1231 (save-excursion
|
|
|
1232 (save-window-excursion
|
|
|
1233 (get-buffer-create strokes-buffer-name)
|
|
|
1234 (set-window-buffer current-window strokes-buffer-name)
|
|
|
1235 (delete-other-windows)
|
|
|
1236 (fundamental-mode)
|
|
|
1237 (auto-save-mode 0)
|
|
|
1238 (if (featurep 'font-lock)
|
|
|
1239 (font-lock-mode 0))
|
|
|
1240 (abbrev-mode 0)
|
|
|
1241 (buffer-disable-undo (current-buffer))
|
|
|
1242 (setq truncate-lines nil)
|
|
|
1243 (strokes-fill-current-buffer-with-whitespace)
|
|
|
1244 (setq strokes-window-configuration (current-window-configuration))
|
|
|
1245 (bury-buffer))))
|
|
|
1246 (t ; `strokes buffer' still exists...
|
|
|
1247 ;; update the strokes-window-configuration for this specific frame...
|
|
|
1248 (save-excursion
|
|
|
1249 (save-window-excursion
|
|
|
1250 (set-window-buffer current-window strokes-buffer-name)
|
|
|
1251 (delete-other-windows)
|
|
|
1252 (strokes-fill-current-buffer-with-whitespace)
|
|
|
1253 (setq strokes-window-configuration (current-window-configuration))
|
|
|
1254 (bury-buffer)))))))
|
|
|
1255
|
|
|
1256 ;;;###autoload
|
|
|
1257 (defun strokes-load-user-strokes ()
|
|
|
1258 "Load user-defined strokes from file named by `strokes-file'."
|
|
|
1259 (interactive)
|
|
|
1260 (cond ((and (file-exists-p strokes-file)
|
|
|
1261 (file-readable-p strokes-file))
|
|
|
1262 (load-file strokes-file))
|
|
|
1263 ((interactive-p)
|
|
|
1264 (error "Trouble loading user-defined strokes; nothing done"))
|
|
|
1265 (t
|
|
|
1266 (message "No user-defined strokes, sorry"))))
|
|
|
1267
|
|
|
1268 ;;;###autoload
|
|
|
1269 (defalias 'load-user-strokes 'strokes-load-user-strokes)
|
|
|
1270
|
|
|
1271 (defun strokes-prompt-user-save-strokes ()
|
|
|
1272 "Save user-defined strokes to file named by `strokes-file'."
|
|
|
1273 (interactive)
|
|
|
1274 (save-excursion
|
|
|
1275 (let ((current strokes-global-map))
|
|
|
1276 (unwind-protect
|
|
|
1277 (progn
|
|
|
1278 (setq strokes-global-map nil)
|
|
|
1279 (strokes-load-user-strokes)
|
|
|
1280 (if (and (not (equal current strokes-global-map))
|
|
|
1281 (or (interactive-p)
|
|
|
1282 (yes-or-no-p-maybe-dialog-box "save your strokes? ")))
|
|
|
1283 (progn
|
|
|
1284 (require 'pp) ; pretty-print variables
|
|
|
1285 (message "Saving strokes in %s..." strokes-file)
|
|
|
1286 (get-buffer-create "*saved-strokes*")
|
|
|
1287 (set-buffer "*saved-strokes*")
|
|
|
1288 (erase-buffer)
|
|
|
1289 (emacs-lisp-mode)
|
|
|
1290 (goto-char (point-min))
|
|
|
1291 (insert-string
|
|
|
1292 ";; -*- Syntax: Emacs-Lisp; Mode: emacs-lisp -*-\n")
|
|
|
1293 (insert-string (format ";;; saved strokes for %s, as of %s\n\n"
|
|
|
1294 (user-full-name)
|
|
|
1295 (format-time-string "%B %e, %Y" nil)))
|
|
|
1296 (message "Saving strokes in %s..." strokes-file)
|
|
|
1297 (insert-string (format "(setq strokes-global-map '%s)"
|
|
|
1298 (pp current)))
|
|
|
1299 (message "Saving strokes in %s..." strokes-file)
|
|
|
1300 (indent-region (point-min) (point-max) nil)
|
|
|
1301 (write-region (point-min)
|
|
|
1302 (point-max)
|
|
|
1303 strokes-file))
|
|
|
1304 (message "(no changes need to be saved)")))
|
|
|
1305 ;; protected
|
|
|
1306 (if (get-buffer "*saved-strokes*")
|
|
|
1307 (kill-buffer (get-buffer "*saved-strokes*")))
|
|
|
1308 (setq strokes-global-map current)))))
|
|
|
1309
|
|
|
1310 (defalias 'save-strokes 'strokes-prompt-user-save-strokes)
|
|
|
1311
|
|
|
1312 (defun strokes-toggle-strokes-buffer (&optional arg)
|
|
|
1313 "Toggle the use of the strokes buffer.
|
|
|
1314 In other words, toggle the variabe `strokes-use-strokes-buffer'.
|
|
|
1315 With ARG, use strokes buffer if and only if ARG is positive or true.
|
|
|
1316 Returns value of `strokes-use-strokes-buffer'."
|
|
|
1317 (interactive "P")
|
|
|
1318 (setq strokes-use-strokes-buffer
|
|
|
1319 (if arg (> (prefix-numeric-value arg) 0)
|
|
|
1320 (not strokes-use-strokes-buffer))))
|
|
|
1321
|
|
177
|
1322 (defun strokes-xpm-for-stroke (&optional stroke bufname b/w-only)
|
|
|
1323 "Create an xpm pixmap for the given STROKE in buffer `*strokes-xpm*'.
|
|
|
1324 If STROKE is not supplied, then `strokes-last-stroke' will be used.
|
|
153
|
1325 Optional BUFNAME to name something else.
|
|
|
1326 The pixmap will contain time information via rainbow dot colors
|
|
177
|
1327 where each individual strokes begins.
|
|
|
1328 Optional B/W-ONLY non-nil will create a mono pixmap, not intended
|
|
|
1329 for trying to figure out the order of strokes, but rather for reading
|
|
|
1330 the stroke as a character in some language."
|
|
|
1331 (interactive)
|
|
153
|
1332 (save-excursion
|
|
|
1333 (let ((buf (get-buffer-create (or bufname "*strokes-xpm*")))
|
|
|
1334 (stroke (strokes-eliminate-consecutive-redundancies
|
|
|
1335 (strokes-fill-stroke
|
|
177
|
1336 (strokes-renormalize-to-grid (or stroke
|
|
|
1337 strokes-last-stroke)
|
|
|
1338 31))))
|
|
153
|
1339 (lift-flag t)
|
|
177
|
1340 (rainbow-chars (list ?R ?O ?Y ?G ?B ?P))) ; ROYGBIV w/o indigo
|
|
153
|
1341 (set-buffer buf)
|
|
|
1342 (erase-buffer)
|
|
177
|
1343 (insert strokes-xpm-header)
|
|
153
|
1344 (loop repeat 33 do
|
|
|
1345 (insert-char ?\")
|
|
|
1346 (insert-char ?\ 33)
|
|
|
1347 (insert "\",")
|
|
177
|
1348 (newline)
|
|
|
1349 finally
|
|
|
1350 (forward-line -1)
|
|
|
1351 (end-of-line)
|
|
|
1352 (insert "}\n"))
|
|
153
|
1353 (loop for point in stroke
|
|
|
1354 for x = (car-safe point)
|
|
|
1355 for y = (cdr-safe point) do
|
|
|
1356 (cond ((consp point)
|
|
|
1357 ;; draw a point, and possibly a starting-point
|
|
177
|
1358 (if (and lift-flag (not b/w-only))
|
|
153
|
1359 ;; mark starting point with the appropriate color
|
|
|
1360 (let ((char (or (car rainbow-chars) ?\.)))
|
|
|
1361 (loop for i from 0 to 2 do
|
|
|
1362 (loop for j from 0 to 2 do
|
|
|
1363 (goto-line (+ 16 i y))
|
|
|
1364 (forward-char (+ 1 j x))
|
|
|
1365 (delete-char 1)
|
|
|
1366 (insert-char char)))
|
|
|
1367 (setq rainbow-chars (cdr rainbow-chars)
|
|
|
1368 lift-flag nil))
|
|
|
1369 ;; Otherwise, just plot the point...
|
|
|
1370 (goto-line (+ 17 y))
|
|
|
1371 (forward-char (+ 2 x))
|
|
|
1372 (subst-char-in-region (point) (1+ (point)) ?\ ?\*)))
|
|
|
1373 ((strokes-lift-p point)
|
|
|
1374 ;; a lift--tell the loop to X out the next point...
|
|
177
|
1375 (setq lift-flag t))))
|
|
|
1376 (when (interactive-p)
|
|
|
1377 (require 'xpm-mode)
|
|
|
1378 (pop-to-buffer "*strokes-xpm*")
|
|
|
1379 ;; (xpm-mode 1)
|
|
|
1380 (xpm-show-image)
|
|
|
1381 (goto-char (point-min))))))
|
|
|
1382
|
|
|
1383 ;;; Strokes Edit stuff...
|
|
|
1384
|
|
|
1385 (defun strokes-edit-quit ()
|
|
|
1386 (interactive)
|
|
|
1387 (or (one-window-p t 0)
|
|
|
1388 (delete-window))
|
|
|
1389 (kill-buffer "*Strokes List*"))
|
|
|
1390
|
|
|
1391 (define-derived-mode edit-strokes-mode list-mode
|
|
|
1392 "Edit-Strokes"
|
|
|
1393 "Major mode for `edit-strokes' and `list-strokes' buffers.
|
|
|
1394
|
|
|
1395 Editing commands:
|
|
|
1396
|
|
|
1397 \\{edit-strokes-mode-map}"
|
|
|
1398 (setq truncate-lines nil
|
|
|
1399 auto-show-mode nil ; don't want problems here either
|
|
|
1400 mode-popup-menu edit-strokes-menu) ; what about extent-specific stuff?
|
|
|
1401 (and (featurep 'menubar)
|
|
|
1402 current-menubar
|
|
|
1403 (set (make-local-variable 'current-menubar)
|
|
|
1404 (copy-sequence current-menubar))
|
|
|
1405 (add-submenu nil edit-strokes-menu)))
|
|
|
1406
|
|
|
1407 (let ((map edit-strokes-mode-map))
|
|
|
1408 (define-key map "<" 'beginning-of-buffer)
|
|
|
1409 (define-key map ">" 'end-of-buffer)
|
|
|
1410 ;; (define-key map "c" 'strokes-copy-other-face)
|
|
|
1411 ;; (define-key map "C" 'strokes-copy-this-face)
|
|
|
1412 ;; (define-key map "s" 'strokes-smaller)
|
|
|
1413 ;; (define-key map "l" 'strokes-larger)
|
|
|
1414 ;; (define-key map "b" 'strokes-bold)
|
|
|
1415 ;; (define-key map "i" 'strokes-italic)
|
|
|
1416 (define-key map "e" 'strokes-list-edit)
|
|
|
1417 ;; (define-key map "f" 'strokes-font)
|
|
|
1418 ;; (define-key map "u" 'strokes-underline)
|
|
|
1419 ;; (define-key map "t" 'strokes-truefont)
|
|
|
1420 ;; (define-key map "F" 'strokes-foreground)
|
|
|
1421 ;; (define-key map "B" 'strokes-background)
|
|
|
1422 ;; (define-key map "D" 'strokes-doc-string)
|
|
|
1423 (define-key map "a" 'strokes-global-set-stroke)
|
|
|
1424 (define-key map "d" 'strokes-list-delete-stroke)
|
|
|
1425 ;; (define-key map "n" 'strokes-list-next)
|
|
|
1426 ;; (define-key map "p" 'strokes-list-prev)
|
|
|
1427 ;; (define-key map " " 'strokes-list-next)
|
|
|
1428 ;; (define-key map "\C-?" 'strokes-list-prev)
|
|
|
1429 (define-key map "g" 'strokes-list-strokes) ; refresh display
|
|
|
1430 (define-key map "q" 'strokes-edit-quit)
|
|
|
1431 (define-key map [(control c) (control c)] 'bury-buffer))
|
|
153
|
1432
|
|
|
1433 ;;;###autoload
|
|
177
|
1434 (defun strokes-edit-strokes (&optional chronological strokes-map)
|
|
|
1435 ;; ### DEAL WITH THE 2nd ARGUMENT ISSUE! ###
|
|
|
1436 "Edit strokes in a pop-up buffer containing strokes and their definitions.
|
|
|
1437 If STROKES-MAP is not given, `strokes-global-map' will be used instead.
|
|
|
1438
|
|
|
1439 Editing commands:
|
|
|
1440
|
|
|
1441 \\{edit-faces-mode-map}"
|
|
|
1442 (interactive "P")
|
|
|
1443 (pop-to-buffer (get-buffer-create "*Strokes List*"))
|
|
|
1444 (reset-buffer (current-buffer)) ; handy function from minibuf.el
|
|
|
1445 (setq strokes-map (or strokes-map
|
|
|
1446 strokes-global-map
|
|
|
1447 (progn
|
|
|
1448 (strokes-load-user-strokes)
|
|
|
1449 strokes-global-map)))
|
|
|
1450 (or chronological
|
|
|
1451 (setq strokes-map (sort (copy-sequence strokes-map)
|
|
|
1452 'strokes-alphabetic-lessp)))
|
|
|
1453 ;; (push-window-configuration)
|
|
|
1454 (insert
|
|
|
1455 "Command Stroke\n"
|
|
|
1456 "------- ------")
|
|
|
1457 (loop for def in strokes-map
|
|
|
1458 for i from 0 to (1- (length strokes-map)) do
|
|
|
1459 (let ((stroke (car def))
|
|
|
1460 (command-name (symbol-name (cdr def))))
|
|
|
1461 (strokes-xpm-for-stroke stroke " *strokes-xpm*")
|
|
|
1462 (newline 2)
|
|
|
1463 (insert-char ?\ 45)
|
|
|
1464 (beginning-of-line)
|
|
|
1465 (insert command-name)
|
|
|
1466 (beginning-of-line)
|
|
|
1467 (forward-char 45)
|
|
|
1468 (set (intern (format "strokes-list-annotation-%d" i))
|
|
|
1469 (make-annotation (make-glyph
|
|
|
1470 (list
|
|
|
1471 (vector 'xpm
|
|
|
1472 :data (buffer-substring
|
|
|
1473 (point-min " *strokes-xpm*")
|
|
|
1474 (point-max " *strokes-xpm*")
|
|
|
1475 " *strokes-xpm*"))
|
|
|
1476 [string :data "[Stroke]"]))
|
|
|
1477 (point) 'text))
|
|
|
1478 (set-annotation-data (symbol-value (intern (format "strokes-list-annotation-%d" i)))
|
|
|
1479 def))
|
|
|
1480 finally do (kill-region (1+ (point)) (point-max)))
|
|
|
1481 (edit-strokes-mode)
|
|
|
1482 (goto-char (point-min)))
|
|
|
1483
|
|
|
1484 ;;;###autoload
|
|
|
1485 (defalias 'edit-strokes 'strokes-edit-strokes)
|
|
|
1486
|
|
|
1487 ;;;###autoload
|
|
|
1488 (defun strokes-list-strokes (&optional chronological strokes-map)
|
|
|
1489 "Pop up a buffer containing an alphabetical listing of strokes in STROKES-MAP.
|
|
|
1490 With CHRONOLOGICAL prefix arg \(\\[universal-argument]\) list strokes
|
|
|
1491 chronologically by command name.
|
|
|
1492 If STROKES-MAP is not given, `strokes-global-map' will be used instead."
|
|
|
1493 (interactive "P")
|
|
|
1494 (setq strokes-map (or strokes-map
|
|
|
1495 strokes-global-map
|
|
|
1496 (progn
|
|
|
1497 (strokes-load-user-strokes)
|
|
|
1498 strokes-global-map)))
|
|
|
1499 (if (not chronological)
|
|
|
1500 ;; then alphabetize the strokes based on command names...
|
|
|
1501 (setq strokes-map (sort (copy-sequence strokes-map)
|
|
|
1502 'strokes-alphabetic-lessp)))
|
|
153
|
1503 (push-window-configuration)
|
|
|
1504 (set-buffer (get-buffer-create "*Strokes List*"))
|
|
|
1505 (setq buffer-read-only nil)
|
|
|
1506 (erase-buffer)
|
|
|
1507 (insert
|
|
|
1508 "Command Stroke\n"
|
|
177
|
1509 "------- ------")
|
|
|
1510 (loop for def in strokes-map do
|
|
153
|
1511 (let ((stroke (car def))
|
|
177
|
1512 (command-name (symbol-name (cdr def))))
|
|
153
|
1513 (strokes-xpm-for-stroke stroke " *strokes-xpm*")
|
|
177
|
1514 (newline 2)
|
|
|
1515 (insert-char ?\ 45)
|
|
153
|
1516 (beginning-of-line)
|
|
177
|
1517 (insert command-name)
|
|
153
|
1518 (beginning-of-line)
|
|
|
1519 (forward-char 45)
|
|
|
1520 (make-annotation (make-glyph
|
|
|
1521 (list
|
|
|
1522 (vector 'xpm
|
|
|
1523 :data (buffer-substring
|
|
|
1524 (point-min " *strokes-xpm*")
|
|
|
1525 (point-max " *strokes-xpm*")
|
|
|
1526 " *strokes-xpm*"))
|
|
|
1527 [string :data "[Image]"]))
|
|
177
|
1528 (point) 'text))
|
|
|
1529 finally do (kill-region (1+ (point)) (point-max)))
|
|
153
|
1530 (view-buffer "*Strokes List*" t)
|
|
|
1531 (goto-char (point-min))
|
|
177
|
1532 (define-key view-minor-mode-map [(q)] (lambda ()
|
|
|
1533 (interactive)
|
|
|
1534 (view-quit)
|
|
|
1535 (pop-window-configuration)
|
|
|
1536 ;; (bury-buffer "*Strokes List*")
|
|
|
1537 (define-key view-minor-mode-map [(q)] 'view-quit))))
|
|
|
1538
|
|
|
1539 (defun strokes-alphabetic-lessp (stroke1 stroke2)
|
|
|
1540 "T iff command name for STROKE1 is less than STROKE2's in lexicographic order."
|
|
|
1541 (let ((command-name-1 (symbol-name (cdr stroke1)))
|
|
|
1542 (command-name-2 (symbol-name (cdr stroke2))))
|
|
|
1543 (string-lessp command-name-1 command-name-2)))
|
|
153
|
1544
|
|
|
1545 ;;;###autoload
|
|
|
1546 (defalias 'list-strokes 'strokes-list-strokes)
|
|
|
1547
|
|
|
1548 ;;;###autoload
|
|
|
1549 (defun strokes-mode (&optional arg)
|
|
|
1550 "Toggle strokes being enabled.
|
|
|
1551 With ARG, turn strokes on if and only if ARG is positive or true.
|
|
|
1552 Note that `strokes-mode' is a global mode. Think of it as a minor
|
|
|
1553 mode in all buffers when activated.
|
|
|
1554 By default, strokes are invoked with mouse button-2. You can define
|
|
|
1555 new strokes with
|
|
|
1556
|
|
|
1557 > M-x global-set-stroke"
|
|
|
1558 (interactive "P")
|
|
|
1559 (let ((on-p (if arg
|
|
|
1560 (> (prefix-numeric-value arg) 0)
|
|
|
1561 (not strokes-mode))))
|
|
|
1562 (cond ((not (device-on-window-system-p))
|
|
|
1563 (error "Can't use strokes without windows"))
|
|
|
1564 (on-p ; turn on strokes
|
|
|
1565 (and (file-exists-p strokes-file)
|
|
|
1566 (null strokes-global-map)
|
|
|
1567 (strokes-load-user-strokes))
|
|
|
1568 (add-hook 'kill-emacs-hook
|
|
|
1569 'strokes-prompt-user-save-strokes)
|
|
|
1570 (add-hook 'select-frame-hook
|
|
|
1571 'strokes-update-window-configuration)
|
|
|
1572 (strokes-update-window-configuration)
|
|
|
1573 (define-key global-map [(button2)] 'strokes-do-stroke)
|
|
|
1574 (define-key global-map [(control button2)] 'strokes-do-stroke)
|
|
|
1575 (define-key global-map [(shift button2)]
|
|
|
1576 'strokes-do-complex-stroke)
|
|
|
1577 (ad-activate-regexp "^strokes-") ; advise button2 commands
|
|
|
1578 (setq strokes-mode t))
|
|
|
1579 (t ; turn off strokes
|
|
|
1580 (if (get-buffer strokes-buffer-name)
|
|
|
1581 (kill-buffer (get-buffer strokes-buffer-name)))
|
|
|
1582 (remove-hook 'select-frame-hook
|
|
|
1583 'strokes-update-window-configuration)
|
|
|
1584 (if (string-match "^strokes-" (symbol-name (key-binding [(button2)])))
|
|
|
1585 (define-key global-map [(button2)] strokes-click-command))
|
|
|
1586 (if (string-match "^strokes-" (symbol-name (key-binding [(control button2)])))
|
|
|
1587 (global-unset-key [(control button2)]))
|
|
|
1588 (if (string-match "^strokes-" (symbol-name (key-binding [(shift button2)])))
|
|
|
1589 (global-unset-key [(shift button2)]))
|
|
|
1590 (ad-deactivate-regexp "^strokes-") ; unadvise strokes-button2 commands
|
|
|
1591 (setq strokes-mode nil))))
|
|
|
1592 (redraw-modeline))
|
|
|
1593
|
|
|
1594 (add-minor-mode 'strokes-mode strokes-modeline-string nil nil 'strokes-mode)
|
|
|
1595
|
|
177
|
1596 (unless (find-face 'strokes-char-face)
|
|
|
1597 (copy-face 'default 'strokes-char-face)
|
|
|
1598 (set-face-background 'strokes-char-face "lightgray"))
|
|
|
1599
|
|
|
1600 (defconst strokes-char-value-hashtable (make-hashtable 62) ;
|
|
|
1601 ; (make-char-table
|
|
|
1602 ; 'syntax)
|
|
|
1603 ; in 20.*
|
|
|
1604 ;; ### This will become a char-table for XEmacs-20 !!! ###
|
|
|
1605 "The table which stores values for the character keys.")
|
|
|
1606 (puthash ?0 0 strokes-char-value-hashtable) ; (put-char-table ?0 0
|
|
|
1607 ; strokes-value-chartable)
|
|
|
1608 ; in 20.*
|
|
|
1609 (puthash ?1 1 strokes-char-value-hashtable)
|
|
|
1610 (puthash ?2 2 strokes-char-value-hashtable)
|
|
|
1611 (puthash ?3 3 strokes-char-value-hashtable)
|
|
|
1612 (puthash ?4 4 strokes-char-value-hashtable)
|
|
|
1613 (puthash ?5 5 strokes-char-value-hashtable)
|
|
|
1614 (puthash ?6 6 strokes-char-value-hashtable)
|
|
|
1615 (puthash ?7 7 strokes-char-value-hashtable)
|
|
|
1616 (puthash ?8 8 strokes-char-value-hashtable)
|
|
|
1617 (puthash ?9 9 strokes-char-value-hashtable)
|
|
|
1618 (puthash ?a 10 strokes-char-value-hashtable)
|
|
|
1619 (puthash ?b 11 strokes-char-value-hashtable)
|
|
|
1620 (puthash ?c 12 strokes-char-value-hashtable)
|
|
|
1621 (puthash ?d 13 strokes-char-value-hashtable)
|
|
|
1622 (puthash ?e 14 strokes-char-value-hashtable)
|
|
|
1623 (puthash ?f 15 strokes-char-value-hashtable)
|
|
|
1624 (puthash ?g 16 strokes-char-value-hashtable)
|
|
|
1625 (puthash ?h 17 strokes-char-value-hashtable)
|
|
|
1626 (puthash ?i 18 strokes-char-value-hashtable)
|
|
|
1627 (puthash ?j 19 strokes-char-value-hashtable)
|
|
|
1628 (puthash ?k 20 strokes-char-value-hashtable)
|
|
|
1629 (puthash ?l 21 strokes-char-value-hashtable)
|
|
|
1630 (puthash ?m 22 strokes-char-value-hashtable)
|
|
|
1631 (puthash ?n 23 strokes-char-value-hashtable)
|
|
|
1632 (puthash ?o 24 strokes-char-value-hashtable)
|
|
|
1633 (puthash ?p 25 strokes-char-value-hashtable)
|
|
|
1634 (puthash ?q 26 strokes-char-value-hashtable)
|
|
|
1635 (puthash ?r 27 strokes-char-value-hashtable)
|
|
|
1636 (puthash ?s 28 strokes-char-value-hashtable)
|
|
|
1637 (puthash ?t 29 strokes-char-value-hashtable)
|
|
|
1638 (puthash ?u 30 strokes-char-value-hashtable)
|
|
|
1639 (puthash ?v 31 strokes-char-value-hashtable)
|
|
|
1640 (puthash ?w 32 strokes-char-value-hashtable)
|
|
|
1641 (puthash ?x 33 strokes-char-value-hashtable)
|
|
|
1642 (puthash ?y 34 strokes-char-value-hashtable)
|
|
|
1643 (puthash ?z 35 strokes-char-value-hashtable)
|
|
|
1644 (puthash ?A 36 strokes-char-value-hashtable)
|
|
|
1645 (puthash ?B 37 strokes-char-value-hashtable)
|
|
|
1646 (puthash ?C 38 strokes-char-value-hashtable)
|
|
|
1647 (puthash ?D 39 strokes-char-value-hashtable)
|
|
|
1648 (puthash ?E 40 strokes-char-value-hashtable)
|
|
|
1649 (puthash ?F 41 strokes-char-value-hashtable)
|
|
|
1650 (puthash ?G 42 strokes-char-value-hashtable)
|
|
|
1651 (puthash ?H 43 strokes-char-value-hashtable)
|
|
|
1652 (puthash ?I 44 strokes-char-value-hashtable)
|
|
|
1653 (puthash ?J 45 strokes-char-value-hashtable)
|
|
|
1654 (puthash ?K 46 strokes-char-value-hashtable)
|
|
|
1655 (puthash ?L 47 strokes-char-value-hashtable)
|
|
|
1656 (puthash ?M 48 strokes-char-value-hashtable)
|
|
|
1657 (puthash ?N 49 strokes-char-value-hashtable)
|
|
|
1658 (puthash ?O 50 strokes-char-value-hashtable)
|
|
|
1659 (puthash ?P 51 strokes-char-value-hashtable)
|
|
|
1660 (puthash ?Q 52 strokes-char-value-hashtable)
|
|
|
1661 (puthash ?R 53 strokes-char-value-hashtable)
|
|
|
1662 (puthash ?S 54 strokes-char-value-hashtable)
|
|
|
1663 (puthash ?T 55 strokes-char-value-hashtable)
|
|
|
1664 (puthash ?U 56 strokes-char-value-hashtable)
|
|
|
1665 (puthash ?V 57 strokes-char-value-hashtable)
|
|
|
1666 (puthash ?W 58 strokes-char-value-hashtable)
|
|
|
1667 (puthash ?X 59 strokes-char-value-hashtable)
|
|
|
1668 (puthash ?Y 60 strokes-char-value-hashtable)
|
|
|
1669 (puthash ?Z 61 strokes-char-value-hashtable)
|
|
|
1670
|
|
|
1671 (defconst strokes-base64-chars
|
|
|
1672 ;; I can easily have made this a vector of single-character strings,
|
|
|
1673 ;; like (vector "0" "1" "2" ...), and then the program would run
|
|
|
1674 ;; faster since it wouldn't then have to call `char-to-string' when it
|
|
|
1675 ;; did the `concat'. I left them as chars here because I want
|
|
|
1676 ;; *them* to change `concat' so that it accepts chars and deals with
|
|
|
1677 ;; them properly. i.e. the form: (concat "abc" ?T "xyz") should
|
|
|
1678 ;; return "abcTxyz" NOT "abc84xyz" (XEmacs 19.*) and NOT an error
|
|
|
1679 ;; (XEmacs 20.*).
|
|
|
1680 ;; (vector "0" "1" "2" "3" "4" "5" "6" "7" "8" "9"
|
|
|
1681 ;; "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o"
|
|
|
1682 ;; "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z" "A" "B" "C" "D"
|
|
|
1683 ;; "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S"
|
|
|
1684 ;; "T" "U" "V" "W" "X" "Y" "Z")
|
|
|
1685 (vector ?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9
|
|
|
1686 ?a ?b ?c ?d ?e ?f ?g ?h ?i ?j ?k ?l ?m ?n ?o ?p ?q ?r ?s ?t ?u ?v ?w ?x ?y ?z
|
|
|
1687 ?A ?B ?C ?D ?E ?F ?G ?H ?I ?J ?K ?L ?M ?N ?O ?P ?Q ?R ?S ?T ?U ?V ?W ?X ?Y ?Z)
|
|
|
1688 "Character vector for fast lookup of base-64 encoding of numbers in [0,61].")
|
|
|
1689
|
|
|
1690 (defsubst strokes-xpm-char-on-p (char)
|
|
|
1691 ;; ### CAUTION: `char-equal' may need to change to `char=' ###
|
|
|
1692 "Non-nil if CHAR represents an `on' bit in the xpm."
|
|
|
1693 (char-equal char ?*))
|
|
|
1694
|
|
|
1695 (defsubst strokes-xpm-char-bit-p (char)
|
|
|
1696 "Non-nil if CHAR represents an `on' or `off' bit in the xpm."
|
|
|
1697 ;; ### CAUTION: `char-equal' may need to change to `char=' ###
|
|
|
1698 (or (char-equal char ?\ )
|
|
|
1699 (char-equal char ?*)))
|
|
|
1700
|
|
|
1701 ;;(defsubst strokes-xor (a b) ### Should I make this an inline function? ###
|
|
|
1702 ;; "T iff one and only one of A and B is non-nil; otherwise, returns nil.
|
|
|
1703 ;;NOTE: Don't use this as a numeric xor since it treats all non-nil
|
|
|
1704 ;; values as t including `0' (zero)."
|
|
|
1705 ;; (eq (null a) (not (null b))))
|
|
|
1706
|
|
|
1707 (defsubst strokes-xpm-encode-length-as-string (length)
|
|
|
1708 "Given some LENGTH in [0,62) do a fast lookup of it's encoding."
|
|
|
1709 (char-to-string (aref strokes-base64-chars length)))
|
|
|
1710
|
|
|
1711 (defsubst strokes-xpm-decode-char (character)
|
|
|
1712 "Given a CHARACTER, do a fast lookup to find its corresponding integer value."
|
|
|
1713 ;; ### NOTE: for XEmacs-20.* this will need to be changed to deal w/
|
|
|
1714 ;; char-tables !!! ###
|
|
|
1715 (gethash character strokes-char-value-hashtable)) ; (get-char-table
|
|
|
1716 ; character
|
|
|
1717 ; strokes-value-chartable)
|
|
|
1718
|
|
|
1719 (defun strokes-xpm-to-compressed-string (&optional xpm-buffer)
|
|
|
1720 "Convert the xpm in XPM-BUFFER into a compressed string representing the stroke.
|
|
|
1721 XPM-BUFFER is an optional argument, and defaults to `*strokes-xpm*'."
|
|
|
1722 (save-excursion
|
|
|
1723 (set-buffer (setq xpm-buffer (or xpm-buffer "*strokes-xpm*")))
|
|
|
1724 (goto-char (point-min))
|
|
|
1725 (search-forward "/* pixels */") ; skip past header junk
|
|
|
1726 (forward-char 2)
|
|
|
1727 ;; a note for below:
|
|
|
1728 ;; the `current-char' is the char being counted -- NOT the char at (point)
|
|
|
1729 ;; which happens to be called `char-at-point'
|
|
|
1730 (let ((compressed-string "+/") ; initialize the output
|
|
|
1731 (count 0) ; keep a current count of
|
|
|
1732 ; `current-char'
|
|
|
1733 (last-char-was-on-p t) ; last entered stream
|
|
|
1734 ; represented `on' bits
|
|
|
1735 (current-char-is-on-p nil) ; current stream represents `on' bits
|
|
|
1736 (char-at-point (char-after))) ; read the first char
|
|
|
1737 (while (not (char-equal char-at-point ?})) ; a `}' denotes the
|
|
|
1738 ; end of the pixmap
|
|
|
1739 (cond ((zerop count) ; must restart counting
|
|
|
1740 ;; check to see if the `char-at-point' is an actual pixmap bit
|
|
|
1741 (when (strokes-xpm-char-bit-p char-at-point)
|
|
|
1742 (setq count 1
|
|
|
1743 current-char-is-on-p (strokes-xpm-char-on-p char-at-point)))
|
|
|
1744 (forward-char 1))
|
|
|
1745 ((= count 61) ; maximum single char's
|
|
|
1746 ; encoding length
|
|
|
1747 (setq compressed-string (concat compressed-string
|
|
|
1748 ;; add a zero-length
|
|
|
1749 ;; encoding when
|
|
|
1750 ;; necessary
|
|
|
1751 (when (eq last-char-was-on-p
|
|
|
1752 current-char-is-on-p)
|
|
|
1753 ;; "0"
|
|
|
1754 (strokes-xpm-encode-length-as-string 0))
|
|
|
1755 (strokes-xpm-encode-length-as-string 61))
|
|
|
1756 last-char-was-on-p current-char-is-on-p
|
|
|
1757 count 0)) ; note that we just set
|
|
|
1758 ; count=0 and *don't* advance
|
|
|
1759 ; (point)
|
|
|
1760 ((strokes-xpm-char-bit-p char-at-point) ; an actual xpm bit
|
|
|
1761 (if (eq current-char-is-on-p
|
|
|
1762 (strokes-xpm-char-on-p char-at-point))
|
|
|
1763 ;; yet another of the same bit-type, so we continue
|
|
|
1764 ;; counting...
|
|
|
1765 (progn
|
|
|
1766 (incf count)
|
|
|
1767 (forward-char 1))
|
|
|
1768 ;; otherwise, it's the opposite bit-type, so we do a
|
|
|
1769 ;; write and then restart count ### NOTE (for myself
|
|
|
1770 ;; to be aware of) ### I really should advance
|
|
|
1771 ;; (point) in this case instead of letting another
|
|
|
1772 ;; iteration go through and letting the case: count=0
|
|
|
1773 ;; take care of this stuff for me. That's why
|
|
|
1774 ;; there's no (forward-char 1) below.
|
|
|
1775 (setq compressed-string (concat compressed-string
|
|
|
1776 ;; add a zero-length
|
|
|
1777 ;; encoding when
|
|
|
1778 ;; necessary
|
|
|
1779 (when (eq last-char-was-on-p
|
|
|
1780 current-char-is-on-p)
|
|
|
1781 ;; "0"
|
|
|
1782 (strokes-xpm-encode-length-as-string 0))
|
|
|
1783 (strokes-xpm-encode-length-as-string count))
|
|
|
1784 count 0
|
|
|
1785 last-char-was-on-p current-char-is-on-p)))
|
|
|
1786 (t ; ELSE it's some other useless
|
|
|
1787 ; char, like `"' or `,'
|
|
|
1788 (forward-char 1)))
|
|
|
1789 (setq char-at-point (char-after)))
|
|
|
1790 (concat compressed-string
|
|
|
1791 (when (> count 0)
|
|
|
1792 (concat (when (eq last-char-was-on-p
|
|
|
1793 current-char-is-on-p)
|
|
|
1794 ;; "0"
|
|
|
1795 (strokes-xpm-encode-length-as-string 0))
|
|
|
1796 (strokes-xpm-encode-length-as-string count)))
|
|
|
1797 "/"))))
|
|
|
1798
|
|
|
1799 (defun strokes-strokify-buffer (&optional buffer)
|
|
|
1800 "Decode stroke strings in BUFFER and display their corresponding glyphs.
|
|
|
1801 BUFFER defaults to the current buffer."
|
|
|
1802 (interactive)
|
|
|
1803 ;; (interactive "*bStrokify buffer: ")
|
|
|
1804 (save-excursion
|
|
|
1805 (set-buffer (or buffer (setq buffer (current-buffer))))
|
|
|
1806 (if (interactive-p)
|
|
|
1807 (message "Strokifying %s..." buffer))
|
|
|
1808 (goto-char (point-min))
|
|
|
1809 (let (ext string)
|
|
|
1810 ;; The comment below is what i'd have to do if I wanted to deal with
|
|
|
1811 ;; random newlines in the midst of the compressed strings.
|
|
|
1812 ;; If I do this, I'll also have to change `strokes-xpm-to-compress-string'
|
|
|
1813 ;; to deal with the newline, and possibly other whitespace stuff. YUCK!
|
|
|
1814 ;; (while (re-search-forward "\\+/\\(\\w\\|
|
|
|
1815 ;;\\)+/" nil t nil (get-buffer buffer))
|
|
|
1816 (while (re-search-forward "\\+/\\w+/" nil t nil (get-buffer buffer))
|
|
|
1817 (setq string (buffer-substring (+ 2 (match-beginning 0))
|
|
|
1818 (1- (match-end 0))))
|
|
|
1819 (strokes-xpm-for-compressed-string string " *strokes-xpm*")
|
|
|
1820 (replace-match " ")
|
|
|
1821 (setq ext (make-extent (1- (point)) (point)))
|
|
|
1822 (set-extent-property ext 'type 'stroke-glyph)
|
|
|
1823 (set-extent-property ext 'start-open t)
|
|
|
1824 (set-extent-property ext 'end-open t)
|
|
|
1825 (set-extent-property ext 'detachable t)
|
|
|
1826 (set-extent-property ext 'duplicable t)
|
|
|
1827 (set-extent-property ext 'data string)
|
|
|
1828 (set-extent-face ext 'strokes-char-face)
|
|
|
1829 (set-extent-end-glyph ext (make-glyph
|
|
|
1830 (list
|
|
|
1831 (vector 'xpm
|
|
|
1832 :data (buffer-substring
|
|
|
1833 (point-min " *strokes-xpm*")
|
|
|
1834 (point-max " *strokes-xpm*")
|
|
|
1835 " *strokes-xpm*"))
|
|
|
1836 [string :data "[Stroke]"])))))
|
|
|
1837 (if (interactive-p)
|
|
|
1838 (message "Strokifying %s...done" buffer))))
|
|
|
1839
|
|
|
1840 (defun strokes-unstrokify-buffer (&optional buffer)
|
|
|
1841 "Convert the glyphs in BUFFER to thier base-64 ASCII representations.
|
|
|
1842 BUFFER defaults to the current buffer"
|
|
|
1843 ;; ### NOTE !!! ### (for me)
|
|
|
1844 ;; For later on, you can/should make the inserted strings atomic
|
|
|
1845 ;; extents, so that the users have a clue that they shouldn't be
|
|
|
1846 ;; editing inside them. Plus, if you make them extents, you can
|
|
|
1847 ;; very easily just hide the glyphs, so if you unstrokify, and the
|
|
|
1848 ;; restrokify, then those that already are glyphed don't need to be
|
|
|
1849 ;; re-calculated, etc. It's just nicer that way. The only things
|
|
|
1850 ;; to worry about is cleanup (i.e. do the glyphs get gc'd when the
|
|
|
1851 ;; buffer is killed?
|
|
|
1852 ;; (interactive "*bUnstrokify buffer: ")
|
|
|
1853 (interactive)
|
|
|
1854 (save-excursion
|
|
|
1855 (set-buffer (setq buffer (or buffer (current-buffer))))
|
|
|
1856 ;; (map-extents
|
|
|
1857 ;; (lambda (ext buf)
|
|
|
1858 ;; (when (eq (extent-property ext 'type) 'stroke-glyph)
|
|
|
1859 ;; (goto-char (extent-start-position ext))
|
|
|
1860 ;; (delete-char 1) ; ### What the hell do I do here? ###
|
|
|
1861 ;; (insert "+/" (extent-property ext 'data) "/")
|
|
|
1862 ;; (delete-extent ext))))))
|
|
|
1863 (let (start)
|
|
|
1864 (map-extents
|
|
|
1865 (lambda (ext buf)
|
|
|
1866 (when (eq (extent-property ext 'type) 'stroke-glyph)
|
|
|
1867 (setq start (goto-char (extent-start-position ext)))
|
|
|
1868 ;; (insert "+/" (extent-property ext 'data) "/")
|
|
|
1869 (insert-string "+/")
|
|
|
1870 (insert-string (extent-property ext 'data))
|
|
|
1871 (insert-string "/")
|
|
|
1872 (delete-char 1)
|
|
|
1873 (set-extent-endpoints ext start (point))
|
|
|
1874 (set-extent-property ext 'type 'stroke-string)
|
|
|
1875 (set-extent-property ext 'atomic t)
|
|
|
1876 ;; (set-extent-property ext 'read-only t)
|
|
|
1877 (set-extent-face ext 'strokes-char-face)
|
|
|
1878 (set-extent-property ext 'stroke-glyph (extent-end-glyph ext))
|
|
|
1879 (set-extent-end-glyph ext nil)))))))
|
|
|
1880
|
|
|
1881 (defun strokes-xpm-for-compressed-string (compressed-string &optional bufname)
|
|
|
1882 "Convert the stroke represented by COMPRESSED-STRING into an xpm.
|
|
|
1883 Store xpm in buffer BUFNAME if supplied \(default is `*strokes-xpm*'\)"
|
|
|
1884 (save-excursion
|
|
|
1885 (or bufname (setq bufname "*strokes-xpm*"))
|
|
|
1886 (erase-buffer (set-buffer (get-buffer-create bufname)))
|
|
|
1887 (insert compressed-string)
|
|
|
1888 (goto-char (point-min))
|
|
|
1889 (let ((current-char-is-on-p nil))
|
|
|
1890 (while (not (eobp))
|
|
|
1891 (insert-char
|
|
|
1892 (if current-char-is-on-p
|
|
|
1893 ?*
|
|
|
1894 ?\ )
|
|
|
1895 (strokes-xpm-decode-char (char-after)))
|
|
|
1896 (delete-char 1)
|
|
|
1897 (setq current-char-is-on-p (not current-char-is-on-p)))
|
|
|
1898 (goto-char (point-min))
|
|
|
1899 (loop repeat 33 do
|
|
|
1900 (insert-char ?\")
|
|
|
1901 (forward-char 33)
|
|
|
1902 (insert "\",\n"))
|
|
|
1903 (goto-char (point-min))
|
|
|
1904 (insert strokes-xpm-header))))
|
|
|
1905
|
|
|
1906 (defun strokes-compose-complex-stroke ()
|
|
|
1907 (interactive "*")
|
|
|
1908 (let ((strokes-grid-resolution 33))
|
|
|
1909 (strokes-read-complex-stroke)
|
|
|
1910 (strokes-xpm-for-stroke nil nil t)
|
|
|
1911 (insert (strokes-xpm-to-compressed-string))
|
|
|
1912 (strokes-strokify-buffer)))
|
|
|
1913
|
|
153
|
1914 (provide 'strokes)
|
|
|
1915 (run-hooks 'strokes-load-hook)
|
|
|
1916
|
|
177
|
1917 ;;; strokes.el ends here |