Function: calc-kbd-loop
calc-kbd-loop is an autoloaded, interactive and byte-compiled function
defined in calc-prog.el.gz.
Signature
(calc-kbd-loop RPT-COUNT &optional INITIAL FINAL DIR)
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/calc/calc-prog.el.gz
(defun calc-kbd-loop (rpt-count &optional initial final dir)
(interactive "P")
(setq rpt-count (if rpt-count (prefix-numeric-value rpt-count) 1000000))
(let* ((count 0)
(parts nil)
(body (vector))
(open last-command-event)
(counter initial)
ch)
(or executing-kbd-macro
(message "Reading loop body..."))
(while (>= count 0)
(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)
body (vconcat body (vector ?Z ch)))
(cond ((memq ch '(?\< ?\( ?\{))
(setq count (1+ count)))
((memq ch '(?\> ?\) ?\}))
(setq count (1- count)))
((and (= ch ?/)
(= count 0))
(setq parts (nconc parts (list (vconcat (substring body 0 -2)
(vector ?Z ?\]) )))
body ""))
((eq ch 7)
(keyboard-quit))))
(setq body (vconcat body (vector ch)))))
(if (/= ch (cdr (assq open '( (?\< . ?\>) (?\( . ?\)) (?\{ . ?\}) ))))
(error "Mismatched Z%c and Z%c in keyboard macro" open ch))
(or executing-kbd-macro
(message "Looping..."))
(setq body (vconcat (substring body 0 -2) (vector ?Z ?\]) ))
(and (not executing-kbd-macro)
(= rpt-count 1000000)
(null parts)
(null counter)
(progn
(message "Warning: Infinite loop! Not executing")
(setq rpt-count 0)))
(or (not initial) dir
(setq dir (math-compare final initial)))
(calc-wrapper
(while (> rpt-count 0)
(let ((part parts))
(if counter
(if (cond ((eq dir 0) (Math-equal final counter))
((eq dir 1) (Math-lessp final counter))
((eq dir -1) (Math-lessp counter final)))
(setq rpt-count 0)
(calc-push counter)))
(while (and part (> rpt-count 0))
(execute-kbd-macro (car part))
(if (math-is-true (calc-top-n 1))
(setq rpt-count 0)
(setq part (cdr part)))
(calc-pop-stack 1))
(if (> rpt-count 0)
(progn
(execute-kbd-macro body)
(if counter
(let ((step (calc-top-n 1)))
(calc-pop-stack 1)
(setq counter (calcFunc-add counter step)))
(setq rpt-count (1- rpt-count))))))))
(or executing-kbd-macro
(message "Looping...done"))))