In one of the previous articles (Vol 3 to be precise) we talked about automatic setup of
filetags, so each of the task in note related to a person is automatically tagged thanks to tag inheritance. Then, in Vol 4 we talked about automatic tagging of tasks whenever a person is mentioned either in the title or the body of some task. This all makes
org-agenda matching capabilities really useful for when we want to see the list of all tasks related to specific person.
In this article, we are going to write a small utility function that asks user to select a person and then presents and
org-agenda buffer with tasks related to selected person.
Believe me, intro is longer than the content!
[2021-03-02 Tue]: Update naming convention to match personal configurations.
[2021-05-10 Mon]: Update post to reflect changes in org-roam v2. Previous version of this article is available on GitHub.
Long story short, here is the function you can bind or call by name using
defun vulpea-agenda-person () ("Show main `org-agenda' view." (interactive)let* ((person (vulpea-select ("Person" :filter-fnlambda (note) ( (seq-contains-p (vulpea-note-tags note)"people")))) (node (org-roam-node-from-id (vulpea-note-id person)))cons (org-roam-node-title node) (names ( (org-roam-node-aliases node))) (tags (seq-map #'vulpea--title-to-tag names))"|"))) (query (string-join tags list t query))) (dlet ((org-agenda-overriding-arguments (nil "M")))) (org-agenda
Now some explanations.
- This code uses vulpea library1 to select a person. You can achieve the same result without
vulpea, of course, but it saves some effort.
vulpea-selectasks the user to select a note and accepts a predicate to show only subset of
org-roamnotes. In this case, we simply present only people notes.
- Once we have a selected
vulpea-note, we can get all titles on that file (e.g. main title and aliases). This is important for alias users. For example, in some notes I want use Mr. Frodo instead of Frodo Baggins, but I want to see tasks tagged as
@FrodoBagginsat the same time. It’s the same person after all (don’t ask me about Gollum, better use
- Now we simply convert those names into tags using
vulpea--title-to-tagfrom Vol 4.
- Then we join the tags using
|separator into single query string.
- The last step is to execute
Margument (match for tags, but list only
TODOitems). In order to pass a query to relevant agenda function, we use
org-agenda-overriding-arguments. Not sure if it’s documented anywhere, but you can read the sources of
org-agendato figure out how to use it.
dlethere is used for dynamic binding. If you are not using lexical scope, you can use regular
That’s it! Now see it in action, again.
Task Management with org-roam Series
- Path to Roam
- Automatic tagging
- Dynamic and fast agenda
- Select a person and view related tasks
Yikes, I advertise my own libraries on this blog!↩︎