]> code.delx.au - gnu-emacs/blobdiff - lisp/edmacro.el
(reset-language-environment): Set
[gnu-emacs] / lisp / edmacro.el
index 7f2d8d47fc04849b21911c6c55fba12f4e559e0b..4ec62152db5205deefbb2fa47bfe9394e4867ad0 100644 (file)
@@ -32,7 +32,7 @@
 ;; in a special buffer.  It prompts you to type a key sequence,
 ;; which should be one of:
 ;;
-;;  * RET or `C-x e' (call-last-kbd-macro), to edit the most 
+;;  * RET or `C-x e' (call-last-kbd-macro), to edit the most
 ;;    recently defined keyboard macro.
 ;;
 ;;  * `M-x' followed by a command name, to edit a named command
@@ -75,8 +75,6 @@
 
 ;;; The user-level commands for editing macros.
 
-;;;###autoload (define-key ctl-x-map "\C-k" 'edit-kbd-macro)
-
 ;;;###autoload
 (defvar edmacro-eight-bits nil
   "*Non-nil if edit-kbd-macro should leave 8-bit characters intact.
@@ -88,6 +86,10 @@ Default nil means to write characters above \\177 in octal notation.")
   (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-store-hook)
+(defvar edmacro-finish-hook)
+(defvar edmacro-original-buffer)
+
 ;;;###autoload
 (defun edit-kbd-macro (keys &optional prefix finish-hook store-hook)
   "Edit a keyboard macro.
@@ -103,7 +105,8 @@ With a prefix argument, format the macro in a more concise way."
       (cond (store-hook
             (setq mac keys)
             (setq cmd nil))
-           ((or (eq cmd 'call-last-kbd-macro)
+           ((or (memq cmd '(call-last-kbd-macro kmacro-call-macro
+                            kmacro-end-or-call-macro kmacro-end-and-call-macro))
                 (member keys '("\r" [return])))
             (or last-kbd-macro
                 (y-or-n-p "No keyboard macro defined.  Create one? ")
@@ -112,8 +115,10 @@ With a prefix argument, format the macro in a more concise way."
             (setq cmd 'last-kbd-macro))
            ((eq cmd 'execute-extended-command)
             (setq cmd (read-command "Name of keyboard macro to edit: "))
+            (if (string-equal cmd "")
+                (error "No command name given"))
             (setq mac (symbol-function cmd)))
-           ((eq cmd 'view-lossage)
+           ((memq cmd '(view-lossage electric-view-lossage))
             (setq mac (recent-keys))
             (setq cmd 'last-kbd-macro))
            ((null cmd)
@@ -591,7 +596,7 @@ If START or END is negative, it counts from the end."
             (if end
                 (let ((res nil))
                   (while (>= (setq end (1- end)) start)
-                    (cl-push (cl-pop seq) res))
+                    (push (pop seq) res))
                   (nreverse res))
               (copy-sequence seq)))
            (t
@@ -603,23 +608,30 @@ If START or END is negative, it counts from the end."
                 (setq i (1+ i) start (1+ start)))
               res))))))
 
-(defun edmacro-fix-menu-commands (macro)
-  (when (vectorp macro)
-    (let ((i 0) ev)
-      (while (< i (length macro))
-       (when (consp (setq ev (aref macro i)))
-         (cond ((equal (cadadr ev) '(menu-bar))
-                (setq macro (vconcat (edmacro-subseq macro 0 i)
-                                     (vector 'menu-bar (car ev))
-                                     (edmacro-subseq macro (1+ i))))
-                (incf i))
+(defun edmacro-fix-menu-commands (macro &optional noerror)
+  (if (vectorp macro)
+      (let (result)
+       ;; Make a list of the elements.
+       (setq macro (append macro nil))
+       (dolist (ev macro)
+         (cond ((atom ev)
+                (push ev result))
+               ((eq (car ev) 'help-echo))
+               ((equal ev '(menu-bar))
+                (push 'menu-bar result))
+               ((equal (cadadr ev) '(menu-bar))
+                (push (vector 'menu-bar (car ev)) result))
                ;; It would be nice to do pop-up menus, too, but not enough
                ;; info is recorded in macros to make this possible.
+               (noerror
+                ;; Just ignore mouse events.
+                nil)
                (t
                 (error "Macros with mouse clicks are not %s"
                        "supported by this command"))))
-       (incf i))))
-  macro)
+       ;; Reverse them again and make them back into a vector.
+       (vconcat (nreverse result)))
+    macro))
 \f
 ;;; Parsing a human-readable keyboard macro.
 
@@ -687,10 +699,12 @@ If START or END is negative, it counts from the end."
                        (error "%s must prefix a single character, not %s"
                               (substring orig-word 0 prefix) word))
                       ((and (/= (logand bits ?\C-\^@) 0) (stringp word)
-                            (string-match "[@-_.a-z?]" word))
+                            ;; We used to accept . and ? here,
+                            ;; but . is simply wrong,
+                            ;; and C-? is not used (we use DEL instead).
+                            (string-match "[@-_a-z]" word))
                        (setq key (list (+ bits (- ?\C-\^@)
-                                          (if (equal word "?") 127
-                                            (logand (aref word 0) 31))))))
+                                          (logand (aref word 0) 31)))))
                       (t
                        (setq key (list (+ bits (aref word 0)))))))))
        (when key
@@ -703,50 +717,14 @@ If START or END is negative, it counts from the end."
       (setq res (edmacro-subseq res 2 -2)))
     (if (and (not need-vector)
             (loop for ch across res
-                  always (and (integerp ch)
+                  always (and (char-valid-p ch)
                               (let ((ch2 (logand ch (lognot ?\M-\^@))))
                                 (and (>= ch2 0) (<= ch2 127))))))
        (concat (loop for ch across res
                      collect (if (= (logand ch ?\M-\^@) 0)
                                  ch (+ ch 128))))
       res)))
-\f
-;;; The following probably ought to go in macros.el:
-
-;;;###autoload
-(defun insert-kbd-macro (macroname &optional keys)
-  "Insert in buffer the definition of kbd macro NAME, as Lisp code.
-Optional second arg KEYS means also record the keys it is on
-\(this is the prefix argument, when calling interactively).
-
-This Lisp code will, when executed, define the kbd macro with the same
-definition it has now.  If you say to record the keys, the Lisp code
-will also rebind those keys to the macro.  Only global key bindings
-are recorded since executing this Lisp code always makes global
-bindings.
-
-To save a kbd macro, visit a file of Lisp code such as your `~/.emacs',
-use this command, and then save the file."
-  (interactive "CInsert kbd macro (name): \nP")
-  (let (definition)
-    (if (string= (symbol-name macroname) "")
-       (progn
-         (setq definition (format-kbd-macro))
-         (insert "(setq last-kbd-macro"))
-      (setq definition (format-kbd-macro macroname))
-      (insert (format "(defalias '%s" macroname)))
-    (if (> (length definition) 50)
-       (insert " (read-kbd-macro\n")
-      (insert "\n  (read-kbd-macro "))
-    (prin1 definition (current-buffer))
-    (insert "))\n")
-    (if keys
-       (let ((keys (where-is-internal macroname '(keymap))))
-         (while keys
-           (insert (format "(global-set-key %S '%s)\n" (car keys) macroname))
-           (setq keys (cdr keys)))))))
 
 (provide 'edmacro)
 
 ;;; edmacro.el ends here
-