有没有办法在不接管emacs的情况下编写这样的东西?
(defun 哑等待(秒)
(让((完成(+(第二(当前时间))秒)))
(while (< (second (current-time)) done)
(消息“等待”))))
(dump-wait 5) 将阻止 emacs 5 秒。反正有没有写这个所以它不会阻塞?我只是想在一个循环中不时检查一些条件,并且仍然能够使用emacs。
谢谢!
最佳答案
(run-at-time time repeat function &rest args)
应该这样做。 nil
作为时间意味着现在。
(setq my-timer
(run-at-time nil 5 (lambda () (message "waiting")))) ; returns timer object
;; or
(setq my-timer
(run-at-time nil 5 'message "waiting"))
(cancel-timer my-timer) ; use timer object from above
编辑:
参数
repeat
需要一个数字作为秒,但是有一个函数 timer-duration
,您可以使用它代替数字。它返回与字符串参数一起提供的秒数。对于大的间隔,这更容易阅读。(timer-duration "3 hours 2 seconds 1 millisec") ; => 10802.001
您可以使用的可能词在变量
timer-duration-words
中定义。
关于emacs - 一段elisp 代码 "yield"可以让emacs 不阻塞吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1474851/