[英]Org-mode: Filter on tag in agenda view?
議程構建視圖時是否可以過濾標簽? 我嘗試了以下方法以僅顯示與工作相關的約會:
("j" "Jobb"
((agenda ""
((org-agenda-skip-function '(org-agenda-skip-entry-if 'notregexp":jobb:"))))
(tags-todo "jobb"))
((org-agenda-compact-blocks nil)))
這僅在直接標記實際約會時有效,但如果約會從父標題繼承其標簽,則無效,如下所示:
* 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>
是否有另一種方法可以顯示繼承其標簽的約會?
問題在於org-agenda-skip-entries-if
如何與'notregexp
交互。 它將跳過任何不匹配的條目:jobb:
。 即使后面的條目繼承了標簽,它也沒有明確列出,所以它們被跳過了。 似乎也沒有任何內置方法可以使用org-agenda-skip-entries-if
匹配(或不匹配)標簽。 如果有這樣一個 function,它可能是查找標簽的更有效方法,但我不知道這樣一個 function。
相反,您必須創建一個自定義 function 來提供所需的搜索格式。
如果您將議程命令更改為:
("j" "Jobb"
((agenda ""
((org-agenda-skip-function '(zin/org-agenda-skip-tag "jobb" 't))))
(tags-todo "jobb"))
((org-agenda-compact-blocks nil)))
並將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))))
你會得到我所理解的你想要的議程視圖。 如果我把它倒過來並且接下來 3 天的條目不應該存在,您只需將 function 更改為(zin/org-agenda-skip-tag "jobb")
或(zin/org-agenda-skip-tag "jobb" 'nil)
,在這種情況下它們是等價的。
在這種情況下, test-new
是我使用的 org 文件的名稱,可以忽略它。 我還將兩個標題都設置為TODO
,以便在測試 function 時可以看到它們,因為我將議程限制為只有一個文件。
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::
在 Jonathan 的回答中使用 function 幾個月來進行這種按塊過濾之后,我發現自己想要一些能夠處理更復雜查詢的東西(比如其他塊類型使用的匹配字符串),我想我' d 將其張貼在這里,以供將來偶然發現此問題的任何人使用。
編輯: my/org-match-at-point-p
的原始實現現在有些過時了。 Org 模式源現在是詞法范圍的,這改變了org-make-tags-matcher
的約定。 過去, todo
和tags-list
變量需要在對org-make-tags-matcher
的調用周圍動態限定范圍,而現在它們似乎被傳遞給從調用返回的 function。 (是的,這好多了,)我已經調整了下面的代碼以匹配新版本。 但我不再使用 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))))
如果您仍在使用舊版本的 Org 模式,這里是原始代碼。 請注意,此版本假定定義my/org-match-at-point-p
的文件是詞法范圍的; 如果沒有,您可以安全地用簡單的defun
替換my/defun-dyn
宏。
(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)))))
可以通過在議程視圖中點擊“/”來過濾Agenda Dispatcher 。
“/” = 在所有議程文件中以及在 org-agenda-text-search-extra-files 中列出的文件中搜索正則表達式。 這個使用Emacs命令多次出現。 前綴參數可用於指定每個匹配項的上下文行數...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.