diff options
| author | Dave Love | 2002-07-01 16:04:39 +0000 |
|---|---|---|
| committer | Dave Love | 2002-07-01 16:04:39 +0000 |
| commit | ded4da9598f57128464f37414c7e09eb03493569 (patch) | |
| tree | e4ceac596cca12c02475c42159bc0475d1f5e66b | |
| parent | f9f1e1fc7580cd1542e20ef9705046d0d867688b (diff) | |
| download | emacs-ded4da9598f57128464f37414c7e09eb03493569.tar.gz emacs-ded4da9598f57128464f37414c7e09eb03493569.zip | |
Doc fixes.
(strokes-mode): Defcustom deleted; replaced by minor mode def with
re-written function.
(strokes-while-inhibiting-garbage-collector): Comment out.
(define-stroke, strokes-fix-button2-command, strokes-insinuated)
(strokes-insinuate, global-set-stroke, describe-stroke)
(load-user-strokes, save-strokes, strokes-bug-address)
(strokes-click-command): Deleted.
(strokes-execute-stroke): Remove strokes-click-p case.
(strokes-describe-stroke): Remove strokes-click-p stuff.
(strokes-help): Fix.
(strokes-report-bug): Alias to report-emacs-bug.
(strokes-prompt-user-save-strokes): Modify format of the file.
(strokes-mode-map, strokes-unload-hook): New.
(strokes-buffer-name): Don't customize.
| -rw-r--r-- | lisp/strokes.el | 583 |
1 files changed, 184 insertions, 399 deletions
diff --git a/lisp/strokes.el b/lisp/strokes.el index 2556dbe6b63..3f5a5bb3a75 100644 --- a/lisp/strokes.el +++ b/lisp/strokes.el | |||
| @@ -32,20 +32,22 @@ | |||
| 32 | ;; > M-x strokes-help | 32 | ;; > M-x strokes-help |
| 33 | 33 | ||
| 34 | ;; and you can learn how to use the package. A mouse stroke, for now, | 34 | ;; and you can learn how to use the package. A mouse stroke, for now, |
| 35 | ;; can be defined as holding the middle button, for instance, and then | 35 | ;; can be defined as holding the shift key and the middle button, for |
| 36 | ;; moving the mouse in whatever pattern you wish, which you have set | 36 | ;; instance, and then moving the mouse in whatever pattern you wish, |
| 37 | ;; Emacs to understand as mapping to a given command. For example, you | 37 | ;; which you have set Emacs to understand as mapping to a given |
| 38 | ;; may wish the have a mouse stroke that looks like a capital `C' which | 38 | ;; command. For example, you may wish the have a mouse stroke that |
| 39 | ;; means `copy-region-as-kill'. Treat strokes just like you do key | 39 | ;; looks like a capital `C' which means `copy-region-as-kill'. Treat |
| 40 | ;; bindings. For example, Emacs sets key bindings globally with the | 40 | ;; strokes just like you do key bindings. For example, Emacs sets key |
| 41 | ;; `global-set-key' command. Likewise, you can do | 41 | ;; bindings globally with the `global-set-key' command. Likewise, you |
| 42 | ;; can do | ||
| 42 | 43 | ||
| 43 | ;; > M-x global-set-stroke | 44 | ;; > M-x strokes-global-set-stroke |
| 44 | 45 | ||
| 45 | ;; to interactively program in a stroke. It would be wise to set the | 46 | ;; to interactively program in a stroke. It would be wise to set the |
| 46 | ;; first one to this very command, so that from then on, you invoke | 47 | ;; first one to this very command, so that from then on, you invoke |
| 47 | ;; `global-set-stroke' with a stroke. likewise, there may eventually | 48 | ;; `strokes-global-set-stroke' with a stroke. Likewise, there may |
| 48 | ;; be a `local-set-stroke' command, also analogous to `local-set-key'. | 49 | ;; eventually be a `strokes-local-set-stroke' command, also analogous |
| 50 | ;; to `local-set-key'. | ||
| 49 | 51 | ||
| 50 | ;; You can always unset the last stroke definition with the command | 52 | ;; You can always unset the last stroke definition with the command |
| 51 | 53 | ||
| @@ -58,19 +60,19 @@ | |||
| 58 | 60 | ||
| 59 | ;; 1) To describe a stroke binding, you can type | 61 | ;; 1) To describe a stroke binding, you can type |
| 60 | 62 | ||
| 61 | ;; > M-x describe-stroke | 63 | ;; > M-x strokes-describe-stroke |
| 62 | 64 | ||
| 63 | ;; analogous to `describe-key'. It's also wise to have a stroke, | 65 | ;; 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 | ;; like an `h', for help, or a `?', mapped to `describe-stroke'. |
| 65 | 67 | ||
| 66 | ;; 2) stroke bindings are set internally through the Lisp function | 68 | ;; 2) stroke bindings are set internally through the Lisp function |
| 67 | ;; `define-stroke', similar to the `define-key' function. some | 69 | ;; `strokes-define-stroke', similar to the `define-key' function. |
| 68 | ;; examples for a 3x3 stroke grid would be | 70 | ;; some examples for a 3x3 stroke grid would be |
| 69 | 71 | ||
| 70 | ;; (define-stroke c-mode-stroke-map | 72 | ;; (strokes-define-stroke c-mode-stroke-map |
| 71 | ;; '((0 . 0) (1 . 1) (2 . 2)) | 73 | ;; '((0 . 0) (1 . 1) (2 . 2)) |
| 72 | ;; 'kill-region) | 74 | ;; 'kill-region) |
| 73 | ;; (define-stroke strokes-global-map | 75 | ;; (strokes-define-stroke strokes-global-map |
| 74 | ;; '((0 . 0) (0 . 1) (0 . 2) (1 . 2) (2 . 2)) | 76 | ;; '((0 . 0) (0 . 1) (0 . 2) (1 . 2) (2 . 2)) |
| 75 | ;; 'list-buffers) | 77 | ;; 'list-buffers) |
| 76 | 78 | ||
| @@ -107,7 +109,7 @@ | |||
| 107 | ;; computers as well as people who don't want to see their strokes. | 109 | ;; computers as well as people who don't want to see their strokes. |
| 108 | 110 | ||
| 109 | ;; If you find that your mouse is accelerating too fast, you can | 111 | ;; If you find that your mouse is accelerating too fast, you can |
| 110 | ;; execute the UNIX X command to slow it down. A good possibility is | 112 | ;; execute an X command to slow it down. A good possibility is |
| 111 | 113 | ||
| 112 | ;; % xset m 5/4 8 | 114 | ;; % xset m 5/4 8 |
| 113 | 115 | ||
| @@ -116,7 +118,7 @@ | |||
| 116 | ;; Whenever you load in the strokes package, you will be able to save | 118 | ;; 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 | ;; what you've done upon exiting Emacs. You can also do |
| 118 | 120 | ||
| 119 | ;; > M-x save-strokes | 121 | ;; > M-x strokes-prompt-user-save-strokes |
| 120 | 122 | ||
| 121 | ;; and it will save your strokes in ~/.strokes, or you may wish to change | 123 | ;; and it will save your strokes in ~/.strokes, or you may wish to change |
| 122 | ;; this by setting the variable `strokes-file'. | 124 | ;; this by setting the variable `strokes-file'. |
| @@ -124,33 +126,20 @@ | |||
| 124 | ;; Note that internally, all of the routines that are part of this | 126 | ;; Note that internally, all of the routines that are part of this |
| 125 | ;; package are able to deal with complex strokes, as they are a superset | 127 | ;; package are able to deal with complex strokes, as they are a superset |
| 126 | ;; of simple strokes. However, the default of this package will map | 128 | ;; of simple strokes. However, the default of this package will map |
| 127 | ;; mouse button2 to the command `strokes-do-stroke', and NOT | 129 | ;; S-mouse-2 to the command `strokes-do-stroke', and M-mouse-2 to |
| 128 | ;; `strokes-do-complex-stroke'. If you wish to use complex strokes, you | 130 | ;; `strokes-do-complex-stroke'. Complex strokes are terminated |
| 129 | ;; will have to override this key mapping. Complex strokes are terminated | 131 | ;; with mouse button 3. |
| 130 | ;; with mouse button3. The strokes package will not interfere with | ||
| 131 | ;; `mouse-yank', but you may want to examine how this is done (see the | ||
| 132 | ;; variable `strokes-click-command') | ||
| 133 | 132 | ||
| 134 | ;; To get strokes to work as part of your your setup, then you'll have | 133 | ;; You can also toggle between strokes mode by simple typing |
| 135 | ;; put the strokes package in your load-path (preferably byte-compiled) | ||
| 136 | ;; and then add the following to your .emacs file (or wherever | ||
| 137 | ;; you put Emacs-specific startup preferences): | ||
| 138 | |||
| 139 | ;;(and window-system | ||
| 140 | ;; (require 'strokes)) | ||
| 141 | |||
| 142 | ;; Once loaded, you can start stroking. You can also toggle between | ||
| 143 | ;; strokes mode by simple typing | ||
| 144 | 134 | ||
| 145 | ;; > M-x strokes-mode | 135 | ;; > M-x strokes-mode |
| 146 | 136 | ||
| 147 | ;; I am now in the process of porting this package to Emacs. I also hope | 137 | ;; I hope that, with the help of others, this package will be useful |
| 148 | ;; that, with the help of others, this package will be useful in entering | 138 | ;; in entering in pictographic-like language text using the mouse |
| 149 | ;; in pictographic-like language text using the mouse (i.e. Korean). | 139 | ;; (i.e. Korean). Japanese and Chinese are a bit trickier, but I'm |
| 150 | ;; Japanese and Chinese are a bit trickier, but I'm sure that with help | 140 | ;; sure that with help it can be done. The next version will allow |
| 151 | ;; it can be done. The next version will allow the user to enter strokes | 141 | ;; the user to enter strokes which "remove the pencil from the paper" |
| 152 | ;; which "remove the pencil from the paper" so to speak, so one character | 142 | ;; so to speak, so one character can have multiple strokes. |
| 153 | ;; can have multiple strokes. | ||
| 154 | 143 | ||
| 155 | ;; You can read more about strokes at: | 144 | ;; You can read more about strokes at: |
| 156 | 145 | ||
| @@ -172,7 +161,7 @@ | |||
| 172 | ;; macros at (near) max speed. | 161 | ;; macros at (near) max speed. |
| 173 | 162 | ||
| 174 | ;; Tasks: (what I'm getting ready for future version)... | 163 | ;; Tasks: (what I'm getting ready for future version)... |
| 175 | ;; 2) use 'strokes-read-complex-stroke for korean, etc. | 164 | ;; 2) use 'strokes-read-complex-stroke for Korean, etc. |
| 176 | ;; 4) buffer-local 'strokes-local-map, and mode-stroke-maps would be nice | 165 | ;; 4) buffer-local 'strokes-local-map, and mode-stroke-maps would be nice |
| 177 | ;; 6) add some hooks, like `strokes-read-stroke-hook' | 166 | ;; 6) add some hooks, like `strokes-read-stroke-hook' |
| 178 | ;; 7) See what people think of the factory settings. Should I change | 167 | ;; 7) See what people think of the factory settings. Should I change |
| @@ -193,10 +182,6 @@ | |||
| 193 | 182 | ||
| 194 | ;;; Constants... | 183 | ;;; Constants... |
| 195 | 184 | ||
| 196 | (defconst strokes-version "2.4-Emacs") | ||
| 197 | |||
| 198 | (defconst strokes-bug-address "cadet@alum.mit.edu") | ||
| 199 | |||
| 200 | (defconst strokes-lift :strokes-lift | 185 | (defconst strokes-lift :strokes-lift |
| 201 | "Symbol representing a stroke lift event for complex strokes. | 186 | "Symbol representing a stroke lift event for complex strokes. |
| 202 | Complex strokes are those which contain two or more simple strokes.") | 187 | Complex strokes are those which contain two or more simple strokes.") |
| @@ -216,17 +201,18 @@ static char * stroke_xpm[] = { | |||
| 216 | \"P c #FFFF0000FFFF\", | 201 | \"P c #FFFF0000FFFF\", |
| 217 | \". c #45458B8B0000\", | 202 | \". c #45458B8B0000\", |
| 218 | /* pixels */\n" | 203 | /* pixels */\n" |
| 219 | "The header to all xpm buffers created by strokes") | 204 | "The header to all xpm buffers created by strokes.") |
| 220 | 205 | ||
| 221 | ;;; user variables... | 206 | ;;; user variables... |
| 222 | 207 | ||
| 223 | (defgroup strokes nil | 208 | (defgroup strokes nil |
| 224 | "Control Emacs through mouse strokes" | 209 | "Control Emacs through mouse strokes" |
| 210 | :link '(emacs-commentary-link "strokes") | ||
| 225 | :link '(url-link "http://www.mit.edu/people/cadet/strokes-help.html") | 211 | :link '(url-link "http://www.mit.edu/people/cadet/strokes-help.html") |
| 226 | :group 'mouse) | 212 | :group 'mouse) |
| 227 | 213 | ||
| 228 | (defcustom strokes-modeline-string " Strokes" | 214 | (defcustom strokes-modeline-string " Strokes" |
| 229 | "*Modeline identification when strokes-mode is on \(default is \" Strokes\"\)." | 215 | "*Modeline identification when Strokes mode is on \(default is \" Strokes\"\)." |
| 230 | :type 'string | 216 | :type 'string |
| 231 | :group 'strokes) | 217 | :group 'strokes) |
| 232 | 218 | ||
| @@ -245,7 +231,7 @@ the value of `strokes-grid-resolution', since a higher grid resolution | |||
| 245 | will correspond to more sample points, and thus more distance | 231 | will correspond to more sample points, and thus more distance |
| 246 | measurements. Usually, this is not a problem since you first set | 232 | measurements. Usually, this is not a problem since you first set |
| 247 | `strokes-grid-resolution' based on what your computer seems to be able | 233 | `strokes-grid-resolution' based on what your computer seems to be able |
| 248 | to handle (though the defaults are usually more than sufficent), and | 234 | to handle (though the defaults are usually more than sufficient), and |
| 249 | then you can set `strokes-minimum-match-score' to something that works | 235 | then you can set `strokes-minimum-match-score' to something that works |
| 250 | for you. The only purpose of this variable is to insure that if you | 236 | for you. The only purpose of this variable is to insure that if you |
| 251 | do a bogus stroke that really doesn't match any of the predefined | 237 | do a bogus stroke that really doesn't match any of the predefined |
| @@ -275,10 +261,8 @@ WARNING: Changing the value of this variable will gravely affect the | |||
| 275 | :type 'file | 261 | :type 'file |
| 276 | :group 'strokes) | 262 | :group 'strokes) |
| 277 | 263 | ||
| 278 | (defcustom strokes-buffer-name " *strokes*" | 264 | (defvar strokes-buffer-name " *strokes*" |
| 279 | "The buffer that the strokes take place in (default is ` *strokes*')." | 265 | "The name of the buffer that the strokes take place in.") |
| 280 | :type 'string | ||
| 281 | :group 'strokes) | ||
| 282 | 266 | ||
| 283 | (defcustom strokes-use-strokes-buffer t | 267 | (defcustom strokes-use-strokes-buffer t |
| 284 | "*If non-nil, the strokes buffer is used and strokes are displayed. | 268 | "*If non-nil, the strokes buffer is used and strokes are displayed. |
| @@ -288,29 +272,8 @@ the delay in switching to the strokes buffer." | |||
| 288 | :type 'boolean | 272 | :type 'boolean |
| 289 | :group 'strokes) | 273 | :group 'strokes) |
| 290 | 274 | ||
| 291 | (defcustom strokes-click-command 'mouse-yank-at-click | ||
| 292 | "*Command to execute when stroke is actually a `click' event. | ||
| 293 | This is set to `mouse-yank-at-click' by default." | ||
| 294 | :type 'function | ||
| 295 | :group 'strokes) | ||
| 296 | |||
| 297 | ;;; internal variables... | 275 | ;;; internal variables... |
| 298 | 276 | ||
| 299 | ;; This is an internal variable, but we defcustom it so Customize can | ||
| 300 | ;; use it. | ||
| 301 | ;;;###autoload | ||
| 302 | (defcustom strokes-mode nil | ||
| 303 | "Non-nil when `strokes' is globally enabled. | ||
| 304 | Setting this variable directly does not take effect. Use either Customize | ||
| 305 | or M-x strokes-mode." | ||
| 306 | :type 'boolean | ||
| 307 | :set (lambda (symbol value) | ||
| 308 | (strokes-mode (or value 0))) | ||
| 309 | :initialize 'custom-initialize-default | ||
| 310 | :require 'strokes | ||
| 311 | :version "21.1" | ||
| 312 | :group 'strokes) | ||
| 313 | |||
| 314 | (defvar strokes-window-configuration nil | 277 | (defvar strokes-window-configuration nil |
| 315 | "The special window configuration used when entering strokes. | 278 | "The special window configuration used when entering strokes. |
| 316 | This is set properly in the function `strokes-update-window-configuration'.") | 279 | This is set properly in the function `strokes-update-window-configuration'.") |
| @@ -345,10 +308,11 @@ corresponding interactive function") | |||
| 345 | 308 | ||
| 346 | ;;; Macros... | 309 | ;;; Macros... |
| 347 | 310 | ||
| 348 | (defmacro strokes-while-inhibiting-garbage-collector (&rest forms) | 311 | ;; unused |
| 349 | "Execute FORMS without interference from the garbage collector." | 312 | ;; (defmacro strokes-while-inhibiting-garbage-collector (&rest forms) |
| 350 | `(let ((gc-cons-threshold 134217727)) | 313 | ;; "Execute FORMS without interference from the garbage collector." |
| 351 | ,@forms)) | 314 | ;; `(let ((gc-cons-threshold 134217727)) |
| 315 | ;; ,@forms)) | ||
| 352 | 316 | ||
| 353 | (defsubst strokes-click-p (stroke) | 317 | (defsubst strokes-click-p (stroke) |
| 354 | "Non-nil if STROKE is really click." | 318 | "Non-nil if STROKE is really click." |
| @@ -372,14 +336,12 @@ corresponding interactive function") | |||
| 372 | (defmacro strokes-define-stroke (stroke-map stroke def) | 336 | (defmacro strokes-define-stroke (stroke-map stroke def) |
| 373 | "Add STROKE to STROKE-MAP alist with given command DEF." | 337 | "Add STROKE to STROKE-MAP alist with given command DEF." |
| 374 | `(if (strokes-click-p ,stroke) | 338 | `(if (strokes-click-p ,stroke) |
| 375 | (error "That's a click, not a stroke; see `strokes-click-command'") | 339 | (error "That's a click, not a stroke") |
| 376 | (setq ,stroke-map (cons (cons ,stroke ,def) | 340 | (setq ,stroke-map (cons (cons ,stroke ,def) |
| 377 | (strokes-remassoc ,stroke ,stroke-map))))) | 341 | (strokes-remassoc ,stroke ,stroke-map))))) |
| 378 | 342 | ||
| 379 | (defalias 'define-stroke 'strokes-define-stroke) | ||
| 380 | |||
| 381 | (defsubst strokes-square (x) | 343 | (defsubst strokes-square (x) |
| 382 | "Returns the square of the number X" | 344 | "Return the square of the number X." |
| 383 | (* x x)) | 345 | (* x x)) |
| 384 | 346 | ||
| 385 | (defsubst strokes-distance-squared (p1 p2) | 347 | (defsubst strokes-distance-squared (p1 p2) |
| @@ -392,105 +354,6 @@ P1 and P2 are cons cells in the form (X . Y)." | |||
| 392 | (+ (strokes-square (- x2 x1)) | 354 | (+ (strokes-square (- x2 x1)) |
| 393 | (strokes-square (- y2 y1))))) | 355 | (strokes-square (- y2 y1))))) |
| 394 | 356 | ||
| 395 | ;;; Advice for various functions... | ||
| 396 | |||
| 397 | ;; I'd originally wanted to write a macro that would just take in the | ||
| 398 | ;; generic functions which use mouse button2 in various modes. Most of | ||
| 399 | ;; them are identical in form: they take an event as the single argument | ||
| 400 | ;; and then do their thing. I tried writing a macro that looked | ||
| 401 | ;; something like this, but failed. Advice just ain't that easy. The | ||
| 402 | ;; one that bugged me the most was `Manual-follow-xref', because that had | ||
| 403 | ;; &rest arguments, and I didn't know how to work around it in defadvice. | ||
| 404 | ;; However, I was able to fix up most of the important modes (i.e. the | ||
| 405 | ;; ones I use all the time). One `bug' in the program that I just can't | ||
| 406 | ;; seem to figure out is why I can only advise other button2 functions | ||
| 407 | ;; successfully when the variable `strokes-use-strokes-buffer' is nil. I | ||
| 408 | ;; did all the save-excursion/save-window-excursion stuff SPECIFICALLY so | ||
| 409 | ;; that using the strokes buffer or not would absolutely not affect any | ||
| 410 | ;; other part of the program. If someone can figure out how to make the | ||
| 411 | ;; following advices work w/ regardless of that variable | ||
| 412 | ;; `strokes-use-strokes-buffer', then that would be a great victory. If | ||
| 413 | ;; someone out there would be kind enough to make the commented code | ||
| 414 | ;; below work, I'd be grateful. By the way, I put the `protect' keywords | ||
| 415 | ;; there to insure that if a stroke went bad, then | ||
| 416 | ;; `strokes-click-command' would be set back. If this isn't necessary, | ||
| 417 | ;; then feel free to let me know. | ||
| 418 | |||
| 419 | ;; For what follows, I really wanted something that would work like this: | ||
| 420 | |||
| 421 | ;;(strokes-fix-button2 'vm-mouse-button-2) | ||
| 422 | |||
| 423 | ;; Or even better, I could have simply done something like: | ||
| 424 | |||
| 425 | ;;(mapcar 'strokes-fix-button2 | ||
| 426 | ;; '(vm-mouse-button-2 | ||
| 427 | ;; rmail-summary-mouse-goto-msg | ||
| 428 | ;; <rest of them>)) | ||
| 429 | |||
| 430 | ;;; With help from Hans (author of advice.el)... | ||
| 431 | (defmacro strokes-fix-button2-command (command) | ||
| 432 | "Fix COMMAND so that it can also work with strokes. | ||
| 433 | COMMAND must take one event argument. | ||
| 434 | Example of how one might fix up a command that's bound to button2 | ||
| 435 | and which is an interactive funcion of one event argument: | ||
| 436 | |||
| 437 | \(strokes-fix-button2-command 'rmail-summary-mouse-goto-msg)" | ||
| 438 | (let ((command (eval command))) | ||
| 439 | `(progn | ||
| 440 | (defadvice ,command (around strokes-fix-button2 compile preactivate) | ||
| 441 | ,(format "Fix %s to work with strokes." command) | ||
| 442 | (let ((strokes-click-command | ||
| 443 | ',(intern (format "ad-Orig-%s" command)))) | ||
| 444 | (strokes-do-stroke (ad-get-arg 0))))))) | ||
| 445 | |||
| 446 | (defvar strokes-insinuated nil) | ||
| 447 | |||
| 448 | (defun strokes-insinuate () | ||
| 449 | "Insinuate Emacs with strokes advices." | ||
| 450 | (unless strokes-insinuated | ||
| 451 | (strokes-fix-button2-command 'vm-mouse-button-2) | ||
| 452 | (strokes-fix-button2-command 'rmail-summary-mouse-goto-msg) | ||
| 453 | (strokes-fix-button2-command 'Buffer-menu-mouse-select) | ||
| 454 | (strokes-fix-button2-command 'w3-widget-button-click) | ||
| 455 | (strokes-fix-button2-command 'widget-image-button-press) | ||
| 456 | (strokes-fix-button2-command 'Info-follow-clicked-node) | ||
| 457 | (strokes-fix-button2-command 'compile-mouse-goto-error) | ||
| 458 | (strokes-fix-button2-command 'gdbsrc-select-or-yank) | ||
| 459 | (strokes-fix-button2-command 'hypropos-mouse-get-doc) | ||
| 460 | (strokes-fix-button2-command 'gnus-mouse-pick-group) | ||
| 461 | (strokes-fix-button2-command 'gnus-mouse-pick-article) | ||
| 462 | (strokes-fix-button2-command 'gnus-article-push-button) | ||
| 463 | (strokes-fix-button2-command 'dired-mouse-find-file) | ||
| 464 | (strokes-fix-button2-command 'url-dired-find-file-mouse) | ||
| 465 | (strokes-fix-button2-command 'dired-u-r-mouse-toggle) | ||
| 466 | (strokes-fix-button2-command 'dired-u-w-mouse-toggle) | ||
| 467 | (strokes-fix-button2-command 'dired-u-x-mouse-toggle) | ||
| 468 | (strokes-fix-button2-command 'dired-g-r-mouse-toggle) | ||
| 469 | (strokes-fix-button2-command 'dired-g-w-mouse-toggle) | ||
| 470 | (strokes-fix-button2-command 'dired-g-x-mouse-toggle) | ||
| 471 | (strokes-fix-button2-command 'dired-o-r-mouse-toggle) | ||
| 472 | (strokes-fix-button2-command 'dired-o-w-mouse-toggle) | ||
| 473 | (strokes-fix-button2-command 'isearch-yank-x-selection) | ||
| 474 | (strokes-fix-button2-command 'occur-mode-mouse-goto) | ||
| 475 | (strokes-fix-button2-command 'cvs-mouse-find-file) | ||
| 476 | (setq strokes-insinuated t))) | ||
| 477 | |||
| 478 | ;;; I can fix the customize widget button click, but then | ||
| 479 | ;;; people will get confused when they try to customize | ||
| 480 | ;;; strokes with the mouse and customize tells them that | ||
| 481 | ;;; `strokes-click-command' is mapped to `ad-Orig-widget-button-click' | ||
| 482 | ;;(strokes-fix-button2-command 'widget-button-click) | ||
| 483 | |||
| 484 | ;;; without the advice, each advised function would look like... | ||
| 485 | ;;(defadvice vm-mouse-button-2 (around vm-strokes activate protect) | ||
| 486 | ;; "Allow strokes to work in VM." | ||
| 487 | ;; (if strokes-use-strokes-buffer | ||
| 488 | ;; ;; then strokes is no good and we'll have to use the original | ||
| 489 | ;; ad-do-it | ||
| 490 | ;; ;; otherwise, we can make strokes work too... | ||
| 491 | ;; (let ((strokes-click-command 'ad-Orig-vm-mouse-button-2)) | ||
| 492 | ;; (strokes-do-stroke (ad-get-arg 0))))) | ||
| 493 | |||
| 494 | ;;; Functions... | 357 | ;;; Functions... |
| 495 | 358 | ||
| 496 | (defsubst strokes-mouse-event-p (event) | 359 | (defsubst strokes-mouse-event-p (event) |
| @@ -526,7 +389,7 @@ If LINE is nil, return the last position visible in WINDOW." | |||
| 526 | (defun strokes-event-closest-point (event &optional start-window) | 389 | (defun strokes-event-closest-point (event &optional start-window) |
| 527 | "Return the nearest position to where EVENT ended its motion. | 390 | "Return the nearest position to where EVENT ended its motion. |
| 528 | This is computed for the window where EVENT's motion started, | 391 | This is computed for the window where EVENT's motion started, |
| 529 | or for window WINDOW if that is specified." | 392 | or for window START-WINDOW if that is specified." |
| 530 | (or start-window (setq start-window (posn-window (event-start event)))) | 393 | (or start-window (setq start-window (posn-window (event-start event)))) |
| 531 | (if (eq start-window (posn-window (event-end event))) | 394 | (if (eq start-window (posn-window (event-end event))) |
| 532 | (if (eq (posn-point (event-end event)) 'vertical-line) | 395 | (if (eq (posn-point (event-end event)) 'vertical-line) |
| @@ -557,7 +420,7 @@ or for window WINDOW if that is specified." | |||
| 557 | (interactive) | 420 | (interactive) |
| 558 | (let ((command (cdar strokes-global-map))) | 421 | (let ((command (cdar strokes-global-map))) |
| 559 | (if (y-or-n-p | 422 | (if (y-or-n-p |
| 560 | (format "really delete last stroke definition, defined to `%s'? " | 423 | (format "Really delete last stroke definition, defined to `%s'? " |
| 561 | command)) | 424 | command)) |
| 562 | (progn | 425 | (progn |
| 563 | (setq strokes-global-map (cdr strokes-global-map)) | 426 | (setq strokes-global-map (cdr strokes-global-map)) |
| @@ -575,13 +438,10 @@ documentation for the `strokes-define-stroke' function." | |||
| 575 | (list | 438 | (list |
| 576 | (and (or strokes-mode (strokes-mode t)) | 439 | (and (or strokes-mode (strokes-mode t)) |
| 577 | (strokes-read-complex-stroke | 440 | (strokes-read-complex-stroke |
| 578 | "Define a new stroke. Draw with button1 (or 2). End with button3...")) | 441 | "Draw with mouse button 1 (or 2). End with button 3...")) |
| 579 | (read-command "command to map stroke to: "))) | 442 | (read-command "Command to map stroke to: "))) |
| 580 | (strokes-define-stroke strokes-global-map stroke command)) | 443 | (strokes-define-stroke strokes-global-map stroke command)) |
| 581 | 444 | ||
| 582 | ;;;###autoload | ||
| 583 | (defalias 'global-set-stroke 'strokes-global-set-stroke) | ||
| 584 | |||
| 585 | ;;(defun global-unset-stroke (stroke); FINISH THIS DEFUN! | 445 | ;;(defun global-unset-stroke (stroke); FINISH THIS DEFUN! |
| 586 | ;; "delete all strokes matching STROKE from `strokes-global-map', | 446 | ;; "delete all strokes matching STROKE from `strokes-global-map', |
| 587 | ;; letting the user input | 447 | ;; letting the user input |
| @@ -592,11 +452,12 @@ documentation for the `strokes-define-stroke' function." | |||
| 592 | ;; (strokes-define-stroke 'strokes-global-map stroke command)) | 452 | ;; (strokes-define-stroke 'strokes-global-map stroke command)) |
| 593 | 453 | ||
| 594 | (defun strokes-get-grid-position (stroke-extent position &optional grid-resolution) | 454 | (defun strokes-get-grid-position (stroke-extent position &optional grid-resolution) |
| 595 | "Map POSITION to a new grid position based on its STROKE-EXTENT and GRID-RESOLUTION. | 455 | "Map POSITION to a new grid position. |
| 456 | Do so based on its STROKE-EXTENT and GRID-RESOLUTION. | ||
| 596 | STROKE-EXTENT as a list \(\(XMIN . YMIN\) \(XMAX . YMAX\)\). | 457 | STROKE-EXTENT as a list \(\(XMIN . YMIN\) \(XMAX . YMAX\)\). |
| 597 | If POSITION is a `strokes-lift', then it is itself returned. | 458 | If POSITION is a `strokes-lift', then it is itself returned. |
| 598 | Optional GRID-RESOLUTION may be used in place of STROKES-GRID-RESOLUTION. | 459 | Optional GRID-RESOLUTION may be used in place of STROKES-GRID-RESOLUTION. |
| 599 | The grid is a square whose dimesion is [0,GRID-RESOLUTION)." | 460 | The grid is a square whose dimension is [0,GRID-RESOLUTION)." |
| 600 | (cond ((consp position) ; actual pixel location | 461 | (cond ((consp position) ; actual pixel location |
| 601 | (let ((grid-resolution (or grid-resolution strokes-grid-resolution)) | 462 | (let ((grid-resolution (or grid-resolution strokes-grid-resolution)) |
| 602 | (x (car position)) | 463 | (x (car position)) |
| @@ -617,7 +478,7 @@ The grid is a square whose dimesion is [0,GRID-RESOLUTION)." | |||
| 617 | strokes-lift))) | 478 | strokes-lift))) |
| 618 | 479 | ||
| 619 | (defun strokes-get-stroke-extent (pixel-positions) | 480 | (defun strokes-get-stroke-extent (pixel-positions) |
| 620 | "From a list of absolute PIXEL-POSITIONS, returns absolute spatial extent. | 481 | "From a list of absolute PIXEL-POSITIONS, return absolute spatial extent. |
| 621 | The return value is a list ((XMIN . YMIN) (XMAX . YMAX))." | 482 | The return value is a list ((XMIN . YMIN) (XMAX . YMAX))." |
| 622 | (if pixel-positions | 483 | (if pixel-positions |
| 623 | (let ((xmin (caar pixel-positions)) | 484 | (let ((xmin (caar pixel-positions)) |
| @@ -658,7 +519,7 @@ The return value is a list ((XMIN . YMIN) (XMAX . YMAX))." | |||
| 658 | nil)) | 519 | nil)) |
| 659 | 520 | ||
| 660 | (defun strokes-eliminate-consecutive-redundancies (entries) | 521 | (defun strokes-eliminate-consecutive-redundancies (entries) |
| 661 | "Returns a list with no consecutive redundant entries." | 522 | "Return a list with no consecutive redundant entries." |
| 662 | ;; defun a grande vitesse grace a Dave G. | 523 | ;; defun a grande vitesse grace a Dave G. |
| 663 | (loop for element on entries | 524 | (loop for element on entries |
| 664 | if (not (equal (car element) (cadr element))) | 525 | if (not (equal (car element) (cadr element))) |
| @@ -686,7 +547,7 @@ The return value is a list ((XMIN . YMIN) (XMAX . YMAX))." | |||
| 686 | "Map POSITIONS to a new grid whose dimensions are based on GRID-RESOLUTION. | 547 | "Map POSITIONS to a new grid whose dimensions are based on GRID-RESOLUTION. |
| 687 | POSITIONS is a list of positions and stroke-lifts. | 548 | POSITIONS is a list of positions and stroke-lifts. |
| 688 | Optional GRID-RESOLUTION may be used in place of STROKES-GRID-RESOLUTION. | 549 | Optional GRID-RESOLUTION may be used in place of STROKES-GRID-RESOLUTION. |
| 689 | The grid is a square whose dimesion is [0,GRID-RESOLUTION)." | 550 | The grid is a square whose dimension is [0,GRID-RESOLUTION)." |
| 690 | (or grid-resolution (setq grid-resolution strokes-grid-resolution)) | 551 | (or grid-resolution (setq grid-resolution strokes-grid-resolution)) |
| 691 | (let ((stroke-extent (strokes-get-stroke-extent positions))) | 552 | (let ((stroke-extent (strokes-get-stroke-extent positions))) |
| 692 | (mapcar (function | 553 | (mapcar (function |
| @@ -728,7 +589,7 @@ NOTE: This is where the global variable `strokes-last-stroke' is set." | |||
| 728 | delta-x))))) | 589 | delta-x))))) |
| 729 | (cond ((not both-are-points-p) | 590 | (cond ((not both-are-points-p) |
| 730 | (list current)) | 591 | (list current)) |
| 731 | ((null slope) ; undefinded vertical slope | 592 | ((null slope) ; undefined vertical slope |
| 732 | (if (>= delta-y 0) | 593 | (if (>= delta-y 0) |
| 733 | (loop for y from y1 below y2 | 594 | (loop for y from y1 below y2 |
| 734 | collect (cons x1 y)) | 595 | collect (cons x1 y)) |
| @@ -766,7 +627,7 @@ NOTE: This is where the global variable `strokes-last-stroke' is set." | |||
| 766 | y)))))))))) | 627 | y)))))))))) |
| 767 | 628 | ||
| 768 | (defun strokes-rate-stroke (stroke1 stroke2) | 629 | (defun strokes-rate-stroke (stroke1 stroke2) |
| 769 | "Rates STROKE1 with STROKE2 and returns a score based on a distance metric. | 630 | "Rates STROKE1 with STROKE2 and return a score based on a distance metric. |
| 770 | Note: the rating is an error rating, and therefore, a return of 0 | 631 | Note: the rating is an error rating, and therefore, a return of 0 |
| 771 | represents a perfect match. Also note that the order of stroke | 632 | represents a perfect match. Also note that the order of stroke |
| 772 | arguments is order-independent for the algorithm used here." | 633 | arguments is order-independent for the algorithm used here." |
| @@ -820,7 +681,7 @@ arguments is order-independent for the algorithm used here." | |||
| 820 | nil)) | 681 | nil)) |
| 821 | 682 | ||
| 822 | (defun strokes-match-stroke (stroke stroke-map) | 683 | (defun strokes-match-stroke (stroke stroke-map) |
| 823 | "Finds the best matching command of STROKE in STROKE-MAP. | 684 | "Find the best matching command of STROKE in STROKE-MAP. |
| 824 | Returns the corresponding match as (COMMAND . SCORE)." | 685 | Returns the corresponding match as (COMMAND . SCORE)." |
| 825 | (if (and stroke stroke-map) | 686 | (if (and stroke stroke-map) |
| 826 | (let ((score (strokes-rate-stroke stroke (caar stroke-map))) | 687 | (let ((score (strokes-rate-stroke stroke (caar stroke-map))) |
| @@ -871,7 +732,8 @@ Optional EVENT is acceptable as the starting event of the stroke" | |||
| 871 | ;; we can draw that point | 732 | ;; we can draw that point |
| 872 | (progn | 733 | (progn |
| 873 | (goto-char point) | 734 | (goto-char point) |
| 874 | (subst-char-in-region point (1+ point) ?\ strokes-character)) | 735 | (subst-char-in-region point (1+ point) |
| 736 | ?\ strokes-character)) | ||
| 875 | ;; otherwise, we can start drawing the next time... | 737 | ;; otherwise, we can start drawing the next time... |
| 876 | (setq safe-to-draw-p t)) | 738 | (setq safe-to-draw-p t)) |
| 877 | (push (cdr (mouse-pixel-position)) | 739 | (push (cdr (mouse-pixel-position)) |
| @@ -880,7 +742,8 @@ Optional EVENT is acceptable as the starting event of the stroke" | |||
| 880 | ;; protected | 742 | ;; protected |
| 881 | ;; clean up strokes buffer and then bury it. | 743 | ;; clean up strokes buffer and then bury it. |
| 882 | (when (equal (buffer-name) strokes-buffer-name) | 744 | (when (equal (buffer-name) strokes-buffer-name) |
| 883 | (subst-char-in-region (point-min) (point-max) strokes-character ?\ ) | 745 | (subst-char-in-region (point-min) (point-max) |
| 746 | strokes-character ?\ ) | ||
| 884 | (goto-char (point-min)) | 747 | (goto-char (point-min)) |
| 885 | (bury-buffer)))) | 748 | (bury-buffer)))) |
| 886 | ;; Otherwise, don't use strokes buffer and read stroke silently | 749 | ;; Otherwise, don't use strokes buffer and read stroke silently |
| @@ -897,15 +760,16 @@ Optional EVENT is acceptable as the starting event of the stroke" | |||
| 897 | pix-locs)) | 760 | pix-locs)) |
| 898 | (setq event (read-event)))) | 761 | (setq event (read-event)))) |
| 899 | (setq grid-locs (strokes-renormalize-to-grid (nreverse pix-locs))) | 762 | (setq grid-locs (strokes-renormalize-to-grid (nreverse pix-locs))) |
| 900 | (strokes-fill-stroke (strokes-eliminate-consecutive-redundancies grid-locs))))) | 763 | (strokes-fill-stroke |
| 764 | (strokes-eliminate-consecutive-redundancies grid-locs))))) | ||
| 901 | 765 | ||
| 902 | ;;;###autoload | 766 | ;;;###autoload |
| 903 | (defun strokes-read-complex-stroke (&optional prompt event) | 767 | (defun strokes-read-complex-stroke (&optional prompt event) |
| 904 | "Read a complex stroke (interactively) and return the stroke. | 768 | "Read a complex stroke (interactively) and return the stroke. |
| 905 | Optional PROMPT in minibuffer displays before and during stroke reading. | 769 | Optional PROMPT in minibuffer displays before and during stroke reading. |
| 906 | Note that a complex stroke allows the user to pen-up and pen-down. This | 770 | Note that a complex stroke allows the user to pen-up and pen-down. This |
| 907 | is implemented by allowing the user to paint with button1 or button2 and | 771 | is implemented by allowing the user to paint with button 1 or button 2 and |
| 908 | then complete the stroke with button3. | 772 | then complete the stroke with button 3. |
| 909 | Optional EVENT is acceptable as the starting event of the stroke" | 773 | Optional EVENT is acceptable as the starting event of the stroke" |
| 910 | (save-excursion | 774 | (save-excursion |
| 911 | (save-window-excursion | 775 | (save-window-excursion |
| @@ -928,7 +792,8 @@ Optional EVENT is acceptable as the starting event of the stroke" | |||
| 928 | (let ((point (strokes-event-closest-point event))) | 792 | (let ((point (strokes-event-closest-point event))) |
| 929 | (when point | 793 | (when point |
| 930 | (goto-char point) | 794 | (goto-char point) |
| 931 | (subst-char-in-region point (1+ point) ?\ strokes-character)) | 795 | (subst-char-in-region point (1+ point) |
| 796 | ?\ strokes-character)) | ||
| 932 | (push (cdr (mouse-pixel-position)) | 797 | (push (cdr (mouse-pixel-position)) |
| 933 | pix-locs))) | 798 | pix-locs))) |
| 934 | (setq event (read-event))) | 799 | (setq event (read-event))) |
| @@ -945,7 +810,8 @@ Optional EVENT is acceptable as the starting event of the stroke" | |||
| 945 | (strokes-eliminate-consecutive-redundancies grid-locs))) | 810 | (strokes-eliminate-consecutive-redundancies grid-locs))) |
| 946 | ;; protected | 811 | ;; protected |
| 947 | (when (equal (buffer-name) strokes-buffer-name) | 812 | (when (equal (buffer-name) strokes-buffer-name) |
| 948 | (subst-char-in-region (point-min) (point-max) strokes-character ?\ ) | 813 | (subst-char-in-region (point-min) (point-max) |
| 814 | strokes-character ?\ ) | ||
| 949 | (goto-char (point-min)) | 815 | (goto-char (point-min)) |
| 950 | (bury-buffer))))))) | 816 | (bury-buffer))))))) |
| 951 | 817 | ||
| @@ -957,19 +823,7 @@ If no stroke matches, nothing is done and return value is nil." | |||
| 957 | (let* ((match (strokes-match-stroke stroke strokes-global-map)) | 823 | (let* ((match (strokes-match-stroke stroke strokes-global-map)) |
| 958 | (command (car match)) | 824 | (command (car match)) |
| 959 | (score (cdr match))) | 825 | (score (cdr match))) |
| 960 | (cond ((strokes-click-p stroke) | 826 | (cond ((and match (<= score strokes-minimum-match-score)) |
| 961 | ;; This is the case of a `click' type event. | ||
| 962 | ;; The `sit-for' is a minor frob that has to do with timing | ||
| 963 | ;; problems. Without the `sit-for', mouse-yank will not | ||
| 964 | ;; yank at the proper location if the user opted for | ||
| 965 | ;; mouse-yank-at-point to be nil (i.e. mouse-yank takes | ||
| 966 | ;; place at pointer position). The sit-for tells redisplay | ||
| 967 | ;; to be sure to wait for the `*strokes*' buffer to vanish | ||
| 968 | ;; from consideration when deciding on a point to be used | ||
| 969 | ;; for mouse-yank. | ||
| 970 | (sit-for 0) | ||
| 971 | (command-execute strokes-click-command)) | ||
| 972 | ((and match (<= score strokes-minimum-match-score)) | ||
| 973 | (message "%s" command) | 827 | (message "%s" command) |
| 974 | (command-execute command)) | 828 | (command-execute command)) |
| 975 | ((null strokes-global-map) | 829 | ((null strokes-global-map) |
| @@ -978,7 +832,7 @@ If no stroke matches, nothing is done and return value is nil." | |||
| 978 | (format "No strokes loaded. Load `%s'? " | 832 | (format "No strokes loaded. Load `%s'? " |
| 979 | strokes-file)) | 833 | strokes-file)) |
| 980 | (strokes-load-user-strokes)) | 834 | (strokes-load-user-strokes)) |
| 981 | (error "No strokes defined; use `global-set-stroke'"))) | 835 | (error "No strokes defined; use `strokes-global-set-stroke'"))) |
| 982 | (t | 836 | (t |
| 983 | (error | 837 | (error |
| 984 | "No stroke matches; see variable `strokes-minimum-match-score'") | 838 | "No stroke matches; see variable `strokes-minimum-match-score'") |
| @@ -1006,38 +860,23 @@ This must be bound to a mouse event." | |||
| 1006 | (interactive | 860 | (interactive |
| 1007 | (list | 861 | (list |
| 1008 | (strokes-read-complex-stroke | 862 | (strokes-read-complex-stroke |
| 1009 | "Enter stroke to describe; end with button3..."))) | 863 | "Enter stroke to describe; end with button 3..."))) |
| 1010 | (let* ((match (strokes-match-stroke stroke strokes-global-map)) | 864 | (let* ((match (strokes-match-stroke stroke strokes-global-map)) |
| 1011 | (command (or (and (strokes-click-p stroke) | 865 | (command (car match)) |
| 1012 | strokes-click-command) | ||
| 1013 | (car match))) | ||
| 1014 | (score (cdr match))) | 866 | (score (cdr match))) |
| 1015 | (if (or (and match | 867 | (if (and match |
| 1016 | (<= score strokes-minimum-match-score)) | 868 | (<= score strokes-minimum-match-score)) |
| 1017 | (and (strokes-click-p stroke) | ||
| 1018 | strokes-click-command)) | ||
| 1019 | (message "That stroke maps to `%s'" command) | 869 | (message "That stroke maps to `%s'" command) |
| 1020 | (message "That stroke is undefined")) | 870 | (message "That stroke is undefined")) |
| 1021 | (sleep-for 1))) ; helpful for recursive edits | 871 | (sleep-for 1))) ; helpful for recursive edits |
| 1022 | 872 | ||
| 1023 | ;;;###autoload | 873 | ;;;###autoload |
| 1024 | (defalias 'describe-stroke 'strokes-describe-stroke) | ||
| 1025 | |||
| 1026 | ;;;###autoload | ||
| 1027 | (defun strokes-help () | 874 | (defun strokes-help () |
| 1028 | "Get instructional help on using the `strokes' package." | 875 | "Get instruction on using the `strokes' package." |
| 1029 | (interactive) | 876 | (interactive) |
| 1030 | (let ((helpdoc | 877 | (with-output-to-temp-buffer "*Help with Strokes*" |
| 1031 | "This is help for the strokes package. | 878 | (princ |
| 1032 | 879 | "This is help for the strokes package. | |
| 1033 | If you find something wrong with strokes, or feel that it can be | ||
| 1034 | improved in some way, then please feel free to email me: | ||
| 1035 | |||
| 1036 | David Bakhash <cadet@mit.edu> | ||
| 1037 | |||
| 1038 | or just do | ||
| 1039 | |||
| 1040 | M-x strokes-report-bug | ||
| 1041 | 880 | ||
| 1042 | ------------------------------------------------------------ | 881 | ------------------------------------------------------------ |
| 1043 | 882 | ||
| @@ -1051,7 +890,7 @@ right every time. | |||
| 1051 | 890 | ||
| 1052 | Strokes also allows you to compose documents graphically. You can | 891 | Strokes also allows you to compose documents graphically. You can |
| 1053 | fully edit documents in Chinese, Japanese, etc. based on Emacs | 892 | fully edit documents in Chinese, Japanese, etc. based on Emacs |
| 1054 | strokes. Once you've done so, you can ascii compress-and-encode them | 893 | strokes. Once you've done so, you can ASCII compress-and-encode them |
| 1055 | and then safely save them for later use, send letters to friends | 894 | and then safely save them for later use, send letters to friends |
| 1056 | \(using Emacs, of course). Strokes will later decode these documents, | 895 | \(using Emacs, of course). Strokes will later decode these documents, |
| 1057 | extracting the strokes for editing use once again, so the editing | 896 | extracting the strokes for editing use once again, so the editing |
| @@ -1072,16 +911,16 @@ To toggle strokes-mode, you just do | |||
| 1072 | 911 | ||
| 1073 | When you're ready to start defining strokes, just use the command | 912 | When you're ready to start defining strokes, just use the command |
| 1074 | 913 | ||
| 1075 | > M-x global-set-stroke | 914 | > M-x strokes-global-set-stroke |
| 1076 | 915 | ||
| 1077 | You will see a ` *strokes*' buffer which is waiting for you to enter in | 916 | You will see a ` *strokes*' buffer which is waiting for you to enter in |
| 1078 | your stroke. When you enter in the stroke, you draw with button1 or | 917 | your stroke. When you enter in the stroke, you draw with button 1 or |
| 1079 | button2, and then end with button3. Next, you enter in the command | 918 | button 2, and then end with button 3. Next, you enter in the command |
| 1080 | which will be executed when that stroke is invoked. Simple as that. | 919 | which will be executed when that stroke is invoked. Simple as that. |
| 1081 | For now, try to define a stroke to copy a region. This is a popular | 920 | For now, try to define a stroke to copy a region. This is a popular |
| 1082 | edit command, so type | 921 | edit command, so type |
| 1083 | 922 | ||
| 1084 | > M-x global-set-stroke | 923 | > M-x strokes-global-set-stroke |
| 1085 | 924 | ||
| 1086 | Then, in the ` *strokes*' buffer, draw the letter `C' (for `copy') | 925 | Then, in the ` *strokes*' buffer, draw the letter `C' (for `copy') |
| 1087 | and then, when it asks you to enter the command to map that to, type | 926 | and then, when it asks you to enter the command to map that to, type |
| @@ -1089,21 +928,18 @@ and then, when it asks you to enter the command to map that to, type | |||
| 1089 | > copy-region-as-kill | 928 | > copy-region-as-kill |
| 1090 | 929 | ||
| 1091 | That's about as hard as it gets. | 930 | That's about as hard as it gets. |
| 1092 | Remember: paint with button1 or button2 and then end with button3. | 931 | Remember: paint with button 1 or button 2 and then end with button 3. |
| 1093 | 932 | ||
| 1094 | If ever you want to know what a certain strokes maps to, then do | 933 | If ever you want to know what a certain strokes maps to, then do |
| 1095 | 934 | ||
| 1096 | > M-x describe-stroke | 935 | > M-x strokes-describe-stroke |
| 1097 | 936 | ||
| 1098 | and you can enter in any arbitrary stroke. Remember: The strokes | 937 | and you can enter in any arbitrary stroke. Remember: The strokes |
| 1099 | package lets you program in simple and complex (multi-lift) strokes. | 938 | package lets you program in simple and complex (multi-lift) strokes. |
| 1100 | The only difference is how you *invoke* the two. You will most likely | 939 | The only difference is how you *invoke* the two. You will most likely |
| 1101 | use simple strokes, as complex strokes were developed for | 940 | use simple strokes, as complex strokes were developed for |
| 1102 | Chinese/Japanese/Korean. So the middle mouse button (mouse-2) will | 941 | Chinese/Japanese/Korean. So the shifted middle mouse button (S-mouse-2) will |
| 1103 | invoke the command `strokes-do-stroke' in buffers where button2 doesn't | 942 | invoke the command `strokes-do-stroke'. |
| 1104 | already have a meaning other than its original, which is `mouse-yank'. | ||
| 1105 | But don't worry: `mouse-yank' will still work with strokes. See the | ||
| 1106 | variable `strokes-click-command'. | ||
| 1107 | 943 | ||
| 1108 | If ever you define a stroke which you don't like, then you can unset | 944 | If ever you define a stroke which you don't like, then you can unset |
| 1109 | it with the command | 945 | it with the command |
| @@ -1130,24 +966,23 @@ You can change this location by setting the variable `strokes-file'. | |||
| 1130 | You will be prompted to save them when you exit Emacs, or you can save | 966 | You will be prompted to save them when you exit Emacs, or you can save |
| 1131 | them with | 967 | them with |
| 1132 | 968 | ||
| 1133 | > M-x save-strokes | 969 | > M-x strokes-save-strokes |
| 1134 | 970 | ||
| 1135 | Your strokes get loaded automatically when you enable `strokes-mode'. | 971 | Your strokes get loaded automatically when you enable `strokes-mode'. |
| 1136 | You can also load in your user-defined strokes with | 972 | You can also load in your user-defined strokes with |
| 1137 | 973 | ||
| 1138 | > M-x load-user-strokes | 974 | > M-x strokes-load-user-strokes |
| 1139 | 975 | ||
| 1140 | ** Strokes for pictographic editing... | 976 | ** Strokes for pictographic editing... |
| 1141 | 977 | ||
| 1142 | If you'd like to create graphical files with strokes, you'll have to | 978 | If you'd like to create graphical files with strokes, you'll have to |
| 1143 | be running a version of Emacs with XPM support. You use the | 979 | be running a version of Emacs with XPM support. You use the binding |
| 1144 | binding C-mouse-2 to start drawing your strokes. These are just | 980 | to `strokes-compose-complex-stroke' to start drawing your strokes. |
| 1145 | complex strokes, and thus you continue drawing with mouse-1 or mouse-2 and | 981 | These are just complex strokes, and thus continue drawing with mouse-1 |
| 1146 | end with mouse-3-3. Then the stroke image gets inserted into the | 982 | or mouse-2 and end with mouse-3. Then the stroke image gets inserted |
| 1147 | buffer. You treat it like any other character, which you can copy, | 983 | into the buffer. You treat it somewhat like any other character, |
| 1148 | paste, delete, move, etc. The command which is bound to C-mouse-2 is | 984 | which you can copy, paste, delete, move, etc. When all is done, you |
| 1149 | called `strokes-compose-complex-stroke'. When all is done, you may | 985 | may want to send the file, or save it. This is done with |
| 1150 | want to send the file, or save it. This is done with | ||
| 1151 | 986 | ||
| 1152 | > M-x strokes-encode-buffer | 987 | > M-x strokes-encode-buffer |
| 1153 | 988 | ||
| @@ -1164,47 +999,17 @@ o The command `strokes-do-complex-stroke' is invoked with M-mouse-2, | |||
| 1164 | o Strokes are a bit computer-dependent in that they depend somewhat on | 999 | o Strokes are a bit computer-dependent in that they depend somewhat on |
| 1165 | the speed of the computer you're working on. This means that you | 1000 | the speed of the computer you're working on. This means that you |
| 1166 | may have to tweak some variables. You can read about them in the | 1001 | may have to tweak some variables. You can read about them in the |
| 1167 | commentary of `strokes.el'. Better to just use apropos and read their | 1002 | commentary of `strokes.el'. Better to just use \\[apropos] and read their |
| 1168 | docstrings. All variables/functions start with `strokes'. The one | 1003 | docstrings. All variables/functions start with `strokes'. The one |
| 1169 | variable which many people wanted to see was | 1004 | variable which many people wanted to see was |
| 1170 | `strokes-use-strokes-buffer' which allows the user to use strokes | 1005 | `strokes-use-strokes-buffer' which allows the user to use strokes |
| 1171 | silently--without displaying the strokes. All variables can be set | 1006 | silently--without displaying the strokes. All variables can be set |
| 1172 | by customizing the group named `strokes' via the customization package: | 1007 | by customizing the group `strokes' via \[customize-group].") |
| 1173 | 1008 | (set-buffer standard-output) | |
| 1174 | > M-x customize")) | 1009 | (help-mode)) |
| 1175 | (with-output-to-temp-buffer "*Help with Strokes*" | 1010 | (print-help-return-message)) |
| 1176 | (princ helpdoc) | ||
| 1177 | (set-buffer standard-output) | ||
| 1178 | (help-mode) | ||
| 1179 | (print-help-return-message)))) | ||
| 1180 | 1011 | ||
| 1181 | (defun strokes-report-bug () | 1012 | (defalias 'strokes-report-bug 'report-emacs-bug) |
| 1182 | "Submit a bug report for strokes." | ||
| 1183 | (interactive) | ||
| 1184 | (let ((reporter-prompt-for-summary-p t)) | ||
| 1185 | (reporter-submit-bug-report | ||
| 1186 | strokes-bug-address "Strokes" | ||
| 1187 | (cons | ||
| 1188 | 'strokes-version | ||
| 1189 | (nconc | ||
| 1190 | (mapcar | ||
| 1191 | 'intern | ||
| 1192 | (sort | ||
| 1193 | (let (completion-ignore-case) | ||
| 1194 | (all-completions "strokes-" obarray 'user-variable-p)) | ||
| 1195 | 'string-lessp)) | ||
| 1196 | (list 'reporter-version))) | ||
| 1197 | (function | ||
| 1198 | (lambda () | ||
| 1199 | (save-excursion | ||
| 1200 | (mail-position-on-field "subject") | ||
| 1201 | (beginning-of-line) | ||
| 1202 | (skip-chars-forward "^:\n") | ||
| 1203 | (if (looking-at ": Strokes;") | ||
| 1204 | (progn | ||
| 1205 | (goto-char (match-end 0)) | ||
| 1206 | (delete-char -1) | ||
| 1207 | (insert " " strokes-version " bug:"))))))))) | ||
| 1208 | 1013 | ||
| 1209 | (defsubst strokes-fill-current-buffer-with-whitespace () | 1014 | (defsubst strokes-fill-current-buffer-with-whitespace () |
| 1210 | "Erase the contents of the current buffer and fill it with whitespace." | 1015 | "Erase the contents of the current buffer and fill it with whitespace." |
| @@ -1216,7 +1021,7 @@ o Strokes are a bit computer-dependent in that they depend somewhat on | |||
| 1216 | 1021 | ||
| 1217 | (defun strokes-window-configuration-changed-p () | 1022 | (defun strokes-window-configuration-changed-p () |
| 1218 | "Non-nil if the `strokes-window-configuration' frame properties changed. | 1023 | "Non-nil if the `strokes-window-configuration' frame properties changed. |
| 1219 | This is based on the last time the `strokes-window-configuration was updated." | 1024 | This is based on the last time `strokes-window-configuration' was updated." |
| 1220 | (compare-window-configurations (current-window-configuration) | 1025 | (compare-window-configurations (current-window-configuration) |
| 1221 | strokes-window-configuration)) | 1026 | strokes-window-configuration)) |
| 1222 | 1027 | ||
| @@ -1271,9 +1076,6 @@ This is based on the last time the `strokes-window-configuration was updated." | |||
| 1271 | (t | 1076 | (t |
| 1272 | (message "No user-defined strokes, sorry")))) | 1077 | (message "No user-defined strokes, sorry")))) |
| 1273 | 1078 | ||
| 1274 | ;;;###autoload | ||
| 1275 | (defalias 'load-user-strokes 'strokes-load-user-strokes) | ||
| 1276 | |||
| 1277 | (defun strokes-prompt-user-save-strokes () | 1079 | (defun strokes-prompt-user-save-strokes () |
| 1278 | "Save user-defined strokes to file named by `strokes-file'." | 1080 | "Save user-defined strokes to file named by `strokes-file'." |
| 1279 | (interactive) | 1081 | (interactive) |
| @@ -1295,12 +1097,12 @@ This is based on the last time the `strokes-window-configuration was updated." | |||
| 1295 | (emacs-lisp-mode) | 1097 | (emacs-lisp-mode) |
| 1296 | (goto-char (point-min)) | 1098 | (goto-char (point-min)) |
| 1297 | (insert | 1099 | (insert |
| 1298 | ";; -*- Syntax: Emacs-Lisp; Mode: emacs-lisp -*-\n") | 1100 | ";; -*- emacs-lisp -*-\n") |
| 1299 | (insert (format ";;; saved strokes for %s, as of %s\n\n" | 1101 | (insert (format ";;; saved strokes for %s, as of %s\n\n" |
| 1300 | (user-full-name) | 1102 | (user-full-name) |
| 1301 | (format-time-string "%B %e, %Y" nil))) | 1103 | (format-time-string "%B %e, %Y" nil))) |
| 1302 | (message "Saving strokes in %s..." strokes-file) | 1104 | (message "Saving strokes in %s..." strokes-file) |
| 1303 | (insert (format "(setq strokes-global-map '%s)" | 1105 | (insert (format "(setq strokes-global-map\n'%s)" |
| 1304 | (pp current))) | 1106 | (pp current))) |
| 1305 | (message "Saving strokes in %s..." strokes-file) | 1107 | (message "Saving strokes in %s..." strokes-file) |
| 1306 | (indent-region (point-min) (point-max) nil) | 1108 | (indent-region (point-min) (point-max) nil) |
| @@ -1313,11 +1115,9 @@ This is based on the last time the `strokes-window-configuration was updated." | |||
| 1313 | (kill-buffer (get-buffer "*saved-strokes*"))) | 1115 | (kill-buffer (get-buffer "*saved-strokes*"))) |
| 1314 | (setq strokes-global-map current))))) | 1116 | (setq strokes-global-map current))))) |
| 1315 | 1117 | ||
| 1316 | (defalias 'save-strokes 'strokes-prompt-user-save-strokes) | ||
| 1317 | |||
| 1318 | (defun strokes-toggle-strokes-buffer (&optional arg) | 1118 | (defun strokes-toggle-strokes-buffer (&optional arg) |
| 1319 | "Toggle the use of the strokes buffer. | 1119 | "Toggle the use of the strokes buffer. |
| 1320 | In other words, toggle the variabe `strokes-use-strokes-buffer'. | 1120 | In other words, toggle the variable `strokes-use-strokes-buffer'. |
| 1321 | With ARG, use strokes buffer if and only if ARG is positive or true. | 1121 | With ARG, use strokes buffer if and only if ARG is positive or true. |
| 1322 | Returns value of `strokes-use-strokes-buffer'." | 1122 | Returns value of `strokes-use-strokes-buffer'." |
| 1323 | (interactive "P") | 1123 | (interactive "P") |
| @@ -1326,7 +1126,7 @@ Returns value of `strokes-use-strokes-buffer'." | |||
| 1326 | (not strokes-use-strokes-buffer)))) | 1126 | (not strokes-use-strokes-buffer)))) |
| 1327 | 1127 | ||
| 1328 | (defun strokes-xpm-for-stroke (&optional stroke bufname b/w-only) | 1128 | (defun strokes-xpm-for-stroke (&optional stroke bufname b/w-only) |
| 1329 | "Create an xpm pixmap for the given STROKE in buffer ` *strokes-xpm*'. | 1129 | "Create an XPM pixmap for the given STROKE in buffer ` *strokes-xpm*'. |
| 1330 | If STROKE is not supplied, then `strokes-last-stroke' will be used. | 1130 | If STROKE is not supplied, then `strokes-last-stroke' will be used. |
| 1331 | Optional BUFNAME to name something else. | 1131 | Optional BUFNAME to name something else. |
| 1332 | The pixmap will contain time information via rainbow dot colors | 1132 | The pixmap will contain time information via rainbow dot colors |
| @@ -1366,15 +1166,15 @@ the stroke as a character in some language." | |||
| 1366 | (let ((char (or (car rainbow-chars) ?\.))) | 1166 | (let ((char (or (car rainbow-chars) ?\.))) |
| 1367 | (loop for i from 0 to 2 do | 1167 | (loop for i from 0 to 2 do |
| 1368 | (loop for j from 0 to 2 do | 1168 | (loop for j from 0 to 2 do |
| 1369 | (goto-line (+ 16 i y)) | 1169 | (goto-line (+ 16 i y)) |
| 1370 | (forward-char (+ 1 j x)) | 1170 | (forward-char (+ 1 j x)) |
| 1371 | (delete-char 1) | 1171 | (delete-char 1) |
| 1372 | (insert char))) | 1172 | (insert char))) |
| 1373 | (setq rainbow-chars (cdr rainbow-chars) | 1173 | (setq rainbow-chars (cdr rainbow-chars) |
| 1374 | lift-flag nil)) | 1174 | lift-flag nil)) |
| 1375 | ;; Otherwise, just plot the point... | 1175 | ;; Otherwise, just plot the point... |
| 1376 | (goto-line (+ 17 y)) | 1176 | (goto-line (+ 17 y)) |
| 1377 | (forward-char (+ 2 x)) | 1177 | (forward-char (+ 2 x)) |
| 1378 | (subst-char-in-region (point) (1+ (point)) ?\ ?\*))) | 1178 | (subst-char-in-region (point) (1+ (point)) ?\ ?\*))) |
| 1379 | ((strokes-lift-p point) | 1179 | ((strokes-lift-p point) |
| 1380 | ;; a lift--tell the loop to X out the next point... | 1180 | ;; a lift--tell the loop to X out the next point... |
| @@ -1386,7 +1186,7 @@ the stroke as a character in some language." | |||
| 1386 | (put-image (create-image (buffer-string) 'xpm t :ascent 100) | 1186 | (put-image (create-image (buffer-string) 'xpm t :ascent 100) |
| 1387 | (line-end-position)))))) | 1187 | (line-end-position)))))) |
| 1388 | 1188 | ||
| 1389 | ;;; Strokes Edit stuff... ### NOT IMLEMENTED YET ### | 1189 | ;;; Strokes Edit stuff... ### NOT IMPLEMENTED YET ### |
| 1390 | 1190 | ||
| 1391 | ;;(defun strokes-edit-quit () | 1191 | ;;(defun strokes-edit-quit () |
| 1392 | ;; (interactive) | 1192 | ;; (interactive) |
| @@ -1545,65 +1345,50 @@ If STROKES-MAP is not given, `strokes-global-map' will be used instead." | |||
| 1545 | (command-name-2 (symbol-name (cdr stroke2)))) | 1345 | (command-name-2 (symbol-name (cdr stroke2)))) |
| 1546 | (string-lessp command-name-1 command-name-2))) | 1346 | (string-lessp command-name-1 command-name-2))) |
| 1547 | 1347 | ||
| 1548 | ;;;###autoload | 1348 | (defvar strokes-mode-map |
| 1549 | (defun strokes-mode (&optional arg) | 1349 | (let ((map (make-sparse-keymap))) |
| 1550 | "Toggle strokes being enabled. | 1350 | (define-key map [(shift down-mouse-2)] 'strokes-do-stroke) |
| 1551 | With ARG, turn strokes on if and only if ARG is positive or true. | 1351 | (define-key map [(meta down-mouse-2)] 'strokes-do-complex-stroke) |
| 1552 | Note that `strokes-mode' is a global mode. Think of it as a minor | 1352 | map)) |
| 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 | 1353 | ||
| 1557 | > M-x global-set-stroke | 1354 | ;;;###autoload |
| 1355 | (define-minor-mode strokes-mode | ||
| 1356 | "Toggle Strokes global minor mode.\\<strokes-mode-map> | ||
| 1357 | With ARG, turn strokes on if and only if ARG is positive. | ||
| 1358 | Strokes are pictographic mouse gestures which invoke commands. | ||
| 1359 | Strokes are invoked with \\[strokes-do-stroke]. You can define | ||
| 1360 | new strokes with \\[strokes-global-set-stroke]. See also | ||
| 1361 | \\[strokes-do-complex-stroke] for `complex' strokes. | ||
| 1558 | 1362 | ||
| 1559 | To use strokes for pictographic editing, such as Chinese/Japanese, use | 1363 | To use strokes for pictographic editing, such as Chinese/Japanese, use |
| 1560 | S-mouse-2, which draws strokes and inserts them. Encode/decode your | 1364 | \\[strokes-compose-complex-stroke], which draws strokes and inserts them. |
| 1561 | strokes with | 1365 | Encode/decode your strokes with \\[strokes-encode-buffer], |
| 1366 | \\[strokes-decode-buffer]. | ||
| 1367 | |||
| 1368 | \\{strokes-mode-map}" | ||
| 1369 | nil strokes-modeline-string strokes-mode-map | ||
| 1370 | :group 'strokes :global t | ||
| 1371 | (cond ((not (display-mouse-p)) | ||
| 1372 | (error "Can't use Strokes without a mouse")) | ||
| 1373 | (strokes-mode ; turn on strokes | ||
| 1374 | (and (file-exists-p strokes-file) | ||
| 1375 | (null strokes-global-map) | ||
| 1376 | (strokes-load-user-strokes)) | ||
| 1377 | (add-hook 'kill-emacs-query-functions | ||
| 1378 | 'strokes-prompt-user-save-strokes) | ||
| 1379 | (add-hook 'select-frame-hook | ||
| 1380 | 'strokes-update-window-configuration) | ||
| 1381 | (strokes-update-window-configuration)) | ||
| 1382 | (t ; turn off strokes | ||
| 1383 | (if (get-buffer strokes-buffer-name) | ||
| 1384 | (kill-buffer (get-buffer strokes-buffer-name))) | ||
| 1385 | (remove-hook 'select-frame-hook | ||
| 1386 | 'strokes-update-window-configuration)))) | ||
| 1562 | 1387 | ||
| 1563 | > M-x strokes-encode-buffer | ||
| 1564 | > M-x strokes-decode-buffer" | ||
| 1565 | (interactive "P") | ||
| 1566 | (let ((on-p (if arg | ||
| 1567 | (> (prefix-numeric-value arg) 0) | ||
| 1568 | (not strokes-mode)))) | ||
| 1569 | (cond ((not (display-mouse-p)) | ||
| 1570 | (error "Can't use strokes without a mouse")) | ||
| 1571 | (on-p ; turn on strokes | ||
| 1572 | (strokes-insinuate) ; make sure defadvices are set | ||
| 1573 | (and (file-exists-p strokes-file) | ||
| 1574 | (null strokes-global-map) | ||
| 1575 | (strokes-load-user-strokes)) | ||
| 1576 | (add-hook 'kill-emacs-query-functions | ||
| 1577 | 'strokes-prompt-user-save-strokes) | ||
| 1578 | (add-hook 'select-frame-hook | ||
| 1579 | 'strokes-update-window-configuration) | ||
| 1580 | (strokes-update-window-configuration) | ||
| 1581 | (define-key global-map [(down-mouse-2)] 'strokes-do-stroke) | ||
| 1582 | (define-key global-map [(meta down-mouse-2)] | ||
| 1583 | 'strokes-do-complex-stroke) | ||
| 1584 | ;; (define-key global-map [(control down-mouse-2)] 'strokes-do-complex-stroke) | ||
| 1585 | (ad-activate-regexp "^strokes-") ; advise button2 commands | ||
| 1586 | (setq strokes-mode t)) | ||
| 1587 | (t ; turn off strokes | ||
| 1588 | (if (get-buffer strokes-buffer-name) | ||
| 1589 | (kill-buffer (get-buffer strokes-buffer-name))) | ||
| 1590 | (remove-hook 'select-frame-hook | ||
| 1591 | 'strokes-update-window-configuration) | ||
| 1592 | (if (string-match "^strokes-" (symbol-name (key-binding [(down-mouse-2)]))) | ||
| 1593 | (define-key global-map [(down-mouse-2)] strokes-click-command)) | ||
| 1594 | (if (string-match "^strokes-" (symbol-name (key-binding [(meta down-mouse-2)]))) | ||
| 1595 | (global-unset-key [(meta down-mouse-2)])) | ||
| 1596 | (if (string-match "^strokes-" (symbol-name (key-binding [(control down-mouse-2)]))) | ||
| 1597 | (global-unset-key [(control down-mouse-2)])) | ||
| 1598 | ;; (if (string-match "^strokes-" (symbol-name (key-binding [(shift button2)]))) | ||
| 1599 | ;; (global-unset-key [(shift button2)])) | ||
| 1600 | (ad-deactivate-regexp "^strokes-") ; unadvise strokes-button2 commands | ||
| 1601 | (setq strokes-mode nil)))) | ||
| 1602 | (force-mode-line-update)) | ||
| 1603 | 1388 | ||
| 1604 | ;;;; strokes-xpm stuff (later may be separate)... | 1389 | ;;;; strokes-xpm stuff (later may be separate)... |
| 1605 | 1390 | ||
| 1606 | ;; This is the stuff that will eventuall be used for composing letters in | 1391 | ;; This is the stuff that will eventually be used for composing letters in |
| 1607 | ;; any language, compression, decompression, graphics, editing, etc. | 1392 | ;; any language, compression, decompression, graphics, editing, etc. |
| 1608 | 1393 | ||
| 1609 | (defface strokes-char-face '((t (:background "lightgray"))) | 1394 | (defface strokes-char-face '((t (:background "lightgray"))) |
| @@ -1679,7 +1464,7 @@ strokes with | |||
| 1679 | 1464 | ||
| 1680 | (defconst strokes-base64-chars | 1465 | (defconst strokes-base64-chars |
| 1681 | ;; I wanted to make this a vector of individual like (vector ?0 | 1466 | ;; I wanted to make this a vector of individual like (vector ?0 |
| 1682 | ;; ?1 ?2 ...), but `concat' in XEmacs-20.* refuses to accept single | 1467 | ;; ?1 ?2 ...), but `concat' refuses to accept single |
| 1683 | ;; characters. | 1468 | ;; characters. |
| 1684 | (vector "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" | 1469 | (vector "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" |
| 1685 | "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" | 1470 | "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" |
| @@ -1696,11 +1481,11 @@ strokes with | |||
| 1696 | "Character vector for fast lookup of base-64 encoding of numbers in [0,61].") | 1481 | "Character vector for fast lookup of base-64 encoding of numbers in [0,61].") |
| 1697 | 1482 | ||
| 1698 | (defsubst strokes-xpm-char-on-p (char) | 1483 | (defsubst strokes-xpm-char-on-p (char) |
| 1699 | "Non-nil if CHAR represents an `on' bit in the xpm." | 1484 | "Non-nil if CHAR represents an `on' bit in the XPM." |
| 1700 | (eq char ?*)) | 1485 | (eq char ?*)) |
| 1701 | 1486 | ||
| 1702 | (defsubst strokes-xpm-char-bit-p (char) | 1487 | (defsubst strokes-xpm-char-bit-p (char) |
| 1703 | "Non-nil if CHAR represents an `on' or `off' bit in the xpm." | 1488 | "Non-nil if CHAR represents an `on' or `off' bit in the XPM." |
| 1704 | (or (eq char ?\ ) | 1489 | (or (eq char ?\ ) |
| 1705 | (eq char ?*))) | 1490 | (eq char ?*))) |
| 1706 | 1491 | ||
| @@ -1711,7 +1496,7 @@ strokes with | |||
| 1711 | ;; (eq (null a) (not (null b)))) | 1496 | ;; (eq (null a) (not (null b)))) |
| 1712 | 1497 | ||
| 1713 | (defsubst strokes-xpm-encode-length-as-string (length) | 1498 | (defsubst strokes-xpm-encode-length-as-string (length) |
| 1714 | "Given some LENGTH in [0,62) do a fast lookup of it's encoding." | 1499 | "Given some LENGTH in [0,62) do a fast lookup of its encoding." |
| 1715 | (aref strokes-base64-chars length)) | 1500 | (aref strokes-base64-chars length)) |
| 1716 | 1501 | ||
| 1717 | (defsubst strokes-xpm-decode-char (character) | 1502 | (defsubst strokes-xpm-decode-char (character) |
| @@ -1719,10 +1504,10 @@ strokes with | |||
| 1719 | (aref strokes-char-table character)) | 1504 | (aref strokes-char-table character)) |
| 1720 | 1505 | ||
| 1721 | (defun strokes-xpm-to-compressed-string (&optional xpm-buffer) | 1506 | (defun strokes-xpm-to-compressed-string (&optional xpm-buffer) |
| 1722 | "Convert the xpm in XPM-BUFFER into a compressed string representing the stroke. | 1507 | "Convert XPM in XPM-BUFFER to compressed string representing the stroke. |
| 1723 | XPM-BUFFER is an optional argument, and defaults to `*strokes-xpm*'." | 1508 | XPM-BUFFER defaults to ` *strokes-xpm*'." |
| 1724 | (save-excursion | 1509 | (save-excursion |
| 1725 | (set-buffer (setq xpm-buffer (or xpm-buffer "*strokes-xpm*"))) | 1510 | (set-buffer (setq xpm-buffer (or xpm-buffer " *strokes-xpm*"))) |
| 1726 | (goto-char (point-min)) | 1511 | (goto-char (point-min)) |
| 1727 | (search-forward "/* pixels */") ; skip past header junk | 1512 | (search-forward "/* pixels */") ; skip past header junk |
| 1728 | (forward-char 2) | 1513 | (forward-char 2) |
| @@ -1742,19 +1527,19 @@ XPM-BUFFER is an optional argument, and defaults to `*strokes-xpm*'." | |||
| 1742 | ;; check to see if the `char-at-point' is an actual pixmap bit | 1527 | ;; check to see if the `char-at-point' is an actual pixmap bit |
| 1743 | (when (strokes-xpm-char-bit-p char-at-point) | 1528 | (when (strokes-xpm-char-bit-p char-at-point) |
| 1744 | (setq count 1 | 1529 | (setq count 1 |
| 1745 | current-char-is-on-p (strokes-xpm-char-on-p char-at-point))) | 1530 | current-char-is-on-p (strokes-xpm-char-on-p char-at-point))) |
| 1746 | (forward-char 1)) | 1531 | (forward-char 1)) |
| 1747 | ((= count 61) ; maximum single char's | 1532 | ((= count 61) ; maximum single char's |
| 1748 | ; encoding length | 1533 | ; encoding length |
| 1749 | (setq compressed-string (concat compressed-string | 1534 | (setq compressed-string |
| 1750 | ;; add a zero-length | 1535 | (concat compressed-string |
| 1751 | ;; encoding when | 1536 | ;; add a zero-length encoding when |
| 1752 | ;; necessary | 1537 | ;; necessary |
| 1753 | (when (eq last-char-was-on-p | 1538 | (when (eq last-char-was-on-p |
| 1754 | current-char-is-on-p) | 1539 | current-char-is-on-p) |
| 1755 | ;; "0" | 1540 | ;; "0" |
| 1756 | (strokes-xpm-encode-length-as-string 0)) | 1541 | (strokes-xpm-encode-length-as-string 0)) |
| 1757 | (strokes-xpm-encode-length-as-string 61)) | 1542 | (strokes-xpm-encode-length-as-string 61)) |
| 1758 | last-char-was-on-p current-char-is-on-p | 1543 | last-char-was-on-p current-char-is-on-p |
| 1759 | count 0)) ; note that we just set | 1544 | count 0)) ; note that we just set |
| 1760 | ; count=0 and *don't* advance | 1545 | ; count=0 and *don't* advance |
| @@ -1774,15 +1559,15 @@ XPM-BUFFER is an optional argument, and defaults to `*strokes-xpm*'." | |||
| 1774 | ;; iteration go through and letting the case: count=0 | 1559 | ;; iteration go through and letting the case: count=0 |
| 1775 | ;; take care of this stuff for me. That's why | 1560 | ;; take care of this stuff for me. That's why |
| 1776 | ;; there's no (forward-char 1) below. | 1561 | ;; there's no (forward-char 1) below. |
| 1777 | (setq compressed-string (concat compressed-string | 1562 | (setq compressed-string |
| 1778 | ;; add a zero-length | 1563 | (concat compressed-string |
| 1779 | ;; encoding when | 1564 | ;; add a zero-length encoding when |
| 1780 | ;; necessary | 1565 | ;; necessary |
| 1781 | (when (eq last-char-was-on-p | 1566 | (when (eq last-char-was-on-p |
| 1782 | current-char-is-on-p) | 1567 | current-char-is-on-p) |
| 1783 | ;; "0" | 1568 | ;; "0" |
| 1784 | (strokes-xpm-encode-length-as-string 0)) | 1569 | (strokes-xpm-encode-length-as-string 0)) |
| 1785 | (strokes-xpm-encode-length-as-string count)) | 1570 | (strokes-xpm-encode-length-as-string count)) |
| 1786 | count 0 | 1571 | count 0 |
| 1787 | last-char-was-on-p current-char-is-on-p))) | 1572 | last-char-was-on-p current-char-is-on-p))) |
| 1788 | (t ; ELSE it's some other useless | 1573 | (t ; ELSE it's some other useless |
| @@ -1816,7 +1601,7 @@ Optional FORCE non-nil will ignore the buffer's read-only status." | |||
| 1816 | (message "Strokifying %s..." buffer) | 1601 | (message "Strokifying %s..." buffer) |
| 1817 | (goto-char (point-min)) | 1602 | (goto-char (point-min)) |
| 1818 | (let (ext string image) | 1603 | (let (ext string image) |
| 1819 | ;; The comment below is what i'd have to do if I wanted to | 1604 | ;; The comment below is what I'd have to do if I wanted to |
| 1820 | ;; deal with random newlines in the midst of the compressed | 1605 | ;; deal with random newlines in the midst of the compressed |
| 1821 | ;; strings. If I do this, I'll also have to change | 1606 | ;; strings. If I do this, I'll also have to change |
| 1822 | ;; `strokes-xpm-to-compress-string' to deal with the newline, | 1607 | ;; `strokes-xpm-to-compress-string' to deal with the newline, |
| @@ -1840,7 +1625,7 @@ Optional FORCE non-nil will ignore the buffer's read-only status." | |||
| 1840 | (message "Strokifying %s...done" buffer))))) | 1625 | (message "Strokifying %s...done" buffer))))) |
| 1841 | 1626 | ||
| 1842 | (defun strokes-encode-buffer (&optional buffer force) | 1627 | (defun strokes-encode-buffer (&optional buffer force) |
| 1843 | "Convert the glyphs in BUFFER to thier base-64 ASCII representations. | 1628 | "Convert the glyphs in BUFFER to their base-64 ASCII representations. |
| 1844 | Optional BUFFER defaults to the current buffer. | 1629 | Optional BUFFER defaults to the current buffer. |
| 1845 | Optional FORCE non-nil will ignore the buffer's read-only status." | 1630 | Optional FORCE non-nil will ignore the buffer's read-only status." |
| 1846 | ;; ### NOTE !!! ### (for me) | 1631 | ;; ### NOTE !!! ### (for me) |
| @@ -1889,10 +1674,10 @@ Optional FORCE non-nil will ignore the buffer's read-only status." | |||
| 1889 | (message "Encoding strokes in %s...done" buffer))))) | 1674 | (message "Encoding strokes in %s...done" buffer))))) |
| 1890 | 1675 | ||
| 1891 | (defun strokes-xpm-for-compressed-string (compressed-string &optional bufname) | 1676 | (defun strokes-xpm-for-compressed-string (compressed-string &optional bufname) |
| 1892 | "Convert the stroke represented by COMPRESSED-STRING into an xpm. | 1677 | "Convert the stroke represented by COMPRESSED-STRING into an XPM. |
| 1893 | Store xpm in buffer BUFNAME if supplied \(default is `*strokes-xpm*'\)" | 1678 | Store XPM in buffer BUFNAME if supplied \(default is ` *strokes-xpm*'\)" |
| 1894 | (save-excursion | 1679 | (save-excursion |
| 1895 | (or bufname (setq bufname "*strokes-xpm*")) | 1680 | (or bufname (setq bufname " *strokes-xpm*")) |
| 1896 | (set-buffer (get-buffer-create bufname)) | 1681 | (set-buffer (get-buffer-create bufname)) |
| 1897 | (erase-buffer) | 1682 | (erase-buffer) |
| 1898 | (insert compressed-string) | 1683 | (insert compressed-string) |
| @@ -1917,7 +1702,7 @@ Store xpm in buffer BUFNAME if supplied \(default is `*strokes-xpm*'\)" | |||
| 1917 | ;;;###autoload | 1702 | ;;;###autoload |
| 1918 | (defun strokes-compose-complex-stroke () | 1703 | (defun strokes-compose-complex-stroke () |
| 1919 | ;; ### NOTE !!! ### | 1704 | ;; ### NOTE !!! ### |
| 1920 | ;; Even though we have lexical scoping, it's somewhat ugly how I | 1705 | ;; Even though we don't have lexical scoping, it's somewhat ugly how I |
| 1921 | ;; pass around variables in the global name space. I can/should | 1706 | ;; pass around variables in the global name space. I can/should |
| 1922 | ;; change this. | 1707 | ;; change this. |
| 1923 | "Read a complex stroke and insert its glyph into the current buffer." | 1708 | "Read a complex stroke and insert its glyph into the current buffer." |
| @@ -1930,11 +1715,11 @@ Store xpm in buffer BUFNAME if supplied \(default is `*strokes-xpm*'\)" | |||
| 1930 | ;; strokes-decode-buffer does a save-excursion. | 1715 | ;; strokes-decode-buffer does a save-excursion. |
| 1931 | (forward-char))) | 1716 | (forward-char))) |
| 1932 | 1717 | ||
| 1933 | (or (assq 'strokes-mode minor-mode-alist) | 1718 | (defun strokes-unload-hook () |
| 1934 | (setq minor-mode-alist (cons (list 'strokes-mode strokes-modeline-string) | 1719 | (strokes-mode -1) |
| 1935 | minor-mode-alist))) | 1720 | (remove-hook 'kill-emacs-query-functions 'strokes-prompt-user-save-strokes)) |
| 1936 | 1721 | ||
| 1937 | (provide 'strokes) | ||
| 1938 | (run-hooks 'strokes-load-hook) | 1722 | (run-hooks 'strokes-load-hook) |
| 1723 | (provide 'strokes) | ||
| 1939 | 1724 | ||
| 1940 | ;;; strokes.el ends here | 1725 | ;;; strokes.el ends here |