all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Spencer Baugh <sbaugh@janestreet.com>
To: 67836@debbugs.gnu.org
Cc: Stefan Monnier <monnier@iro.umontreal.ca>
Subject: bug#67836: 29.1.90; map-y-or-n-p doesn't terminate when run in a kmacro in batch mode
Date: Fri, 15 Dec 2023 10:44:47 -0500	[thread overview]
Message-ID: <ier7clfwjv4.fsf@janestreet.com> (raw)
In-Reply-To: <iera5qbwk54.fsf@janestreet.com> (Spencer Baugh's message of "Fri, 15 Dec 2023 10:38:47 -0500")

[-- Attachment #1: Type: text/plain, Size: 21 bytes --]


Patch fixing this.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Make-ding-terminate-keyboard-macros-even-in-batch-mo.patch --]
[-- Type: text/x-patch, Size: 3728 bytes --]

From f894cbede9b65e6449c80393efb9d3417c9f661c Mon Sep 17 00:00:00 2001
From: Spencer Baugh <sbaugh@janestreet.com>
Date: Fri, 15 Dec 2023 09:57:19 -0500
Subject: [PATCH] Make ding terminate keyboard macros even in batch mode

ding's docstring states that it terminates keyboard macros.  But, due
to what seems to be an oversight, it does not do that while executing
in batch mode.

Generally, this means that some functions may infinite loop while run
in a keyboard macro in batch mode.

One concrete example: map-y-or-n-p will infinite-loop if run in a
keyboard macro while in batch mode.

Now ding properly terminates keyboard macros while running in batch
mode.  A test showing map-y-or-n-p behaves correctly in keyboard
macros is included.

* src/dispnew.c (bitch_at_user): Always signal while in a keyboard
macro, even if in batch mode. (bug#67836)
* test/lisp/emacs-lisp/map-ynp-tests.el (map-ynp-tests-simple-call)
(test-map-ynp-kmacro): Add.
---
 src/dispnew.c                         |  6 ++--
 test/lisp/emacs-lisp/map-ynp-tests.el | 46 +++++++++++++++++++++++++++
 2 files changed, 49 insertions(+), 3 deletions(-)
 create mode 100644 test/lisp/emacs-lisp/map-ynp-tests.el

diff --git a/src/dispnew.c b/src/dispnew.c
index e4037494775..645311be8c0 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -6185,14 +6185,14 @@ DEFUN ("ding", Fding, Sding, 0, 1, 0,
 void
 bitch_at_user (void)
 {
-  if (noninteractive)
-    putchar (07);
-  else if (!INTERACTIVE)  /* Stop executing a keyboard macro.  */
+  if (!NILP (Vexecuting_kbd_macro))  /* Stop executing a keyboard macro.  */
     {
       const char *msg
 	= "Keyboard macro terminated by a command ringing the bell";
       Fsignal (Quser_error, list1 (build_string (msg)));
     }
+  else if (noninteractive)
+    putchar (07);
   else
     ring_bell (XFRAME (selected_frame));
 }
diff --git a/test/lisp/emacs-lisp/map-ynp-tests.el b/test/lisp/emacs-lisp/map-ynp-tests.el
new file mode 100644
index 00000000000..4f5d10ee7f9
--- /dev/null
+++ b/test/lisp/emacs-lisp/map-ynp-tests.el
@@ -0,0 +1,46 @@
+;;; map-ynp-tests.el --- Tests for map-ynp.el        -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2023 Free Software Foundation, Inc.
+
+;; Author: Spencer Baugh <sbaugh@catern.com>
+;; Maintainer: emacs-devel@gnu.org
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Tests for map-ynp.el.
+
+;;; Code:
+
+(require 'ert)
+
+(defun map-ynp-tests-simple-call ()
+  (map-y-or-n-p ""  #'ignore '(1)))
+
+(ert-deftest test-map-ynp-kmacro ()
+  "Test that map-y-or-n-p in a kmacro terminates on end of input"
+  (execute-kbd-macro (read-kbd-macro "M-: (map-ynp-tests-simple-call) RET y"))
+  (should-error
+   (execute-kbd-macro (read-kbd-macro "M-: (map-ynp-tests-simple-call) RET")))
+  (unless noninteractive
+    (let ((noninteractive t))
+      (execute-kbd-macro (read-kbd-macro "M-: (map-ynp-tests-simple-call) RET y"))
+      (should-error
+       (execute-kbd-macro (read-kbd-macro "M-: (map-ynp-tests-simple-call) RET"))))))
+
+(provide 'map-ynp-tests)
+;;; map-ynp-tests.el ends here
-- 
2.39.3


  reply	other threads:[~2023-12-15 15:44 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-15 15:38 bug#67836: 29.1.90; map-y-or-n-p doesn't terminate when run in a kmacro in batch mode Spencer Baugh
2023-12-15 15:44 ` Spencer Baugh [this message]
2023-12-15 16:18   ` Eli Zaretskii
2023-12-15 22:55     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-12-16  8:11       ` Eli Zaretskii
2023-12-16 13:13         ` sbaugh
2023-12-16 13:52           ` Eli Zaretskii
2023-12-16 15:11             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-12-16 15:55               ` Eli Zaretskii
2023-12-16 16:55                 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-12-16 17:24                   ` Eli Zaretskii

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=ier7clfwjv4.fsf@janestreet.com \
    --to=sbaugh@janestreet.com \
    --cc=67836@debbugs.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 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.