org--agenda-prefix-format %? does not work

ぐ巨炮叔叔 提交于 2019-12-21 06:04:11

问题


Currently, I have my global TODO list shown as follows thanks to erikstokes:

(org-agenda-prefix-format " %i %?-12(concat \"[ \"(org-format-outline-path (list (nth 1 (org-get-outline-path)))) \" ]\") ")))

which outputs:

for org layout:

However, as you can see, for Task A, even though there is nothing in the project, it still shows up on the list.

describe-variable for org-agenda-prefix-format says :

If the first character after `%' is a question mark, the entire field
will only be included if the corresponding value applies to the current
entry.  This is useful for fields which should have fixed width when
present, but zero width when absent. 

So I feel like by using %?, [ ] shouldn't be there for Task A, yet it still shows up.


回答1:


The problem is that the field is never empty: it will always contain at least the left and right square brackets plus the white space to bring it to a width of 12.

The solution is to write a function that returns either an empty string or the bracketed project and use that in the format:

  (defun foo ()
     (let ((x (nth 1 (org-get-outline-path))))
       (if x
           (concat "[ " (org-format-outline-path (list x)) " ]")
         "")))

  (setq org-agenda-prefix-format " %i %?-12(foo) "


来源:https://stackoverflow.com/questions/35910204/org-agenda-prefix-format-does-not-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!