Merge from emacs-23; up to 2012-01-19T07:15:48Z!rgm@gnu.org.
[bpt/emacs.git] / lisp / edmacro.el
index 1c2f910..32915e3 100644 (file)
@@ -1,7 +1,6 @@
 ;;; edmacro.el --- keyboard macro editor
 
-;; Copyright (C) 1993, 1994, 2001, 2002, 2003, 2004,
-;;   2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+;; Copyright (C) 1993-1994, 2001-2012 Free Software Foundation, Inc.
 
 ;; Author: Dave Gillespie <daveg@synaptics.com>
 ;; Maintainer: Dave Gillespie <daveg@synaptics.com>
@@ -37,7 +36,7 @@
 ;;  * `M-x' followed by a command name, to edit a named command
 ;;    whose definition is a keyboard macro.
 ;;
-;;  * `C-h l' (view-lossage), to edit the 100 most recent keystrokes
+;;  * `C-h l' (view-lossage), to edit the 300 most recent keystrokes
 ;;    and install them as the "current" macro.
 ;;
 ;;  * any key sequence whose definition is a keyboard macro.
 ;; With a prefix argument, `edit-kbd-macro' will format the
 ;; macro in a more concise way that omits the comments.
 
-;; This package requires GNU Emacs 19 or later, and daveg's CL
-;; package 2.02 or later.  (CL 2.02 comes standard starting with
-;; Emacs 19.18.)  This package does not work with Emacs 18 or
-;; Lucid Emacs.
-
 ;;; Code:
 \f
 (eval-when-compile
 
 ;;; The user-level commands for editing macros.
 
-;;;###autoload
-(defvar edmacro-eight-bits nil
-  "*Non-nil if edit-kbd-macro should leave 8-bit characters intact.
-Default nil means to write characters above \\177 in octal notation.")
+(defcustom edmacro-eight-bits nil
+  "Non-nil if `edit-kbd-macro' should leave 8-bit characters intact.
+Default nil means to write characters above \\177 in octal notation."
+  :type 'boolean
+  :group 'kmacro)
 
-(defvar edmacro-mode-map nil)
-(unless edmacro-mode-map
-  (setq edmacro-mode-map (make-sparse-keymap))
-  (define-key edmacro-mode-map "\C-c\C-c" 'edmacro-finish-edit)
-  (define-key edmacro-mode-map "\C-c\C-q" 'edmacro-insert-key))
+(defvar edmacro-mode-map
+  (let ((map (make-sparse-keymap)))
+    (define-key map "\C-c\C-c" 'edmacro-finish-edit)
+    (define-key map "\C-c\C-q" 'edmacro-insert-key)
+    map))
 
 (defvar edmacro-store-hook)
 (defvar edmacro-finish-hook)
@@ -96,7 +91,7 @@ Default nil means to write characters above \\177 in octal notation.")
   "Edit a keyboard macro.
 At the prompt, type any key sequence which is bound to a keyboard macro.
 Or, type `C-x e' or RET to edit the last keyboard macro, `C-h l' to edit
-the last 100 keystrokes as a keyboard macro, or `M-x' to edit a macro by
+the last 300 keystrokes as a keyboard macro, or `M-x' to edit a macro by
 its command name.
 With a prefix argument, format the macro in a more concise way."
   (interactive "kKeyboard macro to edit (C-x e, M-x, C-h l, or keys): \nP")
@@ -230,7 +225,7 @@ or nil, use a compact 80-column format."
      "This command is valid only in buffers created by `edit-kbd-macro'"))
   (run-hooks 'edmacro-finish-hook)
   (let ((cmd nil) (keys nil) (no-keys nil)
-       (mac-counter nil) (mac-format nil) (kmacro nil)
+       (mac-counter nil) (mac-format nil)
        (top (point-min)))
     (goto-char top)
     (let ((case-fold-search nil))
@@ -245,7 +240,7 @@ or nil, use a compact 80-column format."
                        (setq cmd (and (not (equal str "none"))
                                       (intern str)))
                        (and (fboundp cmd) (not (arrayp (symbol-function cmd)))
-                            (not (setq kmacro (get cmd 'kmacro)))
+                            (not (get cmd 'kmacro))
                             (not (y-or-n-p
                                   (format "Command %s is already defined; %s"
                                           cmd "proceed? ")))
@@ -349,7 +344,7 @@ or nil, use a compact 80-column format."
     (insert (edmacro-format-keys key) " ")))
 
 (defun edmacro-mode ()
-  "\\<edmacro-mode-map>Keyboard Macro Editing mode.  Press
+  "\\<edmacro-mode-map>Keyboard Macro Editing mode.  Press \
 \\[edmacro-finish-edit] to save and exit.
 To abort the edit, just kill this buffer with \\[kill-buffer] RET.
 
@@ -597,7 +592,8 @@ doubt, use whitespace."
 (defun edmacro-mismatch (cl-seq1 cl-seq2 cl-start1 cl-end1 cl-start2 cl-end2)
   "Compare SEQ1 with SEQ2, return index of first mismatching element.
 Return nil if the sequences match.  If one sequence is a prefix of the
-other, the return value indicates the end of the shorted sequence."
+other, the return value indicates the end of the shorted sequence.
+\n(fn SEQ1 SEQ2 START1 END1 START2 END2)"
   (let (cl-test cl-test-not cl-key cl-from-end)
     (or cl-end1 (setq cl-end1 (length cl-seq1)))
     (or cl-end2 (setq cl-end2 (length cl-seq2)))
@@ -647,7 +643,7 @@ If START or END is negative, it counts from the end."
               res))))))
 
 (defun edmacro-sanitize-for-string (seq)
-  "Convert a key sequence vector into a string.
+  "Convert a key sequence vector SEQ into a string.
 The string represents the same events; Meta is indicated by bit 7.
 This function assumes that the events can be stored in a string."
   (setq seq (copy-sequence seq))
@@ -686,14 +682,22 @@ This function assumes that the events can be stored in a string."
 
 (defun edmacro-parse-keys (string &optional need-vector)
   (let ((case-fold-search nil)
+       (len (length string)) ; We won't alter string in the loop below.
        (pos 0)
        (res []))
-    (while (and (< pos (length string))
+    (while (and (< pos len)
                (string-match "[^ \t\n\f]+" string pos))
-      (let ((word (substring string (match-beginning 0) (match-end 0)))
-           (key nil)
-           (times 1))
-       (setq pos (match-end 0))
+      (let* ((word-beg (match-beginning 0))
+            (word-end (match-end 0))
+            (word (substring string word-beg len))
+            (times 1)
+            key)
+       ;; Try to catch events of the form "<as df>".
+       (if (string-match "\\`<[^ <>\t\n\f][^>\t\n\f]*>" word)
+           (setq word (match-string 0 word)
+                 pos (+ word-beg (match-end 0)))
+         (setq word (substring string word-beg word-end)
+               pos word-end))
        (when (string-match "\\([0-9]+\\)\\*." word)
          (setq times (string-to-number (substring word 0 (match-end 1))))
          (setq word (substring word (1+ (match-end 1)))))
@@ -776,5 +780,4 @@ This function assumes that the events can be stored in a string."
 
 (provide 'edmacro)
 
-;; arch-tag: 726807b4-3ae6-49de-b0ae-b9590973e0d7
 ;;; edmacro.el ends here