[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#28008: 25.2; Resume kmacro definition errors C-u C-u <F3>
From: |
Tino Calancha |
Subject: |
bug#28008: 25.2; Resume kmacro definition errors C-u C-u <F3> |
Date: |
Fri, 11 Aug 2017 22:17:57 +0900 (JST) |
User-agent: |
Alpine 2.20 (DEB 67 2015-01-07) |
On Fri, 11 Aug 2017, Eli Zaretskii wrote:
** Patch 1 always save the macro in `last-kbd-macro' after an error or 'C-g'.
Then, A. B. and D.2 behaves similarly.
** Patch 2 adds a new variable `last-aborted-kbd-macro': it saves the partial
macro there after an error or 'C-g'. Called `start-kbd-macro' with
APPEND non-nil offers to append on `last-aborted-kbd-macro'; possible
answers
are 'yes', 'no' or 'del' (i.e., append on `last-aborted-kbd-macro' after
delete
its last character).
This is not backward compatible; for instance, the snippets A, B above
won't be
saved in `last-kbd-macro' (currently they do).
It's more tidy; it separates 'good macros', i.e. those ended after
'F4' or 'C-x )', from 'partial macros', i.e., those ended after an error or
'C-g'.
All these low-level changes just to support an obscure use case? Is
really worth the risk to break macros to cater to that?
That depends of how often someone uses kbd macros. I rarely use
them, but the people using them frequently might suffer D.2 from time to
time.
Actually, the patch#1 is quite short: i included a docstring fix from
the patch#2 by mistake.
The C code changes in patch#1 are just:
3 files changed, 41 insertions(+), 2 deletions(-)
Here is patch#1 upated:
--8<-----------------------------cut here---------------start------------->8---
commit fe424d1371ec467b9a257fa75c8c3f734135e6dd
Author: Tino Calancha <tino.calancha@gmail.com>
Date: Fri Aug 11 22:11:08 2017 +0900
Save aborted kbd macro definitions
While a defining a kbd macro, if we get an error or if the user inputs C-g,
then save the aborted kbd macro record (Bug#28008).
* lisp/kmacro.el (kmacro-start-macro): Signal an error if APPEND is non-nil
and last-kbd-macro is nil.
* src/keyboard.c (cmd_error): Increase buffer size for macroerror
to accommodate new error message.
If we are defining a kbd macro and we got an error, then save the
current progress in last-kbd-macro.
(init_kboard): Initialize last-aborted-kbd-macro.
(mark_kboards): Mark last-aborted-kbd-macro.
* src/keyboard.h (save_aborted_kbd_macro): Declare this function.
* src/macros.c (save_aborted_kbd_macro): New function.
(store_kbd_macro_char): Call save_aborted_kbd_macro when user inputs C-g.
diff --git a/lisp/kmacro.el b/lisp/kmacro.el
index 2db8061fa4..8eff7e5c2e 100644
--- a/lisp/kmacro.el
+++ b/lisp/kmacro.el
@@ -584,7 +584,8 @@ kmacro-start-macro
kmacro-last-counter kmacro-counter
kmacro-counter-format kmacro-default-counter-format
kmacro-counter-format-start kmacro-default-counter-format))
-
+ (when (and append (null last-kbd-macro))
+ (user-error "No kbd macro has been defined"))
(start-kbd-macro append
(and append
(if kmacro-execute-before-append
diff --git a/src/keyboard.c b/src/keyboard.c
index 97069a24ac..5111e2c358 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -941,7 +941,8 @@ static Lisp_Object
cmd_error (Lisp_Object data)
{
Lisp_Object old_level, old_length;
- char macroerror[sizeof "After..kbd macro iterations: "
+ char macroerror[sizeof "Saved aborted kbd macro in \
+`last-kbd-macro' after error: "
+ INT_STRLEN_BOUND (EMACS_INT)];
#ifdef HAVE_WINDOW_SYSTEM
@@ -949,7 +950,13 @@ cmd_error (Lisp_Object data)
cancel_hourglass ();
#endif
- if (!NILP (executing_kbd_macro))
+ if (!NILP (KVAR (current_kboard, defining_kbd_macro)))
+ {
+ sprintf (macroerror,
+ "Saved aborted kbd macro in `last-kbd-macro' after error: ");
+ save_aborted_kbd_macro (false);
+ }
+ else if (!NILP (executing_kbd_macro))
{
if (executing_kbd_macro_iterations == 1)
sprintf (macroerror, "After 1 kbd macro iteration: ");
diff --git a/src/keyboard.h b/src/keyboard.h
index 2219c01135..676ccd83cc 100644
--- a/src/keyboard.h
+++ b/src/keyboard.h
@@ -463,6 +463,8 @@ extern bool lucid_event_type_list_p (Lisp_Object);
extern void kbd_buffer_store_event (struct input_event *);
extern void kbd_buffer_store_buffered_event (union buffered_input_event *,
struct input_event *);
+extern Lisp_Object save_aborted_kbd_macro (bool);
+
INLINE void
kbd_buffer_store_event_hold (struct input_event *event,
struct input_event *hold_quit)
diff --git a/src/macros.c b/src/macros.c
index f0ffda3f44..1935e4fd2f 100644
--- a/src/macros.c
+++ b/src/macros.c
@@ -39,6 +39,32 @@ EMACS_INT executing_kbd_macro_iterations;
Lisp_Object executing_kbd_macro;
+/* Save the aborted macro.
+ Called if an error happens, or if the user inputs C-g,
+ while defining a kbd macro. */
+
+Lisp_Object
+save_aborted_kbd_macro (bool msg)
+{
+ struct kboard *kb = current_kboard;
+ /* Must contain something; otherwise don't save it. */
+ if (kb->kbd_macro_end != kb->kbd_macro_buffer)
+ {
+ end_kbd_macro ();
+ if (msg)
+ {
+ message1 ("Saved aborted kbd macro in `last-kbd-macro'");
+ /* Set inhibit_quit to until sleep_for ends */
+ Vinhibit_quit = Qt;
+ Fsleep_for (make_number (1), Qnil);
+ Vinhibit_quit = Qnil;
+ }
+ }
+
+ return Qnil;
+}
+
+
DEFUN ("start-kbd-macro", Fstart_kbd_macro, Sstart_kbd_macro, 1, 2, "P",
doc: /* Record subsequent keyboard input, defining a keyboard macro.
The commands are recorded even as they are executed.
@@ -182,6 +208,10 @@ store_kbd_macro_char (Lisp_Object c)
if (!NILP (KVAR (kb, defining_kbd_macro)))
{
+ /* We received a Quit: save the current kboard in Vlast_kbd_macro */
+ if (XFASTINT (c) == quit_char)
+ save_aborted_kbd_macro (true);
+
if (kb->kbd_macro_ptr - kb->kbd_macro_buffer == kb->kbd_macro_bufsize)
{
ptrdiff_t ptr_offset = kb->kbd_macro_ptr - kb->kbd_macro_buffer;
--8<-----------------------------cut here---------------end--------------->8---