当议程构建其视图时,是否可以过滤标签?我尝试过以下内容仅显示与工作相关的约会:
("j" "Jobb"
((agenda ""
((org-agenda-skip-function '(org-agenda-skip-entry-if 'notregexp":jobb:"))))
(tags-todo "jobb"))
((org-agenda-compact-blocks nil)))
Run Code Online (Sandbox Code Playgroud)
仅当实际约会被直接标记时才有效,但如果约会从父标题继承其标记,则不会这样:
* Tider :jobb:
** Millas arbetstider
<2012-04-11 ons 05:00-09:00>
<2012-04-12 tor 04:15-08:30>
<2012-04-13 fre 14:30-18:30>
Run Code Online (Sandbox Code Playgroud)
有没有其他方法可以执行此操作,以便显示继承其标记的约会?
Jon*_*pin 12
问题在于如何org-agenda-skip-entries-if与之互动'notregexp.它将跳过任何不匹配的条目:jobb:.即使后面的条目继承了标记,它也没有明确列出,因此它们被跳过.似乎没有任何内置方法匹配(或不匹配)标签使用org-agenda-skip-entries-if.如果有这样的功能,它可能是寻找标签的更有效方法,但我不知道这样的功能.
您必须创建一个自定义函数,以提供所需的搜索格式.
如果您将议程命令更改为:
("j" "Jobb"
((agenda ""
((org-agenda-skip-function '(zin/org-agenda-skip-tag "jobb" 't))))
(tags-todo "jobb"))
((org-agenda-compact-blocks nil)))
Run Code Online (Sandbox Code Playgroud)
并定义zin/org-agenda-skip-tag为:
(defun zin/org-agenda-skip-tag (tag &optional others)
"Skip all entries that correspond to TAG.
If OTHERS is true, skip all entries that do not correspond to TAG."
(let ((next-headline (save-excursion (or (outline-next-heading) (point-max))))
(current-headline (or (and (org-at-heading-p)
(point))
(save-excursion (org-back-to-heading)))))
(if others
(if (not (member tag (org-get-tags-at current-headline)))
next-headline
nil)
(if (member tag (org-get-tags-at current-headline))
next-headline
nil))))
Run Code Online (Sandbox Code Playgroud)
你会得到我理解的你想要的议程视图.如果我向后退,并且接下来3天的条目不应该出现,你只需要将函数更改为(zin/org-agenda-skip-tag "jobb")或者(zin/org-agenda-skip-tag "jobb" 'nil),在这种情况下它们是等效的.
在这种情况下test-new,我正在使用的组织文件的名称,它可以被忽略.我还设置了两个标题,TODO以便在测试函数时使它们可见,因为我将议程限制为仅一个文件.
Week-agenda (W15):
Monday 9 April 2012 W15
Tuesday 10 April 2012
Wednesday 11 April 2012
test-new: 5:00- 9:00 TODO Millas arbetstider :jobb::
Thursday 12 April 2012
test-new: 4:15- 8:30 TODO Millas arbetstider :jobb::
Friday 13 April 2012
test-new: 14:30-18:30 TODO Millas arbetstider :jobb::
Saturday 14 April 2012
Sunday 15 April 2012
================================================================================
Headlines with TAGS match: jobb
test-new: TODO Tider :jobb:
test-new: TODO Millas arbetstider :jobb::
Run Code Online (Sandbox Code Playgroud)
在使用乔纳森的答案中的函数几个月来进行这种按块过滤之后,我发现自己想要一些能够处理更复杂查询的东西(比如其他块类型使用的匹配字符串),我想我'我将其发布在这里,供将来偶然发现此问题的任何人使用。
编辑: 的原始实现my/org-match-at-point-p现在有些过时了。Org 模式源现在是词法范围的,这改变了org-make-tags-matcher. 过去,todo和tags-list变量需要在对 的调用周围动态限定作用域org-make-tags-matcher,而现在它们似乎被传递给从调用返回的函数。(耶!这好多了!)我已经调整了下面的代码以匹配新版本,但我不再使用 Org 模式了,所以它只进行了轻微的测试。
(defun my/org-match-at-point-p (match)
"Return non-nil if headline at point matches MATCH.
Here MATCH is a match string of the same format used by
`org-tags-view'."
(funcall (cdr (org-make-tags-matcher match))
(org-get-todo-state)
(org-get-tags-at)
(org-reduced-level (org-current-level))))
(defun my/org-agenda-skip-without-match (match)
"Skip current headline unless it matches MATCH.
Return nil if headline containing point matches MATCH (which
should be a match string of the same format used by
`org-tags-view'). If headline does not match, return the
position of the next headline in current buffer.
Intended for use with `org-agenda-skip-function', where this will
skip exactly those headlines that do not match."
(save-excursion
(unless (org-at-heading-p) (org-back-to-heading))
(let ((next-headline (save-excursion
(or (outline-next-heading) (point-max)))))
(if (my/org-match-at-point-p match) nil next-headline))))
Run Code Online (Sandbox Code Playgroud)
如果您仍在使用旧版本的 Org 模式,这里是原始代码。请注意,此版本假定定义的文件my/org-match-at-point-p是词法范围的;如果没有,您可以安全地my/defun-dyn用简单的defun.
(defmacro my/defun-dyn (&rest def)
"As `defun', but always in dynamic scope.
A function defined in this way ignores the value of
`lexical-binding' and treats it as if it were nil.
\(fn NAME ARGLIST &optional DOCSTRING DECL &rest BODY)"
(declare (debug defun)
(indent defun)
(doc-string 3))
`(eval '(defun ,@def) nil))
(my/defun-dyn my/org-match-at-point-p (match &optional todo-only)
"Return non-nil if headline at point matches MATCH.
Here MATCH is a match string of the same format used by
`org-tags-view'.
If the optional argument TODO-ONLY is non-nil, do not declare a
match unless headline at point is a todo item."
(let ((todo (org-get-todo-state))
(tags-list (org-get-tags-at)))
(eval (cdr (org-make-tags-matcher match)))))
Run Code Online (Sandbox Code Playgroud)