emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Matt Lundin <mdl@imapmail.org>
To: radoslawg@gmail.com
Cc: Org-mode ml <emacs-orgmode@gnu.org>
Subject: Re: Filtering agenda by tags.
Date: Wed, 20 Apr 2011 10:02:38 -0400	[thread overview]
Message-ID: <87vcy99g1t.fsf@fastmail.fm> (raw)
In-Reply-To: <4DAEDCAA.3060005@gmail.com> ("Radosław Grzanka"'s message of "Wed, 20 Apr 2011 15:16:26 +0200")

Radosław Grzanka <radoslawg@gmail.com> writes:

>   yes, I've simplified examples to the point which made no sense. I'm
> very sorry.
>   All entries should have had some kind of timestamp, deadline or
> schedule. Yes, I'd like daily/weekly agenda view filtered by tags.

No problem. Maybe the tags search examples I provided will prove useful
to someone else who stumbles across them. :)

> - org-agenda-filter-preset - but that seems not to support "or" (maybe
> I'm missing something?)

Filtering allows for inherited tags but not for or logic. It's a quick
and simple way to include or exclude by tag. E.g., '("+work" "+internet")
will filter for items tagged work and internet.

> - org-agenda-skip-function - which I found googling around - with
> regexp like '(org-agenda-skip-subtree-if 'regexp ":work:")' - but that
> seems not to support "inherited" tags.

The regexp argument of org-agenda-skip-subtree-if function, on the other
hand, allows for or logic but not for inherited tags. E.g., 

(org-agenda-skip-subtree-if 'notregexp ":\\(work\\|internet\\):")

...will find items tagged with work or internet, but only if they are
local.

I believe the only option is to write a skip function that uses
org-entry-get to get all the tags at point.

Here's an example:

--8<---------------cut here---------------start------------->8---
(defun org-agenda-skip-entry-unless-tags (tags)
  "Skip entries that do not contain specified tags.
TAGS is a list specifying which tags should be displayed.
Inherited tags will be considered."
  (let ((subtree-end (save-excursion (org-end-of-subtree t)))
	(atags (split-string (org-entry-get nil "ALLTAGS") ":")))
    (if (catch 'match
	  (mapc (lambda (tag)
		  (when (member tag atags)
		    (throw 'match t)))
		tags)
	  nil)
	nil
      subtree-end)))
			
(setq org-agenda-custom-commands
      '(("x" "Work and internet" agenda ""
	 ((org-agenda-skip-function '(org-agenda-skip-entry-unless-tags '("work" "internet")))))))
--8<---------------cut here---------------end--------------->8---

Best,
Matt

  reply	other threads:[~2011-04-20 14:02 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-20 10:17 Filtering agenda by tags Radosław Grzanka
2011-04-20 12:52 ` Matt Lundin
2011-04-20 13:05   ` Radosław Grzanka
2011-04-20 13:12     ` Matt Lundin
2011-04-20 13:16       ` Radosław Grzanka
2011-04-20 14:02         ` Matt Lundin [this message]
2011-04-30 15:48           ` Mike McLean

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87vcy99g1t.fsf@fastmail.fm \
    --to=mdl@imapmail.org \
    --cc=emacs-orgmode@gnu.org \
    --cc=radoslawg@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).