Re: [RFC PATCH v1 0/1] Avoid accidentally overwriting macro recording
Benno Schulenberg <[email protected]> Sat, 14 Feb 2026 16:57:46 +0100
| Newsgroups | gmane.editors.nano.devel |
|---|---|
| Message-ID | <[email protected]> |
> I personally love this change, I have accidentally overrode macros plenty of > times. Accidentally running a destructive macro can usually be undone, Well, with "destructive" I meant a macro that does something that cannot be undone, like writing stuff out to a file. (Of course, that file could be under version control, but it's not nano that can undo those changes.) > but there's isn't really a way to get a macro back. Yeah. I guess that point weighs more heavily. And when the user wants to clear a dangerous macro, it is easy enough to overwrite it with something innocuous, like M-D or toggling something twice. So... a cleaned up patch is attached. Is it okay with you, Charles? Benno
0001-macro-cancel-the-recording-if-nothing-was-entered-be.patch
(text/x-patch, 1.7 KB)
From 617045f09046cfceaf65b9e42ffe6acdd0c69631 Mon Sep 17 00:00:00 2001 From: Charles Mirabile <[email protected]> Date: Tue, 10 Feb 2026 12:21:21 -0500 Subject: [PATCH] macro: cancel the recording if nothing was entered between start and stop When the user stops a macro recording immediately after starting it, cancel the recording and restore the macro that existed previously, instead of storing a new empty macro. Signed-off-by: Charles Mirabile <[email protected]> Signed-off-by: Benno Schulenberg <[email protected]> --- src/winio.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/winio.c b/src/winio.c index f6d07f56..4767ace2 100644 --- a/src/winio.c +++ b/src/winio.c @@ -79,6 +79,10 @@ static int *macro_buffer = NULL; /* A buffer where the recorded key codes are stored. */ static size_t macro_length = 0; /* The current length of the macro. */ +static int *previous_macro = NULL; + /* The macro that existed when recording is started. */ +static size_t previous_length = 0; + /* The length of that previous macro. */ static size_t milestone = 0; /* Where the last burst of recorded keystrokes started. */ @@ -96,9 +100,18 @@ void record_macro(void) recording = !recording; if (recording) { + previous_macro = macro_buffer; + previous_length = macro_length; + macro_buffer = NULL; macro_length = 0; statusline(REMARK, _("Recording a macro...")); + } else if (milestone == 0) { + free(macro_buffer); + macro_buffer = previous_macro; + macro_length = previous_length; + statusline(REMARK, _("Cancelled")); } else { + free(previous_macro); /* Snip the keystroke that invoked this function. */ macro_length = milestone; statusline(REMARK, _("Stopped recording")); -- 2.53.0
OpenPGP_signature.asc
(application/pgp-signature, 840 B)
-----BEGIN PGP SIGNATURE----- wsF5BAABCAAjFiEEFo5vQpe/16ea/USWUUu+Lrjhlh8FAmmQm3oFAwAAAAAACgkQUUu+Lrjhlh+g Eg//RHnAlSdgi4tdrUcZ+TN3HbBsuDtbFWVjzl30+91P0fCrY3/ENHPBdIQXg2WYOmgnC5B1eUG+ F9dEYCBmLtNKTjf/vQe9VzbmF5GpWz+m/1wpu/hxyiQowZQm5VfCR0vZ/rE/nQ54fMWZBHfosW1A 7fBAE6b17DJmnpaI1SCCWAhYkrmKk671U33rRPKTAe5tuZ0IDfYAhWoEzvcHaankEfGXAvrzDfJU KKQuMTZ6miugxRfisv6uYwC39dzr5ChZbvGloJWe8YWUyqrkDBBEZ70/V8qu5sPFGLMxzzqHCOsE 1YD5TWzy30bMSVIyad80PtcoRl9AxftRX5c+uRDnxyItqpfuqZrYM5GTizNHpUalDURX7bISReWy Hj3r38zwyTIJwFUsnb7YUFU9R4pK6MQ7UNyWumAt/dBsrme7ti8ZbsficDEmMQyM3H36OGqOWpmA yTVAhGXNPmoCD9/lUor4tfANRlbgXAR1dPaKQSGaDpJoD9Jf9lmjQJTfMKhYQ3Fe2YiP0wcJ8wFe 5dH1XQCbfMAXD0r2AAouuSsknCRFBZBN6hmxczVofgnG0gx/9Ds9SmJVImNEqSvDtGYaYpyNJP8Y ZyN4vriYsxw7YH3jtofUNKt5/rIHGHHvMLevCEStUNpdri1370rIrrnYd7OZEoWJg8hj4HJ1i2cz oSM= =HfVO -----END PGP SIGNATURE-----