Fix problems caught with --enable-gcc-warnings
[emacs.git] / lisp / strokes.el
bloba4f4a14af324f257558af3de619cca86a0233062
1 ;;; strokes.el --- control Emacs through mouse strokes
3 ;; Copyright (C) 1997, 2000-2015 Free Software Foundation, Inc.
5 ;; Author: David Bakhash <cadet@alum.mit.edu>
6 ;; Maintainer: emacs-devel@gnu.org
7 ;; Keywords: lisp, mouse, extensions
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;;; Commentary:
26 ;; This is the strokes package. It is intended to allow the user to
27 ;; control Emacs by means of mouse strokes. Once strokes is loaded, you
28 ;; can always get help be invoking `strokes-help':
30 ;; > M-x strokes-help
32 ;; and you can learn how to use the package. A mouse stroke, for now,
33 ;; can be defined as holding the shift key and the middle button, for
34 ;; instance, and then moving the mouse in whatever pattern you wish,
35 ;; which you have set Emacs to understand as mapping to a given
36 ;; command. For example, you may wish the have a mouse stroke that
37 ;; looks like a capital `C' which means `copy-region-as-kill'. Treat
38 ;; strokes just like you do key bindings. For example, Emacs sets key
39 ;; bindings globally with the `global-set-key' command. Likewise, you
40 ;; can do
42 ;; > M-x strokes-global-set-stroke
44 ;; to interactively program in a stroke. It would be wise to set the
45 ;; first one to this very command, so that from then on, you invoke
46 ;; `strokes-global-set-stroke' with a stroke. Likewise, there may
47 ;; eventually be a `strokes-local-set-stroke' command, also analogous
48 ;; to `local-set-key'.
50 ;; You can always unset the last stroke definition with the command
52 ;; > M-x strokes-unset-last-stroke
54 ;; and the last stroke that was added to `strokes-global-map' will be
55 ;; removed.
57 ;; Other analogies between strokes and key bindings are as follows:
59 ;; 1) To describe a stroke binding, you can type
61 ;; > M-x strokes-describe-stroke
63 ;; analogous to `describe-key'. It's also wise to have a stroke,
64 ;; like an `h', for help, or a `?', mapped to `describe-stroke'.
66 ;; 2) stroke bindings are set internally through the Lisp function
67 ;; `strokes-define-stroke', similar to the `define-key' function.
68 ;; some examples for a 3x3 stroke grid would be
70 ;; (strokes-define-stroke c-mode-stroke-map
71 ;; '((0 . 0) (1 . 1) (2 . 2))
72 ;; 'kill-region)
73 ;; (strokes-define-stroke strokes-global-map
74 ;; '((0 . 0) (0 . 1) (0 . 2) (1 . 2) (2 . 2))
75 ;; 'list-buffers)
77 ;; however, if you would probably just have the user enter in the
78 ;; stroke interactively and then set the stroke to whatever he/she
79 ;; entered. The Lisp function to interactively read a stroke is
80 ;; `strokes-read-stroke'. This is especially helpful when you're
81 ;; on a fast computer that can handle a 9x9 stroke grid.
83 ;; NOTE: only global stroke bindings are currently implemented,
84 ;; however mode- and buffer-local stroke bindings may eventually
85 ;; be implemented in a future version.
87 ;; The important variables to be aware of for this package are listed
88 ;; below. They can all be altered through the customizing package via
90 ;; > M-x customize
92 ;; and customizing the group named `strokes'. You can also read
93 ;; documentation on the variables there.
95 ;; `strokes-minimum-match-score' (determines the threshold of error that
96 ;; makes a stroke acceptable or unacceptable. If your strokes aren't
97 ;; matching, then you should raise this variable.
99 ;; `strokes-grid-resolution' (determines the grid dimensions that you use
100 ;; when defining/reading strokes. The finer the grid your computer can
101 ;; handle, the more you can do, but even a 3x3 grid is pretty cool.)
102 ;; The default value (9) should be fine for most decent computers.
103 ;; NOTE: This variable should not be set to a number less than 3.
105 ;; `strokes-display-strokes-buffer' will allow you to hide the strokes
106 ;; buffer when doing simple strokes. This is a speedup for slow
107 ;; computers as well as people who don't want to see their strokes.
109 ;; If you find that your mouse is accelerating too fast, you can
110 ;; execute an X command to slow it down. A good possibility is
112 ;; % xset m 5/4 8
114 ;; which seems, heuristically, to work okay, without much disruption.
116 ;; Whenever you load in the strokes package, you will be able to save
117 ;; what you've done upon exiting Emacs. You can also do
119 ;; > M-x strokes-prompt-user-save-strokes
121 ;; and it will save your strokes in your `strokes-file'.
123 ;; Note that internally, all of the routines that are part of this
124 ;; package are able to deal with complex strokes, as they are a superset
125 ;; of simple strokes. However, the default of this package will map
126 ;; S-mouse-2 to the command `strokes-do-stroke', and M-mouse-2 to
127 ;; `strokes-do-complex-stroke'. Complex strokes are terminated
128 ;; with mouse button 3.
130 ;; You can also toggle between strokes mode by simple typing
132 ;; > M-x strokes-mode
134 ;; I hope that, with the help of others, this package will be useful
135 ;; in entering in pictographic-like language text using the mouse
136 ;; (i.e. Korean). Japanese and Chinese are a bit trickier, but I'm
137 ;; sure that with help it can be done. The next version will allow
138 ;; the user to enter strokes which "remove the pencil from the paper"
139 ;; so to speak, so one character can have multiple strokes.
141 ;; NOTE (Oct 7, 2006): The URLs below seem to be invalid!!!
143 ;; You can read more about strokes at:
145 ;; http://www.mit.edu/people/cadet/strokes-help.html
147 ;; If you're interested in using strokes for writing English into Emacs
148 ;; using strokes, then you'll want to read about it on the web page above
149 ;; or just download from http://www.mit.edu/people/cadet/strokes-abc.el,
150 ;; which is nothing but a file with some helper commands for inserting
151 ;; alphanumerics and punctuation.
153 ;; Great thanks to Rob Ristroph for his generosity in letting me use
154 ;; his PC to develop this, Jason Johnson for his help in algorithms,
155 ;; Euna Kim for her help in Korean, and massive thanks to the helpful
156 ;; guys on the help instance on athena (zeno, jered, amu, gsstark,
157 ;; ghudson, etc) Special thanks to Steve Baur, Kyle Jones, and Hrvoje
158 ;; Niksic for all their help. And special thanks to Dave Gillespie
159 ;; for all the elisp help--he is responsible for helping me use the cl
160 ;; macros at (near) max speed.
162 ;; Tasks: (what I'm getting ready for future version)...
163 ;; 2) use 'strokes-read-complex-stroke for Korean, etc.
164 ;; 4) buffer-local 'strokes-local-map, and mode-stroke-maps would be nice
165 ;; 6) add some hooks, like `strokes-read-stroke-hook'
166 ;; 7) See what people think of the factory settings. Should I change
167 ;; them? They're all pretty arbitrary in a way. I guess they
168 ;; should be minimal, but computers are getting lots faster, and
169 ;; if I choose the defaults too conservatively, then strokes will
170 ;; surely disappoint some people on decent machines (until they
171 ;; figure out M-x customize). I need feedback.
172 ;; Other: I always have the most beta version of strokes, so if you
173 ;; want it just let me know.
175 ;; Fixme: Use pbm instead of xpm for pixmaps to work generally.
177 ;;; Code:
179 ;;; Requirements and provisions...
181 (autoload 'mail-position-on-field "sendmail")
182 (eval-when-compile (require 'cl-lib))
184 ;;; Constants...
186 (defconst strokes-lift :strokes-lift
187 "Symbol representing a stroke lift event for complex strokes.
188 Complex strokes are those which contain two or more simple strokes.")
190 (defconst strokes-xpm-header "/* XPM */
191 static char * stroke_xpm[] = {
192 /* width height ncolors cpp [x_hot y_hot] */
193 \"33 33 9 1 26 23\",
194 /* colors */
195 \" c none s none\",
196 \"* c #000000 s foreground\",
197 \"R c #FFFF00000000\",
198 \"O c #FFFF80000000\",
199 \"Y c #FFFFFFFF0000\",
200 \"G c #0000FFFF0000\",
201 \"B c #00000000FFFF\",
202 \"P c #FFFF0000FFFF\",
203 \". c #45458B8B0000\",
204 /* pixels */\n"
205 "The header to all XPM buffers created by strokes.")
207 ;;; user variables...
209 (defgroup strokes nil
210 "Control Emacs through mouse strokes."
211 :link '(emacs-commentary-link "strokes")
212 :group 'mouse)
214 (define-obsolete-variable-alias 'strokes-modeline-string 'strokes-lighter
215 "24.3")
217 (defcustom strokes-lighter " Strokes"
218 "Mode line identifier for Strokes mode."
219 :type 'string
220 :group 'strokes)
222 (defcustom strokes-character ?@
223 "Character used when drawing strokes in the strokes buffer.
224 \(The default is `@', which works well.)"
225 :type 'character
226 :group 'strokes)
228 (defcustom strokes-minimum-match-score 1000
229 "Minimum score for a stroke to be considered a possible match.
230 Setting this variable to 0 would require a perfectly precise match.
231 The default value is 1000, but it's mostly dependent on how precisely
232 you manage to replicate your user-defined strokes. It also depends on
233 the value of `strokes-grid-resolution', since a higher grid resolution
234 will correspond to more sample points, and thus more distance
235 measurements. Usually, this is not a problem since you first set
236 `strokes-grid-resolution' based on what your computer seems to be able
237 to handle (though the defaults are usually more than sufficient), and
238 then you can set `strokes-minimum-match-score' to something that works
239 for you. The only purpose of this variable is to insure that if you
240 do a bogus stroke that really doesn't match any of the predefined
241 ones, then strokes should NOT pick the one that came closest."
242 :type 'integer
243 :group 'strokes)
245 (defcustom strokes-grid-resolution 9
246 "Integer defining dimensions of the stroke grid.
247 The grid is a square grid, where `strokes-grid-resolution' defaults to
248 `9', making a 9x9 grid whose coordinates go from (0 . 0) on the top
249 left to ((strokes-grid-resolution - 1) . (strokes-grid-resolution - 1))
250 on the bottom right. The greater the resolution, the more intricate
251 your strokes can be.
252 NOTE: This variable should be odd and MUST NOT be less than 3 and need
253 not be greater than 33, which is the resolution of the pixmaps.
254 WARNING: Changing the value of this variable will gravely affect the
255 strokes you have already programmed in. You should try to
256 figure out what it should be based on your needs and on how
257 quick the particular platform(s) you're operating on, and
258 only then start programming in your custom strokes."
259 :type 'integer
260 :group 'strokes)
262 (defcustom strokes-file (locate-user-emacs-file "strokes" ".strokes")
263 "File containing saved strokes for Strokes mode."
264 :version "24.4" ; added locate-user-emacs-file
265 :type 'file
266 :group 'strokes)
268 (defvar strokes-buffer-name " *strokes*"
269 "The name of the buffer that the strokes take place in.")
271 (defcustom strokes-use-strokes-buffer t
272 "If non-nil, the strokes buffer is used and strokes are displayed.
273 If nil, strokes will be read the same, however the user will not be
274 able to see the strokes. This be helpful for people who don't like
275 the delay in switching to the strokes buffer."
276 :type 'boolean
277 :group 'strokes)
279 ;;; internal variables...
281 (defvar strokes-window-configuration nil
282 "The special window configuration used when entering strokes.
283 This is set properly in the function `strokes-update-window-configuration'.")
285 (defvar strokes-last-stroke nil
286 "Last stroke entered by the user.
287 Its value gets set every time the function `strokes-fill-stroke'
288 gets called, since that is the best time to set the variable.")
290 (defvar strokes-global-map '()
291 "Association list of strokes and their definitions.
292 Each entry is (STROKE . COMMAND) where STROKE is itself a list of
293 coordinates (X . Y) where X and Y are lists of positions on the
294 normalized stroke grid, with the top left at (0 . 0). COMMAND is
295 the corresponding interactive function.")
297 (defvar strokes-load-hook nil
298 "Functions to be called when Strokes is loaded.")
300 ;;; ### NOT IMPLEMENTED YET ###
301 ;;(defvar edit-strokes-menu
302 ;; '("Edit-Strokes"
303 ;; ["Add stroke..." strokes-global-set-stroke t]
304 ;; ["Delete stroke..." strokes-edit-delete-stroke t]
305 ;; ["Change stroke" strokes-smaller t]
306 ;; ["Change definition" strokes-larger t]
307 ;; ["[Re]List Strokes chronologically" strokes-list-strokes t]
308 ;; ["[Re]List Strokes alphabetically" strokes-list-strokes t]
309 ;; ["Quit" strokes-edit-quit t]
310 ;; ))
312 ;;; Macros...
314 ;; unused
315 ;; (defmacro strokes-while-inhibiting-garbage-collector (&rest forms)
316 ;; "Execute FORMS without interference from the garbage collector."
317 ;; `(let ((gc-cons-threshold 134217727))
318 ;; ,@forms))
320 (defsubst strokes-click-p (stroke)
321 "Non-nil if STROKE is really click."
322 (< (length stroke) 2))
324 ;;; old, but worked pretty good (just in case)...
325 ;;(defmacro strokes-define-stroke (stroke-map stroke def)
326 ;; "Add STROKE to STROKE-MAP alist with given command DEF"
327 ;; (list 'if (list '< (list 'length stroke) 2)
328 ;; (list 'error
329 ;; "That's a click, not a stroke. See `strokes-click-command'")
330 ;; (list 'setq stroke-map (list 'cons (list 'cons stroke def)
331 ;; (list 'remassoc stroke stroke-map)))))
333 (defsubst strokes-remassoc (key list)
334 (let (elt)
335 (while (setq elt (assoc key list))
336 (setq list (delete elt list))))
337 list)
339 (defmacro strokes-define-stroke (stroke-map stroke def)
340 "Add STROKE to STROKE-MAP alist with given command DEF."
341 `(if (strokes-click-p ,stroke)
342 (error "That's a click, not a stroke")
343 (setq ,stroke-map (cons (cons ,stroke ,def)
344 (strokes-remassoc ,stroke ,stroke-map)))))
346 (defsubst strokes-square (x)
347 "Return the square of the number X."
348 (* x x))
350 (defsubst strokes-distance-squared (p1 p2)
351 "Compute the distance (squared) between to points P1 and P2.
352 P1 and P2 are cons cells in the form (X . Y)."
353 (let ((x1 (car p1))
354 (y1 (cdr p1))
355 (x2 (car p2))
356 (y2 (cdr p2)))
357 (+ (strokes-square (- x2 x1))
358 (strokes-square (- y2 y1)))))
360 ;;; Functions...
362 (defsubst strokes-mouse-event-p (event)
363 (and (consp event) (symbolp (car event))
364 (or (eq (car event) 'mouse-movement)
365 (memq 'click (get (car event) 'event-symbol-elements))
366 (memq 'down (get (car event) 'event-symbol-elements))
367 (memq 'drag (get (car event) 'event-symbol-elements)))))
369 (defsubst strokes-button-press-event-p (event)
370 (and (consp event) (symbolp (car event))
371 (memq 'down (get (car event) 'event-symbol-elements))))
373 (defsubst strokes-button-release-event-p (event)
374 (and (consp event) (symbolp (car event))
375 (or (memq 'click (get (car event) 'event-symbol-elements))
376 (memq 'drag (get (car event) 'event-symbol-elements)))))
378 (defun strokes-event-closest-point-1 (window &optional line)
379 "Return position of start of line LINE in WINDOW.
380 If LINE is nil, return the last position visible in WINDOW."
381 (let* ((total (- (window-height window)
382 (if (window-minibuffer-p window)
383 0 1)))
384 (distance (or line total)))
385 (save-excursion
386 (goto-char (window-start window))
387 (if (= (vertical-motion distance) distance)
388 (if (not line)
389 (forward-char -1)))
390 (point))))
392 (defun strokes-event-closest-point (event &optional start-window)
393 "Return the nearest position to where EVENT ended its motion.
394 This is computed for the window where EVENT's motion started,
395 or for window START-WINDOW if that is specified."
396 (or start-window (setq start-window (posn-window (event-start event))))
397 (if (eq start-window (posn-window (event-end event)))
398 (if (eq (posn-point (event-end event)) 'vertical-line)
399 (strokes-event-closest-point-1 start-window
400 (cdr (posn-col-row (event-end event))))
401 (if (eq (posn-point (event-end event)) 'mode-line)
402 (strokes-event-closest-point-1 start-window)
403 (posn-point (event-end event))))
404 ;; EVENT ended in some other window.
405 (let* ((end-w (posn-window (event-end event)))
406 (end-w-top)
407 (w-top (nth 1 (window-edges start-window))))
408 (setq end-w-top
409 (if (windowp end-w)
410 (nth 1 (window-edges end-w))
411 (/ (cdr (posn-x-y (event-end event)))
412 (frame-char-height end-w))))
413 (if (>= end-w-top w-top)
414 (strokes-event-closest-point-1 start-window)
415 (window-start start-window)))))
417 (defun strokes-lift-p (object)
418 "Return non-nil if OBJECT is a stroke-lift."
419 (eq object strokes-lift))
421 (defun strokes-unset-last-stroke ()
422 "Undo the last stroke definition."
423 (interactive)
424 (let ((command (cdar strokes-global-map)))
425 (if (y-or-n-p
426 (format-message
427 "Really delete last stroke definition, defined to `%s'? "
428 command))
429 (progn
430 (setq strokes-global-map (cdr strokes-global-map))
431 (message "That stroke has been deleted"))
432 (message "Nothing done"))))
434 ;;;###autoload
435 (defun strokes-global-set-stroke (stroke command)
436 "Interactively give STROKE the global binding as COMMAND.
437 Works just like `global-set-key', except for strokes. COMMAND is
438 a symbol naming an interactively-callable function. STROKE is a
439 list of sampled positions on the stroke grid as described in the
440 documentation for the `strokes-define-stroke' function.
442 See also `strokes-global-set-stroke-string'."
443 (interactive
444 (list
445 (and (or strokes-mode (strokes-mode t))
446 (strokes-read-complex-stroke
447 "Draw with mouse button 1 (or 2). End with button 3..."))
448 (read-command "Command to map stroke to: ")))
449 (strokes-define-stroke strokes-global-map stroke command))
451 (defun strokes-global-set-stroke-string (stroke string)
452 "Interactively give STROKE the global binding as STRING.
453 Works just like `global-set-key', except for strokes. STRING
454 is a string to be inserted by the stroke. STROKE is a list of
455 sampled positions on the stroke grid as described in the
456 documentation for the `strokes-define-stroke' function.
458 Compare `strokes-global-set-stroke'."
459 (interactive
460 (list
461 (and (or strokes-mode (strokes-mode t))
462 (strokes-read-complex-stroke
463 "Draw with mouse button 1 (or 2). End with button 3..."))
464 (read-string "String to map stroke to: ")))
465 (strokes-define-stroke strokes-global-map stroke string))
467 ;;(defun global-unset-stroke (stroke); FINISH THIS DEFUN!
468 ;; "delete all strokes matching STROKE from `strokes-global-map',
469 ;; letting the user input
470 ;; the stroke with the mouse"
471 ;; (interactive
472 ;; (list
473 ;; (strokes-read-stroke "Enter the stroke you want to delete...")))
474 ;; (strokes-define-stroke 'strokes-global-map stroke command))
476 (defun strokes-get-grid-position (stroke-extent position &optional grid-resolution)
477 "Map POSITION to a new grid position.
478 Do so based on its STROKE-EXTENT and GRID-RESOLUTION.
479 STROKE-EXTENT is a list ((XMIN . YMIN) (XMAX . YMAX)).
480 If POSITION is a `strokes-lift', then it is itself returned.
481 Optional GRID-RESOLUTION may be used in place of `strokes-grid-resolution'.
482 The grid is a square whose dimension is [0,GRID-RESOLUTION)."
483 (cond ((consp position) ; actual pixel location
484 (let ((grid-resolution (or grid-resolution strokes-grid-resolution))
485 (x (car position))
486 (y (cdr position))
487 (xmin (caar stroke-extent))
488 (ymin (cdar stroke-extent))
489 ;; the `1+' is there to insure that the
490 ;; formula evaluates correctly at the boundaries
491 (xmax (1+ (car (cadr stroke-extent))))
492 (ymax (1+ (cdr (cadr stroke-extent)))))
493 (cons (floor (* grid-resolution
494 (/ (float (- x xmin))
495 (- xmax xmin))))
496 (floor (* grid-resolution
497 (/ (float (- y ymin))
498 (- ymax ymin)))))))
499 ((strokes-lift-p position) ; stroke lift
500 strokes-lift)))
502 (defun strokes-get-stroke-extent (pixel-positions)
503 "From a list of absolute PIXEL-POSITIONS, return absolute spatial extent.
504 The return value is a list ((XMIN . YMIN) (XMAX . YMAX))."
505 (if pixel-positions
506 (let ((xmin (caar pixel-positions))
507 (xmax (caar pixel-positions))
508 (ymin (cdar pixel-positions))
509 (ymax (cdar pixel-positions))
510 (rest (cdr pixel-positions)))
511 (while rest
512 (if (consp (car rest))
513 (let ((x (caar rest))
514 (y (cdar rest)))
515 (if (< x xmin)
516 (setq xmin x))
517 (if (> x xmax)
518 (setq xmax x))
519 (if (< y ymin)
520 (setq ymin y))
521 (if (> y ymax)
522 (setq ymax y))))
523 (setq rest (cdr rest)))
524 (let ((delta-x (- xmax xmin))
525 (delta-y (- ymax ymin)))
526 (if (> delta-x delta-y)
527 (setq ymin (- ymin
528 (/ (- delta-x delta-y)
530 ymax (+ ymax
531 (/ (- delta-x delta-y)
532 2)))
533 (setq xmin (- xmin
534 (/ (- delta-y delta-x)
536 xmax (+ xmax
537 (/ (- delta-y delta-x)
538 2))))
539 (list (cons xmin ymin)
540 (cons xmax ymax))))
541 nil))
543 (defun strokes-eliminate-consecutive-redundancies (entries)
544 "Return a list with no consecutive redundant entries."
545 ;; defun a grande vitesse grace a Dave G.
546 (cl-loop for element on entries
547 if (not (equal (car element) (cadr element)))
548 collect (car element)))
549 ;; (cl-loop for element on entries
550 ;; nconc (if (not (equal (car el) (cadr el)))
551 ;; (list (car el)))))
552 ;; yet another (orig) way of doing it...
553 ;; (if entries
554 ;; (let* ((current (car entries))
555 ;; (rest (cdr entries))
556 ;; (non-redundant-list (list current))
557 ;; (next nil))
558 ;; (while rest
559 ;; (setq next (car rest))
560 ;; (if (equal current next)
561 ;; (setq rest (cdr rest))
562 ;; (setq non-redundant-list (cons next non-redundant-list)
563 ;; current next
564 ;; rest (cdr rest))))
565 ;; (nreverse non-redundant-list))
566 ;; nil))
568 (defun strokes-renormalize-to-grid (positions &optional grid-resolution)
569 "Map POSITIONS to a new grid whose dimensions are based on GRID-RESOLUTION.
570 POSITIONS is a list of positions and stroke-lifts.
571 Optional GRID-RESOLUTION may be used in place of `strokes-grid-resolution'.
572 The grid is a square whose dimension is [0,GRID-RESOLUTION)."
573 (or grid-resolution (setq grid-resolution strokes-grid-resolution))
574 (let ((stroke-extent (strokes-get-stroke-extent positions)))
575 (mapcar (function
576 (lambda (pos)
577 (strokes-get-grid-position stroke-extent pos grid-resolution)))
578 positions)))
580 (defun strokes-fill-stroke (unfilled-stroke &optional force)
581 "Fill in missing grid locations in the list of UNFILLED-STROKE.
582 If FORCE is non-nil, then fill the stroke even if it's `stroke-click'.
583 NOTE: This is where the global variable `strokes-last-stroke' is set."
584 (setq strokes-last-stroke ; this is global
585 (if (and (strokes-click-p unfilled-stroke)
586 (not force))
587 unfilled-stroke
588 (cl-loop
589 for grid-locs on unfilled-stroke
590 nconc (let* ((current (car grid-locs))
591 (current-is-a-point-p (consp current))
592 (next (cadr grid-locs))
593 (next-is-a-point-p (consp next))
594 (both-are-points-p (and current-is-a-point-p
595 next-is-a-point-p))
596 (x1 (and current-is-a-point-p
597 (car current)))
598 (y1 (and current-is-a-point-p
599 (cdr current)))
600 (x2 (and next-is-a-point-p
601 (car next)))
602 (y2 (and next-is-a-point-p
603 (cdr next)))
604 (delta-x (and both-are-points-p
605 (- x2 x1)))
606 (delta-y (and both-are-points-p
607 (- y2 y1)))
608 (slope (and both-are-points-p
609 (if (zerop delta-x)
610 nil ; undefined vertical slope
611 (/ (float delta-y)
612 delta-x)))))
613 (cond ((not both-are-points-p)
614 (list current))
615 ((null slope) ; undefined vertical slope
616 (if (>= delta-y 0)
617 (cl-loop for y from y1 below y2
618 collect (cons x1 y))
619 (cl-loop for y from y1 above y2
620 collect (cons x1 y))))
621 ((zerop slope) ; (= y1 y2)
622 (if (>= delta-x 0)
623 (cl-loop for x from x1 below x2
624 collect (cons x y1))
625 (cl-loop for x from x1 above x2
626 collect (cons x y1))))
627 ((>= (abs delta-x) (abs delta-y))
628 (if (> delta-x 0)
629 (cl-loop for x from x1 below x2
630 collect (cons x
631 (+ y1
632 (round (* slope
633 (- x x1))))))
634 (cl-loop for x from x1 above x2
635 collect (cons x
636 (+ y1
637 (round (* slope
638 (- x x1))))))))
639 (t ; (< (abs delta-x) (abs delta-y))
640 (if (> delta-y 0)
641 ;; FIXME: Reduce redundancy between branches.
642 (cl-loop for y from y1 below y2
643 collect (cons (+ x1
644 (round (/ (- y y1)
645 slope)))
647 (cl-loop for y from y1 above y2
648 collect (cons (+ x1
649 (round (/ (- y y1)
650 slope)))
651 y))))))))))
653 (defun strokes-rate-stroke (stroke1 stroke2)
654 "Rate STROKE1 with STROKE2 and return a score based on a distance metric.
655 Note: the rating is an error rating, and therefore, a return of 0
656 represents a perfect match. Also note that the order of stroke
657 arguments is order-independent for the algorithm used here."
658 (if (and stroke1 stroke2)
659 (let ((rest1 (cdr stroke1))
660 (rest2 (cdr stroke2))
661 (err (strokes-distance-squared (car stroke1)
662 (car stroke2))))
663 (while (and rest1 rest2)
664 (while (and (consp (car rest1))
665 (consp (car rest2)))
666 (setq err (+ err
667 (strokes-distance-squared (car rest1)
668 (car rest2)))
669 stroke1 rest1
670 stroke2 rest2
671 rest1 (cdr stroke1)
672 rest2 (cdr stroke2)))
673 (cond ((and (strokes-lift-p (car rest1))
674 (strokes-lift-p (car rest2)))
675 (setq rest1 (cdr rest1)
676 rest2 (cdr rest2)))
677 ((strokes-lift-p (car rest2))
678 (while (consp (car rest1))
679 (setq err (+ err
680 (strokes-distance-squared (car rest1)
681 (car stroke2)))
682 rest1 (cdr rest1))))
683 ((strokes-lift-p (car rest1))
684 (while (consp (car rest2))
685 (setq err (+ err
686 (strokes-distance-squared (car stroke1)
687 (car rest2)))
688 rest2 (cdr rest2))))))
689 (if (null rest2)
690 (while (consp (car rest1))
691 (setq err (+ err
692 (strokes-distance-squared (car rest1)
693 (car stroke2)))
694 rest1 (cdr rest1))))
695 (if (null rest1)
696 (while (consp (car rest2))
697 (setq err (+ err
698 (strokes-distance-squared (car stroke1)
699 (car rest2)))
700 rest2 (cdr rest2))))
701 (if (or (strokes-lift-p (car rest1))
702 (strokes-lift-p (car rest2)))
703 (setq err nil)
704 err))
705 nil))
707 (defun strokes-match-stroke (stroke stroke-map)
708 "Find the best matching command of STROKE in STROKE-MAP.
709 Returns the corresponding match as (COMMAND . SCORE)."
710 (if (and stroke stroke-map)
711 (let ((score (strokes-rate-stroke stroke (caar stroke-map)))
712 (command (cdar stroke-map))
713 (map (cdr stroke-map)))
714 (while map
715 (let ((newscore (strokes-rate-stroke stroke (caar map))))
716 (if (or (and newscore score (< newscore score))
717 (and newscore (null score)))
718 (setq score newscore
719 command (cdar map)))
720 (setq map (cdr map))))
721 (if score
722 (cons command score)
723 nil))
724 nil))
726 (defsubst strokes-fill-current-buffer-with-whitespace ()
727 "Erase the contents of the current buffer and fill it with whitespace."
728 (erase-buffer)
729 (cl-loop repeat (frame-height) do
730 (insert-char ?\s (1- (frame-width)))
731 (newline))
732 (goto-char (point-min)))
734 ;;;###autoload
735 (defun strokes-read-stroke (&optional prompt event)
736 "Read a simple stroke (interactively) and return the stroke.
737 Optional PROMPT in minibuffer displays before and during stroke reading.
738 This function will display the stroke interactively as it is being
739 entered in the strokes buffer if the variable
740 `strokes-use-strokes-buffer' is non-nil.
741 Optional EVENT is acceptable as the starting event of the stroke."
742 (save-excursion
743 (let ((pix-locs nil)
744 (grid-locs nil)
745 (safe-to-draw-p nil))
746 (if strokes-use-strokes-buffer
747 ;; switch to the strokes buffer and
748 ;; display the stroke as it's being read
749 (save-window-excursion
750 (set-window-configuration strokes-window-configuration)
751 ;; The frame has been resized, so we need to refill the
752 ;; strokes buffer so that the strokes canvas is the whole
753 ;; visible buffer.
754 (unless (> 1 (abs (- (line-end-position) (window-width))))
755 (strokes-fill-current-buffer-with-whitespace))
756 (when prompt
757 (message "%s" prompt)
758 (setq event (read-event))
759 (or (strokes-button-press-event-p event)
760 (error "You must draw with the mouse")))
761 (unwind-protect
762 (track-mouse
763 (or event (setq event (read-event)
764 safe-to-draw-p t))
765 (while (not (strokes-button-release-event-p event))
766 (if (strokes-mouse-event-p event)
767 (let ((point (strokes-event-closest-point event)))
768 (if (and point safe-to-draw-p)
769 ;; we can draw that point
770 (progn
771 (goto-char point)
772 (subst-char-in-region point (1+ point)
773 ?\s strokes-character))
774 ;; otherwise, we can start drawing the next time...
775 (setq safe-to-draw-p t))
776 (push (cdr (mouse-pixel-position))
777 pix-locs)))
778 (setq event (read-event)))))
779 ;; protected
780 ;; clean up strokes buffer and then bury it.
781 (when (equal (buffer-name) strokes-buffer-name)
782 (subst-char-in-region (point-min) (point-max)
783 strokes-character ?\s)
784 (goto-char (point-min))
785 (bury-buffer))))
786 ;; Otherwise, don't use strokes buffer and read stroke silently
787 (when prompt
788 (message "%s" prompt)
789 (setq event (read-event))
790 (or (strokes-button-press-event-p event)
791 (error "You must draw with the mouse")))
792 (track-mouse
793 (or event (setq event (read-event)))
794 (while (not (strokes-button-release-event-p event))
795 (if (strokes-mouse-event-p event)
796 (push (cdr (mouse-pixel-position))
797 pix-locs))
798 (setq event (read-event))))
799 (setq grid-locs (strokes-renormalize-to-grid (nreverse pix-locs)))
800 (strokes-fill-stroke
801 (strokes-eliminate-consecutive-redundancies grid-locs)))))
803 ;;;###autoload
804 (defun strokes-read-complex-stroke (&optional prompt event)
805 "Read a complex stroke (interactively) and return the stroke.
806 Optional PROMPT in minibuffer displays before and during stroke reading.
807 Note that a complex stroke allows the user to pen-up and pen-down. This
808 is implemented by allowing the user to paint with button 1 or button 2 and
809 then complete the stroke with button 3.
810 Optional EVENT is acceptable as the starting event of the stroke."
811 (save-excursion
812 (save-window-excursion
813 (set-window-configuration strokes-window-configuration)
814 (let ((pix-locs nil)
815 (grid-locs nil))
816 (if prompt
817 (while (not (strokes-button-press-event-p event))
818 (message "%s" prompt)
819 (setq event (read-event))))
820 (unwind-protect
821 (track-mouse
822 (or event (setq event (read-event)))
823 (while (not (and (strokes-button-press-event-p event)
824 (eq 'mouse-3
825 (car (get (car event)
826 'event-symbol-elements)))))
827 (while (not (strokes-button-release-event-p event))
828 (if (strokes-mouse-event-p event)
829 (let ((point (strokes-event-closest-point event)))
830 (when point
831 (goto-char point)
832 (subst-char-in-region point (1+ point)
833 ?\s strokes-character))
834 (push (cdr (mouse-pixel-position))
835 pix-locs)))
836 (setq event (read-event)))
837 (push strokes-lift pix-locs)
838 (while (not (strokes-button-press-event-p event))
839 (setq event (read-event))))
840 ;; ### KLUDGE! ### sit and wait
841 ;; for some useless event to
842 ;; happen to fix the minibuffer bug.
843 (while (not (strokes-button-release-event-p (read-event))))
844 (setq pix-locs (nreverse (cdr pix-locs))
845 grid-locs (strokes-renormalize-to-grid pix-locs))
846 (strokes-fill-stroke
847 (strokes-eliminate-consecutive-redundancies grid-locs)))
848 ;; protected
849 (when (equal (buffer-name) strokes-buffer-name)
850 (subst-char-in-region (point-min) (point-max)
851 strokes-character ?\s)
852 (goto-char (point-min))
853 (bury-buffer)))))))
855 (defun strokes-execute-stroke (stroke)
856 "Given STROKE, execute the command which corresponds to it.
857 The command will be executed provided one exists for that stroke,
858 based on the variable `strokes-minimum-match-score'.
859 If no stroke matches, nothing is done and return value is nil."
860 ;; FIXME: Undocument return value. It is not documented for all cases,
861 ;; and doesn't allow to difference between no stroke matches and
862 ;; command-execute returning nil, anyway.
863 (let* ((match (strokes-match-stroke stroke strokes-global-map))
864 (command (car match))
865 (score (cdr match)))
866 (cond ((and match (<= score strokes-minimum-match-score))
867 (message "%s" command)
868 (command-execute command))
869 ((null strokes-global-map)
870 (if (file-exists-p strokes-file)
871 (and (y-or-n-p
872 (format-message "No strokes loaded. Load `%s'? "
873 strokes-file))
874 (strokes-load-user-strokes))
875 (error "No strokes defined; use `strokes-global-set-stroke'")))
877 (error
878 "No stroke matches; see variable `strokes-minimum-match-score'")
879 nil))))
881 ;;;###autoload
882 (defun strokes-do-stroke (event)
883 "Read a simple stroke from the user and then execute its command.
884 This must be bound to a mouse event."
885 (interactive "e")
886 (or strokes-mode (strokes-mode t))
887 (strokes-execute-stroke (strokes-read-stroke nil event)))
889 ;;;###autoload
890 (defun strokes-do-complex-stroke (event)
891 "Read a complex stroke from the user and then execute its command.
892 This must be bound to a mouse event."
893 (interactive "e")
894 (or strokes-mode (strokes-mode t))
895 (strokes-execute-stroke (strokes-read-complex-stroke nil event)))
897 ;;;###autoload
898 (defun strokes-describe-stroke (stroke)
899 "Displays the command which STROKE maps to, reading STROKE interactively."
900 (interactive
901 (list
902 (strokes-read-complex-stroke
903 "Enter stroke to describe; end with button 3...")))
904 (let* ((match (strokes-match-stroke stroke strokes-global-map))
905 (command (car match))
906 (score (cdr match)))
907 (if (and match
908 (<= score strokes-minimum-match-score))
909 (message "That stroke maps to `%s'" command)
910 (message "That stroke is undefined"))
911 (sleep-for 1))) ; helpful for recursive edits
913 ;;;###autoload
914 (defun strokes-help ()
915 "Get instruction on using the Strokes package."
916 (interactive)
917 (with-output-to-temp-buffer "*Help with Strokes*"
918 (princ
919 (substitute-command-keys
920 "This is help for the strokes package.
922 ------------------------------------------------------------
924 ** Strokes...
926 The strokes package allows you to define strokes, made with
927 the mouse or other pointer device, that Emacs can interpret as
928 corresponding to commands, and then executes the commands. It does
929 character recognition, so you don't have to worry about getting it
930 right every time.
932 Strokes also allows you to compose documents graphically. You can
933 fully edit documents in Chinese, Japanese, etc. based on Emacs
934 strokes. Once you've done so, you can ASCII compress-and-encode them
935 and then safely save them for later use, send letters to friends
936 \(using Emacs, of course). Strokes will later decode these documents,
937 extracting the strokes for editing use once again, so the editing
938 cycle can continue.
940 To toggle strokes-mode, invoke the command
942 > M-x strokes-mode
944 ** Strokes for controlling the behavior of Emacs...
946 When you're ready to start defining strokes, just use the command
948 > M-x strokes-global-set-stroke
950 You will see a ` *strokes*' buffer which is waiting for you to enter in
951 your stroke. When you enter in the stroke, you draw with button 1 or
952 button 2, and then end with button 3. Next, you enter in the command
953 which will be executed when that stroke is invoked. Simple as that.
954 For now, try to define a stroke to copy a region. This is a popular
955 edit command, so type
957 > M-x strokes-global-set-stroke
959 Then, in the ` *strokes*' buffer, draw the letter `C' (for `copy')
960 and then, when it asks you to enter the command to map that to, type
962 > copy-region-as-kill
964 That's about as hard as it gets.
965 Remember: paint with button 1 or button 2 and then end with button 3.
967 If ever you want to know what a certain strokes maps to, then do
969 > M-x strokes-describe-stroke
971 and you can enter in any arbitrary stroke. Remember: The strokes
972 package lets you program in simple and complex (multi-lift) strokes.
973 The only difference is how you *invoke* the two. You will most likely
974 use simple strokes, as complex strokes were developed for
975 Chinese/Japanese/Korean. So the shifted middle mouse button (S-mouse-2)
976 will invoke the command `strokes-do-stroke'.
978 If ever you define a stroke which you don't like, then you can unset
979 it with the command
981 > M-x strokes-unset-last-stroke
983 You can always get an idea of what your current strokes look like with
984 the command
986 > M-x strokes-list-strokes
988 Your strokes will be displayed in alphabetical order (based on command
989 names) and the beginning of each simple stroke will be marked by a
990 color dot. Since you may have several simple strokes in a complex
991 stroke, the dot colors are arranged in the rainbow color sequence,
992 `ROYGBIV'. If you want a listing of your strokes from most recent
993 down, then use a prefix argument:
995 > C-u M-x strokes-list-strokes
997 Your strokes are stored as you enter them. They get saved into the
998 file specified by the `strokes-file' variable, along with other strokes
999 configuration variables. You will be prompted to save them when you
1000 exit Emacs, or you can save them with
1002 > M-x strokes-prompt-user-save-strokes
1004 Your strokes get loaded automatically when you enable `strokes-mode'.
1005 You can also load in your user-defined strokes with
1007 > M-x strokes-load-user-strokes
1009 ** Strokes for pictographic editing...
1011 If you'd like to create graphical files with strokes, you'll have to
1012 be running a version of Emacs with XPM support. You use the binding
1013 to `strokes-compose-complex-stroke' to start drawing your strokes.
1014 These are just complex strokes, and thus continue drawing with mouse-1
1015 or mouse-2 and end with mouse-3. Then the stroke image gets inserted
1016 into the buffer. You treat it somewhat like any other character,
1017 which you can copy, paste, delete, move, etc. When all is done, you
1018 may want to send the file, or save it. This is done with
1020 > M-x strokes-encode-buffer
1022 Likewise, to decode the strokes from a strokes-encoded buffer you do
1024 > M-x strokes-decode-buffer
1026 ** A few more important things...
1028 o The command `strokes-do-complex-stroke' is invoked with M-mouse-2,
1029 so that you can execute complex strokes (i.e. with more than one lift)
1030 if preferred.
1032 o Strokes are a bit computer-dependent in that they depend somewhat on
1033 the speed of the computer you're working on. This means that you
1034 may have to tweak some variables. You can read about them in the
1035 commentary of `strokes.el'. Better to just use \\[apropos] and read their
1036 docstrings. All variables/functions start with `strokes'. The one
1037 variable which many people wanted to see was
1038 `strokes-use-strokes-buffer' which allows the user to use strokes
1039 silently--without displaying the strokes. All variables can be set
1040 by customizing the group `strokes' via \\[customize-group]."))
1041 (set-buffer standard-output)
1042 (help-mode)
1043 (help-print-return-message)))
1045 (define-obsolete-function-alias 'strokes-report-bug 'report-emacs-bug "24.1")
1047 (defun strokes-window-configuration-changed-p ()
1048 "Non-nil if the `strokes-window-configuration' frame properties changed.
1049 This is based on the last time `strokes-window-configuration' was updated."
1050 (compare-window-configurations (current-window-configuration)
1051 strokes-window-configuration))
1053 (defun strokes-update-window-configuration ()
1054 "Ensure that `strokes-window-configuration' is up-to-date."
1055 (interactive)
1056 (let ((current-window (selected-window)))
1057 (cond ((or (window-minibuffer-p current-window)
1058 (window-dedicated-p current-window))
1059 ;; don't try to update strokes window configuration
1060 ;; if window is dedicated or a minibuffer
1061 nil)
1062 ((or (called-interactively-p 'interactive)
1063 (not (buffer-live-p (get-buffer strokes-buffer-name)))
1064 (null strokes-window-configuration))
1065 ;; create `strokes-window-configuration' from scratch...
1066 (save-excursion
1067 (save-window-excursion
1068 (set-buffer (get-buffer-create strokes-buffer-name))
1069 (set-window-buffer current-window strokes-buffer-name)
1070 (delete-other-windows)
1071 (fundamental-mode)
1072 (auto-save-mode 0)
1073 (font-lock-mode 0)
1074 (abbrev-mode 0)
1075 (buffer-disable-undo (current-buffer))
1076 (setq truncate-lines nil)
1077 (strokes-fill-current-buffer-with-whitespace)
1078 (setq strokes-window-configuration (current-window-configuration))
1079 (bury-buffer))))
1080 ((strokes-window-configuration-changed-p) ; simple update
1081 ;; update the strokes-window-configuration for this
1082 ;; specific frame...
1083 (save-excursion
1084 (save-window-excursion
1085 (set-window-buffer current-window strokes-buffer-name)
1086 (delete-other-windows)
1087 (strokes-fill-current-buffer-with-whitespace)
1088 (setq strokes-window-configuration (current-window-configuration))
1089 (bury-buffer)))))))
1091 ;;;###autoload
1092 (defun strokes-load-user-strokes ()
1093 "Load user-defined strokes from file named by `strokes-file'."
1094 (interactive)
1095 (cond ((and (file-exists-p strokes-file)
1096 (file-readable-p strokes-file))
1097 (load-file strokes-file))
1098 ((called-interactively-p 'interactive)
1099 (error "Trouble loading user-defined strokes; nothing done"))
1101 (message "No user-defined strokes, sorry"))))
1103 (defun strokes-prompt-user-save-strokes ()
1104 "Save user-defined strokes to file named by `strokes-file'."
1105 (interactive)
1106 (save-excursion
1107 (let ((current strokes-global-map))
1108 (unwind-protect
1109 (progn
1110 (setq strokes-global-map nil)
1111 (strokes-load-user-strokes)
1112 (if (and (not (equal current strokes-global-map))
1113 (or (called-interactively-p 'interactive)
1114 (yes-or-no-p "Save your strokes? ")))
1115 (progn
1116 (require 'pp) ; pretty-print variables
1117 (message "Saving strokes in %s..." strokes-file)
1118 (get-buffer-create "*saved-strokes*")
1119 (set-buffer "*saved-strokes*")
1120 (erase-buffer)
1121 (emacs-lisp-mode)
1122 (goto-char (point-min))
1123 (insert
1124 ";; -*- emacs-lisp -*-\n")
1125 (insert (format ";;; saved strokes for %s, as of %s\n\n"
1126 (user-full-name)
1127 (format-time-string "%B %e, %Y" nil)))
1128 (message "Saving strokes in %s..." strokes-file)
1129 (insert (format "(setq strokes-global-map\n'%s)"
1130 (pp current)))
1131 (message "Saving strokes in %s..." strokes-file)
1132 (indent-region (point-min) (point-max) nil)
1133 (write-region (point-min)
1134 (point-max)
1135 strokes-file))
1136 (message "(no changes need to be saved)")))
1137 ;; protected
1138 (if (get-buffer "*saved-strokes*")
1139 (kill-buffer (get-buffer "*saved-strokes*")))
1140 (setq strokes-global-map current)))))
1142 (defun strokes-toggle-strokes-buffer (&optional arg)
1143 "Toggle the use of the strokes buffer.
1144 In other words, toggle the variable `strokes-use-strokes-buffer'.
1145 With ARG, use strokes buffer if and only if ARG is positive or true.
1146 Returns value of `strokes-use-strokes-buffer'."
1147 (interactive "P")
1148 (setq strokes-use-strokes-buffer
1149 (if arg (> (prefix-numeric-value arg) 0)
1150 (not strokes-use-strokes-buffer))))
1152 (defun strokes-xpm-for-stroke (&optional stroke bufname b/w-only)
1153 "Create an XPM pixmap for the given STROKE in buffer \" *strokes-xpm*\".
1154 If STROKE is not supplied, then `strokes-last-stroke' will be used.
1155 Optional BUFNAME to name something else.
1156 The pixmap will contain time information via rainbow dot colors
1157 where each individual strokes begins.
1158 Optional B/W-ONLY non-nil will create a mono pixmap, not intended
1159 for trying to figure out the order of strokes, but rather for reading
1160 the stroke as a character in some language."
1161 (interactive)
1162 (save-excursion
1163 (let ((buf (get-buffer-create (or bufname " *strokes-xpm*")))
1164 (stroke (strokes-eliminate-consecutive-redundancies
1165 (strokes-fill-stroke
1166 (strokes-renormalize-to-grid (or stroke
1167 strokes-last-stroke)
1168 31))))
1169 (lift-flag t)
1170 (rainbow-chars (list ?R ?O ?Y ?G ?B ?P))) ; ROYGBIV w/o indigo
1171 (set-buffer buf)
1172 (erase-buffer)
1173 (insert strokes-xpm-header)
1174 (cl-loop repeat 33 do
1175 (insert ?\")
1176 (insert-char ?\s 33)
1177 (insert "\",")
1178 (newline)
1179 finally
1180 (forward-line -1)
1181 (end-of-line)
1182 (insert "}\n"))
1183 (cl-loop for point in stroke
1184 for x = (car-safe point)
1185 for y = (cdr-safe point) do
1186 (cond ((consp point)
1187 ;; draw a point, and possibly a starting-point
1188 (if (and lift-flag (not b/w-only))
1189 ;; mark starting point with the appropriate color
1190 (let ((char (or (car rainbow-chars) ?\.)))
1191 (cl-loop for i from 0 to 2 do
1192 (cl-loop for j from 0 to 2 do
1193 (goto-char (point-min))
1194 (forward-line (+ 15 i y))
1195 (forward-char (+ 1 j x))
1196 (delete-char 1)
1197 (insert char)))
1198 (setq rainbow-chars (cdr rainbow-chars)
1199 lift-flag nil))
1200 ;; Otherwise, just plot the point...
1201 (goto-char (point-min))
1202 (forward-line (+ 16 y))
1203 (forward-char (+ 2 x))
1204 (subst-char-in-region (point) (1+ (point)) ?\s ?\*)))
1205 ((strokes-lift-p point)
1206 ;; a lift--tell the loop to X out the next point...
1207 (setq lift-flag t))))
1208 (when (called-interactively-p 'interactive)
1209 (pop-to-buffer " *strokes-xpm*")
1210 ;; (xpm-mode 1)
1211 (goto-char (point-min))
1212 (put-image (create-image (buffer-string) 'xpm t :ascent 100)
1213 (line-end-position))))))
1215 ;;; Strokes Edit stuff... ### NOT IMPLEMENTED YET ###
1217 ;;(defun strokes-edit-quit ()
1218 ;; (interactive)
1219 ;; (or (one-window-p t 0)
1220 ;; (delete-window))
1221 ;; (kill-buffer "*Strokes List*"))
1223 ;;(define-derived-mode edit-strokes-mode list-mode
1224 ;; "Edit-Strokes"
1225 ;; "Major mode for `edit-strokes' and `list-strokes' buffers.
1227 ;;Editing commands:
1229 ;;\\{edit-strokes-mode-map}"
1230 ;; (setq truncate-lines nil
1231 ;; auto-show-mode nil ; don't want problems here either
1232 ;; mode-popup-menu edit-strokes-menu) ; what about extent-specific stuff?
1233 ;; (and (featurep 'menubar)
1234 ;; current-menubar
1235 ;; (set (make-local-variable 'current-menubar)
1236 ;; (copy-sequence current-menubar))
1237 ;; (add-submenu nil edit-strokes-menu)))
1239 ;;(let ((map edit-strokes-mode-map))
1240 ;; (define-key map "<" 'beginning-of-buffer)
1241 ;; (define-key map ">" 'end-of-buffer)
1242 ;; ;; (define-key map "c" 'strokes-copy-other-face)
1243 ;; ;; (define-key map "C" 'strokes-copy-this-face)
1244 ;; ;; (define-key map "s" 'strokes-smaller)
1245 ;; ;; (define-key map "l" 'strokes-larger)
1246 ;; ;; (define-key map "b" 'strokes-bold)
1247 ;; ;; (define-key map "i" 'strokes-italic)
1248 ;; (define-key map "e" 'strokes-list-edit)
1249 ;; ;; (define-key map "f" 'strokes-font)
1250 ;; ;; (define-key map "u" 'strokes-underline)
1251 ;; ;; (define-key map "t" 'strokes-truefont)
1252 ;; ;; (define-key map "F" 'strokes-foreground)
1253 ;; ;; (define-key map "B" 'strokes-background)
1254 ;; ;; (define-key map "D" 'strokes-doc-string)
1255 ;; (define-key map "a" 'strokes-global-set-stroke)
1256 ;; (define-key map "d" 'strokes-list-delete-stroke)
1257 ;; ;; (define-key map "n" 'strokes-list-next)
1258 ;; ;; (define-key map "p" 'strokes-list-prev)
1259 ;; ;; (define-key map " " 'strokes-list-next)
1260 ;; ;; (define-key map "\C-?" 'strokes-list-prev)
1261 ;; (define-key map "g" 'strokes-list-strokes) ; refresh display
1262 ;; (define-key map "q" 'strokes-edit-quit)
1263 ;; (define-key map [(control c) (control c)] 'bury-buffer))
1265 ;;;;;###autoload
1266 ;;(defun strokes-edit-strokes (&optional chronological strokes-map)
1267 ;; ;; ### DEAL WITH THE 2nd ARGUMENT ISSUE! ###
1268 ;; "Edit strokes in a pop-up buffer containing strokes and their definitions.
1269 ;;If STROKES-MAP is not given, `strokes-global-map' will be used instead.
1271 ;;Editing commands:
1273 ;;\\{edit-faces-mode-map}"
1274 ;; (interactive "P")
1275 ;; (pop-to-buffer (get-buffer-create "*Strokes List*"))
1276 ;; (reset-buffer (current-buffer)) ; handy function from minibuf.el
1277 ;; (setq strokes-map (or strokes-map
1278 ;; strokes-global-map
1279 ;; (progn
1280 ;; (strokes-load-user-strokes)
1281 ;; strokes-global-map)))
1282 ;; (or chronological
1283 ;; (setq strokes-map (sort (copy-sequence strokes-map)
1284 ;; 'strokes-alphabetic-lessp)))
1285 ;; ;; (push-window-configuration)
1286 ;; (insert
1287 ;; "Command Stroke\n"
1288 ;; "------- ------")
1289 ;; (cl-loop for def in strokes-map
1290 ;; for i from 0 to (1- (length strokes-map)) do
1291 ;; (let ((stroke (car def))
1292 ;; (command-name (symbol-name (cdr def))))
1293 ;; (strokes-xpm-for-stroke stroke " *strokes-xpm*")
1294 ;; (newline 2)
1295 ;; (insert-char ?\s 45)
1296 ;; (beginning-of-line)
1297 ;; (insert command-name)
1298 ;; (beginning-of-line)
1299 ;; (forward-char 45)
1300 ;; (set (intern (format "strokes-list-annotation-%d" i))
1301 ;; (make-annotation (make-glyph
1302 ;; (list
1303 ;; (vector 'xpm
1304 ;; :data (buffer-substring
1305 ;; (point-min " *strokes-xpm*")
1306 ;; (point-max " *strokes-xpm*")
1307 ;; " *strokes-xpm*"))
1308 ;; [string :data "[Stroke]"]))
1309 ;; (point) 'text))
1310 ;; (set-annotation-data (symbol-value (intern (format "strokes-list-annotation-%d" i)))
1311 ;; def))
1312 ;; finally do (kill-region (1+ (point)) (point-max)))
1313 ;; (edit-strokes-mode)
1314 ;; (goto-char (point-min)))
1316 ;;;;;###autoload
1317 ;;(defalias 'edit-strokes 'strokes-edit-strokes)
1319 (defvar view-mode-map)
1321 ;;;###autoload
1322 (defun strokes-list-strokes (&optional chronological strokes-map)
1323 "Pop up a buffer containing an alphabetical listing of strokes in STROKES-MAP.
1324 With CHRONOLOGICAL prefix arg (\\[universal-argument]) list strokes chronologically
1325 by command name.
1326 If STROKES-MAP is not given, `strokes-global-map' will be used instead."
1327 (interactive "P")
1328 (setq strokes-map (or strokes-map
1329 strokes-global-map
1330 (progn
1331 (strokes-load-user-strokes)
1332 strokes-global-map)))
1333 (if (not chronological)
1334 ;; then alphabetize the strokes based on command names...
1335 (setq strokes-map (sort (copy-sequence strokes-map)
1336 (function strokes-alphabetic-lessp))))
1337 (let ((config (current-window-configuration)))
1338 (set-buffer (get-buffer-create "*Strokes List*"))
1339 (setq buffer-read-only nil)
1340 (erase-buffer)
1341 (insert
1342 "Command Stroke\n"
1343 "------- ------")
1344 (cl-loop
1345 for def in strokes-map do
1346 (let ((stroke (car def))
1347 (command-name (if (symbolp (cdr def))
1348 (symbol-name (cdr def))
1349 (prin1-to-string (cdr def)))))
1350 (strokes-xpm-for-stroke stroke " *strokes-xpm*")
1351 (newline 2)
1352 (insert-char ?\s 45)
1353 (beginning-of-line)
1354 (insert command-name)
1355 (beginning-of-line)
1356 (forward-char 45)
1357 (insert-image
1358 (create-image (with-current-buffer " *strokes-xpm*"
1359 (buffer-string))
1360 'xpm t
1361 :color-symbols
1362 `(("foreground"
1363 . ,(frame-parameter nil 'foreground-color))))))
1364 finally do (unless (eobp)
1365 (kill-region (1+ (point)) (point-max))))
1366 (view-buffer "*Strokes List*" nil)
1367 (set (make-local-variable 'view-mode-map)
1368 (let ((map (copy-keymap view-mode-map)))
1369 (define-key map "q" `(lambda ()
1370 (interactive)
1371 (View-quit)
1372 (set-window-configuration ,config)))
1373 map))
1374 (goto-char (point-min))))
1376 (defun strokes-alphabetic-lessp (stroke1 stroke2)
1377 "Return t if STROKE1's command name precedes STROKE2's in lexicographic order."
1378 (let ((command-name-1 (symbol-name (cdr stroke1)))
1379 (command-name-2 (symbol-name (cdr stroke2))))
1380 (string-lessp command-name-1 command-name-2)))
1382 (defvar strokes-mode-map
1383 (let ((map (make-sparse-keymap)))
1384 (define-key map [(shift down-mouse-2)] 'strokes-do-stroke)
1385 (define-key map [(meta down-mouse-2)] 'strokes-do-complex-stroke)
1386 map))
1388 ;;;###autoload
1389 (define-minor-mode strokes-mode
1390 "Toggle Strokes mode, a global minor mode.
1391 With a prefix argument ARG, enable Strokes mode if ARG is
1392 positive, and disable it otherwise. If called from Lisp,
1393 enable the mode if ARG is omitted or nil.
1395 \\<strokes-mode-map>
1396 Strokes are pictographic mouse gestures which invoke commands.
1397 Strokes are invoked with \\[strokes-do-stroke]. You can define
1398 new strokes with \\[strokes-global-set-stroke]. See also
1399 \\[strokes-do-complex-stroke] for `complex' strokes.
1401 To use strokes for pictographic editing, such as Chinese/Japanese, use
1402 \\[strokes-compose-complex-stroke], which draws strokes and inserts them.
1403 Encode/decode your strokes with \\[strokes-encode-buffer],
1404 \\[strokes-decode-buffer].
1406 \\{strokes-mode-map}"
1407 nil strokes-lighter strokes-mode-map
1408 :group 'strokes :global t
1409 (cond ((not (display-mouse-p))
1410 (error "Can't use Strokes without a mouse"))
1411 (strokes-mode ; turn on strokes
1412 (and (file-exists-p strokes-file)
1413 (null strokes-global-map)
1414 (strokes-load-user-strokes))
1415 (add-hook 'kill-emacs-query-functions
1416 'strokes-prompt-user-save-strokes)
1417 (add-hook 'select-frame-hook
1418 'strokes-update-window-configuration)
1419 (strokes-update-window-configuration))
1420 (t ; turn off strokes
1421 (if (get-buffer strokes-buffer-name)
1422 (kill-buffer (get-buffer strokes-buffer-name)))
1423 (remove-hook 'select-frame-hook
1424 'strokes-update-window-configuration))))
1427 ;;;; strokes-xpm stuff (later may be separate)...
1429 ;; This is the stuff that will eventually be used for composing letters in
1430 ;; any language, compression, decompression, graphics, editing, etc.
1432 (defface strokes-char '((t (:background "lightgray")))
1433 "Face for strokes characters."
1434 :version "21.1"
1435 :group 'strokes)
1437 (put 'strokes 'char-table-extra-slots 0)
1438 (defconst strokes-char-table (make-char-table 'strokes) ;
1439 "The table which stores values for the character keys.")
1440 (aset strokes-char-table ?0 0)
1441 (aset strokes-char-table ?1 1)
1442 (aset strokes-char-table ?2 2)
1443 (aset strokes-char-table ?3 3)
1444 (aset strokes-char-table ?4 4)
1445 (aset strokes-char-table ?5 5)
1446 (aset strokes-char-table ?6 6)
1447 (aset strokes-char-table ?7 7)
1448 (aset strokes-char-table ?8 8)
1449 (aset strokes-char-table ?9 9)
1450 (aset strokes-char-table ?a 10)
1451 (aset strokes-char-table ?b 11)
1452 (aset strokes-char-table ?c 12)
1453 (aset strokes-char-table ?d 13)
1454 (aset strokes-char-table ?e 14)
1455 (aset strokes-char-table ?f 15)
1456 (aset strokes-char-table ?g 16)
1457 (aset strokes-char-table ?h 17)
1458 (aset strokes-char-table ?i 18)
1459 (aset strokes-char-table ?j 19)
1460 (aset strokes-char-table ?k 20)
1461 (aset strokes-char-table ?l 21)
1462 (aset strokes-char-table ?m 22)
1463 (aset strokes-char-table ?n 23)
1464 (aset strokes-char-table ?o 24)
1465 (aset strokes-char-table ?p 25)
1466 (aset strokes-char-table ?q 26)
1467 (aset strokes-char-table ?r 27)
1468 (aset strokes-char-table ?s 28)
1469 (aset strokes-char-table ?t 29)
1470 (aset strokes-char-table ?u 30)
1471 (aset strokes-char-table ?v 31)
1472 (aset strokes-char-table ?w 32)
1473 (aset strokes-char-table ?x 33)
1474 (aset strokes-char-table ?y 34)
1475 (aset strokes-char-table ?z 35)
1476 (aset strokes-char-table ?A 36)
1477 (aset strokes-char-table ?B 37)
1478 (aset strokes-char-table ?C 38)
1479 (aset strokes-char-table ?D 39)
1480 (aset strokes-char-table ?E 40)
1481 (aset strokes-char-table ?F 41)
1482 (aset strokes-char-table ?G 42)
1483 (aset strokes-char-table ?H 43)
1484 (aset strokes-char-table ?I 44)
1485 (aset strokes-char-table ?J 45)
1486 (aset strokes-char-table ?K 46)
1487 (aset strokes-char-table ?L 47)
1488 (aset strokes-char-table ?M 48)
1489 (aset strokes-char-table ?N 49)
1490 (aset strokes-char-table ?O 50)
1491 (aset strokes-char-table ?P 51)
1492 (aset strokes-char-table ?Q 52)
1493 (aset strokes-char-table ?R 53)
1494 (aset strokes-char-table ?S 54)
1495 (aset strokes-char-table ?T 55)
1496 (aset strokes-char-table ?U 56)
1497 (aset strokes-char-table ?V 57)
1498 (aset strokes-char-table ?W 58)
1499 (aset strokes-char-table ?X 59)
1500 (aset strokes-char-table ?Y 60)
1501 (aset strokes-char-table ?Z 61)
1503 (defconst strokes-base64-chars
1504 ;; I wanted to make this a vector of individual like (vector ?0
1505 ;; ?1 ?2 ...), but `concat' refuses to accept single
1506 ;; characters.
1507 (vector "0" "1" "2" "3" "4" "5" "6" "7" "8" "9"
1508 "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o"
1509 "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z" "A" "B" "C" "D"
1510 "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S"
1511 "T" "U" "V" "W" "X" "Y" "Z")
1512 ;; (vector [?0] [?1] [?2] [?3] [?4] [?5] [?6] [?7] [?8] [?9]
1513 ;; [?a] [?b] [?c] [?d] [?e] [?f] [?g] [?h] [?i] [?j]
1514 ;; [?k] [?l] [?m] [?n] [?o] [?p] [?q] [?r] [?s] [?t]
1515 ;; [?u] [?v] [?w] [?x] [?y] [?z]
1516 ;; [?A] [?B] [?C] [?D] [?E] [?F] [?G] [?H] [?I] [?J]
1517 ;; [?K] [?L] [?M] [?N] [?O] [?P] [?Q] [?R] [?S] [?T]
1518 ;; [?U] [?V] [?W] [?X] [?Y] [?Z])
1519 "Character vector for fast lookup of base-64 encoding of numbers in [0,61].")
1521 (defsubst strokes-xpm-char-on-p (char)
1522 "Non-nil if CHAR represents an `on' bit in the XPM."
1523 (eq char ?*))
1525 (defsubst strokes-xpm-char-bit-p (char)
1526 "Non-nil if CHAR represents an `on' or `off' bit in the XPM."
1527 (or (eq char ?\s)
1528 (eq char ?*)))
1530 ;;(defsubst strokes-xor (a b) ### Should I make this an inline function? ###
1531 ;; "T if one and only one of A and B is non-nil; otherwise, returns nil.
1532 ;;NOTE: Don't use this as a numeric xor since it treats all non-nil
1533 ;; values as t including `0' (zero)."
1534 ;; (eq (null a) (not (null b))))
1536 (defsubst strokes-xpm-encode-length-as-string (length)
1537 "Given some LENGTH in [0,62) do a fast lookup of its encoding."
1538 (aref strokes-base64-chars length))
1540 (defsubst strokes-xpm-decode-char (character)
1541 "Given a CHARACTER, do a fast lookup to find its corresponding integer value."
1542 (aref strokes-char-table character))
1544 (defun strokes-xpm-to-compressed-string (&optional xpm-buffer)
1545 "Convert XPM in XPM-BUFFER to compressed string representing the stroke.
1546 XPM-BUFFER defaults to \" *strokes-xpm*\"."
1547 (with-current-buffer (setq xpm-buffer (or xpm-buffer " *strokes-xpm*"))
1548 (goto-char (point-min))
1549 (search-forward "/* pixels */") ; skip past header junk
1550 (forward-char 2)
1551 ;; a note for below:
1552 ;; the `current-char' is the char being counted -- NOT the char at (point)
1553 ;; which happens to be called `char-at-point'
1554 (let ((compressed-string "+/") ; initialize the output
1555 (count 0) ; keep a current count of
1556 ; `current-char'
1557 (last-char-was-on-p t) ; last entered stream
1558 ; represented `on' bits
1559 (current-char-is-on-p nil) ; current stream represents `on' bits
1560 (char-at-point (char-after))) ; read the first char
1561 (while (not (eq char-at-point ?})) ; a `}' denotes the
1562 ; end of the pixmap
1563 (cond ((zerop count) ; must restart counting
1564 ;; check to see if the `char-at-point' is an actual pixmap bit
1565 (when (strokes-xpm-char-bit-p char-at-point)
1566 (setq count 1
1567 current-char-is-on-p (strokes-xpm-char-on-p char-at-point)))
1568 (forward-char 1))
1569 ((= count 61) ; maximum single char's
1570 ; encoding length
1571 (setq compressed-string
1572 (concat compressed-string
1573 ;; add a zero-length encoding when
1574 ;; necessary
1575 (when (eq last-char-was-on-p
1576 current-char-is-on-p)
1577 ;; "0"
1578 (strokes-xpm-encode-length-as-string 0))
1579 (strokes-xpm-encode-length-as-string 61))
1580 last-char-was-on-p current-char-is-on-p
1581 count 0)) ; note that we just set
1582 ; count=0 and *don't* advance
1583 ; (point)
1584 ((strokes-xpm-char-bit-p char-at-point) ; an actual xpm bit
1585 (if (eq current-char-is-on-p
1586 (strokes-xpm-char-on-p char-at-point))
1587 ;; yet another of the same bit-type, so we continue
1588 ;; counting...
1589 (progn
1590 (cl-incf count)
1591 (forward-char 1))
1592 ;; otherwise, it's the opposite bit-type, so we do a
1593 ;; write and then restart count ### NOTE (for myself
1594 ;; to be aware of) ### I really should advance
1595 ;; (point) in this case instead of letting another
1596 ;; iteration go through and letting the case: count=0
1597 ;; take care of this stuff for me. That's why
1598 ;; there's no (forward-char 1) below.
1599 (setq compressed-string
1600 (concat compressed-string
1601 ;; add a zero-length encoding when
1602 ;; necessary
1603 (when (eq last-char-was-on-p
1604 current-char-is-on-p)
1605 ;; "0"
1606 (strokes-xpm-encode-length-as-string 0))
1607 (strokes-xpm-encode-length-as-string count))
1608 count 0
1609 last-char-was-on-p current-char-is-on-p)))
1610 (t ; ELSE it's some other useless
1611 ; char, like `"' or `,'
1612 (forward-char 1)))
1613 (setq char-at-point (char-after)))
1614 (concat compressed-string
1615 (when (> count 0)
1616 (concat (when (eq last-char-was-on-p
1617 current-char-is-on-p)
1618 ;; "0"
1619 (strokes-xpm-encode-length-as-string 0))
1620 (strokes-xpm-encode-length-as-string count)))
1621 "/"))))
1623 ;;;###autoload
1624 (defun strokes-decode-buffer (&optional buffer force)
1625 "Decode stroke strings in BUFFER and display their corresponding glyphs.
1626 Optional BUFFER defaults to the current buffer.
1627 Optional FORCE non-nil will ignore the buffer's read-only status."
1628 (interactive)
1629 ;; (interactive "*bStrokify buffer: ")
1630 (with-current-buffer (setq buffer (get-buffer (or buffer (current-buffer))))
1631 (when (or (not buffer-read-only)
1632 force
1633 inhibit-read-only
1634 (y-or-n-p
1635 (format "Buffer %s is read-only. Strokify anyway? " buffer)))
1636 (let ((inhibit-read-only t))
1637 (message "Strokifying %s..." buffer)
1638 (goto-char (point-min))
1639 (let (string image)
1640 ;; The comment below is what I'd have to do if I wanted to
1641 ;; deal with random newlines in the midst of the compressed
1642 ;; strings. If I do this, I'll also have to change
1643 ;; `strokes-xpm-to-compress-string' to deal with the newline,
1644 ;; and possibly other whitespace stuff. YUCK!
1645 ;; (while (re-search-forward "\\+/\\(\\w\\|\\)+/" nil t nil (get-buffer buffer))
1646 (while (with-current-buffer buffer
1647 (when (re-search-forward "\\+/\\(\\w+\\)/" nil t nil)
1648 (setq string (match-string 1))
1649 (goto-char (match-end 0))
1650 (replace-match " ")
1652 (strokes-xpm-for-compressed-string string " *strokes-xpm*")
1653 (setq image (create-image (with-current-buffer " *strokes-xpm*"
1654 (buffer-string))
1655 'xpm t))
1656 (insert-image image
1657 (propertize " "
1658 'type 'stroke-glyph
1659 'stroke-glyph image
1660 'data string))))
1661 (message "Strokifying %s...done" buffer)))))
1663 (defun strokes-encode-buffer (&optional buffer force)
1664 "Convert the glyphs in BUFFER to their base-64 ASCII representations.
1665 Optional BUFFER defaults to the current buffer.
1666 Optional FORCE non-nil will ignore the buffer's read-only status."
1667 ;; ### NOTE !!! ### (for me)
1668 ;; For later on, you can/should make the inserted strings atomic
1669 ;; extents, so that the users have a clue that they shouldn't be
1670 ;; editing inside them. Plus, if you make them extents, you can
1671 ;; very easily just hide the glyphs, so if you unstrokify, and the
1672 ;; restrokify, then those that already are glyphed don't need to be
1673 ;; re-calculated, etc. It's just nicer that way. The only things
1674 ;; to worry about is cleanup (i.e. do the glyphs get gc'd when the
1675 ;; buffer is killed?
1676 ;; (interactive "*bUnstrokify buffer: ")
1677 (interactive)
1678 (with-current-buffer (setq buffer (or buffer (current-buffer)))
1679 (when (or (not buffer-read-only)
1680 force
1681 inhibit-read-only
1682 (y-or-n-p
1683 (format "Buffer %s is read-only. Encode anyway? " buffer)))
1684 (message "Encoding strokes in %s..." buffer)
1685 ;; (map-extents
1686 ;; (lambda (ext buf)
1687 ;; (when (eq (extent-property ext 'type) 'stroke-glyph)
1688 ;; (goto-char (extent-start-position ext))
1689 ;; (delete-char 1) ; ### What the hell do I do here? ###
1690 ;; (insert "+/" (extent-property ext 'data) "/")
1691 ;; (delete-extent ext))))))
1692 (let ((inhibit-read-only t)
1693 (start nil)
1694 glyph)
1695 (while (or (and (bobp)
1696 (get-text-property (point) 'type))
1697 (setq start (next-single-property-change (point) 'type)))
1698 (when (eq 'stroke-glyph (get-text-property (point) 'type))
1699 (goto-char start)
1700 (setq start (point-marker)
1701 glyph (get-text-property start 'display))
1702 (insert "+/" (get-text-property (point) 'data) ?/)
1703 (delete-char 1)
1704 (add-text-properties start (point)
1705 (list 'type 'stroke-string
1706 'face 'strokes-char
1707 'stroke-glyph glyph
1708 'display nil))))
1709 (message "Encoding strokes in %s...done" buffer)))))
1711 (defun strokes-xpm-for-compressed-string (compressed-string &optional bufname)
1712 "Convert the stroke represented by COMPRESSED-STRING into an XPM.
1713 Store XPM in buffer BUFNAME if supplied (default is \" *strokes-xpm*\")"
1714 (or bufname (setq bufname " *strokes-xpm*"))
1715 (with-current-buffer (get-buffer-create bufname)
1716 (erase-buffer)
1717 (insert compressed-string)
1718 (goto-char (point-min))
1719 (let ((current-char-is-on-p nil))
1720 (while (not (eobp))
1721 (insert-char
1722 (if current-char-is-on-p
1724 ?\s)
1725 (strokes-xpm-decode-char (char-after)))
1726 (delete-char 1)
1727 (setq current-char-is-on-p (not current-char-is-on-p)))
1728 (goto-char (point-min))
1729 (cl-loop repeat 33 do
1730 (insert ?\")
1731 (forward-char 33)
1732 (insert "\",\n"))
1733 (goto-char (point-min))
1734 (insert strokes-xpm-header))))
1736 ;;;###autoload
1737 (defun strokes-compose-complex-stroke ()
1738 ;; ### NOTE !!! ###
1739 ;; Even though we don't have lexical scoping, it's somewhat ugly how I
1740 ;; pass around variables in the global name space. I can/should
1741 ;; change this.
1742 "Read a complex stroke and insert its glyph into the current buffer."
1743 (interactive "*")
1744 (let ((strokes-grid-resolution 33))
1745 (strokes-read-complex-stroke)
1746 (strokes-xpm-for-stroke nil " *strokes-xpm*" t)
1747 (insert (strokes-xpm-to-compressed-string " *strokes-xpm*"))
1748 (strokes-decode-buffer)
1749 ;; strokes-decode-buffer does a save-excursion.
1750 (forward-char)))
1752 (defun strokes-unload-function ()
1753 "Unload the Strokes library."
1754 (strokes-mode -1)
1755 ;; continue standard unloading
1756 nil)
1758 (run-hooks 'strokes-load-hook)
1759 (provide 'strokes)
1761 ;;; strokes.el ends here