在emacs lisp中,可以通过run-with-timer
和run-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中是否有某种方法可以获取此类计时器的错误报告,最好是完整的堆栈跟踪?
答案 0 :(得分: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)))
我在echo区域和*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])