From: Noam Postavsky <npostavs@gmail.com>
To: "Francesco Potortì" <pot@gnu.org>
Cc: 35486@debbugs.gnu.org
Subject: bug#35486: 26.1; insert-kbd-macro now creates unreadable list code
Date: Sun, 05 May 2019 13:50:17 -0400 [thread overview]
Message-ID: <87v9yolrja.fsf@gmail.com> (raw)
In-Reply-To: <858svsmq75.fsf@gmail.com> (npostavs@gmail.com's message of "Mon, 29 Apr 2019 17:55:42 -0400")
[-- Attachment #1: Type: text/plain, Size: 675 bytes --]
severity 35486 minor
tags 35486 + patch
quit
npostavs@gmail.com writes:
> I think the kmacro-bind-to-key is important to preserve the way macro
> counters work, but it seems like we should be able to add some special
> casing to at least get something like this:
>
> (fset 'approve
> (lambda (&optional arg)
> "Keyboard macro."
> (interactive "p")
> (kmacro-exec-ring-item (quote ([?\M-x ?u ?n ?d ?i ?g ?e ?s ?t ?i ?f ?y return ?d ?d ?\C-x ?q ?d ?e ?\M-k] 0 "%d")) arg)))
Following an existing FIXME, the following patch produces
(fset 'approve
(kmacro-lambda-form [?\M-x ?u ?n ?d ?i ?g ?e ?s ?t ?i ?f ?y return ?d ?d ?\C-x ?q ?d ?e ?\M-k] 0 "%d"))
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-diff, Size: 3095 bytes --]
From fe7420c67f18195aa85853dbfc6afcdf65e9d5a0 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@gmail.com>
Date: Sun, 5 May 2019 13:24:15 -0400
Subject: [PATCH] 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 fc34e16708..01dc058614 100644
--- a/lisp/kmacro.el
+++ b/lisp/kmacro.el
@@ -776,6 +776,7 @@ (defun kmacro-end-call-mouse (event)
;; 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 ba6a840d60..4b38506d8a 100644
--- a/lisp/macros.el
+++ b/lisp/macros.el
@@ -36,6 +36,16 @@ (require 'kmacro)
;;;###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 @@ (defun insert-kbd-macro (macroname &optional keys)
(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)
--
2.11.0
next prev parent reply other threads:[~2019-05-05 17:50 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-29 9:36 bug#35486: 26.1; insert-kbd-macro now creates unreadable list code Francesco Potortì
2019-04-29 21:55 ` npostavs
2019-05-05 17:50 ` Noam Postavsky [this message]
2019-05-12 12:07 ` Noam Postavsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87v9yolrja.fsf@gmail.com \
--to=npostavs@gmail.com \
--cc=35486@debbugs.gnu.org \
--cc=pot@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.