GNU bug report logs - #35486
26.1; insert-kbd-macro now creates unreadable list code

Previous Next

Package: emacs;

Reported by: Francesco Potortì <pot <at> gnu.org>

Date: Mon, 29 Apr 2019 09:37:01 UTC

Severity: minor

Tags: fixed, patch

Found in version 26.1

Fixed in version 27.1

Done: Noam Postavsky <npostavs <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 35486 in the body.
You can then email your comments to 35486 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#35486; Package emacs. (Mon, 29 Apr 2019 09:37:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Francesco Potortì <pot <at> gnu.org>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Mon, 29 Apr 2019 09:37:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Francesco Potortì <pot <at> gnu.org>
To: bug-gnu-emacs <at> gnu.org
Subject: 26.1; insert-kbd-macro now creates unreadable list code
Date: Mon, 29 Apr 2019 11:36:29 +0200
The insert-kbd-macro function now creates code like this:

(fset 'rmail-remove-me
   (lambda (&optional arg) "Keyboard macro." (interactive "p")
   (kmacro-exec-ring-item (quote ([21 114 80 108 101 101 97 97 115 97
   115 ...

rather than this as before:

(fset 'approve
   "\C-[xundigestify\C-mdd\C-xqde\M-k\M-k\M-k\M-k\C-c\C-crApproved: ...

This makes it impossible to understand at a glance what a given macro
does by browsing the lisp code.  I find this to be a regression.  Can
this be undone, or at least controlled by an option?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#35486; Package emacs. (Mon, 29 Apr 2019 21:57:02 GMT) Full text and rfc822 format available.

Message #8 received at 35486 <at> debbugs.gnu.org (full text, mbox):

From: npostavs <at> gmail.com
To: Francesco Potortì <pot <at> gnu.org>
Cc: 35486 <at> debbugs.gnu.org
Subject: Re: bug#35486: 26.1; insert-kbd-macro now creates unreadable list code
Date: Mon, 29 Apr 2019 17:55:42 -0400
Francesco Potortì <pot <at> gnu.org> writes:

> The insert-kbd-macro function now creates code like this:
>
> (fset 'rmail-remove-me
>    (lambda (&optional arg) "Keyboard macro." (interactive "p")
>    (kmacro-exec-ring-item (quote ([21 114 80 108 101 101 97 97 115 97
>    115 ...
>
> rather than this as before:
>
> (fset 'approve
>    "\C-[xundigestify\C-mdd\C-xqde\M-k\M-k\M-k\M-k\C-c\C-crApproved: ...

By "before", do you mean Emacs 21?  It looks like the (lambda ()
(kmacro-exec-ring-item ...)) thing was added in [1: 18d1e6c], which was
fairly long ago.

[1: 18d1e6c]: 2004-09-09 20:48:12 +0000
  (kmacro-bind-to-key): Associate dedicated macro counter and format with binding.
  https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=18d1e6c9fd4d8d446329ceb48a83ddca373f72c0

> This makes it impossible to understand at a glance what a given macro
> does by browsing the lisp code.  I find this to be a regression.  Can
> this be undone, or at least controlled by an option?

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)))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#35486; Package emacs. (Sun, 05 May 2019 17:51:02 GMT) Full text and rfc822 format available.

Message #11 received at 35486 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> gmail.com>
To: Francesco Potortì <pot <at> gnu.org>
Cc: 35486 <at> debbugs.gnu.org
Subject: Re: bug#35486: 26.1; insert-kbd-macro now creates unreadable list code
Date: Sun, 05 May 2019 13:50:17 -0400
[Message part 1 (text/plain, inline)]
severity 35486 minor
tags 35486 + patch
quit

npostavs <at> 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"))

[0001-Improve-printing-for-named-keyboard-macros-Bug-35486.patch (text/x-diff, inline)]
From fe7420c67f18195aa85853dbfc6afcdf65e9d5a0 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs <at> 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


Severity set to 'minor' from 'normal' Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Sun, 05 May 2019 17:51:02 GMT) Full text and rfc822 format available.

Added tag(s) patch. Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Sun, 05 May 2019 17:51:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#35486; Package emacs. (Sun, 12 May 2019 12:09:02 GMT) Full text and rfc822 format available.

Message #18 received at 35486 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> gmail.com>
To: Francesco Potortì <pot <at> gnu.org>
Cc: 35486 <at> debbugs.gnu.org
Subject: Re: bug#35486: 26.1; insert-kbd-macro now creates unreadable list code
Date: Sun, 12 May 2019 08:07:57 -0400
tags 35486 fixed
close 35486 27.1
quit

Noam Postavsky <npostavs <at> gmail.com> writes:
>
> 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"))

Pushed to master.

29531785a1 2019-05-12T08:05:01-04:00 "Improve printing for named keyboard macros (Bug#35486)"
https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=29531785a17acf519070b73b488ad87ddd94aff7





Added tag(s) fixed. Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Sun, 12 May 2019 12:09:03 GMT) Full text and rfc822 format available.

bug marked as fixed in version 27.1, send any further explanations to 35486 <at> debbugs.gnu.org and Francesco Potortì <pot <at> gnu.org> Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Sun, 12 May 2019 12:09:03 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 10 Jun 2019 11:24:08 GMT) Full text and rfc822 format available.

This bug report was last modified 4 years and 315 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.