2

在 emacs lisp 中,可以通过run-with-timerandrun-with-async-timer命令实现一种伪异步形式。例如,考虑以下简单的倒数计时器:

(defun -c (i)
 (cond 
  ((= i 0)  (error "TESTERROR"))
  (t
   (message "Countdown at %d" i)
   (run-with-timer 1 nil '-c (1- i)))))

运行(-c 3)将显示消息

Countdown at 3
Countdown at 2
Countdown at 1

信号错误将被忽略。

emacs lisp 中是否有某种方法可以获取此类计时器的错误报告,最好使用完整的堆栈跟踪?

4

1 回答 1

0

我没有观察到您使用 Emacs 24.3.50.3 描述的行为:

(lexical-let ((countdown 3) timer)
  (defun countdown ()
    (message "countdown %d" countdown)
    (when (zerop (decf countdown))
      (cancel-timer timer)
      (error "BOOM")))
  (setq timer (run-with-timer 1 1 'countdown)))

我在回声区域和中看到*Messages*

countdown 3
countdown 2
countdown 1
Entering debugger...

然后在*Backtrace*

Debugger entered--Lisp error: (error "BOOM")
  signal(error ("BOOM"))
  error("BOOM")
  (progn (cancel-timer (symbol-value G66502)) (error "BOOM"))
  (if (zerop (let* ((v G66503)) (set v (1- (symbol-value G66503))))) (progn (cancel-timer (symbol-value G66502)) (error "BOOM")))
  (lambda (G66502 G66503) (message "countdown %d" (symbol-value G66503)) (if (zerop (let* ((v G66503)) (set v (1- (symbol-value G66503))))) (progn (cancel-timer (symbol-value G66502)) (error "BOOM"))))(--timer-- --countdown--)
  apply((lambda (G66502 G66503) (message "countdown %d" (symbol-value G66503)) (if (zerop (let* ((v G66503)) (set v (1- (symbol-value G66503))))) (progn (cancel-timer (symbol-value G66502)) (error "BOOM")))) --timer-- --countdown-- nil)
  countdown()
  apply(countdown nil)
  byte-code("r\301\302H\303H\"\210)\301\207" [timer apply 5 6] 4)
  timer-event-handler([t 20941 51022 556644 1 countdown nil nil 176000])
于 2013-06-28T17:29:18.287 回答