【问题标题】:Custom diary-sunrise function not working. `autoload-diary`? (Emacs.)自定义日记日出功能不起作用。 `自动加载日记`? (Emacs。)
【发布时间】:2014-04-06 23:42:18
【问题描述】:

简介:

基于 Emacs 的diary-sunrise-sunset 的现有代码,我尝试创建两个新函数diary-sunrisediary-sunset

我的原因在下面的“XY 描述”标题下。

我有下面的代码似乎可以工作,除非我用新的 Emacs 重新启动。我可以通过暂时使用原来的内置diary-sunrise-sunset 来解决这个问题。从那时起,我的功能表现得很漂亮。

换句话说,我必须使用内置的%%(diary-sunrise-sunset) 一次,然后我的%%(diary-sunrise)%%(diary-sunset) 才能工作。

问题:

你能帮我解决我对这些函数的使用问题,这样我就不必采取首先调用内置函数的尴尬步骤吗?

在我看来可疑的代码行是那些去的代码

;;;###diary-autoload

虽然我对加载程序的必要性有所了解,但我不确定这里发生了什么,或者这是否是问题所在。 (我从未见过那种特殊的语法。)

我尝试过M-: (require 'solar)M-: (require 'diary),但都没有奏效(现在calendar)。我已经尝试将我的代码放在我的.emacs 和内置的.../lisp/calendar/solar.el(和字节重新编译)中,但都没有奏效。

我的功能:

(它们都是对solar-sunrise-sunset-stringdiary-sunrise-sunset 的轻微修改,它们都在.../lisp/calendar/solar.el 中定义)。

日出:

(defun solar-sunrise-string (date &optional nolocation)
  "String of *local* time of sunrise and daylight on Gregorian DATE."
  (let ((l (solar-sunrise-sunset date)))
    (format
     "%s (%s hours daylight)"
     (if (car l)
     (concat "Sunset " (apply 'solar-time-string (car l)))
       "no sunset")
     (nth 2 l)
     )))
;; To be called from diary-list-sexp-entries, where DATE is bound.
;;;###diary-autoload
(defun diary-sunrise ()
  "Local time of sunrise as a diary entry.
  Accurate to a few seconds."
  (or (and calendar-latitude calendar-longitude calendar-time-zone)
      (solar-setup))
  (solar-sunrise-string date))

日落:

(defun solar-sunset-string (date &optional nolocation)
  "String of *local* time of sunset and daylight on Gregorian DATE."
  (let ((l (solar-sunrise-sunset date)))
    (format
     "%s (%s hours daylight)"
     (if (cadr l)
     (concat "Sunset " (apply 'solar-time-string (cadr l)))
       "no sunset")
     (nth 2 l)
     )))
;; To be called from diary-list-sexp-entries, where DATE is bound.
;;;###diary-autoload
(defun diary-sunset ()
  "Local time of sunset as a diary entry.
  Accurate to a few seconds."
  (or (and calendar-latitude calendar-longitude calendar-time-zone)
      (solar-setup))
  (solar-sunset-string date))

XY 描述:

我正在使用 Emacs 的 Org 模式,并且刚刚开始使用议程视图。我喜欢内置的 diary-sunrise-sunset 函数,但想进行一些小的调整以使其更符合我的喜好。

基本上,Org-mode 的议程视图会提取它第一次看到的日记 sexp %%(diary-sunrise-sunset),例如

Sat, Apr 5, 2014
Sunrise 6:43am (PDT), sunset 7:42pm (PDT) at Springfield, OH (12:59 hours daylight)

并因此输入

6:43am........  Sunrise (PDT), sunset 7:42pm (PDT) at Springfield, OH (12:59 hours daylight)

在议程视图中。

我希望它做的更像是,

 6:43am........  Sunrise (PDT) (12:59 hours daylight)
 8:00am........  ----------------
10:00am........  ----------------
12:00pm........  ----------------
 2:00pm........  ----------------
 4:00pm........  ----------------
 5:51pm........  now - - - - - - - - - - - - - - - - - - - - - - - - -
 6:00pm........  ----------------
 7:42pm........  Sunset (PDT) (12:59 hours daylight)

这里的数据被分成两次,而不是全部只在日出时间写入。

奖金:

一个 sn-p 以便C-c a d 会给你一个美好的一天议程视图:

(setq org-agenda-custom-commands 
      '(("d" "day's agenda"
         agenda ""
         (
          (org-agenda-files '("/e/org/agendatest.org"))
          (org-agenda-prefix-format "%t %s")
          (org-agenda-span 'day)
          (org-agenda-timegrid-use-ampm t)
          )
         )
        ))

【问题讨论】:

    标签: emacs elisp org-mode autoload dot-emacs


    【解决方案1】:

    在我的问题的最后一段(第八段?)中,我撒了谎,(require 'solar) 是答案......我没有足够努力,因为它没有响应自动完成。

    通往答案的风景优美的路线让我分心:

    我做了一些 Edebugging,想知道我使用的任何东西是否有自动加载 cookie(还没有完全理解),但后来注意到 solar.el 的末尾有一个 (provide 'solar),所以我认为 (require 'solar) 有去工作。它做到了,就是这样。

    从我的问题中的代码中,我删除了自动加载cookies(不确定是否有必要),并添加(require 'solar),它就可以工作了!享受!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-31
      • 2016-04-23
      • 1970-01-01
      • 1970-01-01
      • 2016-08-29
      • 2019-11-15
      相关资源
      最近更新 更多