组织议程正则表达式搜索类别

时间:2013-12-21 03:31:27

标签: regex emacs elisp org-mode

我喜欢使用:CATEGORY:属性构建我的组织模式项目,但org-agenda-filter-by-regexp(绑定到=)似乎无法识别类别。查看相当大的TODO项目列表时,能够将列表缩小到匹配的类别会很有帮助。

我知道我可以使用org-agenda-filter-by-category<),但必须在类别条目上执行此命令。

有没有办法让regexp过滤Org议程包括类别?

下面的函数执行我想要的功能,但我无法通过org-agenda调度程序将其作为自定义议程命令。

(defun rnkn/org-category-match (str)
  "Org Agenda match TODO headlines matching :CATEGORY: property STR."
  (interactive "sCategory: ")
  (org-tags-view t (concat "CATEGORY={" str "}")))

2 个答案:

答案 0 :(得分:2)

输入M-x org-agenda RET m,然后输入正则表达式 - 例如PropertyDrawerName={regex}


上一个答案(在原始海报编辑问题之前) - 当前版本的org-element-property / org-element-headline-parser使用所有大写字母作为属性抽屉参数:

  
(defun example-one ()
(interactive)
  (require 'org-element)
  (let* (
     (org-todo-keywords '((sequence "Active(a)" "Next Action(n)" "Reference(r)"  "Someday(s)" "Delegated(d)" "|" "None(N)") ))
     (sample-todo (concat
       "* TASKS\n\n"
       "** Active [#A] smith @ drawer-one (fishing) | drawer-two (tennis). :lawlist:\n"
       "   DEADLINE: <2013-12-21 Sat 17:00>  SCHEDULED: <2013-12-21 Sat>\n"
       "   :PROPERTIES:\n"
       "   :DRAWER-ONE:  fishing\n"
       "   :DRAWER-TWO:  tennis\n"
       "   :END:\n\n"
       "** Next Action [#B] doe @ drawer-one (football) | drawer-two (bowling). :fred:\n"
       "   DEADLINE: <2013-12-22 Sun 08:30>  SCHEDULED: <2013-12-22 Sun>\n"
       "   :PROPERTIES:\n"
       "   :DRAWER-ONE:  football\n"
       "   :DRAWER-TWO:  bowling\n"
       "   :END:\n\n"
       "* EVENTS\n\n"
       "** Reference [#C] john @ drawer-one (fishing) | drawer-two (sky-diving). :george:\n"
       "   DEADLINE: <2013-12-23 Mon 10:15>  SCHEDULED: <2013-12-23 Mon>\n"
       "   :PROPERTIES:\n"
       "   :DRAWER-ONE:  fishing\n"
       "   :DRAWER-TWO:  sky-diving\n"
       "   :END:\n\n"
       "* UNDATED\n\n"
       "** Someday [#D] jane @ drawer-one (basket-ball) | drawer-two (bowling). :sam:\n"
       "   DEADLINE: <2013-12-24 Tues 12:00>  SCHEDULED: <2013-12-24 Tues>\n"
       "   :PROPERTIES:\n"
       "   :DRAWER-ONE:  basket-ball\n"
       "   :DRAWER-TWO:  bowling\n"
       "   :END:")))
     (if (get-buffer "foo.org")
       (progn
         (switch-to-buffer "foo.org")
         (erase-buffer)
         (delete-other-windows))
       (switch-to-buffer (get-buffer-create "foo.org")))
     (org-mode)
     (insert sample-todo)
     (goto-char (point-min))
     (or (y-or-n-p (format "For this example work, you must save this buffer as a file.  Proceed with example?"))
         (error "Canceled."))
     (write-file "~/Desktop/foo.org" t)
     (let* (
         (filename (buffer-file-name))
         (org-agenda-files (list filename))
         (org-agenda-only-exact-dates t)
         (org-agenda-show-all-dates nil)
         (org-deadline-warning-days 0)
         (org-agenda-time-grid nil)
         (org-agenda-span 'month)
         (org-agenda-entry-types '(:deadline))
         (month "12")
         (year "2013")
         (org-agenda-start-day (concat year "-" month "-" "01"))
         (drawer-content (read-string "basket-ball | bowling | fishing | football | sky-diving | tennis:  " nil))
         (org-agenda-skip-function (lambda ()
           (org-back-to-heading t)
           (let* (
               (element (org-element-at-point))
               (drawer-one (org-element-property :DRAWER-ONE element))
               (drawer-two (org-element-property :DRAWER-TWO element)))
             (cond
               ((not (or
                     (equal drawer-one drawer-content)
                     (equal drawer-two drawer-content)))
                 (org-end-of-subtree t))
               (t nil) )) )))
     (org-agenda-list))))

(defun example-two ()
(interactive)
  (let* (
      (drawer (read-string "Select a property drawer (e.g., ToodledoFolder):  "))
      (drawer-content (read-string (concat "Select the content of the " drawer " property drawer (e.g., EVENTS):  "))))
    (org-tags-view nil (concat drawer "=\"" drawer-content "\"" ))))

答案 1 :(得分:0)

我正在使用以下函数按类别进行过滤(解决<的问题)。

(defun stu/org-agenda-filter-by-category ()
  "Filter lines in the agenda buffer that have a specific category."
  (interactive)
  (let ((cat (read-string "Select the category:  ")))
    ;;(stu/show-agenda-and-todo)
    (org-agenda-filter-apply
    (setq org-agenda-category-filter
      (list (concat "+" cat))) 'category)))

我使用(stu / show-agenda-and-todo)来确保它过滤每个可能的任务,而不仅仅是缓冲区中显示的任务。