alphapapa / alphapapa/org-ql

Custom predicate example for tutorial appendix

未关闭
#152 16 条评论 0 个 reaction 已指派 1 人 已被 @alphapapa 认领 在 GitHub 查看
docs
主要语言
Emacs Lisp
星标
1.6k
派生
120
PR 合并指标
30 天内没有已合并 PR

描述

Hi Adam,

Thanks for making such an awesome package for org. It has taken org to the next level for me. With that said, I was hoping to get some guidance on two things I'm trying to do. My Elisp is definitely at the basic level, so please bear with me if these appear to be silly questions.

### Reuse current window
I've bound a function to a key that prompts me for information that is then used for an `org-ql-search`. I'm trying to find a way to have the results open in the current window instead of a new window. For example, if my frame contains two windows (A and B):

```
A B
A B
```

When I invoke my command with the cursor in window A, the result is the following where V is the `org-ql` view:

```
A B
V B
```

I'd like the following instead:

```
V B
V B
```

Here is my code. `kaz/org-on-one-view` is the interactive function that prompts me for a person's name with completion which is dynamically loaded (thanks to `org-ql-select` btw) with people's names extracted from headings in my agenda files, and then uses super agenda groups (and my new `:take` selector I wrote):

```elisp
(defun kaz/org-get-person-from-heading ()
"Return the name of the person in a 1:1 heading.
Extract PERSON from a heading in the form of \"[YYYY-MM-DD HH:MM:SS] PERSON 1:1\"."
(let ((heading (org-get-heading)))
(when (string-match "\\(?:] +\\)?\\(\\w+\\(?: +\\w+\\)*\\) 1:1" heading)
(match-string-no-properties 1 heading))))

(defun kaz/org-get-people ()
"Return a list of all people from 1:1 headings."
(-distinct
(org-ql-select
(org-agenda-files)
'(heading " 1:1")
:action #'kaz/org-get-person-from-heading)))

(defun kaz/one-on-one-view (name)
"Open a 1:1 agenda view for NAME."
(interactive (list (completing-read "Person: " (kaz/org-get-people))))
(let ((tagname (downcase (s-replace " " "_" name))))
(org-ql-search
(org-agenda-files)
`(or (tags ,tagname) (heading ,(concat name " 1:1")))
:title (format "%s 1:1" name)
:super-groups '((:name "Today" :scheduled today)
(:name "Due today" :deadline today)
(:name "Important" :priority "A")
(:name "Overdue" :deadline past)
(:name "Due soon" :deadline future)
(:name "Scheduled" :scheduled future :order 99)
(:name "Next" :todo "TODO")
(:name "Waiting" :todo "WAIT")
(:name "Projects" :todo ("PROJ"))
(:name "Last 3 Meetings" :take (-3 :heading-regexp "1:1"))
(:name "On-hold" :todo "HOLD" :order 100)))))

(map! :leader "o a o" #'kaz/one-on-one-view)
```

### Open the last meeting
Once I've opened the results of the above search, 90% of the time, I immediately move the cursor to the "Last 3 Meetings" section, then `TAB` on the most recent entry (last one on the page) to open a second window with the minutes from my last meeting, then I narrow that org buffer to the heading.

I'd like to incorporate that with my function above, so I was looking for guidance as I'm not familiar with Elisp. Should I use `save-excursion`, move point around in the org-ql view buffer to the last item in my "Last 3 Meetings", then just invoke `org-agenda-goto`? Would that be a reasonable approach? It feels unnatural that I'm positioning a cursor in a buffer to invoke some command, but I get the feeling this is quite common in Elisp. I was hoping you could confirm I've not strayed too far off the path.

Thanks again!

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。