bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#61549: 30.0.50; [PATCH] New keyboard macro counter functions


From: Alex Bochannek
Subject: bug#61549: 30.0.50; [PATCH] New keyboard macro counter functions
Date: Mon, 10 Jun 2024 20:06:52 -0700
User-agent: Gnus/5.13 (Gnus v5.13)

Michael,

Michael Heerdegen <michael_heerdegen@web.de> writes:

> Alex Bochannek <alex@bochannek.com> writes:
>
>> I think this is a very reasonable idea. I'll have a look at how to
>> generalize this and submit a patch.
>
> Yes, this is the question.  AFAIK, there is currently no way to put an
> Elisp function into a register.

This may not work, but I was thinking along the lines of storing the
text for a lambda in a string register and then doing something like:

(setq kmacro-counter (funcall (read (get-register ?A)) kmacro-counter))

Haven't really tried it and this may be a bad idea for any number of
reasons.

> Pranshu <pranshusharma366@gmail.com> writes:
>
>> Also there are multiple ways to include a seires of numbers, such as
>> 'C-x r N'.  iirc calc has a way in which you can copy numbers to a
>> rectangleular region.  Apart form numbering lists, I am unable to
>> think of another use for using a formula for the macro counte.r
>
> @Alex: do you see other uses?

I use keyboard macros frequently when I am manipulating multiple text
buffers to extract or merge data. Basically, anytime it gets slightly
too complicated for a quick AWK one-liner. The example of generating a
list of numbers came up in an IRC conversation and I wrote about it in a
blog post:

https://abochannek.github.io/emacs/2023/03/09/emacs-kbdmacros.html
(There is a link to a first part in that post that explains the history
of keyboard macros in Emacs.)

The examples are artificial and caused me to look into different ways to
do counter increments. After I implemented the conditional increment, I
found myself using it occasionally with keyboard macros to parse
irregular text files and collect bits and pieces from multiple buffers
that I then numbered in different ways. I certainly don't use it
frequently and the conditional quit is more useful.

The way I used to do construct lists with macros before is to have a
buffer with pre-generated numbers and have the macro kill/yank numbers
from there. Generalizing C-x r N may be helpful for that, I tend to just
use C-u M-! and then seq or jot, depending on what I need.

You may notice a couple of things in my blog post. I am suggesting
number registers as an alternative to the macro counter. They work well
in most cases except that they don't have a way to change the increment
conditionally either. Secondly, I am jealously looking at Calc macros,
because what I really want for keyboard macros is programmability with
proper loops and conditional branching.

I don't honestly know (nor do I know how to find out) how widely
keyboard macros in Emacs are used. I quickly record a new macro almost
daily and have in the past stored more complicated named macros in my
init file for later recall. Because what I use them for is usually
one-time work, I have not built up a library of functions for myself. I
would guess that my average keyboard macro is maybe between five and
twenty commands.

-- 
Alex.





reply via email to

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