]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/calc/calc-prog.el: Switch to new method of detecting end of kbd macro
authorTim Ruffing <crypto@timruffing.de>
Sat, 9 Mar 2024 11:29:39 +0000 (12:29 +0100)
committerEshel Yaron <me@eshelyaron.com>
Mon, 11 Mar 2024 09:26:57 +0000 (10:26 +0100)
'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>
(cherry picked from commit df3e0bcbdbcfe907d7572b5561dd2bf9c3715a4a)

lisp/calc/calc-prog.el

index 03210995eb3f97c2848e989bea729d1cfeb303af..8dff7f1f264295560ec29b124ba14398fee5579b 100644 (file)
@@ -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)