我的 .emacs
中有以下函数,它会在我工作了适当的时间后通知我。
问题是,我无法对值 time 和 msg 进行硬编码,所以我每次都必须重新输入它们。
(defun timed-notification(time msg)
(interactive "sNotification when (e.g: 2 minutes, 60 seconds, 3 days): \nsMessage: ")
(run-at-time time
nil
(lambda (msg) (terminal-notifier-notify "Pomodoro" msg))
msg))
(setq column-number-mode t)
如何将时间设置为“25 分钟”,并将消息设置为“休息一下,时间到了!”?
这是我的尝试:
(defun timed-notification()
;(interactive "sNotification when (e.g: 2 minutes, 60 seconds, 3 days): \nsMessage: ")
(run-at-time 25
nil
(lambda ("Time's up")
(terminal-notifier-notify "Take a break, time's up!" msg))
msg))
(setq column-number-mode t)
最佳答案
像最初那样定义您的函数,然后使用您想要的参数调用它一次。 interactive
形式,顾名思义,仅在您实际以交互方式调用函数时使用。当您从代码调用它时,您传递参数;所以 interactive
表单被简单地忽略了。
(defun timed-notification (time msg)
(interactive "sNotification when (e.g: 2 minutes, 60 seconds, 3 days): \nsMessage: ")
(run-at-time time nil (lambda (msg) (terminal-notifier-notify "Pomodoro" msg)) msg))
(setq column-number-mode t)
(timed-notification 25 "Take a break, time's up!") ;; New addition
关于emacs - 如何在 emacs lisp 中硬编码参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25165911/