all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Tino Calancha <tino.calancha@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: vianchielfaura@gmail.com, 28008@debbugs.gnu.org,
	Tino Calancha <tino.calancha@gmail.com>
Subject: bug#28008: 25.2; Resume kmacro definition errors C-u C-u <F3>
Date: Fri, 11 Aug 2017 22:17:57 +0900 (JST)	[thread overview]
Message-ID: <alpine.DEB.2.20.1708112207420.17216@calancha-pc> (raw)
In-Reply-To: <83shgyqmwn.fsf@gnu.org>



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---





  reply	other threads:[~2017-08-11 13:17 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-08  4:10 bug#28008: 25.2; Resume kmacro definition errors C-u C-u <F3> Allen Li
2017-08-08  5:26 ` Tino Calancha
2017-08-08 17:16   ` Allen Li
2017-08-11 12:41     ` Tino Calancha
2017-08-11 13:00       ` Eli Zaretskii
2017-08-11 13:17         ` Tino Calancha [this message]
2017-08-12  3:03           ` Tino Calancha
2017-08-13 21:13             ` Allen Li
2017-09-18 20:02           ` Allen Li
2017-09-19  7:42 ` Allen Li
2017-09-30  3:47   ` Allen Li
2017-09-30  4:20     ` Tino Calancha
2017-09-30 13:48   ` Eli Zaretskii
2020-08-24 14:07     ` Lars Ingebrigtsen
2018-09-09  0:23 ` Allen Li

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.DEB.2.20.1708112207420.17216@calancha-pc \
    --to=tino.calancha@gmail.com \
    --cc=28008@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=vianchielfaura@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.