Search code examples
emacsorg-mode

%s in org-agenda-prefix-format doesn't display dates in the TODO view


I've been trying to add SCHEDULED and DEADLINE dates to the global TODO List in the org-mode-agenda (I'm using spacemacs).

From what I've read the variable to change should be org-agenda-prefix-format

In the help menu that I accessed through C-h+v it says these formatting characters work:

%c   the category of the item, "Diary" for entries from the diary,
       or as given by the CATEGORY keyword or derived from the file name
  %e   the effort required by the item
  %l   the level of the item (insert X space(s) if item is of level X)
  %i   the icon category of the item, see `org-agenda-category-icon-alist'
  %T   the last tag of the item (ignore inherited tags, which come first)
  %t   the HH:MM time-of-day specification if one applies to the entry
  %s   Scheduling/Deadline information, a short string
  %b   show breadcrumbs, i.e., the names of the higher levels
  %(expression) Eval EXPRESSION and replace the control string
                by the result

And by using %?s the field should only be shown if the value applies for the entry.

So I added the following line to my .spacemacs file:

(setq org-agenda-prefix-format "%?s ")

However this has no effect on the TODO list, but only on the weekly/daily agenda view.


Solution

  • Looks like %s is ignored in the TODO list: https://emacs.stackexchange.com/a/12373/19819 (in comment).

    Instead you can use a custom expression:

    "%(let ((scheduled (org-get-scheduled-time (point)))) (if scheduled (format-time-string \"%Y-%m-%d\" scheduled) \"\")) "
    

    To just use this for the todo list modify the todo entry in org-agenda-prefix-format only:

    (setq org-agenda-prefix-format
          '((agenda  . " %i %-12:c%?-12t% s")
            (todo  . " %(let ((scheduled (org-get-scheduled-time (point)))) (if scheduled (format-time-string \"%Y-%m-%d\" scheduled) \"\")) %i %-12:c")
            (tags  . " %i %-12:c")
            (search . " %i %-12:c")))