自定义org agend view时org-agenda-skip-function变量的小结

  自定义org agenda view时,设置org-agenda-skip-function变量可以对时间戳、TODO关键字、标签甚至自定义的特定标识进行筛选,十分好用。这个变量还有个全局版本org-agenda-skip-function-global。

  org-agenda-skip-function的值要求是个函数,可以使用预定义的函数,也可以自定义方法进行筛选:

  1、利用org-agenda-skip-entry-if或者org-agenda-skip-subtree-if函数

  subtree是指本标题及以下所有子标题内容;entry是指本标题的内容(到下个同级或者下级标题之前)。

  这两个函数都接受如下symbol作为参数:

  scheduled      是否包含SCHEDULED

  notscheduled 是否不包含SCHEDULED

  deadline         是否包含DEADLINE

  notdeadline    是否不包含DEADLINE

  timestamp      是否包含时间戳(SCHEDULED或者DEDLINE)

  nottimestamp 是否不包含时间戳(SCHEDULED或者DEDLINE)

  regexp            是否满足后面一个参数表示的正则表达式

  notregexp       是否不满足后面一个参数表示的正则表达式

  todo                是否满足后面一个参数表示的TODO关键字

  nottodo           是否不满足后面一个参数表示的TODO关键字

  OR                  用于连接多个条件

  比如以下例子,表示生成所有标题包括TODO关键字的列表,但跳过所有包含时间戳的entry;换句话说,就是列出所有没有确定SCHEDULED和DEADLINE的TODO事项:

  (org-add-agenda-custom-command

    '("j" todo "TODO"

      ((org-agenda-skip-function '(org-agenda-skip-entry-if 'timestamp))

    ))

  )

  参数为regexp和notregexp时,后面跟随的参数是一个正则表达式,比如:

  (org-add-agenda-custom-command
     '("b" todo "PROJECT"
      ((org-agenda-skip-function '(org-agenda-skip-entry-if 'regexp ":waiting:"))

    ))

  )

  参数为todo和nottodo时,后面跟随的参数可以是单个具体的TODO关键字,比如:

  (org-add-agenda-custom-command

    '("d" agenda ""

      ((org-agenda-skip-function '(org-agenda-skip-entry-if ‘todo 'DONE))

    ))

  )

  也可以是一个列表,比如:

  (org-add-agenda-custom-command

    '("d" agenda ""

      ((org-agenda-skip-function '(org-agenda-skip-entry-if ‘todo '("TODO" "WAITING")))

    ))

  )

  还可以是星号*,表示匹配所有TODO关键字。

  上面给出的例子都是根据一个条件进行筛选,实际上还可以用OR连接多个条件筛选,以下例子筛选所有没有时间戳且TAG有“张三”的TODO事项:

  (org-add-agenda-custom-command

    '("j" todo "TODO"

      ((org-agenda-skip-function '(org-agenda-skip-entry-if 'timestamp 'OR 'notregexp ":张三:"))

    ))

  )

  org mode手册中包含了更多的例子

  2、根据org-agenda-skip-function要求的返回值自己写

  在进行筛选的时候,org-agenda-skip-function绑定的函数如果返回的是nil,什么都不会跳过;如果返回了一个位置,那么就跳到这个位置,这个位置之前的部分都被跳过。

  org mode的手册给出了这种函数的一般形式,以筛选waiting标签为例:

  (defun my-skip-unless-waiting ()

    (let ((subtree-end (save-excursion (org-end-of-subtree t))))

      (if (re-search-forward ":waiting:" subtree-end t)

          nil                  ; tag found, do not skip

        subtree-end))) ; tag not found, continue after end of subtree

(org-add-agenda-custom-command
   '("b" todo "PROJECT"
       ((org-agenda-skip-function 'my-skip-unless-waiting)
        (org-agenda-overriding-header "Projects waiting for something: "))))

 

上一篇:Agenda文档与源码学习


下一篇:将执行文件转化为bat批处理文件的工具(批处理文件方式提供)