如何在组织模式下匹配/解析任务结束时的注释

2024-03-08

我正在寻找一种与我所说的“注释”相匹配的方法,“注释”是组织任务的最后一行(或一组行),上面写着:“These are the notes of the task."


我真的写了一篇long正则表达式may完成这项工作,但我希望 org-mode 已经提供了更好的东西:

"^\\(\\*\\*\\)\\(?: +\\(Active\\|Next Action\\|Hold\\|Reference\\|Delegated\\|Postponed\\|Waiting\\|Someday\\|Planning\\|Canceled\\|None\\)\\)?\\(?: +\\(\\[#.\\]\\)\\)?\\(?: +\\(.*?\\)\\)??\\(?:[ ]+\\(:[[:alnum:]_@#%:]+:\\)\\)?[ ]*\\(?:\\(\n\\)\\)?\\(?: +\\(DEADLINE:\\|SCHEDULED:\\)\\)?\\(?: +\\(<\\)\\([^>]+\\)\\(>\\)\\)?\\(?: +\\(DEADLINE:\\|SCHEDULED:\\)\\)?\\(?: +\\(<\\)\\([^>]+\\)\\(>\\)\\)?\\(?:\\(\n\\)\\)?\\(?: +\\(CLOSED:.*\\)\\)?\\(?:\\(\n\\)\\)?\\(?: +\\(:PROPERTIES:\\)\\)?\\(?:\\(\n\\)\\)?\\(?: +\\(:ToodledoID:\\)\\)?\\(?: +\\([0-9]+\\)\\)?\\(?:\\(\n\\)\\)?\\(?: +\\(:ToodledoFolder:\\)\\)?\\(?: +\\(EVENTS\\|TASKS\\|UNDATED\\|DONE\\|CONTACT\\)\\)?\\(?:\\(\n\\)\\)\\(?: +\\(:Hash:\\)\\)?\\(?: +\\(.*+\\)\\)?\\(?:\\(\n\\)\\)?\\(?: +\\(:END:\\)\\)?\\(?:\\(\n\\)\\)?\\(.*\\(?:\n.*\\)*?\\)\\(?:^\\)"

** Delegated [#A] 0 @ Title of the task. :event:lawlist:
   DEADLINE: <2014-01-11 Sat 08:00>  SCHEDULED: <2014-01-11 Sat>
   :PROPERTIES:
   :ToodledoID: 353081871
   :ToodledoFolder: EVENTS
   :Hash: 20657e7586fcc67da708789d7bbc0fbd
   :END:
These are the notes of the task.

我发现使用的解析组织任务的最完整示例org-element-parse-buffer,但我仍然没有看到仅提取注释的关键:https://github.com/yyr/org-mode/blob/master/testing/lisp/test-org-element.el https://github.com/yyr/org-mode/blob/master/testing/lisp/test-org-element.el

如果可能的话,我想要类似的东西假想 code (org-element-property :notes (org-element-at-point)), which doesn't需要缩小到子树来提取音符。我有几百个任务,我正在寻找一种方法quickly梳理主组织文件并创建我自己的自定义议程缓冲区,显示第一个和perhaps第二行(如果截止日期或已安排)和最后的注释如果它们存在的话。我有一种感觉,如果我必须缩小到 200 个任务的子树,那么生成最终显示将会有很大的延迟。


任务的前两行已经这样处理:

(defvar lawlist-org-heading-regexp
  "^\\(\\*+\\)\\(?: +\\(.*?\\)\\)?[ \t]*\\(\n.*DEADLINE.*$\\)"
  "Custom match org headline, plus the second line with a deadline.")

(setq txt
  (save-excursion
    (org-back-to-heading t)
    (when (looking-at org-heading-regexp)
        (concat
          (match-string 1)
          " "
          (match-string 2)
          (if (and (looking-at lawlist-org-heading-regexp) (match-string 3))
            (match-string 3))
          "\n" )))) )

(message "%s" (org-element-map (org-element-parse-buffer) 'paragraph 'identity nil t))给了我以下内容:

 (paragraph 
  (:begin 244 
      :end 276 
      :contents-begin 244 
      :contents-end 276 
      :post-blank 0 
      :post-affiliated 244 
      :parent (section 
           (:begin 58 
               :end 276 
               :contents-begin 58 
               :contents-end 276 
               :post-blank 0 
               :parent (headline 
                (:raw-value 0 
                        @ 
                        Title of the task. 
                        :begin 1 
                        :end 276 
                        :pre-blank 0 
                        :hiddenp nil 
                        :contents-begin 58 
                        :contents-end 276 
                        :level 2 
                        :priority 65 
                        :tags (event lawlist) 
                        :todo-keyword Delegated 
                        :todo-type todo 
                        :post-blank 0 
                        :footnote-section-p nil 
                        :archivedp nil 
                        :commentedp nil 
                        :quotedp nil 
                        :deadline (timestamp 
                               (:type active 
                                  :raw-value <2014-01-11 Sat 08:00> 
                                  :year-start 2014 
                                  :month-start 1 
                                  :day-start 11 
                                  :hour-start 8 
                                  :minute-start 0 
                                  :year-end 2014 
                                  :month-end 1 
                                  :day-end 11 
                                  :hour-end 8 
                                  :minute-end 0 
                                  :begin 71 
                                  :end 95 
                                  :post-blank 2)) 
                        :scheduled (timestamp 
                            (:type active 
                                   :raw-value <2014-01-11 Sat>
                                   :year-start 2014
                                   :month-start 1
                                   :day-start 11
                                   :hour-start nil
                                   :minute-start nil
                                   :year-end 2014
                                   :month-end 1
                                   :day-end 11
                                   :hour-end nil
                                   :minute-end nil
                                   :begin 106
                                   :end 122
                                   :post-blank 0))
                        :TOODLEDOID 353081871
                        :TOODLEDOFOLDER EVENTS
                        :HASH 20657e7586fcc67da708789d7bbc0fbd
                        :CATEGORY .scratch
                        :title (0 @ Title of the task.)
                        :parent (org-data nil #4)) #2)) 
           (planning (:closed nil
                  :deadline (timestamp 
                         (:type active
                            :raw-value <2014-01-11 Sat 08:00>
                            :year-start 2014
                            :month-start 1
                            :day-start 11
                            :hour-start 8
                            :minute-start 0
                            :year-end 2014
                            :month-end 1
                            :day-end 11
                            :hour-end 8
                            :minute-end 0
                            :begin 71
                            :end 95
                            :post-blank 2))
                  :scheduled (timestamp 
                          (:type active
                             :raw-value <2014-01-11 Sat>
                             :year-start 2014
                             :month-start 1
                             :day-start 11
                             :hour-start nil
                             :minute-start nil
                             :year-end 2014
                             :month-end 1
                             :day-end 11
                             :hour-end nil
                             :minute-end nil
                             :begin 106
                             :end 122
                             :post-blank 0))
                  :begin 58
                  :end 123
                  :post-blank 0
                  :parent #2)) 
           (property-drawer (:begin 123
                    :end 244
                    :hiddenp nil
                    :contents-begin 139
                    :contents-end 235
                    :post-blank 0
                    :post-affiliated 123
                    :parent #2) 
                (node-property (:key ToodledoID
                             :value 353081871
                             :begin 139
                             :end 165
                             :post-blank 0
                             :parent #3)) 
                (node-property (:key ToodledoFolder
                             :value EVENTS
                             :begin 165
                             :end 192
                             :post-blank 0
                             :parent #3)) 
                (node-property (:key Hash
                             :value 20657e7586fcc67da708789d7bbc0fbd
                             :begin 192
                             :end 235
                             :post-blank 0
                             :parent #3))) 
           #0))
  These are the notes of the task.)

EDIT(2014 年 1 月 7 日):第一份工作草案。正则表达式的尾部将匹配注释,直到下一个空行——即注释可能是带有硬回车的几行,并且它们之间没有空行。

EDIT(2014 年 1 月 14 日):修订了 31 和 32,以便在缓冲区末尾不需要最终的新行 - 即,现在可以识别缓冲区末尾没有注释的任务。修改了 20 至 24,以便:ToodledoID:抽屉和:ToodledoFolder:抽屉可以互换。修改示例get-whopper排除 32 的功能。

EDIT(2014 年 11 月 14 日):稍微更新了正则表达式,但功能保持不变。

EDIT(2014 年 12 月 2 日):删除了自定义功能并替换为库存org-back-to-heading.

EDIT(2014 年 12 月 6 日:对正则表达式进行重大修改。正则表达式现在支持大多数条目的可选项目,并且缓冲区末尾不需要最终新行。通过新的修订版,正则表达式可以在风俗*Org Agenda*仅显示原始待办事项中的部分项目的缓冲区——例如,标题+截止日期/计划/已关闭+注释;或仅标题+注释。这:tag:然而, 是一个强制锚点——即,正则表达式至少需要一 (1) 个标签才能正常工作。行结尾——即\n-- 不再对匹配条目进行编号。正则表达式现在支持捆绑在一起的待办事项条目,没有任何新行将它们分开。请参阅有关非捕获组的相关线程:https://stackoverflow.com/a/3513858/2112489 https://stackoverflow.com/a/3513858/2112489另请参阅有关多行正则表达式 emacs 的相关线程:http://www.emacswiki.org/emacs/MultilineRegexp http://www.emacswiki.org/emacs/MultilineRegexp

(defvar whopper-regexp (concat
  "^\\(\\*\\*\\)" ;; 1
  "\\(?: +\\(Active\\|Next Action\\|Hold\\|Reference\\|Delegated\\|Postponed\\|Waiting\\|Someday\\|Planning\\|Canceled\\|None\\)\\)?" ;; 2
  "\\(?: +\\(\\[#.\\]\\)\\)?" ;; 3
  "\\(?: +\\(.*?\\)\\)?" ;; 4
  "\\(?:[ ]+\\(:[[:alnum:]_@#%:]+:\\)\\)" ;; 5 ;; mandatory-anchor
  "\\(?:\n +\\(DEADLINE:\\|SCHEDULED:\\)\\)?" ;; 6
  "\\(?: +\\(<\\)\\([^>]+\\)\\(>\\)\\)?" ;; 7 | 8 | 9
  "\\(?: +\\(DEADLINE:\\|SCHEDULED:\\)\\)?" ;; 10
  "\\(?: +\\(<\\)\\([^>]+\\)\\(>\\)\\)?" ;; 11 | 12 | 13
  "\\(?:\n +\\(CLOSED:.*\\)\\)?" ;; 14
  "\\(?:\n +\\(:PROPERTIES:\\)\\)?" ;; 15
  "\\(?:\n +\\(:ToodledoID:\\|:ToodledoFolder:\\)\\)?" ;; 16
  "\\(?: +\\([0-9]+\\|EVENTS\\|TASKS\\|UNDATED\\|DONE\\|CONTACT\\)\\)?" ;; 17
  "\\(?:\n +\\(:ToodledoID:\\|:ToodledoFolder:\\)\\)?" ;; 18
  "\\(?: +\\([0-9]+\\|EVENTS\\|TASKS\\|UNDATED\\|DONE\\|CONTACT\\)\\)?" ;; 19
  "\\(?:\n +\\(:Hash:\\)\\)?" ;; 20
  "\\(?: +\\(.*\\)\\)?" ;; 21
  "\\(?:\n +\\(:END:\\)\\)?" ;; 22
  "\\(?:\n\\([a-zA-z0-9_@#%:-]+.*\\(?:\n[a-zA-z0-9_@#%:-].*[^\n]\\)*\\)\\)?" ;; 23
  ) "Custom regexp for tasks, events, undated, none, and contacts.")

(defun get-whopper ()
  (save-excursion
    (org-back-to-heading t)
    (when (looking-at whopper-regexp)
      (concat
        (when (not (null (match-string 1)))
          (match-string 1)) ;; stars
        (when (not (null (match-string 2)))
          (concat " " (match-string 2))) ;; todo-state
        (when (not (null (match-string 3)))
          (concat " " (match-string 3))) ;; priority
        (when (not (null (match-string 4)))
          (concat " " (match-string 4))) ;; title
        (when (not (null (match-string 5)))
          (concat " " (match-string 5))) ;; tag
        (cond
          ((and
              (not (null (match-string 6)))    ;; DEADLINE:
              (not (null (match-string 7)))    ;; <-deadline
              (not (null (match-string 8)))    ;; deadline-time-stamp
              (not (null (match-string 9)))    ;; >-deadline
              (not (null (match-string 10)))   ;; SCHEDULED:
              (not (null (match-string 11)))   ;; <-scheduled
              (not (null (match-string 12)))   ;; scheduled-time-stamp
              (not (null (match-string 13))) ) ;; >-scheduled
            (concat
              "\n   "
              (match-string 6)    ;; DEADLINE:
              " "
              (match-string 7)    ;; <-deadline
              (match-string 8)    ;; deadline-time-stamp
              (match-string 9)    ;; >-deadline
              "  "
              (match-string 10)    ;; SCHEDULED:
              " "
              (match-string 11)    ;; <-scheduled
              (match-string 12)    ;; scheduled-time-stamp
              (match-string 13) )) ;; >-scheduled
          ((and
              (not (null (match-string 6))) ;; DEADLINE:
              (not (null (match-string 7))) ;; <-deadline
              (not (null (match-string 8))) ;; deadline-time-stamp
              (not (null (match-string 9))) ;; >-deadline
              (null (match-string 10))      ;; SCHEDULED:
              (null (match-string 11))      ;; <-scheduled
              (null (match-string 12))      ;; scheduled-time-stamp
              (null (match-string 13)) )    ;; >-scheduled
            (concat
              "\n   "
              (match-string 6)    ;; DEADLINE:
              " "
              (match-string 7)    ;; <-deadline
              (match-string 8)    ;; deadline-time-stamp
              (match-string 9)) ) ;; >-deadline
          ((and
              (null (match-string 6))          ;; DEADLINE:
              (null (match-string 7))          ;; <-deadline
              (null (match-string 8))          ;; deadline-time-stamp
              (null (match-string 9))          ;; >-deadline
              (not (null (match-string 10)))   ;; SCHEDULED:
              (not (null (match-string 11)))   ;; <-scheduled
              (not (null (match-string 12)))   ;; scheduled-time-stamp
              (not (null (match-string 13))) ) ;; >-scheduled
            (concat
              "\n   "
              (match-string 10)     ;; SCHEDULED:
              " "
              (match-string 11)     ;; <-scheduled
              (match-string 12)     ;; scheduled-time-stamp
              (match-string 13)) )) ;; >-scheduled
        (when (not (null (match-string 14)))
          (concat "\n   " (match-string 14))) ;; CLOSED:
        (when (not (null (match-string 15)))
          (concat "\n   " (match-string 15))) ;; :PROPERTIES:
        (when (not (null (match-string 16)))
          (concat "\n   " (match-string 16)))      ;; :ToodledoID:
        (when (not (null (match-string 17)))
          (concat " " (match-string 17)))   ;; id-string
        (when (not (null (match-string 18)))
          (concat "\n   " (match-string 18)))      ;; :ToodledoFolder:
        (when (not (null (match-string 19)))
          (concat " " (match-string 19)))   ;; folder-name
        (when (not (null (match-string 20)))
          (concat "\n   " (match-string 20)))      ;; :HASH:
        (when (not (null (match-string 21)))
          (concat " " (match-string 21)))   ;; hash-string
        (when (not (null (match-string 22)))
          (concat "\n   " (match-string 22))) ;; :END:
        (when (not (null (match-string 23)))
          (concat "\n" (match-string 23))) )))) ;; notes
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在组织模式下匹配/解析任务结束时的注释 的相关文章

随机推荐

  • Macos 上输出中的 gnuplot pdfcairo 未命名 Type 3 字体

    带有 pdfcairo 终端的 Gnuplot 似乎在字体方面给出了奇怪的行为 其中生成的 pdf 具有未命名的 Type 3 字体 以下是 pdffonts 在输出 pdf 文件上的输出 name type encoding emb su
  • 在Java中将ANSI字符转换为UTF-8

    有没有办法使用 Java 将 ANSI 字符串转换为 UTF 我有一个自定义序列化程序 它使用 DataInputStream 类的 readUTF 和 writeUTF 方法来反序列化和序列化字符串 如果我收到一个以 ANSI 编码的字符
  • setTimeout 无法绑定到“this”原型函数[重复]

    这个问题在这里已经有答案了 我写了一个代码 我想看看 Hello world 每一秒 但我已经undefined我找不到我的错误在哪里 function Greeting message delay this message message
  • 将形状添加到幻灯片并设置格式

    我正在尝试制作下面的 vba 脚本来向 powerpoint 幻灯片添加注释注释 这个想法是 该脚本可用于向幻灯片添加 待检查的注释 因此 我将其设置在一个显示菜单的小插件中 以便添加 TBC TBU TBD 注释 该子系统时不时地显示错误
  • 不是作为 jQuery Deferred 执行的异步函数

    假设我想以同步方式处理一些任务 所以我有这个函数 function executePromiseQueueSync queue var seed Deferred finalPromise finalPromise reduce queue
  • 启用安全辅助紧急模式

    对我来说 实施和学习这是一件非常有趣和新鲜的事情 我的申请有一些要求 为此 我进行了很多搜索 但找不到合适且有价值的东西或链接 所以我在这里发布我的问题 其功能有 1 在三星设备中有Safety Assistance您可以在其中找到菜单Em
  • 简单的多维 C 型数组出现分段错误:11

    const int L 10 std complex
  • cv2.Canny() 是否执行高斯模糊?

    我知道在使用 Canny 检测边缘之前对图像应用高斯模糊非常重要 我的问题是 cv2 Canny 单独进行高斯模糊或者有必要应用cv2 GaussianBlur before cv2 Canny 文档在这一点上并不清楚 回想一下 在 Pyt
  • Pyspark from_unixtime (unix_timestamp) 不转换为时间戳

    我正在使用 Pyspark 和 Python 2 7 我在字符串中有一个日期列 带毫秒 并且想转换为时间戳 这是我到目前为止所尝试过的 df df withColumn end time from unixtime unix timesta
  • Excel VBA 文本框时间验证为 [h]:mm

    我正在开发 VBA Excel 用户窗体 需要以 h mm 格式输入时间 这意味着小时数可以不受限制 并且不会像 hh mm 格式那样在 23 59 之后循环回 0 我在网上搜索过没有结果 这是我当前使用的代码 Private Sub Tx
  • 运行任务时显示 Gradle 控制台

    当我在 Android Stduio 中运行 gradle 任务时 如何显示 gradle 控制台 当我执行任务时 会弹出运行对话框 但控制台不会弹出 我希望能够看到 gradle 控制台 以便可以看到输出 但我不想永久看到 gradle
  • 通过多次变换替换和维护角色实体

    问题 我们的系统中存在各种格式的字符实体 例如 amp and amp amp 如果需要的话 我们需要将它们转换为标准 XML 字符实体 amp lt gt apos quot 然后通过几个单独的转换将它们维护为实体 给定 XML
  • MPI_Isend 和 MPI_Irecv 似乎导致死锁

    我在 MPI 中使用非阻塞通信在进程之间发送各种消息 然而 我似乎陷入了僵局 我用过PADB see here http padb pittman org uk 查看消息队列并得到以下输出 1 msg12 Operation 1 pendi
  • Windows 应用商店应用程序:更改应用程序栏按钮的图标?

    我想更改 Windows 应用商店应用程序中 AppBar 按钮的图标 我发现 AppBar 按钮具有如下所示的 XAML 标记
  • Websphere Liberty Profile 中的 Java EE-Timer / @Schedule

    我想使用计时器服务 特别是 Schedule注解 http docs oracle com javaee 6 api javax ejb Schedule html 在 WebSphere Liberty Profile 中 那可能吗 有一
  • 如何在WebBrowser Control中设置当前的document.domain以避免“访问被拒绝”?

    如何设置电流document domain在 WebBrowser Control 中避免跨域调用 XMLHTTP 请求或 Iframe frame 访问 中的 访问被拒绝 我试过了 CurrentDocument WebBrowserCo
  • codeigniter 活动记录,生成,但不执行查询

    我正在工作一个库 需要将 sql 查询作为字符串来完成其工作 我正在使用 CodeIgniter 及其数据库类的活动记录实现 我知道我可以像这样回显 SQL 语句 但我只想生成这个查询 而不是执行它 echo this gt db gt l
  • 如何更改android中的启动活动?

    我有两项活动 即login and calendar在我的应用程序中 目前我的startup活动是 calendar 我想运行login作为第一个活动不是calendar 启动活动 Launcher Activity 在项目的 Androi
  • Clojure 符号用作函数时有什么作用?

    在尝试解决 4Clojure 问题时 通用计算引擎 http www 4clojure com problem 121 涉及重新实现评估 我不小心最终调用了这样的内容 apply 16 8 而不是预期的 apply 16 8 这带来了返回的
  • 如何在组织模式下匹配/解析任务结束时的注释

    我正在寻找一种与我所说的 注释 相匹配的方法 注释 是组织任务的最后一行 或一组行 上面写着 These are the notes of the task 我真的写了一篇long正则表达式may完成这项工作 但我希望 org mode 已