2

Keyboard Macros - recording a sequence of keystrokes - start by 'C-x (' and end by 'C-x )' - to be replayed - for example by 'C-x e' - is such a useful tool. It's like the perfect stepping stone between keyboard shortcuts and programming. It's like programming based on intuition, like a graphical user interface of an operating system. It is an enabler for lay persons, very easy to understand. But - adding interruption points within the sequence from where the keyboard macro pauses - start by 'C-u C-x q', end by 'M-C-c', the latter also for continuation when playbacked and being ready with the manual input - and gives possibility to manually change things before the keyboard macro continues its automatism after it? That makes keyboard macros much, much more useful, like exponentially, mindblowingly. But the thing is this - now we're cutting to the chase: Sometimes in your keyboard macros, stops happen where you don't quite know - maybe anymore - why the stop has been placed, what should be changed manually and how for proper continuation of the keyboard macro. It's moments like these, where keyboard macro embedded notes would be very handy - briefing you what the stop is good for, what to input and how.

'How many garbage items have we found so far today additionally? (enter [0-9]*)'

That's something, what would be just so helpful, such an ease when being displayed anywhere on the screen while such a stop within keyboard macro execution.

One possibility always is, to make input of that question the last thing right into the buffer before you type in 'C-u C-x q' for the stop.

|-------------------------------------------------------------------------------------------+---|
| 'How many garbage items have we found so far today additionally? (enter [0-9]*)'[pointer] |   |
|-------------------------------------------------------------------------------------------+---|

Followed by manual input answering the help question

|--------------------------------------------------------------------------------------------+---|
| 'How many garbage items have we found so far today additionally? (enter [0-9]*)'7[pointer] |   |
|--------------------------------------------------------------------------------------------+---|

The caveat: Now the little help question needs to be removed out of the table cell - which is a set of actions, which also can be made as part of the macro.

But - wouldn't it be more beautiful, efficient, if that help question is inserted, appears not in the buffer, but in the echo area/mini buffer, like a message?

How to do that?!

My attempt was making shell-command echo as part of the keyboard macro:

M-! echo 'How many garbage items have we found so far today additionally? (enter [0-9]*)'

While doing it, it appears successful: In the echo area/mini-buffer

U:**- *scratch* Bot L32 (Org def)
'How many garbage items have we found so far today additionally? (enter [0-9]*)

But, as soon as you playback the keyboard macro, and the stop happens, the echo area/mini-buffer stays empty - not displaying the help question. What's wrong in the described process, that the help question doesn't appear beforehand and stays there including the beginning of the stop start where manual input can be placed then? What to change, so that the help question appears beforehand in the echo area/mini-buffer as intended?

1 Answer 1

2

I'd guess it's some interaction between macro replay and shell-command. Note that the shell command output from echo still ends up in the *Messages* buffer, but if it gets copied to the echo area in the macro-replay scenario, it's seemingly getting overwritten again.

However there's no need to run new processes just to get Emacs to display a message. You can trivially do that in elisp.

Instead of M-! echo foo

Use M-: (message "foo")

Experimentally (in Emacs 28.2) that doesn't get erased from the echo area when you run the macro.

1
  • BEAUTIFUL! Works like a charm. Thank you so much, phils. To add to the goodness: Also works with older GNU Emacs versions, like for example GNU Emacs 24.5.
    – starquake
    Jul 5, 2023 at 14:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.