unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* strokes.el revamp
@ 2002-04-30  9:40 Dave Love
  2002-04-30 10:43 ` Colin Marquardt
  0 siblings, 1 reply; 2+ messages in thread
From: Dave Love @ 2002-04-30  9:40 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 326 bytes --]

My previous hack at strokes.el obviously didn't produce something
usable.  The original overloading of mouse-2 just loses and presumably
no-one uses it.  The following seems better and potentially useful for
input of technical characters, for instance.  I suspect the doc and
commentary needs more review than I've given it.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch, Size: 41607 bytes --]

2002-04-28  Dave Love  <fx@gnu.org>

	Make strokes a proper minor mode, and don't try to overload
	mouse-2, which doesn't work satisfactorily.  Use S-mouse-2 instead.

	* strokes.elL 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.
	
===================================================================
RCS file: strokes.el,v
retrieving revision 1.1
diff -u -r1.1 strokes.el
--- strokes.el	2002/04/27 23:58:54	1.1
+++ strokes.el	2002/04/28 17:10:45
@@ -32,20 +32,22 @@
 ;; > M-x strokes-help
 
 ;; and you can learn how to use the package.  A mouse stroke, for now,
-;; can be defined as holding the middle button, for instance, and then
-;; moving the mouse in whatever pattern you wish, which you have set
-;; Emacs to understand as mapping to a given command.  For example, you
-;; may wish the have a mouse stroke that looks like a capital `C' which
-;; means `copy-region-as-kill'.  Treat strokes just like you do key
-;; bindings.  For example, Emacs sets key bindings globally with the
-;; `global-set-key' command.  Likewise, you can do
+;; can be defined as holding the shift key and the middle button, for
+;; instance, and then moving the mouse in whatever pattern you wish,
+;; which you have set Emacs to understand as mapping to a given
+;; command.  For example, you may wish the have a mouse stroke that
+;; looks like a capital `C' which means `copy-region-as-kill'.  Treat
+;; strokes just like you do key bindings.  For example, Emacs sets key
+;; bindings globally with the `global-set-key' command.  Likewise, you
+;; can do
 
-;; > M-x global-set-stroke
+;; > M-x strokes-global-set-stroke
 
 ;; to interactively program in a stroke.  It would be wise to set the
 ;; first one to this very command, so that from then on, you invoke
-;; `global-set-stroke' with a stroke.  likewise, there may eventually
-;; be a `local-set-stroke' command, also analogous to `local-set-key'.
+;; `strokes-global-set-stroke' with a stroke.  Likewise, there may
+;; eventually be a `strokes-local-set-stroke' command, also analogous
+;; to `local-set-key'.
 
 ;; You can always unset the last stroke definition with the command
 
@@ -58,19 +60,19 @@
 
 ;;    1) To describe a stroke binding, you can type
 
-;;       > M-x describe-stroke
+;;       > M-x strokes-describe-stroke
 
 ;;       analogous to `describe-key'.  It's also wise to have a stroke,
 ;;       like an `h', for help, or a `?', mapped to `describe-stroke'.
 
 ;;    2) stroke bindings are set internally through the Lisp function
-;;       `define-stroke', similar to the `define-key' function.  some
-;;       examples for a 3x3 stroke grid would be
+;;       `strokes-define-stroke', similar to the `define-key' function.
+;;       some examples for a 3x3 stroke grid would be
 
-;;       (define-stroke c-mode-stroke-map
+;;       (strokes-define-stroke c-mode-stroke-map
 ;;                      '((0 . 0) (1 . 1) (2 . 2))
 ;;                      'kill-region)
-;;       (define-stroke strokes-global-map
+;;       (strokes-define-stroke strokes-global-map
 ;;                      '((0 . 0) (0 . 1) (0 . 2) (1 . 2) (2 . 2))
 ;;                      'list-buffers)
 
@@ -107,7 +109,7 @@
 ;; computers as well as people who don't want to see their strokes.
 
 ;; If you find that your mouse is accelerating too fast, you can
-;; execute the UNIX X command to slow it down.  A good possibility is
+;; execute an X command to slow it down.  A good possibility is
 
 ;; % xset m 5/4 8
 
@@ -116,7 +118,7 @@
 ;; Whenever you load in the strokes package, you will be able to save
 ;; what you've done upon exiting Emacs.  You can also do
 
-;; > M-x save-strokes
+;; > M-x strokes-propmpt-user-save-strokes
 
 ;; and it will save your strokes in ~/.strokes, or you may wish to change
 ;; this by setting the variable `strokes-file'.
@@ -124,33 +126,20 @@
 ;; Note that internally, all of the routines that are part of this
 ;; package are able to deal with complex strokes, as they are a superset
 ;; of simple strokes.  However, the default of this package will map
-;; mouse button2 to the command `strokes-do-stroke', and NOT
-;; `strokes-do-complex-stroke'.  If you wish to use complex strokes, you
-;; will have to override this key mapping.  Complex strokes are terminated
-;; with mouse button3.  The strokes package will not interfere with
-;; `mouse-yank', but you may want to examine how this is done (see the
-;; variable `strokes-click-command')
-
-;; To get strokes to work as part of your your setup, then you'll have
-;; put the strokes package in your load-path (preferably byte-compiled)
-;; and then add the following to your .emacs file (or wherever
-;; you put Emacs-specific startup preferences):
+;; S-mouse-2 to the command `strokes-do-stroke', and M-mouse-2 to
+;; `strokes-do-complex-stroke'.  Complex strokes are terminated
+;; with mouse button 3.
 
-;;(and window-system
-;;     (require 'strokes))
-
-;; Once loaded, you can start stroking.  You can also toggle between
-;; strokes mode by simple typing
+;; You can also toggle between strokes mode by simple typing
 
 ;; > M-x strokes-mode
 
-;; I am now in the process of porting this package to Emacs.  I also hope
-;; that, with the help of others, this package will be useful in entering
-;; in pictographic-like language text using the mouse (i.e. Korean).
-;; Japanese and Chinese are a bit trickier, but I'm sure that with help
-;; it can be done.  The next version will allow the user to enter strokes
-;; which "remove the pencil from the paper" so to speak, so one character
-;; can have multiple strokes.
+;; I hope that, with the help of others, this package will be useful
+;; in entering in pictographic-like language text using the mouse
+;; (i.e. Korean).  Japanese and Chinese are a bit trickier, but I'm
+;; sure that with help it can be done.  The next version will allow
+;; the user to enter strokes which "remove the pencil from the paper"
+;; so to speak, so one character can have multiple strokes.
 
 ;; You can read more about strokes at:
 
@@ -195,8 +184,6 @@
 
 (defconst strokes-version "2.4-Emacs")
 
-(defconst strokes-bug-address "cadet@alum.mit.edu")
-
 (defconst strokes-lift :strokes-lift
   "Symbol representing a stroke lift event for complex strokes.
 Complex strokes are those which contain two or more simple strokes.")
@@ -216,17 +203,18 @@
 \"P	c #FFFF0000FFFF\",
 \".	c #45458B8B0000\",
 /* pixels */\n"
-  "The header to all xpm buffers created by strokes")
+  "The header to all xpm buffers created by strokes.")
 
 ;;; user variables...
 
 (defgroup strokes nil
   "Control Emacs through mouse strokes"
+  :link '(emacs-commentary-link "strokes")
   :link '(url-link "http://www.mit.edu/people/cadet/strokes-help.html")
   :group 'mouse)
 
 (defcustom strokes-modeline-string " Strokes"
-  "*Modeline identification when strokes-mode is on \(default is \" Strokes\"\)."
+  "*Modeline identification when Strokes mode is on \(default is \" Strokes\"\)."
   :type 'string
   :group 'strokes)
 
@@ -275,10 +263,8 @@
   :type 'file
   :group 'strokes)
 
-(defcustom strokes-buffer-name " *strokes*"
-  "The buffer that the strokes take place in (default is ` *strokes*')."
-  :type 'string
-  :group 'strokes)
+(defvar strokes-buffer-name " *strokes*"
+  "The name of the buffer that the strokes take place in.")
 
 (defcustom strokes-use-strokes-buffer t
   "*If non-nil, the strokes buffer is used and strokes are displayed.
@@ -288,29 +274,8 @@
   :type 'boolean
   :group 'strokes)
 
-(defcustom strokes-click-command 'mouse-yank-at-click
-  "*Command to execute when stroke is actually a `click' event.
-This is set to `mouse-yank-at-click' by default."
-  :type 'function
-  :group 'strokes)
-
 ;;; internal variables...
 
-;; This is an internal variable, but we defcustom it so Customize can
-;; use it.
-;;;###autoload
-(defcustom strokes-mode nil
-  "Non-nil when `strokes' is globally enabled.
-Setting this variable directly does not take effect.  Use either Customize
-or M-x strokes-mode."
-  :type 'boolean
-  :set (lambda (symbol value)
-	 (strokes-mode (or value 0)))
-  :initialize 'custom-initialize-default
-  :require 'strokes
-  :version "21.1"
-  :group 'strokes)
-
 (defvar strokes-window-configuration nil
   "The special window configuration used when entering strokes.
 This is set properly in the function `strokes-update-window-configuration'.")
@@ -345,10 +310,11 @@
 
 ;;; Macros...
 
-(defmacro strokes-while-inhibiting-garbage-collector (&rest forms)
-  "Execute FORMS without interference from the garbage collector."
-  `(let ((gc-cons-threshold 134217727))
-     ,@forms))
+;; unused
+;; (defmacro strokes-while-inhibiting-garbage-collector (&rest forms)
+;;   "Execute FORMS without interference from the garbage collector."
+;;   `(let ((gc-cons-threshold 134217727))
+;;      ,@forms))
 
 (defsubst strokes-click-p (stroke)
   "Non-nil if STROKE is really click."
@@ -372,14 +338,12 @@
 (defmacro strokes-define-stroke (stroke-map stroke def)
   "Add STROKE to STROKE-MAP alist with given command DEF."
   `(if (strokes-click-p ,stroke)
-       (error "That's a click, not a stroke; see `strokes-click-command'")
+       (error "That's a click, not a stroke")
      (setq ,stroke-map (cons (cons ,stroke ,def)
 			     (strokes-remassoc ,stroke ,stroke-map)))))
 
-(defalias 'define-stroke 'strokes-define-stroke)
-
 (defsubst strokes-square (x)
-  "Returns the square of the number X"
+  "Return the square of the number X."
   (* x x))
 
 (defsubst strokes-distance-squared (p1 p2)
@@ -392,105 +356,6 @@
     (+ (strokes-square (- x2 x1))
        (strokes-square (- y2 y1)))))
 
-;;; Advice for various functions...
-
-;; I'd originally wanted to write a macro that would just take in the
-;; generic functions which use mouse button2 in various modes.  Most of
-;; them are identical in form: they take an event as the single argument
-;; and then do their thing.  I tried writing a macro that looked
-;; something like this, but failed.  Advice just ain't that easy.  The
-;; one that bugged me the most was `Manual-follow-xref', because that had
-;; &rest arguments, and I didn't know how to work around it in defadvice.
-;; However, I was able to fix up most of the important modes (i.e. the
-;; ones I use all the time).  One `bug' in the program that I just can't
-;; seem to figure out is why I can only advise other button2 functions
-;; successfully when the variable `strokes-use-strokes-buffer' is nil.  I
-;; did all the save-excursion/save-window-excursion stuff SPECIFICALLY so
-;; that using the strokes buffer or not would absolutely not affect any
-;; other part of the program.  If someone can figure out how to make the
-;; following advices work w/ regardless of that variable
-;; `strokes-use-strokes-buffer', then that would be a great victory.  If
-;; someone out there would be kind enough to make the commented code
-;; below work, I'd be grateful.  By the way, I put the `protect' keywords
-;; there to insure that if a stroke went bad, then
-;; `strokes-click-command' would be set back.  If this isn't necessary,
-;; then feel free to let me know.
-
-;; For what follows, I really wanted something that would work like this:
-
-;;(strokes-fix-button2 'vm-mouse-button-2)
-
-;; Or even better, I could have simply done something like:
-
-;;(mapcar 'strokes-fix-button2
-;; 	  '(vm-mouse-button-2
-;;          rmail-summary-mouse-goto-msg
-;;	    <rest of them>))
-
-;;; With help from Hans (author of advice.el)...
-(defmacro strokes-fix-button2-command (command)
-  "Fix COMMAND so that it can also work with strokes.
-COMMAND must take one event argument.
-Example of how one might fix up a command that's bound to button2
-and which is an interactive funcion of one event argument:
-
-\(strokes-fix-button2-command 'rmail-summary-mouse-goto-msg)"
-  (let ((command (eval command)))
-    `(progn
-       (defadvice ,command (around strokes-fix-button2 compile preactivate)
-         ,(format "Fix %s to work with strokes." command)
-         (let ((strokes-click-command
-                  ',(intern (format "ad-Orig-%s" command))))
-             (strokes-do-stroke (ad-get-arg 0)))))))
-
-(defvar strokes-insinuated nil)
-
-(defun strokes-insinuate ()
-  "Insinuate Emacs with strokes advices."
-  (unless strokes-insinuated
-    (strokes-fix-button2-command 'vm-mouse-button-2)
-    (strokes-fix-button2-command 'rmail-summary-mouse-goto-msg)
-    (strokes-fix-button2-command 'Buffer-menu-mouse-select)
-    (strokes-fix-button2-command 'w3-widget-button-click)
-    (strokes-fix-button2-command 'widget-image-button-press)
-    (strokes-fix-button2-command 'Info-follow-clicked-node)
-    (strokes-fix-button2-command 'compile-mouse-goto-error)
-    (strokes-fix-button2-command 'gdbsrc-select-or-yank)
-    (strokes-fix-button2-command 'hypropos-mouse-get-doc)
-    (strokes-fix-button2-command 'gnus-mouse-pick-group)
-    (strokes-fix-button2-command 'gnus-mouse-pick-article)
-    (strokes-fix-button2-command 'gnus-article-push-button)
-    (strokes-fix-button2-command 'dired-mouse-find-file)
-    (strokes-fix-button2-command 'url-dired-find-file-mouse)
-    (strokes-fix-button2-command 'dired-u-r-mouse-toggle)
-    (strokes-fix-button2-command 'dired-u-w-mouse-toggle)
-    (strokes-fix-button2-command 'dired-u-x-mouse-toggle)
-    (strokes-fix-button2-command 'dired-g-r-mouse-toggle)
-    (strokes-fix-button2-command 'dired-g-w-mouse-toggle)
-    (strokes-fix-button2-command 'dired-g-x-mouse-toggle)
-    (strokes-fix-button2-command 'dired-o-r-mouse-toggle)
-    (strokes-fix-button2-command 'dired-o-w-mouse-toggle)
-    (strokes-fix-button2-command 'isearch-yank-x-selection)
-    (strokes-fix-button2-command 'occur-mode-mouse-goto)
-    (strokes-fix-button2-command 'cvs-mouse-find-file)
-    (setq strokes-insinuated t)))
-
-;;; I can fix the customize widget button click, but then
-;;; people will get confused when they try to customize
-;;; strokes with the mouse and customize tells them that
-;;; `strokes-click-command' is mapped to `ad-Orig-widget-button-click'
-;;(strokes-fix-button2-command 'widget-button-click)
-
-;;; without the advice, each advised function would look like...
-;;(defadvice vm-mouse-button-2 (around vm-strokes activate protect)
-;;  "Allow strokes to work in VM."
-;;  (if strokes-use-strokes-buffer
-;;      ;; then strokes is no good and we'll have to use the original
-;;      ad-do-it
-;;    ;; otherwise, we can make strokes work too...
-;;    (let ((strokes-click-command 'ad-Orig-vm-mouse-button-2))
-;;      (strokes-do-stroke (ad-get-arg 0)))))
-
 ;;; Functions...
 
 (defsubst strokes-mouse-event-p (event)
@@ -526,7 +391,7 @@
 (defun strokes-event-closest-point (event &optional start-window)
   "Return the nearest position to where EVENT ended its motion.
 This is computed for the window where EVENT's motion started,
-or for window WINDOW if that is specified."
+or for window START-WINDOW if that is specified."
   (or start-window (setq start-window (posn-window (event-start event))))
   (if (eq start-window (posn-window (event-end event)))
       (if (eq (posn-point (event-end event)) 'vertical-line)
@@ -557,7 +422,7 @@
   (interactive)
   (let ((command (cdar strokes-global-map)))
     (if (y-or-n-p
-	 (format "really delete last stroke definition, defined to `%s'? "
+	 (format "Really delete last stroke definition, defined to `%s'? "
 		 command))
 	(progn
 	  (setq strokes-global-map (cdr strokes-global-map))
@@ -575,13 +440,10 @@
    (list
     (and (or strokes-mode (strokes-mode t))
 	 (strokes-read-complex-stroke
-	  "Define a new stroke.  Draw with button1 (or 2).  End with button3..."))
-    (read-command "command to map stroke to: ")))
+	  "Draw with mouse button 1 (or 2).  End with button 3..."))
+    (read-command "Command to map stroke to: ")))
   (strokes-define-stroke strokes-global-map stroke command))
 
-;;;###autoload
-(defalias 'global-set-stroke 'strokes-global-set-stroke)
-
 ;;(defun global-unset-stroke (stroke); FINISH THIS DEFUN!
 ;;  "delete all strokes matching STROKE from `strokes-global-map',
 ;; letting the user input
@@ -592,7 +454,8 @@
 ;;  (strokes-define-stroke 'strokes-global-map stroke command))
 
 (defun strokes-get-grid-position (stroke-extent position &optional grid-resolution)
-  "Map POSITION to a new grid position based on its STROKE-EXTENT and GRID-RESOLUTION.
+  "Map POSITION to a new grid position.
+Do so  based on its STROKE-EXTENT and GRID-RESOLUTION.
 STROKE-EXTENT as a list \(\(XMIN . YMIN\) \(XMAX . YMAX\)\).
 If POSITION is a `strokes-lift', then it is itself returned.
 Optional GRID-RESOLUTION may be used in place of STROKES-GRID-RESOLUTION.
@@ -617,7 +480,7 @@
 	 strokes-lift)))
 
 (defun strokes-get-stroke-extent (pixel-positions)
-  "From a list of absolute PIXEL-POSITIONS, returns absolute spatial extent.
+  "From a list of absolute PIXEL-POSITIONS, return absolute spatial extent.
 The return value is a list ((XMIN . YMIN) (XMAX . YMAX))."
   (if pixel-positions
       (let ((xmin (caar pixel-positions))
@@ -658,7 +521,7 @@
     nil))
 
 (defun strokes-eliminate-consecutive-redundancies (entries)
-  "Returns a list with no consecutive redundant entries."
+  "Return a list with no consecutive redundant entries."
   ;; defun a grande vitesse grace a Dave G.
   (loop for element on entries
         if (not (equal (car element) (cadr element)))
@@ -766,7 +629,7 @@
 						     y))))))))))
 
 (defun strokes-rate-stroke (stroke1 stroke2)
-  "Rates STROKE1 with STROKE2 and returns a score based on a distance metric.
+  "Rates STROKE1 with STROKE2 and return a score based on a distance metric.
 Note: the rating is an error rating, and therefore, a return of 0
 represents a perfect match.  Also note that the order of stroke
 arguments is order-independent for the algorithm used here."
@@ -820,7 +683,7 @@
     nil))
 
 (defun strokes-match-stroke (stroke stroke-map)
-  "Finds the best matching command of STROKE in STROKE-MAP.
+  "Find the best matching command of STROKE in STROKE-MAP.
 Returns the corresponding match as (COMMAND . SCORE)."
   (if (and stroke stroke-map)
       (let ((score (strokes-rate-stroke stroke (caar stroke-map)))
@@ -871,7 +734,8 @@
 			      ;; we can draw that point
 			      (progn
 				(goto-char point)
-				(subst-char-in-region point (1+ point) ?\  strokes-character))
+				(subst-char-in-region point (1+ point)
+						      ?\  strokes-character))
 			    ;; otherwise, we can start drawing the next time...
 			    (setq safe-to-draw-p t))
 			  (push (cdr (mouse-pixel-position))
@@ -880,7 +744,8 @@
 	    ;; protected
 	    ;; clean up strokes buffer and then bury it.
 	    (when (equal (buffer-name) strokes-buffer-name)
-	      (subst-char-in-region (point-min) (point-max) strokes-character ?\ )
+	      (subst-char-in-region (point-min) (point-max)
+				    strokes-character ?\ )
 	      (goto-char (point-min))
 	      (bury-buffer))))
       ;; Otherwise, don't use strokes buffer and read stroke silently
@@ -897,15 +762,16 @@
 		    pix-locs))
 	  (setq event (read-event))))
       (setq grid-locs (strokes-renormalize-to-grid (nreverse pix-locs)))
-      (strokes-fill-stroke (strokes-eliminate-consecutive-redundancies grid-locs)))))
+      (strokes-fill-stroke
+       (strokes-eliminate-consecutive-redundancies grid-locs)))))
 
 ;;;###autoload
 (defun strokes-read-complex-stroke (&optional prompt event)
   "Read a complex stroke (interactively) and return the stroke.
 Optional PROMPT in minibuffer displays before and during stroke reading.
 Note that a complex stroke allows the user to pen-up and pen-down.  This
-is implemented by allowing the user to paint with button1 or button2 and
-then complete the stroke with button3.
+is implemented by allowing the user to paint with button 1 or button 2 and
+then complete the stroke with button 3.
 Optional EVENT is acceptable as the starting event of the stroke"
   (save-excursion
     (save-window-excursion
@@ -928,7 +794,8 @@
 		      (let ((point (strokes-event-closest-point event)))
 			(when point
 			  (goto-char point)
-			  (subst-char-in-region point (1+ point) ?\ strokes-character))
+			  (subst-char-in-region point (1+ point)
+						?\ strokes-character))
 			(push (cdr (mouse-pixel-position))
 			      pix-locs)))
 		  (setq event (read-event)))
@@ -945,7 +812,8 @@
 	       (strokes-eliminate-consecutive-redundancies grid-locs)))
 	  ;; protected
 	  (when (equal (buffer-name) strokes-buffer-name)
-	    (subst-char-in-region (point-min) (point-max) strokes-character ?\ )
+	    (subst-char-in-region (point-min) (point-max)
+				  strokes-character ?\ )
 	    (goto-char (point-min))
 	    (bury-buffer)))))))
 
@@ -957,19 +825,7 @@
   (let* ((match (strokes-match-stroke stroke strokes-global-map))
 	 (command (car match))
 	 (score (cdr match)))
-    (cond ((strokes-click-p stroke)
-	   ;; This is the case of a `click' type event.
-	   ;; The `sit-for' is a minor frob that has to do with timing
-	   ;; problems.  Without the `sit-for', mouse-yank will not
-	   ;; yank at the proper location if the user opted for
-	   ;; mouse-yank-at-point to be nil (i.e. mouse-yank takes
-	   ;; place at pointer position).  The sit-for tells redisplay
-	   ;; to be sure to wait for the `*strokes*' buffer to vanish
-	   ;; from consideration when deciding on a point to be used
-	   ;; for mouse-yank.
-	   (sit-for 0)
-	   (command-execute strokes-click-command))
-	  ((and match (<= score strokes-minimum-match-score))
+    (cond ((and match (<= score strokes-minimum-match-score))
 	   (message "%s" command)
 	   (command-execute command))
 	  ((null strokes-global-map)
@@ -978,7 +834,7 @@
 		     (format "No strokes loaded.  Load `%s'? "
 			     strokes-file))
 		    (strokes-load-user-strokes))
-	     (error "No strokes defined; use `global-set-stroke'")))
+	     (error "No strokes defined; use `strokes-global-set-stroke'")))
 	  (t
 	   (error
 	    "No stroke matches; see variable `strokes-minimum-match-score'")
@@ -1006,35 +862,28 @@
   (interactive
    (list
     (strokes-read-complex-stroke
-     "Enter stroke to describe; end with button3...")))
+     "Enter stroke to describe; end with button 3...")))
   (let* ((match (strokes-match-stroke stroke strokes-global-map))
-	 (command (or (and (strokes-click-p stroke)
-			   strokes-click-command)
-		      (car match)))
+	 (command (car match))
 	 (score (cdr match)))
-    (if (or (and match
-		 (<= score strokes-minimum-match-score))
-	    (and (strokes-click-p stroke)
-		 strokes-click-command))
+    (if (and match
+	     (<= score strokes-minimum-match-score))
 	(message "That stroke maps to `%s'" command)
       (message "That stroke is undefined"))
     (sleep-for 1)))			; helpful for recursive edits
 
 ;;;###autoload
-(defalias 'describe-stroke 'strokes-describe-stroke)
-
-;;;###autoload
 (defun strokes-help ()
-  "Get instructional help on using the `strokes' package."
+  "Get instruction on using the Strokes package."
   (interactive)
   (with-output-to-temp-buffer "*Help with Strokes*"
-    (let ((helpdoc
-	   "This is help for the strokes package.
+    (princ
+     "This is help for the strokes package.
 
 If you find something wrong with strokes, or feel that it can be
 improved in some way, then please feel free to email me:
 
-David Bakhash <cadet@mit.edu>
+David Bakhash <cadet@alum.mit.edu>
 
 or just do
 
@@ -1051,7 +900,7 @@
 right every time.
 
 Strokes also allows you to compose documents graphically.  You can
-fully edit documents in Chinese, Japanese, etc. based on XEmacs
+fully edit documents in Chinese, Japanese, etc. based on Emacs
 strokes.  Once you've done so, you can ascii compress-and-encode them
 and then safely save them for later use, send letters to friends
 \(using Emacs, of course).  Strokes will later decode these documents,
@@ -1073,16 +922,16 @@
 
 When you're ready to start defining strokes, just use the command
 
-> M-x global-set-stroke
+> M-x strokes-global-set-stroke
 
 You will see a ` *strokes*' buffer which is waiting for you to enter in
-your stroke.  When you enter in the stroke, you draw with button1 or
-button2, and then end with button3.  Next, you enter in the command
+your stroke.  When you enter in the stroke, you draw with button 1 or
+button 2, and then end with button 3.  Next, you enter in the command
 which will be executed when that stroke is invoked.  Simple as that.
 For now, try to define a stroke to copy a region.  This is a popular
 edit command, so type
 
-> M-x global-set-stroke
+> M-x strokes-global-set-stroke
 
 Then, in the ` *strokes*' buffer, draw the letter `C' (for `copy')
 and then, when it asks you to enter the command to map that to, type
@@ -1090,21 +939,18 @@
 > copy-region-as-kill
 
 That's about as hard as it gets.
-Remember: paint with button1 or button2 and then end with button3.
+Remember: paint with button 1 or button 2 and then end with button 3.
 
 If ever you want to know what a certain strokes maps to, then do
 
-> M-x describe-stroke
+> M-x strokes-describe-stroke
 
 and you can enter in any arbitrary stroke.  Remember: The strokes
 package lets you program in simple and complex (multi-lift) strokes.
 The only difference is how you *invoke* the two.  You will most likely
 use simple strokes, as complex strokes were developed for
-Chinese/Japanese/Korean.  So the middle mouse button (mouse-2) will
-invoke the command `strokes-do-stroke' in buffers where button2 doesn't
-already have a meaning other than its original, which is `mouse-yank'.
-But don't worry: `mouse-yank' will still work with strokes.  See the
-variable `strokes-click-command'.
+Chinese/Japanese/Korean.  So the shifted middle mouse button (S-mouse-2) will
+invoke the command `strokes-do-stroke'.
 
 If ever you define a stroke which you don't like, then you can unset
 it with the command
@@ -1131,24 +977,23 @@
 You will be prompted to save them when you exit Emacs, or you can save
 them with
 
-> M-x save-strokes
+> M-x strokes-save-strokes
 
 Your strokes get loaded automatically when you enable `strokes-mode'.
 You can also load in your user-defined strokes with
 
-> M-x load-user-strokes
+> M-x strokes-load-user-strokes
 
 ** Strokes for pictographic editing...
 
 If you'd like to create graphical files with strokes, you'll have to
-be running a version of Emacs with XPM support.  You use the
-binding C-mouse-2 to start drawing your strokes.  These are just
-complex strokes, and thus you continue drawing with mouse-1 or mouse-2 and
-end with mouse-3-3.  Then the stroke image gets inserted into the
-buffer.  You treat it like any other character, which you can copy,
-paste, delete, move, etc.  The command which is bound to C-mouse-2 is
-called `strokes-compose-complex-stroke'.  When all is done, you may
-want to send the file, or save it.  This is done with
+be running a version of Emacs with XPM support.  You use the binding
+to `strokes-compose-complex-stroke' to start drawing your strokes.
+These are just complex strokes, and thus continue drawing with mouse-1
+or mouse-2 and end with mouse-3.  Then the stroke image gets inserted
+into the buffer.  You treat it somewhat like any other character,
+which you can copy, paste, delete, move, etc.  When all is done, you
+may want to send the file, or save it.  This is done with
 
 > M-x strokes-encode-buffer
 
@@ -1165,47 +1010,17 @@
 o Strokes are a bit computer-dependent in that they depend somewhat on
   the speed of the computer you're working on.  This means that you
   may have to tweak some variables.  You can read about them in the
-  commentary of `strokes.el'.  Better to just use apropos and read their
+  commentary of `strokes.el'.  Better to just use \\[apropos] and read their
   docstrings.  All variables/functions start with `strokes'.  The one
   variable which many people wanted to see was
   `strokes-use-strokes-buffer' which allows the user to use strokes
   silently--without displaying the strokes.  All variables can be set
-  by customizing the group named `strokes' via the customization package:
-
-  > M-x customize"))
-    (with-output-to-temp-buffer "*Help"
-      (princ helpdoc)
+  by customizing the group named `strokes' via \\[customize-group].")
       (set-buffer standard-output)
       (help-mode))
-      (print-help-return-message))))
+    (print-help-return-message))
 
-(defun strokes-report-bug ()
-  "Submit a bug report for strokes."
-  (interactive)
-  (let ((reporter-prompt-for-summary-p t))
-    (reporter-submit-bug-report
-     strokes-bug-address "Strokes"
-     (cons
-      'strokes-version
-      (nconc
-       (mapcar
-	'intern
-	(sort
-	 (let (completion-ignore-case)
-	   (all-completions "strokes-" obarray 'user-variable-p))
-	 'string-lessp))
-       (list 'reporter-version)))
-     (function
-      (lambda ()
-	(save-excursion
-	  (mail-position-on-field "subject")
-	  (beginning-of-line)
-	  (skip-chars-forward "^:\n")
-	  (if (looking-at ": Strokes;")
-	      (progn
-		(goto-char (match-end 0))
-		(delete-char -1)
-		(insert " " strokes-version " bug:")))))))))
+(defalias 'strokes-report-bug 'report-emacs-bug)
 
 (defsubst strokes-fill-current-buffer-with-whitespace ()
   "Erase the contents of the current buffer and fill it with whitespace."
@@ -1217,7 +1032,7 @@
 
 (defun strokes-window-configuration-changed-p ()
   "Non-nil if the `strokes-window-configuration' frame properties changed.
-This is based on the last time the `strokes-window-configuration was updated."
+This is based on the last time `strokes-window-configuration' was updated."
   (compare-window-configurations (current-window-configuration)
 				 strokes-window-configuration))
 
@@ -1272,9 +1087,6 @@
 	(t
 	 (message "No user-defined strokes, sorry"))))
 
-;;;###autoload
-(defalias 'load-user-strokes 'strokes-load-user-strokes)
-
 (defun strokes-prompt-user-save-strokes ()
   "Save user-defined strokes to file named by `strokes-file'."
   (interactive)
@@ -1296,12 +1108,12 @@
 		  (emacs-lisp-mode)
 		  (goto-char (point-min))
 		  (insert-string
-		   ";;   -*- Syntax: Emacs-Lisp; Mode: emacs-lisp -*-\n")
+		   ";;   -*- emacs-lisp -*-\n")
 		  (insert-string (format ";;; saved strokes for %s, as of %s\n\n"
 					 (user-full-name)
 					 (format-time-string "%B %e, %Y" nil)))
 		  (message "Saving strokes in %s..." strokes-file)
-		  (insert-string (format "(setq strokes-global-map '%s)"
+		  (insert-string (format "(setq strokes-global-map\n'%s)"
 					 (pp current)))
 		  (message "Saving strokes in %s..." strokes-file)
 		  (indent-region (point-min) (point-max) nil)
@@ -1314,11 +1126,9 @@
 	    (kill-buffer (get-buffer "*saved-strokes*")))
 	(setq strokes-global-map current)))))
 
-(defalias 'save-strokes 'strokes-prompt-user-save-strokes)
-
 (defun strokes-toggle-strokes-buffer (&optional arg)
   "Toggle the use of the strokes buffer.
-In other words, toggle the variabe `strokes-use-strokes-buffer'.
+In other words, toggle the variable `strokes-use-strokes-buffer'.
 With ARG, use strokes buffer if and only if ARG is positive or true.
 Returns value of `strokes-use-strokes-buffer'."
   (interactive "P")
@@ -1367,15 +1177,15 @@
 		       (let ((char (or (car rainbow-chars) ?\.)))
 			 (loop for i from 0 to 2 do
 			       (loop for j from 0 to 2 do
-				     (goto-line (+ 16 i y))	
+				     (goto-line (+ 16 i y))
 				     (forward-char (+ 1 j x))
 				     (delete-char 1)
 				     (insert char)))
 			 (setq rainbow-chars (cdr rainbow-chars)
 			       lift-flag nil))
 		     ;; Otherwise, just plot the point...
-		     (goto-line (+ 17 y))	
-		     (forward-char (+ 2 x))	
+		     (goto-line (+ 17 y))
+		     (forward-char (+ 2 x))
 		     (subst-char-in-region (point) (1+ (point)) ?\  ?\*)))
 		  ((strokes-lift-p point)
 		   ;; a lift--tell the loop to X out the next point...
@@ -1546,65 +1356,50 @@
 	(command-name-2 (symbol-name (cdr stroke2))))
     (string-lessp command-name-1 command-name-2)))
 
-;;;###autoload
-(defun strokes-mode (&optional arg)
-  "Toggle strokes being enabled.
-With ARG, turn strokes on if and only if ARG is positive or true.
-Note that `strokes-mode' is a global mode.  Think of it as a minor
-mode in all buffers when activated.
-By default, strokes are invoked with mouse button-2.  You can define
-new strokes with
+(defvar strokes-mode-map
+  (let ((map (make-sparse-keymap)))
+    (define-key map [(shift down-mouse-2)] 'strokes-do-stroke)
+    (define-key map [(meta down-mouse-2)] 'strokes-do-complex-stroke)
+    map))
 
-> M-x global-set-stroke
+;;;###autoload
+(define-minor-mode strokes-mode
+  "Toggle Strokes global minor mode.\\<strokes-mode-map>
+With ARG, turn strokes on if and only if ARG is positive.
+Strokes are pictographic mouse gestures which invoke commands.
+Strokes are invoked with \\[strokes-do-stroke].  You can define
+new strokes with \\[strokes-global-set-stroke].  See also
+\\[strokes-do-complex-stroke] for `complex' strokes.
 
 To use strokes for pictographic editing, such as Chinese/Japanese, use
-S-mouse-2, which draws strokes and inserts them.  Encode/decode your
-strokes with
+\\[strokes-compose-complex-stroke], which draws strokes and inserts them.
+Encode/decode your strokes with \\[strokes-encode-buffer],
+\\[strokes-decode-buffer].
+
+\\{strokes-mode-map}"
+  nil strokes-modeline-string strokes-mode-map
+  :group 'strokes :global t
+  (cond ((not (display-mouse-p))
+	 (error "Can't use Strokes without a mouse"))
+	(strokes-mode			; turn on strokes
+	 (and (file-exists-p strokes-file)
+	      (null strokes-global-map)
+	      (strokes-load-user-strokes))
+	 (add-hook 'kill-emacs-query-functions
+		   'strokes-prompt-user-save-strokes)
+	 (add-hook 'select-frame-hook
+		   'strokes-update-window-configuration)
+	 (strokes-update-window-configuration))
+	(t				; turn off strokes
+	 (if (get-buffer strokes-buffer-name)
+	     (kill-buffer (get-buffer strokes-buffer-name)))
+	 (remove-hook 'select-frame-hook
+		      'strokes-update-window-configuration))))
 
-> M-x strokes-encode-buffer
-> M-x strokes-decode-buffer"
-  (interactive "P")
-  (let ((on-p (if arg
-		  (> (prefix-numeric-value arg) 0)
-		(not strokes-mode))))
-    (cond ((not (display-mouse-p))
-	   (error "Can't use strokes without a mouse"))
-	  (on-p				; turn on strokes
-	   (strokes-insinuate)		; make sure defadvices are set
-	   (and (file-exists-p strokes-file)
-		(null strokes-global-map)
-		(strokes-load-user-strokes))
-	   (add-hook 'kill-emacs-query-functions
-		     'strokes-prompt-user-save-strokes)
-	   (add-hook 'select-frame-hook
-		     'strokes-update-window-configuration)
-	   (strokes-update-window-configuration)
-	   (define-key global-map [(down-mouse-2)] 'strokes-do-stroke)
-	   (define-key global-map [(meta down-mouse-2)]
-	     'strokes-do-complex-stroke)
-	   ;;	   (define-key global-map [(control down-mouse-2)] 'strokes-do-complex-stroke)
-	   (ad-activate-regexp "^strokes-") ; advise button2 commands
-	   (setq strokes-mode t))
-	  (t				; turn off strokes
-	   (if (get-buffer strokes-buffer-name)
-	       (kill-buffer (get-buffer strokes-buffer-name)))
-	   (remove-hook 'select-frame-hook
-			'strokes-update-window-configuration)
-	   (if (string-match "^strokes-" (symbol-name (key-binding [(down-mouse-2)])))
-	       (define-key global-map [(down-mouse-2)] strokes-click-command))
-	   (if (string-match "^strokes-" (symbol-name (key-binding [(meta down-mouse-2)])))
-	       (global-unset-key [(meta down-mouse-2)]))
-	   (if (string-match "^strokes-" (symbol-name (key-binding [(control down-mouse-2)])))
-	       (global-unset-key [(control down-mouse-2)]))
-	   ;;	   (if (string-match "^strokes-" (symbol-name (key-binding [(shift button2)])))	
-	   ;;	       (global-unset-key [(shift button2)]))
-	   (ad-deactivate-regexp "^strokes-") ; unadvise strokes-button2 commands
-	   (setq strokes-mode nil))))
-  (force-mode-line-update))
 
 ;;;; strokes-xpm stuff (later may be separate)...
 
-;; This is the stuff that will eventuall be used for composing letters in
+;; This is the stuff that will eventually be used for composing letters in
 ;; any language, compression, decompression, graphics, editing, etc.
 
 (defface strokes-char-face '((t (:background "lightgray")))
@@ -1712,7 +1507,7 @@
 ;;  (eq (null a) (not (null b))))
 
 (defsubst strokes-xpm-encode-length-as-string (length)
-  "Given some LENGTH in [0,62) do a fast lookup of it's encoding."
+  "Given some LENGTH in [0,62) do a fast lookup of its encoding."
   (aref strokes-base64-chars length))
 		   
 (defsubst strokes-xpm-decode-char (character)
@@ -1720,10 +1515,10 @@
   (aref strokes-char-table character))
 		   
 (defun strokes-xpm-to-compressed-string (&optional xpm-buffer)
-  "Convert the xpm in XPM-BUFFER into a compressed string representing the stroke.
-XPM-BUFFER is an optional argument, and defaults to `*strokes-xpm*'."
+  "Convert XPM in XPM-BUFFER to compressed string representing the stroke.
+XPM-BUFFER defaults to ` *strokes-xpm*'."
   (save-excursion
-    (set-buffer (setq xpm-buffer (or xpm-buffer "*strokes-xpm*")))
+    (set-buffer (setq xpm-buffer (or xpm-buffer " *strokes-xpm*")))
     (goto-char (point-min))
     (search-forward "/* pixels */")	; skip past header junk
     (forward-char 2)
@@ -1743,19 +1538,19 @@
 	       ;; check to see if the `char-at-point' is an actual pixmap bit
 	       (when (strokes-xpm-char-bit-p char-at-point)
 		 (setq count 1
-		       current-char-is-on-p (strokes-xpm-char-on-p char-at-point)))	       
+		       current-char-is-on-p (strokes-xpm-char-on-p char-at-point)))
 	       (forward-char 1))
 	      ((= count 61)		; maximum single char's
 					; encoding length
-	       (setq compressed-string (concat compressed-string
-					       ;; add a zero-length
-					       ;; encoding when
-					       ;; necessary
-					       (when (eq last-char-was-on-p
-							 current-char-is-on-p)
-						 ;; "0"
-						 (strokes-xpm-encode-length-as-string 0))
-					       (strokes-xpm-encode-length-as-string 61))
+	       (setq compressed-string
+		     (concat compressed-string
+			     ;; add a zero-length encoding when
+			     ;; necessary
+			     (when (eq last-char-was-on-p
+				       current-char-is-on-p)
+			       ;; "0"
+			       (strokes-xpm-encode-length-as-string 0))
+			     (strokes-xpm-encode-length-as-string 61))
 		     last-char-was-on-p current-char-is-on-p
 		     count 0))		; note that we just set
 					; count=0 and *don't* advance
@@ -1775,15 +1570,15 @@
 		 ;; iteration go through and letting the case: count=0
 		 ;; take care of this stuff for me.  That's why
 		 ;; there's no (forward-char 1) below.
-		 (setq compressed-string (concat compressed-string
-						 ;; add a zero-length
-						 ;; encoding when
-						 ;; necessary
-						 (when (eq last-char-was-on-p
-							   current-char-is-on-p)
-						   ;; "0"
-						   (strokes-xpm-encode-length-as-string 0))
-						 (strokes-xpm-encode-length-as-string count))
+		 (setq compressed-string
+		       (concat compressed-string
+			       ;; add a zero-length encoding when
+			       ;; necessary
+			       (when (eq last-char-was-on-p
+					 current-char-is-on-p)
+				 ;; "0"
+				 (strokes-xpm-encode-length-as-string 0))
+			       (strokes-xpm-encode-length-as-string count))
 		       count 0
 		       last-char-was-on-p current-char-is-on-p)))
 	      (t			; ELSE it's some other useless
@@ -1890,10 +1685,10 @@
 	(message "Encoding strokes in %s...done" buffer)))))
 
 (defun strokes-xpm-for-compressed-string (compressed-string &optional bufname)
-  "Convert the stroke represented by COMPRESSED-STRING into an xpm.
-Store xpm in buffer BUFNAME if supplied \(default is `*strokes-xpm*'\)"
+  "Convert the stroke represented by COMPRESSED-STRING into an XPM.
+Store XPM in buffer BUFNAME if supplied \(default is ` *strokes-xpm*'\)"
   (save-excursion
-    (or bufname (setq bufname "*strokes-xpm*"))
+    (or bufname (setq bufname " *strokes-xpm*"))
     (set-buffer (get-buffer-create bufname))
     (erase-buffer)
     (insert compressed-string)
@@ -1918,7 +1713,7 @@
 ;;;###autoload
 (defun strokes-compose-complex-stroke ()
   ;; ### NOTE !!! ###
-  ;; Even though we have lexical scoping, it's somewhat ugly how I
+  ;; Even though we don't have lexical scoping, it's somewhat ugly how I
   ;; pass around variables in the global name space.  I can/should
   ;; change this.
   "Read a complex stroke and insert its glyph into the current buffer."
@@ -1931,11 +1726,11 @@
     ;; strokes-decode-buffer does a save-excursion.
     (forward-char)))
 
-(or (assq 'strokes-mode minor-mode-alist)
-    (setq minor-mode-alist (cons (list 'strokes-mode strokes-modeline-string)
-				 minor-mode-alist)))
+(defun strokes-unload-hook ()
+  (strokes-mode -1)
+  (remove-hook 'kill-emacs-query-functions 'strokes-prompt-user-save-strokes))
 
-(provide 'strokes)
 (run-hooks 'strokes-load-hook)
+(provide 'strokes)
 
 ;;; strokes.el ends here

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: strokes.el revamp
  2002-04-30  9:40 strokes.el revamp Dave Love
@ 2002-04-30 10:43 ` Colin Marquardt
  0 siblings, 0 replies; 2+ messages in thread
From: Colin Marquardt @ 2002-04-30 10:43 UTC (permalink / raw)


d.love@dl.ac.uk (Dave Love) writes:

> My previous hack at strokes.el obviously didn't produce something
> usable.  The original overloading of mouse-2 just loses and presumably
> no-one uses it.  The following seems better and potentially useful for
> input of technical characters, for instance.  I suspect the doc and
> commentary needs more review than I've given it.
[...]
> @@ -116,7 +118,7 @@
>  ;; Whenever you load in the strokes package, you will be able to save
>  ;; what you've done upon exiting Emacs.  You can also do
>  
> -;; > M-x save-strokes
> +;; > M-x strokes-propmpt-user-save-strokes
-----------------------^

Small typo.

Colin

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-04-30 10:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-04-30  9:40 strokes.el revamp Dave Love
2002-04-30 10:43 ` Colin Marquardt

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).