如何在没有议程视图的情况下获取组织模式议程的原始数据?


10

问:如何org-mode在不实际创建议程视图的情况下返回议程视图的原始数据?

我想在任意一天访问我的议程。但是,我本身不想创建议程视图。相反,我想org-mode收集当天将要进入议程视图的所有元素并进行排序,然后将它们返回(最好在列表中)以进行进一步检查和操作。

我以为那org-agenda-list是开始的地方。但是,该功能是一团纠结的野兽,似乎将收集,排序和显示过程混合在一起。因此,我想(希望吗?)我只是在提供所需功能的地方错过了相关功能。

Answers:


4

以下是如何提取进入一个数据稠例如*Org Agenda*缓冲器通常使用功能时org-agenda-list,具有org-agenda-entry-types:deadline:scheduled:timestampsexp:deadline*,和:scheduled*。日期范围- beginend-应该采用公历列表格式-例如,'(6 1 2015)。可自定义的约束范围选项是org-agenda-prefix-formatorg-agenda-entry-types。该函数以列表格式返回结果。

(require 'calendar)
(require 'org)
(require 'org-agenda)
(require 'cl)

;; Portions of following code were extracted from:
;;   https://github.com/kiwanami/emacs-calfw written by Masashi Sakurai
;; Said code has been modified by @lawlist hereinbelow.
;;
(defun org-get-entries-fn (begin end)
"Return org schedule items between BEGIN and END.
USAGE:  (org-get-entries-fn '(6 1 2015) '(12 31 2020))"
  (unless
      (and
        (calendar-date-is-valid-p begin)
        (calendar-date-is-valid-p end))
    (let ((debug-on-quit nil))
      (signal 'quit '("One or both of your Gregorian dates are invalid."))))
  (let* (
      result
      (org-agenda-buffer nil) ;; prevent error from `org-compile-prefix-format'
      ;; The variable `org-agenda-only-exact-dates' is apparently not operational.
      (org-scheduled-past-days 0) ;; avoid duplicate entries for overdue items
      (org-agenda-prefix-format "• ")
      (org-agenda-entry-types '(:scheduled))
      (date-after
        (lambda (date num)
          "Return the date after NUM days from DATE."
          (calendar-gregorian-from-absolute
           (+ (calendar-absolute-from-gregorian date) num))))
      (enumerate-days
        (lambda (begin end)
          "Enumerate date objects between BEGIN and END."
          (when (> (calendar-absolute-from-gregorian begin)
                   (calendar-absolute-from-gregorian end))
            (error "Invalid period : %S - %S" begin end))
          (let ((d begin) ret (cont t))
            (while cont
              (push (copy-sequence d) ret)
              (setq cont (not (equal d end)))
              (setq d (funcall date-after d 1)))
            (nreverse ret)))) )
    (org-compile-prefix-format nil)
    (setq result
      (loop for date in (funcall enumerate-days begin end) append
        (loop for file in (org-agenda-files nil 'ifmode) append
          (progn
            (org-check-agenda-file file)
            (apply 'org-agenda-get-day-entries file date org-agenda-entry-types)))))
    result))
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.