0

I'm trying to get org-agenda-to-appt working but I am currently getting No event to add when running this command.

org-agenda-list returns a bunch of items, one of which has Deadline: prefixed.

My TODO items are properly loaded into the agenda and have DEADLINE associations.

(defun org-agenda-to-appt (&optional refresh filter &rest args)
  "Activate appointments found in `org-agenda-files'.

With a `\\[universal-argument]' prefix, refresh the list of \
appointments.

If FILTER is t, interactively prompt the user for a regular
expression, and filter out entries that don't match it.

If FILTER is a string, use this string as a regular expression
for filtering entries out.

If FILTER is a function, filter out entries against which
calling the function returns nil.  This function takes one
argument: an entry from `org-agenda-get-day-entries'.

FILTER can also be an alist with the car of each cell being
either `headline' or `category'.  For example:

  \\='((headline \"IMPORTANT\")
    (category \"Work\"))

will only add headlines containing IMPORTANT or headlines
belonging to the \"Work\" category.

ARGS are symbols indicating what kind of entries to consider.
By default `org-agenda-to-appt' will use :deadline*, :scheduled*
\(i.e., deadlines and scheduled items with a hh:mm specification)
and :timestamp entries.  See the docstring of `org-diary' for
details and examples.

If an entry has a APPT_WARNTIME property, its value will be used
to override `appt-message-warning-time'."
  (interactive "P")
  (if refresh (setq appt-time-msg-list nil))
  (if (eq filter t)
      (setq filter (read-from-minibuffer "Regexp filter: ")))
  (let* ((cnt 0)                        ; count added events
         (scope (or args '(:deadline* :scheduled* :timestamp)))
         (org-agenda-new-buffers nil)
         (org-deadline-warning-days 0)
         ;; Do not use `org-today' here because appt only takes
         ;; time and without date as argument, so it may pass wrong
         ;; information otherwise
         (today (org-date-to-gregorian
                 (time-to-days (current-time))))
         (org-agenda-restrict nil)
         (files (org-agenda-files 'unrestricted)) entries file
         (org-agenda-buffer nil))
    ;; Get all entries which may contain an appt
    (org-agenda-prepare-buffers files)
    (while (setq file (pop files))
      (setq entries
            (delq nil
                  (append entries
                          (apply 'org-agenda-get-day-entries
                                 file today scope)))))
    ;; Map thru entries and find if we should filter them out
    (mapc
     (lambda (x)
       (let* ((evt (org-trim
                    (replace-regexp-in-string
                     org-bracket-link-regexp "\\3"
                     (or (get-text-property 1 'txt x) ""))))
              (cat (get-text-property (1- (length x)) 'org-category x))
              (tod (get-text-property 1 'time-of-day x))
              (ok (or (null filter)
                      (and (stringp filter) (string-match filter evt))
                      (and (functionp filter) (funcall filter x))
                      (and (listp filter)
                           (let ((cat-filter (cadr (assq 'category filter)))
                                 (evt-filter (cadr (assq 'headline filter))))
                             (or (and (stringp cat-filter)
                                      (string-match cat-filter cat))
                                 (and (stringp evt-filter)
                                      (string-match evt-filter evt)))))))
              (wrn (get-text-property 1 'warntime x)))
         ;; FIXME: Shall we remove text-properties for the appt text?
         ;; (setq evt (set-text-properties 0 (length evt) nil evt))
         (when (and ok tod (not (string-match "\\`DONE\\|CANCELLED" evt)))
           (setq tod (concat "00" (number-to-string tod)))
           (setq tod (when (string-match
                            "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
                       (concat (match-string 1 tod) ":"
                               (match-string 2 tod))))
           (when (if (version< emacs-version "23.3")
                     (appt-add tod evt)
                   (appt-add tod evt wrn))
             (setq cnt (1+ cnt))))))
     entries)
    (org-release-buffers org-agenda-new-buffers)
    (if (eq cnt 0)
        (message "No event to add")
      (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))

The above code is from org-agenda.el that has been loaded.

Here is an example of one of my TODO items from a file within org-agenda-files.

** TODO [#A] Test Item
   DEADLINE: <2017-05-06 Sat>

2 Answers 2

2

You need to have a timestamp on your item. Try

** TODO [#A] Test Item
   DEADLINE: <2017-05-06 Sat 23:00>
2
  • Fixed it, thanks. How'd you figure it out? May 7, 2017 at 4:40
  • 3
    Long experience with repeated failures :-)
    – NickD
    May 7, 2017 at 12:10
1

Not only timestamps interacts with this function. From the doc of org-agenda-to-appt:

ARGS are symbols indicating what kind of entries to consider. By default ‘org-agenda-to-appt’ will use :deadline*, :scheduled* (i.e., deadlines and scheduled items with a hh:mm specification) and :timestamp entries.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.