emacs - 如何在 emacs lisp 中硬编码参数?

标签 emacs lisp elisp

我的 .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/

相关文章:

git - 如何配置 Magit 以使用我的 Github 用户名?

lisp - 用 lisp 进行机器人编程?

emacs - 如何在框架的顶部窗口中使用一个进程而在框架的下部窗口中使用另一个进程来启动 Emacs?

Emacs rgrep 自定义

emacs - 将框架中的所有 Emacs 窗口设置为给定宽度

emacs - 如何在 Emacs 中恢复默认功能?

emacs - 如何使用 YASnippet 在片段中扩展片段?

emacs - 避免在 comint 模式下意外执行

function - Lisp 中的 x++ 等价物?

scheme - 以下表达式中的值、变量、对象和名称之间有什么区别?