emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

emacs-29 573d9675fd7: Fix insertion of keyboard macro containing named k


From: Robert Pluim
Subject: emacs-29 573d9675fd7: Fix insertion of keyboard macro containing named keys
Date: Fri, 24 Feb 2023 05:44:22 -0500 (EST)

branch: emacs-29
commit 573d9675fd74fc50f70b3bc64f24f838f799a8aa
Author: Robert Pluim <rpluim@gmail.com>
Commit: Robert Pluim <rpluim@gmail.com>

    Fix insertion of keyboard macro containing named keys
    
    * lisp/kmacro.el: Autoload `macro--string-to-vector'.
    (kmacro-ring-head): Convert `last-kbd-macro' to a vector if it's a
    string, since `kmacro' uses `key-parse' on it.
    (kmacro-lambda-form): Remove require for 'macros
    * test/lisp/kmacro-tests.el
    (kmacro-tests-name-last-macro-key-parse-syntax):
    Test that insertion of macros that contain strings that look
    like named keys works correctly.
    
    (Bug#61700)
---
 lisp/kmacro.el            |  8 +++++---
 test/lisp/kmacro-tests.el | 14 ++++++++++++++
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/lisp/kmacro.el b/lisp/kmacro.el
index 94d8794bd23..aec4b805474 100644
--- a/lisp/kmacro.el
+++ b/lisp/kmacro.el
@@ -377,10 +377,14 @@ and `kmacro-counter-format'.")
 (defvar kmacro-view-item-no 0)
 
 
+(autoload 'macro--string-to-vector "macros")
 (defun kmacro-ring-head ()
   "Return pseudo head element in macro ring."
   (and last-kbd-macro
-       (kmacro last-kbd-macro kmacro-counter kmacro-counter-format-start)))
+       (kmacro (if (stringp last-kbd-macro)
+                   (macro--string-to-vector last-kbd-macro)
+                 last-kbd-macro)
+               kmacro-counter kmacro-counter-format-start)))
 
 
 (defun kmacro-push-ring (&optional elt)
@@ -841,8 +845,6 @@ KEYS should be a vector or a string that obeys 
`key-valid-p'."
       (setq mac     (nth 0 mac)))
     (when (stringp mac)
       ;; `kmacro' interprets a string according to `key-parse'.
-      (require 'macros)
-      (declare-function macro--string-to-vector "macros")
       (setq mac (macro--string-to-vector mac)))
     (kmacro mac counter format)))
 
diff --git a/test/lisp/kmacro-tests.el b/test/lisp/kmacro-tests.el
index 551fd8b60fc..a325220e8d9 100644
--- a/test/lisp/kmacro-tests.el
+++ b/test/lisp/kmacro-tests.el
@@ -614,6 +614,20 @@ This is a regression test for: Bug#3412, Bug#11817."
   (kmacro-tests-should-insert "bb"
     (kmacro-tests-simulate-command '(kmacro-tests-symbol-for-test))))
 
+;; Bug#61700 inserting named macro when the definition contains things
+;; that `key-parse' thinks are named keys
+(kmacro-tests-deftest kmacro-tests-name-last-macro-key-parse-syntax ()
+  "Name last macro can rebind a symbol it binds."
+  ;; Make sure our symbol is unbound.
+  (when (fboundp 'kmacro-tests-symbol-for-test)
+    (fmakunbound 'kmacro-tests-symbol-for-test))
+  (setplist 'kmacro-tests-symbol-for-test nil)
+  (kmacro-tests-define-macro "<b> hello </>")
+  (kmacro-name-last-macro 'kmacro-tests-symbol-for-test)
+  ;; Now run the function bound to the symbol.
+  (kmacro-tests-should-insert "<b> hello </>"
+    (kmacro-tests-simulate-command '(kmacro-tests-symbol-for-test))))
+
 (kmacro-tests-deftest kmacro-tests-store-in-register ()
   "Macro can be stored in and retrieved from a register."
   (use-local-map kmacro-tests-keymap)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]