Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Search 在组织模式下使用日志中的时间戳进行自定义搜索_Search_Logging_Time_Org Mode - Fatal编程技术网

Search 在组织模式下使用日志中的时间戳进行自定义搜索

Search 在组织模式下使用日志中的时间戳进行自定义搜索,search,logging,time,org-mode,Search,Logging,Time,Org Mode,我想创建一个自定义议程搜索,它将根据日志中的时间条目查找待办事项。具体地说,我想根据标记进入等待状态的时间戳查找标记为等待的项目。这些条目如下所示: :LOGBOOK: - State "WAITING" from "TODO" [2011-11-02 Wed 15:10] \\ Emailed so-and-so about such-and-such. :END: 我可以用航海日志上的信息来做这件事吗?我使用的是7.5版,但如有必要,可以升级 谢谢 编辑:一个用例可能是查

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

:LOGBOOK:
- State "WAITING"     from "TODO"    [2011-11-02 Wed 15:10] \\
  Emailed so-and-so about such-and-such.
:END:
我可以用航海日志上的信息来做这件事吗?我使用的是7.5版,但如有必要,可以升级

谢谢


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

以下内容应该满足您的需要。您只需调整自定义议程命令以适应您的用例。(在测试和配置它时,我使用了TODO关键字)。这段代码的一部分可能与内置组织功能的工作重复,特别是因为它类似于计划和截止日期方法/过期行为,但我看不到任何可重用的特定功能

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

(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)))))
最后一个函数确定今天与上述函数找到的时间戳之间的天数差

(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多天前完成的关键字(而不是像我在第一条评论中链接的示例中那样查找月份与本月/上月匹配的时间戳)


除了Jonathan Leech Pepin answer之外,如果您想查看
CLOSED:
(setq org log done'time)
添加的抽屉配置,您可以改进
zin/find state
功能,如下所示:

(defun zin/find-state (state &optional end all)
  (let ((drawer (if all "" ":.*:\\W" "CLOSED:")))
    (or (re-search-forward (concat drawer ".*State \\\"" state "\\\"\\W+from.*\\[") end t)
        (re-search-forward (concat drawer ".*\\[") end t))))

PS:这只是对答案的一个改进,正确的答案是乔纳森的答案。

根据日志,您需要它的具体原因是什么?如果项目当前正在“等待”,您应该能够基于此进行自定义搜索。我怀疑这里的存档方法可能会有所改变:。只需调整匹配参数以匹配“State\”WAITING\”。尽管我不确定如何仅根据这些时间戳而不是包括的其他时间戳进行排序。一个用例是查找一周前进入等待状态的等待项目。因为我的todo设置已经在日志中记录了它进入等待状态的时间,这似乎是开始的地方。不过,我对其他方法持开放态度。日志中您希望匹配的时间条目是否总是最新的?它要么必须是最新的日志条目,要么必须与该标题的所有日志条目相匹配(无论此后的更新)。我怀疑您只希望它与最近的日志条目匹配,否则它将与您的用例不匹配。谢谢!这看起来正是我需要的。遗憾的是,一些内置功能没有更大用处,因为这似乎是一个常见的用例。另外,还有一个额外的参数'all'传递给zin/find state。删除此选项使代码正确运行。哎呀,实际上,在从
zin/sin/since state
调用
zin/find state
时,调用
t
是额外的。它应该默认为nil,并且需要从议程命令本身传递
t
(如果全部为
t
,它将查找任何事件,而不仅仅是日志中最近的事件,这将产生误报)。我将在我的答案中确定这个值。
(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))))
              )))
(defun zin/find-state (state &optional end all)
  (let ((drawer (if all "" ":.*:\\W" "CLOSED:")))
    (or (re-search-forward (concat drawer ".*State \\\"" state "\\\"\\W+from.*\\[") end t)
        (re-search-forward (concat drawer ".*\\[") end t))))