GNU bug report logs - #77317
31.0.50; insert-kbd-macro RET produces elisp that does not work

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Adam Sjøgren <asjo@HIDDEN>; Done: Adam Sjøgren <asjo@HIDDEN>; Maintainer for emacs is bug-gnu-emacs@HIDDEN.
bug closed, send any further explanations to 77317 <at> debbugs.gnu.org and Adam Sjøgren <asjo@HIDDEN> Request was from Adam Sjøgren <asjo@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

Message received at 77317 <at> debbugs.gnu.org:


Received: (at 77317) by debbugs.gnu.org; 31 Mar 2025 15:37:04 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Mar 31 11:37:03 2025
Received: from localhost ([127.0.0.1]:42492 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tzHC9-0006Sr-N2
	for submit <at> debbugs.gnu.org; Mon, 31 Mar 2025 11:37:03 -0400
Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:54932)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <monnier@HIDDEN>)
 id 1tzHC7-0006RY-8i
 for 77317 <at> debbugs.gnu.org; Mon, 31 Mar 2025 11:36:59 -0400
Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1])
 by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 0C8AC80813;
 Mon, 31 Mar 2025 11:36:52 -0400 (EDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca;
 s=mail; t=1743435411;
 bh=B6nBthh6JwiH8hfUg8zOiOhtOdRprxSnErglnGltGtM=;
 h=From:To:Cc:Subject:In-Reply-To:References:Date:From;
 b=O2+eNZ/jJ/02v3GaOIqC2sYKi0sKrFQaChTyCijNCy8mdLPlsBIq4z7BsuJ52ORFv
 Br0hNm+C2uSYYayZaXfSc5WvudzqkU/B95AawTGqoSnu7PK2jlbJTjJ4ibj4Vkkkh0
 3kGkqddP3XXXbSlzTRN5f/8rT20yCJc1XiFuXskrh8kz9HjthTC6gjUU4r74+EJ+2o
 YeB4Ynslwk21560WViMzJqfKxPzy3v2OdoCE6e1DRhuO7P9h1I/C2PENLJ29OlbsuR
 GxxiCWaPPk50L7tQ53pOsA051+HeJxF3cXwkXPJ9v7Mpro1YClUOSeC+GYkWAWsjTT
 ViIcAhCMVw+RA==
Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1])
 by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 40D5F80781;
 Mon, 31 Mar 2025 11:36:51 -0400 (EDT)
Received: from alfajor (unknown [23.233.149.155])
 by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 28233120205;
 Mon, 31 Mar 2025 11:36:51 -0400 (EDT)
From: Stefan Monnier <monnier@HIDDEN>
To: Adam =?windows-1252?Q?Sj=F8gren?= <asjo@HIDDEN>
Subject: Re: bug#77317: 31.0.50; insert-kbd-macro RET produces elisp that
 does not work
In-Reply-To: <87friwkgpe.fsf@HIDDEN>
Message-ID: <jwvjz85usb3.fsf-monnier+emacs@HIDDEN>
References: <87iknuz5e4.fsf@HIDDEN>
 <jwvy0wpvyu5.fsf-monnier+emacs@HIDDEN>
 <87semwkjcz.fsf@HIDDEN>
 <jwvv7rsvr79.fsf-monnier+emacs@HIDDEN>
 <87friwkgpe.fsf@HIDDEN>
Date: Mon, 31 Mar 2025 11:36:47 -0400
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain
X-SPAM-INFO: Spam detection results:  0
 ALL_TRUSTED                -1 Passed through trusted hosts only via SMTP
 AWL -0.124 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DKIM_SIGNED               0.1 Message has a DKIM or DK signature,
 not necessarily valid
 DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature
 DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's
 domain
 DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from
 domain
X-SPAM-LEVEL: 
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 77317
Cc: 77317 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

>> The patch below makes it emit
>>
>>     (setq last-kbd-macro
>>           (key-parse "A B B A"))
>
> That works perfectly for me - thanks!

Pushed to `master`, thanks.


        Stefan





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#77317; Package emacs. Full text available.

Message received at 77317 <at> debbugs.gnu.org:


Received: (at 77317) by debbugs.gnu.org; 28 Mar 2025 21:07:00 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Mar 28 17:07:00 2025
Received: from localhost ([127.0.0.1]:55713 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tyGuq-0007nH-7Q
	for submit <at> debbugs.gnu.org; Fri, 28 Mar 2025 17:07:00 -0400
Received: from virgil.koldfront.dk ([212.237.178.116]:57428)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <asjo@HIDDEN>) id 1tyGun-0007n5-OO
 for 77317 <at> debbugs.gnu.org; Fri, 28 Mar 2025 17:06:58 -0400
DKIM-Filter: OpenDKIM Filter v2.11.0 virgil.koldfront.dk 0AFB795F6451A
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=koldfront.dk;
 s=mail; t=1743196014;
 bh=ltoIYWV4CghOUa2m67ulb72P3+nbh25cybddOiH7xwE=;
 h=From:To:Cc:Subject:In-Reply-To:References:Date:From;
 b=Jtcg/yX2d2UwVoXtj4Y6Fjmqn/mdD3nwjlX7nmUdrqoQEf9zh/uLjAxqMJXqeZ71D
 kW65BKqwf03EON0Kxam1qRUm13oDY6/FjwR7s5totJwknPGNE2cWny6a7s0apO2Re1
 Da1/vd5GS2fRjUxCBJUDbJo4yE0iUA+wiX2Y/+8NMNyK/isT4Ju8q88gTS5uvVPtzZ
 I5fTfaYCxwRs9vHYYiiVjP2zjoQW455uS8uJtnsmprfS0vMHbgbWimBHp3RUHJgIxG
 fSKJPM3e8ub7e9obcBvX2/7zoRIC885rbvea4x8kD73DOBN/AS6zZZgqW2wobjmBmr
 iO+O4nI7qcVDQ==
Received: from tullinup.koldfront.dk (tullinup.koldfront.dk [192.168.1.102])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (4096 bits))
 (No client certificate requested)
 by virgil.koldfront.dk (Postfix) with ESMTPS id 0AFB795F6451A;
 Fri, 28 Mar 2025 22:06:54 +0100 (CET)
Received: by tullinup.koldfront.dk (Postfix, from userid 1000)
 id DE1D320198045; Fri, 28 Mar 2025 22:06:53 +0100 (CET)
From: =?utf-8?Q?Adam_Sj=C3=B8gren?= <asjo@HIDDEN>
To: Stefan Monnier <monnier@HIDDEN>
Subject: Re: bug#77317: 31.0.50; insert-kbd-macro RET produces elisp that
 does not work
In-Reply-To: <jwvv7rsvr79.fsf-monnier+emacs@HIDDEN>
Organization: koldfront - analysis & revolution, Copenhagen, Denmark
References: <87iknuz5e4.fsf@HIDDEN>
 <jwvy0wpvyu5.fsf-monnier+emacs@HIDDEN>
 <87semwkjcz.fsf@HIDDEN>
 <jwvv7rsvr79.fsf-monnier+emacs@HIDDEN>
X-Face: )qY&CseJ?.:=8F#^~GcSA?F=9eu'{KAFfL1C3/A&:nE?PW\i65"ba0NS)97,
 Q(^@xk}n4Ou
 rPuR#V8I(J_@~H($[ym:`K_+]*kjvW>xH5jbgLBVFGXY:(#4P>zVBklLbdL&XxL\M)%T}3S/IS9lMJ
 ^St'=VZBR<gm`!Dj`dIpp?+$"$l_'JKDN\w-jB;fo0Qy}Tbw
Date: Fri, 28 Mar 2025 22:06:53 +0100
Message-ID: <87friwkgpe.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 77317
Cc: 77317 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

Stefan writes:

> The patch below makes it emit
>
>     (setq last-kbd-macro
>           (key-parse "A B B A"))

That works perfectly for me - thanks!


  Best regards,

    Adam

--=20
 "How's your snow art progressing?"                         Adam Sj=C3=B8gr=
en
 "I've moved into abstraction!"                        asjo@HIDDEN




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#77317; Package emacs. Full text available.

Message received at 77317 <at> debbugs.gnu.org:


Received: (at 77317) by debbugs.gnu.org; 28 Mar 2025 21:00:08 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Mar 28 17:00:08 2025
Received: from localhost ([127.0.0.1]:55675 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tyGoB-0007Re-Ur
	for submit <at> debbugs.gnu.org; Fri, 28 Mar 2025 17:00:08 -0400
Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:49119)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <monnier@HIDDEN>)
 id 1tyGo8-0007MR-SQ
 for 77317 <at> debbugs.gnu.org; Fri, 28 Mar 2025 17:00:05 -0400
Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1])
 by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id A9B36100066;
 Fri, 28 Mar 2025 16:59:57 -0400 (EDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca;
 s=mail; t=1743195596;
 bh=OUFsAmqmxNTrxeDBNZ+9lePItti2hq94h34AnMTr2Ds=;
 h=From:To:Cc:Subject:In-Reply-To:References:Date:From;
 b=k7Xs8BYJ7CPIxEjxH3xUQuX4JzaA2vfIhvfQYy5+JZrmNgcmh/8/HOIHTIheh0y5v
 3NmH/XD72Ukknqff3YUdp3aT45IoxmkHIEMkvozb9oC0kAQggvSx8hraJaakgQrvYD
 dZlmPJWSRzIyYs+oaZSQdyzRt1J/e4LuSXltBmTbcN+2ocqxXitJiOQ0gtYkQYjCrI
 j3YLiLnfD5gsoU5HO25gfqQVmd0wq1mo4GwIAXciGKz4PREGOHKgKUTfA2H6hx9Aqr
 /05OwUnjC/LVRi1lvJAYUFrqYuy4Ggm0SzmLaNJW5tyyv0n40SW9gbGGmJfQG8D7QS
 660PwtLeY6WWg==
Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1])
 by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id E2462100040;
 Fri, 28 Mar 2025 16:59:56 -0400 (EDT)
Received: from alfajor (modemcable054.254-202-24.mc.videotron.ca
 [24.202.254.54])
 by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id C26E91206FB;
 Fri, 28 Mar 2025 16:59:56 -0400 (EDT)
From: Stefan Monnier <monnier@HIDDEN>
To: Adam =?windows-1252?Q?Sj=F8gren?= <asjo@HIDDEN>
Subject: Re: bug#77317: 31.0.50; insert-kbd-macro RET produces elisp that
 does not work
In-Reply-To: <87semwkjcz.fsf@HIDDEN>
Message-ID: <jwvv7rsvr79.fsf-monnier+emacs@HIDDEN>
References: <87iknuz5e4.fsf@HIDDEN>
 <jwvy0wpvyu5.fsf-monnier+emacs@HIDDEN>
 <87semwkjcz.fsf@HIDDEN>
Date: Fri, 28 Mar 2025 16:59:56 -0400
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain
X-SPAM-INFO: Spam detection results:  0
 ALL_TRUSTED                -1 Passed through trusted hosts only via SMTP
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DKIM_SIGNED               0.1 Message has a DKIM or DK signature,
 not necessarily valid
 DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature
 DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's
 domain
 DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from
 domain
X-SPAM-LEVEL: 
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 77317
Cc: 77317 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> For my use-case generating
>
>     (setq last-kbd-macro (kmacro--keys
>        (kmacro "A B B A")))
>
> instead of:
>
>     (setq last-kbd-macro
>        (kmacro "A B B A"))

The patch below makes it emit

    (setq last-kbd-macro
          (key-parse "A B B A"))

> How does that actually work for a named macro? If I name the macro
> "hep" and insert it, I get:
>
>     (defalias 'hep
>        (kmacro "A B B A"))

Yes.

> Maybe that's because I didn't use any counters?

If you use the counter or the format, they'll appear as additional
arguments to the `kmacro` constructor.

> From time to time I edit a list of (spam)domains to reject, and I
> often create a macro that inserts an email-address and changes the .
> to [.] and deletes everything in front of the @.
>
> Instead of recreating that macro when I edit that list, I thought
> "Hey, I can probably save that macro in the file and reconstitute it
> when I need it".
>
> So I found M-x insert-kbd-macro and didn't give a name when prompted
> (as the macro didn't have one), and it promisingly inserted some code,
> which I tried evaluating and executing.

Thanks, that gives a good reason to support that functionality.

> With C-x e I can repeat the macro by pressing e more times.  Is that
> functionality present when I do M-x hep (ie run a named macro)?

No, the named macros are meant to use the "generic" repetition support,
e.g. by binding them to convenient keys or by using `C-x z`.


        Stefan


diff --git a/lisp/macros.el b/lisp/macros.el
index 64b78d1cdf4..25ea303d439 100644
--- a/lisp/macros.el
+++ b/lisp/macros.el
@@ -78,8 +78,6 @@ insert-kbd-macro
       (insert "(defalias '"))
     (prin1 macroname (current-buffer))
     (insert "\n   ")
-    (when (or (stringp definition) (vectorp definition))
-      (setq definition (kmacro (kmacro--to-vector definition))))
     (if (kmacro-p definition)
         (let ((vecdef  (kmacro--keys     definition))
               (counter (kmacro--counter definition))
@@ -93,8 +91,7 @@ insert-kbd-macro
             (insert " ")
             (prin1 format (current-buffer)))
           (insert ")"))
-      ;; FIXME: Shouldn't this signal an error?
-      (prin1 definition (current-buffer)))
+        (prin1 `(key-parse ,(key-description definition)) (current-buffer)))
     (insert ")\n")
     (if keys
         (let ((keys (or (and (symbol-function macroname)





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#77317; Package emacs. Full text available.

Message received at 77317 <at> debbugs.gnu.org:


Received: (at 77317) by debbugs.gnu.org; 28 Mar 2025 20:09:42 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Mar 28 16:09:42 2025
Received: from localhost ([127.0.0.1]:55618 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tyG1N-0004wA-Ik
	for submit <at> debbugs.gnu.org; Fri, 28 Mar 2025 16:09:41 -0400
Received: from virgil.koldfront.dk ([212.237.178.116]:47432)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <asjo@HIDDEN>) id 1tyG1J-0004vu-DE
 for 77317 <at> debbugs.gnu.org; Fri, 28 Mar 2025 16:09:39 -0400
DKIM-Filter: OpenDKIM Filter v2.11.0 virgil.koldfront.dk 8889995F6451A
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=koldfront.dk;
 s=mail; t=1743192572;
 bh=LegWMKDAcolNi1ngSW0a3bALdugY+ka2XaY705fOKLM=;
 h=From:To:Cc:Subject:In-Reply-To:References:Date:From;
 b=ZLVPQldgrPR7AYDielQkUdaco1BfeACdyVKJMN0iM3boLvuQ/p0HJ32ClKMHVuAB7
 wPW1r+k5hYqTUYvL08LAMmIwsRF4o2wX8jR1rT5IJTyMGx0iJ9OVwS+GDwJa7B4sSa
 hwUvfqcpdkCt+LYN4gKYI48WizTH2rmUMfQJzKSe3m0fpnB6Af7JALoQpbYgsTIxUn
 YeTbnlxBxCZR0/kxMVfbYJQQgZIsOHG7yaTIBsJIxxWylq72L4Vupxn7/OmlXRBJJA
 9cVskhjcrb6ilJR1u2eVv9KLAcLCxMKdFvUa+OGn6f/+AxuMv08Eumgq/CtY9tzAJK
 i/U1R3cCedx6g==
Received: from tullinup.koldfront.dk (tullinup.koldfront.dk [192.168.1.102])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256)
 (No client certificate requested)
 by virgil.koldfront.dk (Postfix) with ESMTPS id 8889995F6451A;
 Fri, 28 Mar 2025 21:09:32 +0100 (CET)
Received: by tullinup.koldfront.dk (Postfix, from userid 1000)
 id 769B220198045; Fri, 28 Mar 2025 21:09:32 +0100 (CET)
From: =?utf-8?Q?Adam_Sj=C3=B8gren?= <asjo@HIDDEN>
To: Stefan Monnier <monnier@HIDDEN>
Subject: Re: bug#77317: 31.0.50; insert-kbd-macro RET produces elisp that
 does not work
In-Reply-To: <jwvy0wpvyu5.fsf-monnier+emacs@HIDDEN>
Organization: koldfront - analysis & revolution, Copenhagen, Denmark
References: <87iknuz5e4.fsf@HIDDEN>
 <jwvy0wpvyu5.fsf-monnier+emacs@HIDDEN>
X-Now-Playing: =?utf-8?Q?J=C3=B8rgen?= eller Palle, Det store triumftog (cd
 5) (Monrad & Rislund)
X-Face: )qY&CseJ?.:=8F#^~GcSA?F=9eu'{KAFfL1C3/A&:nE?PW\i65"ba0NS)97,
 Q(^@xk}n4Ou
 rPuR#V8I(J_@~H($[ym:`K_+]*kjvW>xH5jbgLBVFGXY:(#4P>zVBklLbdL&XxL\M)%T}3S/IS9lMJ
 ^St'=VZBR<gm`!Dj`dIpp?+$"$l_'JKDN\w-jB;fo0Qy}Tbw
Date: Fri, 28 Mar 2025 21:09:32 +0100
Message-ID: <87semwkjcz.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 77317
Cc: 77317 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

Stefan writes:

> So to avoid the error you're seeing, as the code currently stands, the
> `(setq last-kbd-macro (kmacro ...))` should be replaced with either
> a call to `kmacro-split-ring-element` or something which has the same
> effect:
>
>     (defun kmacro-split-ring-element (elt)
>       (setq last-kbd-macro (kmacro--keys elt)
>             kmacro-counter (kmacro--counter elt)
>             kmacro-counter-format-start (kmacro--format elt)))
>
> =F0=9F=99=81

Yeah, ok, not exactly pretty.

For my use-case generating

    (setq last-kbd-macro (kmacro--keys
       (kmacro "A B B A")))

instead of:

    (setq last-kbd-macro
       (kmacro "A B B A"))

would be sufficient. I think that would be better than what happens
currently, but I can see it is not as comprehensive as also handling
the counter stuff.

How does that actually work for a named macro? If I name the macro
"hep" and insert it, I get:

    (defalias 'hep
       (kmacro "A B B A"))

Maybe that's because I didn't use any counters?

> Maybe a better fix would be to "force" the user to give a name to the
> macro before inserting it.

Better than inserting some code that doesn't work, agreed.

> Could you explain exactly how you bumped into this problem, more
> specifically what was your intention behind the use of
> `insert-kbd-macro` without giving the macro a name?

I rarely use macros, and I never use named macros (I always forget
about the possibility).

From time to time I edit a list of (spam)domains to reject, and I
often create a macro that inserts an email-address and changes the .
to [.] and deletes everything in front of the @.

Instead of recreating that macro when I edit that list, I thought
"Hey, I can probably save that macro in the file and reconstitute it
when I need it".

So I found M-x insert-kbd-macro and didn't give a name when prompted
(as the macro didn't have one), and it promisingly inserted some code,
which I tried evaluating and executing.

I wondered why it didn't work, and at first I assumed I was doing
something wrong.

Then I tried in an older Emacs and saw it generate something slightly
different, which worked, and then I looked in macros.el and found code
that seemed to specifically handle last-kbd-macro.

Which lead me to believe that it ought to work.

I can see that the manual and the code do not quite agree, but I still
think it is a nice and natural functionality that you can save the
current macro and get it back without having to name it.

With C-x e I can repeat the macro by pressing e more times. Is that
functionality present when I do M-x hep (ie run a named macro)?


  Best regards,

    Adam

--=20
 "People just generally like to disagree."                  Adam Sj=C3=B8gr=
en
                                                       asjo@HIDDEN




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#77317; Package emacs. Full text available.

Message received at 77317 <at> debbugs.gnu.org:


Received: (at 77317) by debbugs.gnu.org; 28 Mar 2025 17:50:46 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Mar 28 13:50:46 2025
Received: from localhost ([127.0.0.1]:55437 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tyDqw-00070U-6I
	for submit <at> debbugs.gnu.org; Fri, 28 Mar 2025 13:50:46 -0400
Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:48408)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <monnier@HIDDEN>)
 id 1tyDqt-00070F-LX
 for 77317 <at> debbugs.gnu.org; Fri, 28 Mar 2025 13:50:44 -0400
Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1])
 by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 856FD100066;
 Fri, 28 Mar 2025 13:50:35 -0400 (EDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca;
 s=mail; t=1743184234;
 bh=3RgZin6ybeQeKGelfc9FWt0AbkO8hhgNJvksgjJEtKM=;
 h=From:To:Cc:Subject:In-Reply-To:References:Date:From;
 b=brgcFTrULRZRHXzDFek881ehoBYDLoGg/QXT0GZlWKWdZAR+rprn/4SXFRkvoUevz
 t86XqDtUeu8fOyXOl3q1dm4qwuqlHQ1u/Agf2Hyd9aeN69gWgou/i8bvuPtZAeG1im
 xZMbclKn1HGO+gj2tq63c25RMBcx9Q2OP6elvf11REshEdeam7TOdtwjdOeR/MYq31
 L9Y5tslri/H2vvewEjMGYFDp7IrWV54ApP3/+XTw1yfm8GK/5N4UifUHwGka/uMcWA
 7g2mQOe2+rURzsTI0YleQrZXHYqWzRaaBVOdHFMjeaA6cw7OqQvSRlD3q/pBNs7M57
 bx1Y5TFsPxaxw==
Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1])
 by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 7F09E100040;
 Fri, 28 Mar 2025 13:50:34 -0400 (EDT)
Received: from alfajor (modemcable031.210-178-173.mc.videotron.ca
 [173.178.210.31])
 by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 5A474120342;
 Fri, 28 Mar 2025 13:50:34 -0400 (EDT)
From: Stefan Monnier <monnier@HIDDEN>
To: Adam =?windows-1252?Q?Sj=F8gren?= <asjo@HIDDEN>
Subject: Re: bug#77317: 31.0.50; insert-kbd-macro RET produces elisp that
 does not work
In-Reply-To: <87iknuz5e4.fsf@HIDDEN>
Message-ID: <jwvy0wpvyu5.fsf-monnier+emacs@HIDDEN>
References: <87iknuz5e4.fsf@HIDDEN>
Date: Fri, 28 Mar 2025 13:50:33 -0400
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-SPAM-INFO: Spam detection results:  0
 ALL_TRUSTED                -1 Passed through trusted hosts only via SMTP
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DKIM_SIGNED               0.1 Message has a DKIM or DK signature,
 not necessarily valid
 DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature
 DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's
 domain
 DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from
 domain
X-SPAM-LEVEL: 
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 77317
Cc: 77317 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> The generated code looks like this:
>
>     (setq last-kbd-macro
>        (kmacro "A B B A"))

Hmm... this is nicely readable, but indeed it bumps into the following
problem:

A keyboard macro is made of 3 elements: the sequence of events, of
course, but also a counter and format string.
The "currently installed" (aka "last") keyboard macro stores those
3 pieces of info in, respectively:

    last-kbd-macro
    kmacro-counter
    kmacro-counter-format

When saved elsewhere (e.g. in the `kmacro-ring` or in an init file),
these three elements are bundled into a single `kmacro` object.

So to avoid the error you're seeing, as the code currently stands, the
`(setq last-kbd-macro (kmacro ...))` should be replaced with either
a call to `kmacro-split-ring-element` or something which has the same
effect:

    (defun kmacro-split-ring-element (elt)
      (setq last-kbd-macro (kmacro--keys elt)
            kmacro-counter (kmacro--counter elt)
            kmacro-counter-format-start (kmacro--format elt)))

=F0=9F=99=81

Maybe a better fix would be to "force" the user to give a name to the
macro before inserting it.

Could you explain exactly how you bumped into this problem, more
specifically what was your intention behind the use of
`insert-kbd-macro` without giving the macro a name?


        Stefan





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#77317; Package emacs. Full text available.

Message received at 77317 <at> debbugs.gnu.org:


Received: (at 77317) by debbugs.gnu.org; 28 Mar 2025 12:31:39 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Mar 28 08:31:39 2025
Received: from localhost ([127.0.0.1]:53243 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1ty8s6-0002g7-N7
	for submit <at> debbugs.gnu.org; Fri, 28 Mar 2025 08:31:39 -0400
Received: from virgil.koldfront.dk ([212.237.178.116]:38330)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <asjo@HIDDEN>) id 1ty8s3-0002fq-Bq
 for 77317 <at> debbugs.gnu.org; Fri, 28 Mar 2025 08:31:36 -0400
DKIM-Filter: OpenDKIM Filter v2.11.0 virgil.koldfront.dk F01AA95F6451A
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=koldfront.dk;
 s=mail; t=1743165092;
 bh=g/1jyQ8YHyBaru82RjYdSyn/PqIGph0htQxA1otQba8=;
 h=From:To:Cc:Subject:In-Reply-To:References:Date:From;
 b=h6GvUnxnoUx1kJ2l8NGIi2zR3MZYXV4Lgb1aMBrw+31TBcL6JORaCN+JMcKTta8jN
 Vl19QIRvS3Tpvm452YOGTIzrP8MhBdhCf/802NVTu/yJwVS1VwAaNXS8xpLcCX+lr5
 AaRmWRfny76fCplmvF5wEnGE8QmICxgMRKD+sd0ol0/gVAXhegMxAL9TMrGfWuoNv1
 f09RG2g7bQr39KOXYqoni8HCPuqZmoX2kVbs+MnsXIIvwd+/lVmo1KfHmdwUMmp9SF
 wXb2aLkzQp4iZwcJcQ5UqowDsBD1je0QZx7Rljwgb+GvyKcrZ7hi3tTpZVSefnIgmU
 7AxAYZEmvvf4A==
Received: from tullinup.koldfront.dk (tullinup.koldfront.dk [192.168.1.102])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256)
 (No client certificate requested)
 by virgil.koldfront.dk (Postfix) with ESMTPS id F01AA95F6451A;
 Fri, 28 Mar 2025 13:31:32 +0100 (CET)
Received: by tullinup.koldfront.dk (Postfix, from userid 1000)
 id D9DAB2019973B; Fri, 28 Mar 2025 13:31:32 +0100 (CET)
From: =?utf-8?Q?Adam_Sj=C3=B8gren?= <asjo@HIDDEN>
To: 77317 <at> debbugs.gnu.org
Subject: Re: bug#77317: 31.0.50; insert-kbd-macro RET produces elisp that
 does not work
In-Reply-To: <86wmc9a0e4.fsf@HIDDEN>
Organization: koldfront - analysis & revolution, Copenhagen, Denmark
References: <87iknuz5e4.fsf@HIDDEN>
 <86wmc9a0e4.fsf@HIDDEN>
X-Face: )qY&CseJ?.:=8F#^~GcSA?F=9eu'{KAFfL1C3/A&:nE?PW\i65"ba0NS)97,
 Q(^@xk}n4Ou
 rPuR#V8I(J_@~H($[ym:`K_+]*kjvW>xH5jbgLBVFGXY:(#4P>zVBklLbdL&XxL\M)%T}3S/IS9lMJ
 ^St'=VZBR<gm`!Dj`dIpp?+$"$l_'JKDN\w-jB;fo0Qy}Tbw
Date: Fri, 28 Mar 2025 13:31:32 +0100
Message-ID: <87semxpc9n.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 77317
Cc: Eli Zaretskii <eliz@HIDDEN>, Stefan Monnier <monnier@HIDDEN>
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

Eli writes:

> So it sounds like this is supposed to work for macros that have been
> given a name.

If you look at the code, there is an explicit path for last-kbd-macro:

    (if (string=3D (symbol-name macroname) "")
	(progn
	  (setq macroname 'last-kbd-macro definition last-kbd-macro)
	  (insert "(setq "))
      (setq definition (symbol-function macroname))

      =C2=B7 macros.el L70-74

which to me indicates an intention of it working, even if the manual
doesn't mention the case. This code has been in macros.el since 1992,
according to git annotate.

If insert-kbd-macro was designed explicitly to not work on the
unnamed, last macro, shouldn't an error be raised or an empty macro
name be rejected, rather than code inserted?

If you try it in a version of Emacs released before 2022-04-01 saving
last-kbd-macro does work - eg Emacs 28.2 as included in Debian 12.

(Just as a side-note: the manual of Emacs 28.2 didn't mention the
possibility either.)

Maybe Stefan Monnier (Cc'd) can shed some light on this, as he
improved the named macro part of insert-kbd-macro in 2022 (c75f65442ddf):

    Also replace the old `kmacro-lambda-form` with a new `kmacro` construct=
or
    which takes a `key-parse` syntax, so that the code inserted with
    `insert-kbd-macro` is now more readable.

     [...]

    * lisp/macros.el (macro--string-to-vector): New function.
    (insert-kbd-macro): Use it.  Generate code using the `kmacro` construct=
or.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#77317; Package emacs. Full text available.

Message received at 77317 <at> debbugs.gnu.org:


Received: (at 77317) by debbugs.gnu.org; 28 Mar 2025 10:57:27 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Mar 28 06:57:27 2025
Received: from localhost ([127.0.0.1]:53041 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1ty7Ow-0003gl-S8
	for submit <at> debbugs.gnu.org; Fri, 28 Mar 2025 06:57:27 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:38510)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <eliz@HIDDEN>) id 1ty7Ou-0003gR-FN
 for 77317 <at> debbugs.gnu.org; Fri, 28 Mar 2025 06:57:25 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1ty7Oj-000562-2V; Fri, 28 Mar 2025 06:57:16 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From:
 Date; bh=9fSooY3QgEi3wHn67GElsRWDqmbdle9vJer3lXLRE3Q=; b=h057c/GmCS4yjWHYPbt8
 DToenrJtY/wTYI321QM8nlN5trmLxnIZyNK4yZ0WSxl2Ds6oUduYizxM681oy8F3BlPxCrh/N7umK
 kqeL6V/6b2koIh357+/GbsmLCS8aPrklQKgR532bTWPNBBYS86giN5lgXBexBVfnryRKME0ecBQ+n
 QEudgJzXDpQu3TC0uB6/6F1/gmMZHZiJZyvgxsB+u7OulHI4tr2P01uzLH9hJV2wx3YvxvzddBRQM
 Xey6sNq8JtG1K9L2jXcBIOVQBZejGovpCEb6KBYqCA8s2/on/EvXkhwHoZZtlZoT0v8OV9W8XWLz7
 c4EyuWQyxkDqMQ==;
Date: Fri, 28 Mar 2025 13:57:07 +0300
Message-Id: <86wmc9a0e4.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Adam =?utf-8?Q?Sj=C3=B8gren?= <asjo@HIDDEN>
In-Reply-To: <87iknuz5e4.fsf@HIDDEN>
 (bug-gnu-emacs@HIDDEN)
Subject: Re: bug#77317: 31.0.50;
 insert-kbd-macro RET produces elisp that does not work
References: <87iknuz5e4.fsf@HIDDEN>
MIME-version: 1.0
Content-type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 77317
Cc: 77317 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> Date: Thu, 27 Mar 2025 19:37:39 +0100
> From:  Adam Sjøgren via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <bug-gnu-emacs@HIDDEN>
> 
> 
> If I record a macro, for instance by pressing C-x ( A B B A C-x ) I can
> do M-x insert-kbd-macro RET to have elisp representing that macro
> inserted in the current buffer.
> 
> If I evaluate that code and then try to execute the macro with C-x e, I
> get the error: "Keyboard macros must be strings or vectors".
> 
> I was expecting the macro to be executed, inserting "ABBA".
> 
> The generated code looks like this:
> 
>     (setq last-kbd-macro
>        (kmacro "A B B A"))
> 
> and if I evaluate it, *Messages* contains:
> 
>     #[256 "\301\242\302^[^\\305\300^B\306#\210\301^L\240*\207" [[65 66
>      66 65] (0) "%d" kmacro-counter-format-start kmacro-counter
>      execute-kbd-macro kmacro-loop-setup-function] 5 kmacro]
> 
> and pressing C-x e to execute the macro results in the above mentioned
> error.
> 
> (Naming the macro and inserting it creates a defalias, which works -
> it's only the last-kbd-macro case that does not work.)

The Emacs user manual says


     If you wish to save a keyboard macro for later use, you can give it a
  name using ‘C-x C-k n’ (‘kmacro-name-last-macro’).  [...]

     Once a macro has a command name, you can save its definition in a
  file.  Then it can be used in another editing session.  First, visit the
  file you want to save the definition in.  Then use this command:

       M-x insert-kbd-macro <RET> MACRONAME <RET>

  This inserts some Lisp code that, when executed later, will define the
  same macro with the same definition it has now.  (You don't need to
  understand Lisp code to do this, because ‘insert-kbd-macro’ writes the
  Lisp code for you.)  Then save the file.  You can load the file later
  with ‘load-file’ (*note Lisp Libraries::).  If the file you save in is
  your init file ‘~/.emacs’ (*note Init File::) then the macro will be
  defined each time you run Emacs.

So it sounds like this is supposed to work for macros that have been
given a name.





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#77317; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 27 Mar 2025 18:38:14 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Mar 27 14:38:14 2025
Received: from localhost ([127.0.0.1]:51332 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1txs7J-0001H0-Fb
	for submit <at> debbugs.gnu.org; Thu, 27 Mar 2025 14:38:14 -0400
Received: from lists.gnu.org ([2001:470:142::17]:39384)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <asjo@HIDDEN>) id 1txs7E-0001Gk-RY
 for submit <at> debbugs.gnu.org; Thu, 27 Mar 2025 14:38:10 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10])
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <asjo@HIDDEN>) id 1txs79-0006AI-4T
 for bug-gnu-emacs@HIDDEN; Thu, 27 Mar 2025 14:38:03 -0400
Received: from virgil.koldfront.dk ([212.237.178.116])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <asjo@HIDDEN>) id 1txs75-0005R8-Gz
 for bug-gnu-emacs@HIDDEN; Thu, 27 Mar 2025 14:38:02 -0400
DKIM-Filter: OpenDKIM Filter v2.11.0 virgil.koldfront.dk 414CD95F6451A
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=koldfront.dk;
 s=mail; t=1743100671;
 bh=1Nd+Zoyl1lIhW0rSXh72h0N5g5i62Q5NBjwbUr6H72Y=;
 h=From:To:Subject:Date:From;
 b=EaFbzHd/aTpDBLKYNsvV0khgggv3NLbidekdzU6nRSF+MiHpaa61kjGz5+hXbl5yR
 HVJIHorCIg7CphfbS8zrVBtJPycOa2UPI1riggQ2fK0IyEiyKebMh2R9rWOWwz+QNK
 gNT5/TYWXCd8mqLrYRKC+wFAYjT7VgeQ7tQmX9nAUXp4mR75QKj73WsTmmtiGWui4Z
 BdjyfHaHh5jpvPMkMmMu6HjQwfZZgdd5ZmEg6WzkKJnYdxeq5ex+g8QvDc3GiCJ1JG
 1TJOcmv3pNDgwlimWFeDmFcHutiS1RRe7JHGTHRY1FMCiNk3lm9brtzuJJ+m5LGVj/
 FWP84tL4EJDQg==
Received: from tullinup.koldfront.dk (tullinup.koldfront.dk [192.168.1.102])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256)
 (No client certificate requested)
 by virgil.koldfront.dk (Postfix) with ESMTPS id 414CD95F6451A
 for <bug-gnu-emacs@HIDDEN>; Thu, 27 Mar 2025 19:37:51 +0100 (CET)
Received: from tullinup (localhost [127.0.0.1])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange ECDHE (prime256v1) server-signature RSA-PSS (2048 bits)
 server-digest SHA256) (No client certificate requested)
 by tullinup.koldfront.dk (Postfix) with ESMTPS id 1B899201AE7F7
 for <bug-gnu-emacs@HIDDEN>; Thu, 27 Mar 2025 19:37:51 +0100 (CET)
From: =?utf-8?Q?Adam_Sj=C3=B8gren?= <asjo@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Subject: 31.0.50; insert-kbd-macro RET produces elisp that does not work
X-Debbugs-Cc: 
Date: Thu, 27 Mar 2025 19:37:39 +0100
Message-ID: <87iknuz5e4.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Received-SPF: pass client-ip=212.237.178.116; envelope-from=asjo@HIDDEN;
 helo=virgil.koldfront.dk
X-Spam_score_int: -27
X-Spam_score: -2.8
X-Spam_bar: --
X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
 RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001,
 RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001,
 SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: 0.9 (/)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.1 (/)


If I record a macro, for instance by pressing C-x ( A B B A C-x ) I can
do M-x insert-kbd-macro RET to have elisp representing that macro
inserted in the current buffer.

If I evaluate that code and then try to execute the macro with C-x e, I
get the error: "Keyboard macros must be strings or vectors".

I was expecting the macro to be executed, inserting "ABBA".

The generated code looks like this:

    (setq last-kbd-macro
       (kmacro "A B B A"))

and if I evaluate it, *Messages* contains:

    #[256 "\301\242\302^[^\\305\300^B\306#\210\301^L\240*\207" [[65 66
     66 65] (0) "%d" kmacro-counter-format-start kmacro-counter
     execute-kbd-macro kmacro-loop-setup-function] 5 kmacro]

and pressing C-x e to execute the macro results in the above mentioned
error.

(Naming the macro and inserting it creates a defalias, which works -
it's only the last-kbd-macro case that does not work.)


In GNU Emacs 31.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
 3.24.38, cairo version 1.16.0) of 2025-03-08 built on tullinup
Repository revision: e78470fd1b2200b44dfb2465e39d7b31674bbc2a
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12101007
System Description: Debian GNU/Linux trixie/sid

Configured using:
 'configure -C --with-tree-sitter --with-xinput2 --without-pgtk
 --with-native-compilation=3Daot'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES NATIVE_COMP
NOTIFY INOTIFY PDUMPER PNG RSVG SECCOMP SOUND SQLITE3 THREADS TIFF
TOOLKIT_SCROLL_BARS TREE_SITTER WEBP X11 XDBE XIM XINERAMA XINPUT2 XPM
XRANDR GTK3 ZLIB

Important settings:
  value of $LANG: en_GB.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  minibuffer-regexp-mode: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug lisp-mnt message mailcap yank-media puny
dired dired-loaddefs rfc822 mml mml-sec password-cache epa derived epg
rfc6068 epg-config gnus-util text-property-search time-date subr-x
mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils
mailheader sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr
mail-utils macros cl-seq cl-extra help-mode edmacro comp-run comp-common
rx kmacro byte-opt gv bytecomp byte-compile cl-loaddefs cl-lib rmc
iso-transl tooltip cconv eldoc paren electric uniquify ediff-hook
vc-hooks lisp-float-type elisp-mode mwheel term/x-win x-win
term/common-win x-dnd touch-screen tool-bar dnd fontset image regexp-opt
fringe tabulated-list replace newcomment text-mode lisp-mode prog-mode
register page tab-bar menu-bar rfn-eshadow isearch easymenu timer select
scroll-bar mouse jit-lock font-lock syntax font-core term/tty-colors
frame minibuffer nadvice seq simple cl-generic indonesian philippine
cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech
european ethiopic indian cyrillic chinese composite emoji-zwj charscript
charprop case-table epa-hook jka-cmpr-hook help abbrev obarray oclosure
cl-preloaded button loaddefs theme-loaddefs faces cus-face macroexp
files window text-properties overlay sha1 md5 base64 format env
code-pages mule custom widget keymap hashtable-print-readable backquote
threads dbusbind inotify lcms2 dynamic-setting system-font-setting
font-render-setting cairo gtk x-toolkit xinput2 x multi-tty move-toolbar
make-network-process tty-child-frames native-compile emacs)

Memory information:
((conses 16 69445 18686) (symbols 48 6645 0) (strings 32 18633 1517)
 (string-bytes 1 595563) (vectors 16 11875)
 (vector-slots 8 161807 10397) (floats 8 30 4) (intervals 56 286 23)
 (buffers 992 12))

--=20
 "You know how everyone says you should stop and            Adam Sj=C3=B8gr=
en
  smell the roses? Well, this morning I did. *Big      asjo@HIDDEN
  deal!* They smelled like a bunch of dumb flowers!
  It was the most mundane experience I've ever had!"




Acknowledgement sent to Adam Sjøgren <asjo@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#77317; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Mon, 31 Mar 2025 16:45:03 UTC

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