emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 2953178 2/2: Improve printing for named keyboard ma


From: Noam Postavsky
Subject: [Emacs-diffs] master 2953178 2/2: Improve printing for named keyboard macros (Bug#35486)
Date: Sun, 12 May 2019 08:06:17 -0400 (EDT)

branch: master
commit 29531785a17acf519070b73b488ad87ddd94aff7
Author: Noam Postavsky <address@hidden>
Commit: Noam Postavsky <address@hidden>

    Improve printing for named keyboard macros (Bug#35486)
    
    * lisp/macros.el (macros--insert-vector-macro): New function,
    extracted from insert-kbd-macro.
    (insert-kbd-macro): Use it and kmacro-extract-lambda to produce nicer
    expressions for macros produced by kmacro-lambda-form.
---
 lisp/kmacro.el |  1 +
 lisp/macros.el | 34 +++++++++++++++++++++-------------
 2 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/lisp/kmacro.el b/lisp/kmacro.el
index fc34e16..01dc058 100644
--- a/lisp/kmacro.el
+++ b/lisp/kmacro.el
@@ -776,6 +776,7 @@ If kbd macro currently being defined end it before 
activating it."
 ;; letters and digits, provided that we inhibit the keymap while
 ;; executing the macro later on (but that's controversial...)
 
+;;;###autoload
 (defun kmacro-lambda-form (mac &optional counter format)
   "Create lambda form for macro bound to symbol or key."
   (if counter
diff --git a/lisp/macros.el b/lisp/macros.el
index ba6a840..4b38506 100644
--- a/lisp/macros.el
+++ b/lisp/macros.el
@@ -36,6 +36,16 @@
 ;;;###autoload
 (defalias 'name-last-kbd-macro #'kmacro-name-last-macro)
 
+(defun macros--insert-vector-macro (definition)
+  "Print DEFINITION, a vector, into the current buffer."
+  (dotimes (i (length definition))
+    (let ((char (aref definition i)))
+      (insert (if (zerop i) ?\[ ?\s))
+      (if (characterp char)
+          (princ (prin1-char char) (current-buffer))
+        (prin1 char (current-buffer)))))
+  (insert ?\]))
+
 ;;;###autoload
 (defun insert-kbd-macro (macroname &optional keys)
   "Insert in buffer the definition of kbd macro MACRONAME, as Lisp code.
@@ -111,19 +121,17 @@ use this command, and then save the file."
                     (delete-region (point) (1+ (point)))
                     (insert "\\M-\\C-?"))))))
       (if (vectorp definition)
-         (let ((len (length definition)) (i 0) char)
-           (while (< i len)
-             (insert (if (zerop i) ?\[ ?\s))
-             (setq char (aref definition i)
-                   i (1+ i))
-             (if (not (numberp char))
-                  (prin1 char (current-buffer))
-                (princ (prin1-char char) (current-buffer))))
-           (insert ?\]))
-        ;; FIXME: For kmacros, we shouldn't write the (lambda ...)
-        ;; gunk but instead we should write something more abstract like
-        ;; (kmacro-create [<keys>] 0 "%d").
-       (prin1 definition (current-buffer))))
+          (macros--insert-vector-macro definition)
+        (pcase (kmacro-extract-lambda definition)
+          (`(,vecdef ,counter ,format)
+           (insert "(kmacro-lambda-form ")
+           (macros--insert-vector-macro vecdef)
+           (insert " ")
+           (prin1 counter (current-buffer))
+           (insert " ")
+           (prin1 format (current-buffer))
+           (insert ")"))
+          (_ (prin1 definition (current-buffer))))))
     (insert ")\n")
     (if keys
         (let ((keys (or (where-is-internal (symbol-function macroname)



reply via email to

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