From 8dfe826a0bb144182fe99b49548788f2469921f7 Mon Sep 17 00:00:00 2001 From: Carsten Dominik Date: Wed, 21 Aug 2019 14:57:15 +0200 Subject: [PATCH] Agenda category filter now offers completion for categories * lisp/org-agenda.el (org-agenda-all-categories): New function. (org-agenda-filter-by-category): Implement completion on categories. --- lisp/org-agenda.el | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el index a57d44fe3..0b7958116 100644 --- a/lisp/org-agenda.el +++ b/lisp/org-agenda.el @@ -7439,17 +7439,30 @@ With a prefix argument, do so in all agenda buffers." "Return the category of the agenda line." (org-get-at-bol 'org-category)) +(defun org-agenda-all-categories () + "Return a list of all categories used in this agenda buffer." + (let ((pos (point-min)) categories) + (while (and (< pos (point-max)) + (setq pos (next-single-property-change + pos 'org-category nil (point-max)))) + (push (get-text-property pos 'org-category) categories)) + (nreverse (org-uniquify (delq nil categories))))) + (defun org-agenda-filter-by-category (strip) "Filter lines in the agenda buffer that have a specific category. The category is that of the current line. -Without prefix argument, keep only the lines of that category. -With a prefix argument, exclude the lines of that category. -" +Without prefix argument STRIP, keep only the lines of that category. +With a prefix argument, exclude the lines of that category." (interactive "P") (if (and org-agenda-filtered-by-category org-agenda-category-filter) (org-agenda-filter-show-all-cat) - (let ((cat (org-no-properties (org-agenda-get-category)))) + (let* ((categories (org-agenda-all-categories)) + (defcat (org-no-properties (or (org-agenda-get-category) + (car categories)))) + (cat (completing-read (format "Category [%s]: " defcat) + (org-agenda-all-categories) + nil t nil nil defcat))) (cond ((and cat strip) (org-agenda-filter-apply