Org Agenda regexp search Categories

2019-06-20 05:26发布

I like to structure my org-mode projects using the :CATEGORY: property, however categories seem not to be recognised by org-agenda-filter-by-regexp (bound to =). When viewing a rather large list of TODO items, it would be helpful to be able to narrow the list to matching categories.

I know that I can use org-agenda-filter-by-category (<), but this command must be executed on the category entry.

Is there a way to regexp filter the Org Agenda including categories?

The function below performs what I'd like, however I can't get it to work from the org-agenda dispatcher as a custom agenda command.

(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条回答
看我几分像从前
2楼-- · 2019-06-20 06:05

I'm using the following function to filter by category (solves the problem of < ).

(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)))

I use (stu/show-agenda-and-todo) to make sure it filters every possible task, not only the ones shown in the buffer.

查看更多
Lonely孤独者°
3楼-- · 2019-06-20 06:23

Type M-x org-agenda RET m and then enter the regex -- e.g., PropertyDrawerName={regex}


Previous Answer (before the original poster edited the question) -- the current version of org-element-property / org-element-headline-parser uses all UPPERCASE letters for the property drawer arguments:

(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 "\"" ))))
查看更多
登录 后发表回答