emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master df3e0bcbdbc 6/7: * lisp/calc/calc-prog.el: Switch to new method o


From: Stefan Monnier
Subject: master df3e0bcbdbc 6/7: * lisp/calc/calc-prog.el: Switch to new method of detecting end of kbd macro
Date: Sun, 10 Mar 2024 10:48:13 -0400 (EDT)

branch: master
commit df3e0bcbdbcfe907d7572b5561dd2bf9c3715a4a
Author: Tim Ruffing <crypto@timruffing.de>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>

    * lisp/calc/calc-prog.el: Switch to new method of detecting end of kbd macro
    
    'read-char' will no longer return -1 as of
    ac82baea1c41ec974ad49f2861ae6c06bda2b4ed. This switches to a cleaner
    method of detecting whether the end of a keyboard macro has been
    reached.
    
    * lisp/calc/calc-prog.el (calc--at-end-of-kmacro-p): New function.
    (calc-kbd-skip-to-else-if): Use the function.
    
    Co-authored-by: Stefan Monnier <monnier@iro.umontreal.ca>
---
 lisp/calc/calc-prog.el | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/lisp/calc/calc-prog.el b/lisp/calc/calc-prog.el
index 03210995eb3..8dff7f1f264 100644
--- a/lisp/calc/calc-prog.el
+++ b/lisp/calc/calc-prog.el
@@ -1225,13 +1225,17 @@ Redefine the corresponding command."
   (interactive)
   (calc-kbd-if))
 
+(defun calc--at-end-of-kmacro-p ()
+  (and (arrayp executing-kbd-macro)
+       (>= executing-kbd-macro-index (length executing-kbd-macro))))
+
 (defun calc-kbd-skip-to-else-if (else-okay)
   (let ((count 0)
        ch)
     (while (>= count 0)
-      (setq ch (read-char))
-      (if (= ch -1)
+      (if (calc--at-end-of-kmacro-p)
          (error "Unterminated Z[ in keyboard macro"))
+      (setq ch (read-char))
       (if (= ch ?Z)
          (progn
            (setq ch (read-char))
@@ -1299,9 +1303,9 @@ Redefine the corresponding command."
     (or executing-kbd-macro
        (message "Reading loop body..."))
     (while (>= count 0)
-      (setq ch (read-event))
-      (if (eq ch -1)
+      (if (calc--at-end-of-kmacro-p)
          (error "Unterminated Z%c in keyboard macro" open))
+      (setq ch (read-event))
       (if (eq ch ?Z)
          (progn
            (setq ch (read-event)
@@ -1427,9 +1431,9 @@ Redefine the corresponding command."
           (if defining-kbd-macro
               (message "Reading body..."))
           (while (>= count 0)
-            (setq ch (read-char))
-            (if (= ch -1)
+            (if (calc--at-end-of-kmacro-p)
                 (error "Unterminated Z` in keyboard macro"))
+            (setq ch (read-char))
             (if (= ch ?Z)
                 (progn
                   (setq ch (read-char)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]