From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Tim Ruffing <crypto@timruffing.de>
Cc: Eli Zaretskii <eliz@gnu.org>, 68272@debbugs.gnu.org
Subject: bug#68272: [PATCH] Fix -1 leaking from C to lisp in 'read-event' etc.
Date: Tue, 05 Mar 2024 11:45:41 -0500 [thread overview]
Message-ID: <jwv8r2w64bt.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <933c41e932327b6c149706ca251c18046d9ffb8b.camel@timruffing.de> (Tim Ruffing's message of "Mon, 04 Mar 2024 19:42:09 +0100")
> Hi, this is an updated patch set.
Looks really nice, thank you.
Comments/nitpicks below.
Eli Zaretskii [2024-03-05 15:10:39] wrote:
> IOW, what about callers that actually _want_ to know when the macro
> ends prematurely?
I couldn't find any, really. Of course, we could export
`at_end_of_macro_p` to ELisp, but I don't see any need for it.
[ Also: define "prematurely". My impression is that the callers of
`read-char` are generally not in a position to know what is premature
and what isn't because it tends to depend on the users' intentions. ]
> +/* Whether the execution of a macro has reached its end.
> + It makes only sense to call this when while executing a macro. */
^^^^ ^^^^
\----------------------^
[ And same for the other copy of that coment. ]
> +/* Return true if there are any pending requeued events (command events
> + or events to be processed by input methods). */
I think I'd say "other levels of the input processing stages" instead of
"input methods", so as to conceptually include any other
"unread_*_events" we may end up with.
> - /* If not, we should actually read a character. */
> + /* If we're at the end of a macro, exit it by returning 0,
> + unless there are unread events pending. */
> + else if (!NILP (Vexecuting_kbd_macro)
> + && at_end_of_macro_p ()
> + && !requeued_events_pending_p ())
> + {
> + t = 0;
> + /* The Microsoft C compiler can't handle the goto that
> + would go here. */
> + dummyflag = true;
> + break;
> + }
This "Microsoft C compiler" business dates back to 1994 (commit
bc536d847736f466727453ca6aa7c07aef6fce46).
I think it's safe to clean it up now :-)
> index 62129be1629..98290e7e276 100644
> --- a/src/macros.c
> +++ b/src/macros.c
> @@ -314,6 +314,29 @@ DEFUN ("execute-kbd-macro", Fexecute_kbd_macro, Sexecute_kbd_macro, 1, 3, 0,
> Vreal_this_command));
> record_unwind_protect (pop_kbd_macro, tem);
>
> + /* The following loop starts the execution of the macro. Individual
> + characters from the macro are read by read_char, which takes care
> + of incrementing executing_kbd_macro_index. The end of the
> + macro is handled as follows:
> + - read_key_sequence asks at_end_of_macro_p whether the end of
> + (one iteration of the macro) has been reached. If so, it returns
> + the magic value 0 to command_loop_1.
> + - command_loop_1 returns Qnil to command_loop_2.
> + - command_loop_2 returns Qnil to this function
> + (but only the returning is relevant, not the actual value).
Could you complete the sequence to the point where we clear
Vexecuting_kbd_macro?
> + If read_char happens to be called at the end of the macro, but
> + before read_key_sequence could handle the end (e.g., because lisp
> + code calls 'read-event', 'read-char', and 'read-char-exclusive'),
> + read_char will simply continue reading other available input
> + (Bug#68272).
Could you clarify here what happens w.r.t the value of
Vexecuting_kbd_macro (AFAICT, we "remain `at_end_of_macro_p`").
> + Note that this is similar (in observable behavior) to a simpler
> + implementation of keyboard macros in which this function simply
> + pushed all characters of the macro into the incoming event queue
> + and returned immediately. Maybe this is the implementation that
> + we ideally would like to have, but switching to it will require
> + a larger code change. */
It might be worth mentioning that the main difference is the
availability of `executing-kbd-macro` to let ELisp code behave
differently when called via a kmacro than via "live input".
Which also kind of justifies why `read-key-sequence` wants to
detect the end: if a kmacro ends in the middle of a key sequence, then
it's triggered both my kmacro and by live input.
[ Of course, we could handle it in the command loop instead:
check and compare the set of pending kmacro events before and after we
call `read-key-sequence`. ]
Stefan
next prev parent reply other threads:[~2024-03-05 16:45 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-05 21:19 bug#68272: [PATCH] Fix -1 leaking from C to lisp in 'read-event' etc Tim Ruffing
2024-01-06 7:42 ` Eli Zaretskii
2024-01-06 14:32 ` Tim Ruffing
2024-01-13 9:39 ` Eli Zaretskii
2024-01-13 17:40 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-02-02 18:04 ` Tim Ruffing
2024-02-06 21:04 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-01 12:14 ` Tim Ruffing
2024-03-04 18:42 ` Tim Ruffing
2024-03-05 13:10 ` Eli Zaretskii
2024-03-05 16:45 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2024-03-05 16:55 ` Eli Zaretskii
2024-03-05 17:57 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-05 18:53 ` Eli Zaretskii
2024-03-05 19:29 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-05 19:55 ` Eli Zaretskii
2024-03-05 20:18 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-06 11:46 ` Eli Zaretskii
2024-03-09 12:33 ` Tim Ruffing
2024-03-09 18:08 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-09 18:37 ` Eli Zaretskii
2024-03-10 8:24 ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-10 14:48 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-06 9:15 ` Andreas Schwab
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwv8r2w64bt.fsf-monnier+emacs@gnu.org \
--to=bug-gnu-emacs@gnu.org \
--cc=68272@debbugs.gnu.org \
--cc=crypto@timruffing.de \
--cc=eliz@gnu.org \
--cc=monnier@iro.umontreal.ca \
/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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).