如何在emacs lisp中对参数进行硬编码?

时间:2014-08-06 16:53:23

标签: emacs lisp elisp

我的.emacs中有以下功能,在我工作了一段合适的时间之后通知我。

问题是,我无法对值时间和消息进行硬编码,因此我每次都必须重新输入它们。

(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)

3 个答案:

答案 0 :(得分:2)

像您最初一样定义您的函数,然后使用您想要的参数调用它一次。 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

答案 1 :(得分:1)

你摆脱了msg参数,但你还在尝试使用它。使用let将局部变量绑定到该值。

(defun timed-notification()
  (interactive)
  (let ((msg "Take a break, time's up!"))
    (run-at-time 25 nil (lambda (mess) (terminal-notifier-notify "pomodoro" mess)) msg)))

答案 2 :(得分:1)

(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)

(defun tf()
  (interactive)
  (timed-notification "1 min" "Take a break, time's up!"))

现在可以为常规pomo调用tf,而当我想要x分钟休息时,原始功能仍然可用。