* Filtering agenda by the "top" category
@ 2012-04-04 20:38 John Wiegley
2012-04-10 20:42 ` Bastien
0 siblings, 1 reply; 2+ messages in thread
From: John Wiegley @ 2012-04-04 20:38 UTC (permalink / raw)
To: emacs-orgmode; +Cc: Dave Abrahams
I discovered the < key in the agenda yesterday (by accident!), which filters
the Agenda down to entries having the same category.
However, I use both *categories* and *projects*. For example:
* Work
:CATEGORY: Work
:OVERLAY: (face (:background "#fdfdeb"))
** PROJECT Foo
:CATEGORY: Foo
I use :CATEGORY: for my project here so it shows up in the leftmost column of
my agenda. I don't want every project displaying as just "Work". I use the
:OVERLAY: so that all Work items have the same background color, which is a
better way of seeing at a glance which *category* every item falls into.
What this means is that although I can use < to filter by *project*, I can't
filter down to the "Work" *category*. So that's what the code below does. I
bind it to >, since I wasn't using what that binding does.
Also, I found a bug: passing a prefix argument to < doesn't have any effect.
The code doesn't use that argument in any meaningful way.
John
(define-key org-agenda-mode-map ">" 'org-agenda-filter-by-top-category)
(defun org-find-top-category (&optional pos)
(save-excursion
(with-current-buffer (if pos (marker-buffer pos) (current-buffer))
(if pos (goto-char pos))
;; Skip up to the topmost parent
(while (ignore-errors (outline-up-heading 1) t))
(ignore-errors
(nth 4 (org-heading-components))))))
(defvar org-agenda-filtered-by-top-category nil)
(defun org-agenda-filter-by-top-category (strip)
"Keep only those lines in the agenda buffer that have a specific category.
The category is that of the current line."
(interactive "P")
(if org-agenda-filtered-by-top-category
(progn
(setq org-agenda-filtered-by-top-category nil)
(org-agenda-filter-show-all-cat))
(let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
(if cat (org-agenda-filter-top-category-apply cat)
(error "No top-level category at point")))))
(defun org-agenda-filter-top-category-apply (category)
"Set FILTER as the new agenda filter and apply it."
(org-agenda-set-mode-name)
(save-excursion
(goto-char (point-min))
(while (not (eobp))
(let* ((pos (org-get-at-bol 'org-hd-marker))
(topcat (and pos (org-find-top-category pos))))
(if (and topcat (not (string= category topcat)))
(org-agenda-filter-hide-line 'category)))
(beginning-of-line 2)))
(if (get-char-property (point) 'invisible)
(org-agenda-previous-line))
(setq org-agenda-filtered-by-top-category t))
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Filtering agenda by the "top" category
2012-04-04 20:38 Filtering agenda by the "top" category John Wiegley
@ 2012-04-10 20:42 ` Bastien
0 siblings, 0 replies; 2+ messages in thread
From: Bastien @ 2012-04-10 20:42 UTC (permalink / raw)
To: John Wiegley; +Cc: Dave Abrahams, emacs-orgmode
Hi John,
John Wiegley <jwiegley@gmail.com> writes:
> I discovered the < key in the agenda yesterday (by accident!), which filters
> the Agenda down to entries having the same category.
>
> However, I use both *categories* and *projects*. For example:
>
> * Work
> :CATEGORY: Work
> :OVERLAY: (face (:background "#fdfdeb"))
> ** PROJECT Foo
> :CATEGORY: Foo
>
> I use :CATEGORY: for my project here so it shows up in the leftmost column of
> my agenda. I don't want every project displaying as just "Work". I use the
> :OVERLAY: so that all Work items have the same background color, which is a
> better way of seeing at a glance which *category* every item falls into.
>
> What this means is that although I can use < to filter by *project*, I can't
> filter down to the "Work" *category*. So that's what the code below does. I
> bind it to >, since I wasn't using what that binding does.
I tested the code and it looks useful.
Could you make a patch against current master?
> Also, I found a bug: passing a prefix argument to < doesn't have any effect.
> The code doesn't use that argument in any meaningful way.
This is now fixed. You can use `C-u <' to filter out the category of
the current line. Thanks for spotting this!
--
Bastien
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-04-10 20:41 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-04 20:38 Filtering agenda by the "top" category John Wiegley
2012-04-10 20:42 ` Bastien
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).