Improve macro handling

* `C-x (` restarts macro learning mode if learning already
* add documentation on macro commands
This commit is contained in:
Charlie Gordon 2024-07-22 08:46:24 +02:00
commit 492a8fc0ce
3 changed files with 43 additions and 5 deletions

View file

@ -7,7 +7,6 @@
* pass `indent` and `style` array to `ColorizeFunc`.
* `S-TAB` -> untabify
* `TAB` and `S-TAB` with selected block -> indent, unindent block
* `C-x (` should restart macro learning mode
* should implement a maximum macro length and abort macro learning mode if reached
* should keep modified status when undoing past a buffer save command
* should swap buffer names in `compare-files`

View file

@ -62,6 +62,15 @@ package for image parsing.
# Commands
### `call-last-kbd-macro()`
Run the last keyboard macro recorded by `start-kbd-macro`.
### `end-kbd-macro()`
Stop recording the keyboard macro. The last keyboard macro can
be run using `call-last-kbd-macro`.
### `isearch-repeat-backward()`
Search for the next match backward.
Retrieve the last search string if search string is empty.
@ -164,6 +173,11 @@ If the RENAMEFILE argument is not null and starts with 'y', an
attempt is made to rename the old visited file to the new name
FILENAME.
### `start-kbd-macro()`
Start recording a keyboard macro. Every key typed is stored into
a list for later replay using `call-last-kbd-macro`
# Implementation
# Structures

33
qe.c
View file

@ -5518,22 +5518,40 @@ void edit_display(QEmacsState *qs)
void do_start_kbd_macro(EditState *s)
{
/*@CMD start-kbd-macro
### `start-kbd-macro()`
Start recording a keyboard macro. Every key typed is stored into
a list for later replay using `call-last-kbd-macro`
*/
QEmacsState *qs = s->qe_state;
if (qs->defining_macro) {
qs->defining_macro = 0;
put_status(s, "Already defining kbd macro");
return;
put_status(s, "Already defining kbd macro: restarting");
} else {
put_status(s, "Defining kbd macro...");
}
qs->defining_macro = 1;
qe_free(&qs->macro_keys);
qs->nb_macro_keys = 0;
qs->macro_keys_size = 0;
put_status(s, "Defining kbd macro...");
}
static void save_last_kbd_macro(EditState *s) {
#ifndef CONFIG_TINY
// XXX: should save the keyboard macro with `name-kbd-macro`
// XXX: should save macro keys to add_string(qe_get_history("macrokeys"), buf, 0)
#endif
}
void do_end_kbd_macro(EditState *s)
{
/*@CMD end-kbd-macro
### `end-kbd-macro()`
Stop recording the keyboard macro. The last keyboard macro can
be run using `call-last-kbd-macro`.
*/
QEmacsState *qs = s->qe_state;
/* if called inside a macro, it is last recorded keys, so ignore
@ -5546,15 +5564,22 @@ void do_end_kbd_macro(EditState *s)
return;
}
qs->defining_macro = 0;
save_last_kbd_macro(s);
put_status(s, "Keyboard macro defined");
}
void do_call_last_kbd_macro(EditState *s)
{
/*@CMD call-last-kbd-macro
### `call-last-kbd-macro()`
Run the last keyboard macro recorded by `start-kbd-macro`.
*/
QEmacsState *qs = s->qe_state;
int set_repeat = (qs->last_key == 'e');
if (qs->defining_macro) {
// XXX: should allow recursive definition
qs->defining_macro = 0;
put_status(s, "Cannot execute macro while defining one");
return;