gpt4 book ai didi

search - 在组织模式下使用 LOGBOOK 中的时间戳进行自定义搜索

转载 作者:行者123 更新时间:2023-12-03 21:39:54 25 4
gpt4 key购买 nike

我想创建一个自定义议程搜索,它将根据日志中的时间条目查找待办事项。具体来说,我想根据标记进入等待状态的时间戳来查找标记为 WAITING 的项目。这些条目如下所示:

:LOGBOOK:
- State "WAITING" from "TODO" [2011-11-02 Wed 15:10] \\
Emailed so-and-so about such-and-such.
:END:

我可以用日志中的信息来做这件事吗?我使用的是 7.5 版,但可以在必要时升级。

谢谢!

编辑:一个用例可能是找到等待状态超过一周的 WAITING 待办事项。 (这通常意味着我需要再次打扰某人。)

最佳答案

以下应该做你需要的。您只需调整自定义议程命令以适合您的用例。 (在测试和配置它时,我使用了我的 TODO 关键字)。此代码的一部分可能重复了内置 org 函数的工作,特别是因为它类似于 Scheduled and Deadline 方法/逾期行为,但我看不到任何可重用的特定函数。

在自定义命令中使用的实际函数如下。

(defun zin/since-state (since todo-state &optional done all)
"List Agenda items that are older than SINCE.

TODO-STATE is a regexp for matching to TODO states. It is provided to
`zin/find-state' to match inactive timestamps.
SINCE is compared to the result of `zin/org-date-diff'. If
`zin/org-date-diff' is greater than SINCE, the entry is shown in the
Agenda.
Optional argument DONE allows for done and not-done headlines to be
evaluated. If DONE is non-nil, match completed tasks.
Optional argument ALL is passed to `zin/find-state' to specify whether
to search for any possible match of STATE, or only in the most recent
log entry."
(let ((next-headline (save-excursion (or (outline-next-heading) (point-max)))))
;; If DONE is non-nil, look for done keywords, if nil look for not-done
(if (member (org-get-todo-state)
(if done
org-done-keywords
org-not-done-keywords))
(let* ((subtree-end (save-excursion (org-end-of-subtree t)))
(subtree-valid (save-excursion
(forward-line 1)
(if (and (< (point) subtree-end)
;; Find the timestamp to test
(zin/find-state todo-state subtree-end all))
(let ((startpoint (point)))
(forward-word 3)
;; Convert timestamp into days difference from today
(zin/org-date-diff startpoint (point)))))))
(if (or (not subtree-valid)
(<= subtree-valid since))
next-headline
nil))
(or next-headline (point-max)))))

以下函数通过 re-search-forward 查找日志条目。
(defun zin/find-state (state &optional end all)
"Used to search through the logbook of subtrees.

Tests to see if the first line of the logbook is a change of todo
status to status STATE
- Status \"STATE\" from ...
The search brings the point to the start of YYYY-MM-DD in inactive timestamps.

Optional argument END defines the point at which to stop searching.
Optional argument ALL when non-nil specifies to look for any occurence
of STATE in the subtree, not just in the most recent entry."
(let ((drawer (if all "" ":.*:\\W")))
(re-search-forward (concat drawer ".*State \\\"" state "\\\"\\W+from.*\\[") end t)))

最后一个函数确定今天与上述函数找到的时间戳之间的天数差异。
(defun zin/org-date-diff (start end &optional compare)
"Calculate difference between selected timestamp to current date.

The difference between the dates is calculated in days.
START and END define the region within which the timestamp is found.
Optional argument COMPARE allows for comparison to a specific date rather than to current date."
(let* ((start-date (if compare compare (calendar-current-date))))
(- (calendar-absolute-from-gregorian start-date) (org-time-string-to-absolute (buffer-substring-no-properties start end)))
))

使用上述函数的两个示例自定义议程命令。第一个匹配您的用例,您只需将“PEND”更改为“WAITING”即可匹配正确的关键字。第二个查找在 30 多天前完成的 DONE 关键字(而不是像我在第一条评论中链接的示例中那样查找与本月/上月匹配的月份的时间戳)。
(setq org-agenda-custom-commands
(quote (("T" "Tasks that have been pending more than 7 days." tags "-REFILE/"
((org-agenda-overriding-header "Pending tasks")
(org-agenda-skip-function '(zin/since-state 7 "PEND"))))
("A" "Tasks that were completed more than 30 days ago." tags "-REFILE/"
((org-agenda-overriding-header "Archivable tasks")
(org-agenda-skip-function '(zin/since-state 30 "\\\(DONE\\\|CANC\\\)" t))))
)))

关于search - 在组织模式下使用 LOGBOOK 中的时间戳进行自定义搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8039416/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com