Improve macro handling

* add `macro-counter` variable
* add `QEState` fields `nb_macro_keys_run`, `macro_counter`, `macro_format`.
* add `int find_key_suffix(const char *str, char c)`
* pass `argval` to `do_call_last_kbd_macro` to handle early exit
* add `clear_macro`, `stop_macro`
* add `int check_format_string(const char *fmt, const char *template)`
* do not use `alloca` for `eb_vprintf`
* add `dbuf_str(db)`: null terminate the buffer and return a string pointer.
* add macro commands:
  `edit-last-kbd-macro`, `name-last-kbd-macro`, `insert-kbd-macro`,
  `read-kbd-macro`, `macro-add-counter`, `macro-set-counter`,
  `macro-insert-counter`, `macro-set-format`
* `start-keyboard-macro` restarts macro learning mode if learning already
* add documentation on macro commands
* stop macros upon errors (when ringing the bell)
* stop macros if prompting the user for confirmation
This commit is contained in:
Charlie Gordon 2024-07-25 14:08:13 +02:00
commit 4be625f5c4
11 changed files with 415 additions and 53 deletions

View file

@ -2341,11 +2341,7 @@ int eb_vprintf(EditBuffer *b, const char *fmt, va_list ap) {
va_end(ap2);
if (len >= size) {
size = len + 1;
#ifdef CONFIG_WIN32
buf = qe_malloc_bytes(size);
#else
buf = alloca(size);
#endif
vsnprintf(buf, size, fmt, ap);
}
/* CG: insert buf encoding according to b->charset and b->eol_type.
@ -2353,10 +2349,8 @@ int eb_vprintf(EditBuffer *b, const char *fmt, va_list ap) {
* XXX: %c does not encode non ASCII characters as utf8.
*/
written = eb_insert_utf8_buf(b, b->offset, buf, len);
#ifdef CONFIG_WIN32
if (buf != buf0)
qe_free(&buf);
#endif
return written;
}