diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el index 184209b..d686bd7 100644 --- a/lisp/org-agenda.el +++ b/lisp/org-agenda.el @@ -2097,6 +2097,7 @@ When nil, `q' will kill the single agenda buffer." org-agenda-tag-filter org-agenda-cat-filter-overlays org-agenda-category-filter + org-agenda-top-headline-filter org-agenda-re-filter-overlays org-agenda-regexp-filter org-agenda-markers @@ -3412,6 +3413,7 @@ If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write." (defvar org-agenda-tag-filter-overlays nil) (defvar org-agenda-cat-filter-overlays nil) +(defvar org-agenda-top-headline-filter-overlays nil) (defvar org-agenda-re-filter-overlays nil) (defun org-agenda-mark-filtered-text () @@ -3425,6 +3427,7 @@ If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write." 'org-filtered t))) (append org-agenda-tag-filter-overlays org-agenda-cat-filter-overlays + org-agenda-top-headline-filter-overlays org-agenda-re-filter-overlays)))) (defun org-agenda-unmark-filtered-text () @@ -7352,6 +7355,11 @@ The category is that of the current line." (list (concat "+" cat))) 'category)) ((error "No category at point")))))) + +(defadvice org-agenda-filter-by-category (after org-agenda-redo-after-cat-filter activate) + "sometimes the filter needs to be redone" + (org-agenda-redo)) + (defun org-find-top-headline (&optional pos) "Find the topmost parent headline and return it." (save-excursion @@ -7371,10 +7379,14 @@ The top headline is that of the current line." (progn (setq org-agenda-filtered-by-top-headline nil org-agenda-top-headline-filter nil) - (org-agenda-filter-show-all-cat)) - (let ((cat (org-find-top-headline (org-get-at-bol 'org-hd-marker)))) - (if cat (org-agenda-filter-top-headline-apply cat strip) - (error "No top-level category at point"))))) + (org-agenda-filter-show-all-top-headlines)) + (let ((tophl (org-find-top-headline (org-get-at-bol 'org-hd-marker)))) + (if tophl (org-agenda-filter-top-headline-apply tophl strip) + (error "No top-level headline at point"))))) + +(defadvice org-agenda-filter-by-top-headline (after org-agenda-redo-after-tophl-filter activate) + "sometimes the filter needs to be redone" + (org-agenda-redo)) (defvar org-agenda-regexp-filter nil) (defun org-agenda-filter-by-regexp (strip) @@ -7403,7 +7415,9 @@ With two prefix arguments, remove the regexp filters." (when org-agenda-category-filter (org-agenda-filter-show-all-cat)) (when org-agenda-regexp-filter - (org-agenda-filter-show-all-re))) + (org-agenda-filter-show-all-re)) + (when org-agenda-top-headline-filter) + (org-agenda-filter-show-all-top-headlines)) (defun org-agenda-filter-by-tag (strip &optional char narrow) "Keep only those lines in the agenda buffer that have a specific tag. @@ -7665,7 +7679,7 @@ When NO-OPERATOR is non-nil, do not add the + operator to returned tags." (tophl (and pos (org-find-top-headline pos)))) (if (and tophl (funcall (if negative 'identity 'not) (string= hl tophl))) - (org-agenda-filter-hide-line 'category))) + (org-agenda-filter-hide-line 'headline))) (beginning-of-line 2))) (if (get-char-property (point) 'invisible) (org-agenda-previous-line)) @@ -7682,6 +7696,7 @@ When NO-OPERATOR is non-nil, do not add the + operator to returned tags." (overlay-put ov 'type type) (cond ((eq type 'tag) (push ov org-agenda-tag-filter-overlays)) ((eq type 'category) (push ov org-agenda-cat-filter-overlays)) + ((eq type 'headline) (push ov org-agenda-top-headline-filter-overlays)) ((eq type 'regexp) (push ov org-agenda-re-filter-overlays))))) (defun org-agenda-fix-tags-filter-overlays-at (&optional pos) @@ -7720,6 +7735,15 @@ When NO-OPERATOR is non-nil, do not add the + operator to returned tags." org-agenda-filter-form nil) (org-agenda-set-mode-name)) +(defun org-agenda-filter-show-all-top-headlines nil + "Remove top headline filter overlays from the agenda buffer." + (mapc 'delete-overlay org-agenda-top-headline-filter-overlays) + (setq org-agenda-top-headline-filter-overlays nil + org-agenda-filtered-by-top-headline nil + org-agenda-top-headline-filter nil + org-agenda-filter-form nil) + (org-agenda-set-mode-name)) + (defun org-agenda-manipulate-query-add () "Manipulate the query by adding a search term with positive selection. Positive selection means the term must be matched for selection of an entry."