emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Filtering agenda by tags.
@ 2011-04-20 10:17 Radosław Grzanka
  2011-04-20 12:52 ` Matt Lundin
  0 siblings, 1 reply; 7+ messages in thread
From: Radosław Grzanka @ 2011-04-20 10:17 UTC (permalink / raw)
  To: Org-mode ml

Hello,
   I have another problem which I fail on resolving.

Let's say I have a org file

--------------
#+FILETAGS: work

* Do something at work
* Do something at the internet    :internet:
--------------

and another file:

--------------

* Do something at home            :home:
* Do something at the internet    :internet:
* Some other untagged task

--------------

I'd like to have two agenda views:

1. should show things I can do at work and internet and untagged tasks
2. should show things I can do at home and internet and untagged tasks

I fail with defining custom agenda views. I've browsed google and 
already tried:
- org-agenda-filter-preset - but that seems not to support "or" (maybe 
I'm missing something?)
- 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.

I'm using latest git checkout org and emacs 23.3.1 on windows.

Thanks for any tip

Radek.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Filtering agenda by tags.
  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
  0 siblings, 1 reply; 7+ messages in thread
From: Matt Lundin @ 2011-04-20 12:52 UTC (permalink / raw)
  To: radoslawg; +Cc: Org-mode ml

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

> Hello,
>   I have another problem which I fail on resolving.
>
> Let's say I have a org file
>
> --------------
> #+FILETAGS: work
>
> * Do something at work
> * Do something at the internet    :internet:
> --------------
>
> and another file:
>
> --------------
>
> * Do something at home            :home:
> * Do something at the internet    :internet:
> * Some other untagged task
>
> --------------
>
> I'd like to have two agenda views:
>
> 1. should show things I can do at work and internet and untagged tasks
> 2. should show things I can do at home and internet and untagged tasks
>

(setq org-agenda-custom-commands
      '(("x" "Work and internet and untagged" tags "+work|+internet|-TAGS={.}")
	("X" "Home and internet and untagged" tags "+home|+interent|-TAGS={.}")))

I am assuming that when you say "untagged", you mean items without local
tags. If you want inherited tags to be considered, use ALLTAGS instead.

> I fail with defining custom agenda views. I've browsed google and
> already tried:
> - org-agenda-filter-preset - but that seems not to support "or" (maybe
> I'm missing something?)
> - 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 simplest solution is just to use a query/match (as above). The
variables org-agenda-filter-preset and org-agenda-skip-function are
meant primarily for agenda views, which are built around timestamps
rather than tags searches. When simply searching for tags, the tags
matcher is the best bet.

Note, you could accomplish the same thing with:

C-c a m "work|internet|-TAGS={.}"

See the following for more information:

- (info "(org) Tag searches")
- (info "(org) Matching tags and properties")
- http://orgmode.org/worg/org-tutorials/advanced-searching.html#tag-searches
- http://orgmode.org/worg/org-tutorials/org-custom-agenda-commands.html

Best,
Matt

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Filtering agenda by tags.
  2011-04-20 12:52 ` Matt Lundin
@ 2011-04-20 13:05   ` Radosław Grzanka
  2011-04-20 13:12     ` Matt Lundin
  0 siblings, 1 reply; 7+ messages in thread
From: Radosław Grzanka @ 2011-04-20 13:05 UTC (permalink / raw)
  To: Org-mode ml

Hello,

W dniu 2011-04-20 14:52, Matt Lundin pisze:
>> I'd like to have two agenda views:
>>
>> 1. should show things I can do at work and internet and untagged tasks
>> 2. should show things I can do at home and internet and untagged tasks

> The simplest solution is just to use a query/match (as above). The
> variables org-agenda-filter-preset and org-agenda-skip-function are
> meant primarily for agenda views, which are built around timestamps

Which is exactly what I want - maybe I was not clear enough. I don't 
want tags search. I want agenda view without entries with given tags (or 
entries only with given tags).

Thanks,
   Radek.

P.S. After not-so-much thinking "untagged" makes no sense anymore.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Filtering agenda by tags.
  2011-04-20 13:05   ` Radosław Grzanka
@ 2011-04-20 13:12     ` Matt Lundin
  2011-04-20 13:16       ` Radosław Grzanka
  0 siblings, 1 reply; 7+ messages in thread
From: Matt Lundin @ 2011-04-20 13:12 UTC (permalink / raw)
  To: radoslawg; +Cc: Org-mode ml

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

> Hello,
>
> W dniu 2011-04-20 14:52, Matt Lundin pisze:
>>> I'd like to have two agenda views:
>>>
>>> 1. should show things I can do at work and internet and untagged tasks
>>> 2. should show things I can do at home and internet and untagged tasks
>
>> The simplest solution is just to use a query/match (as above). The
>> variables org-agenda-filter-preset and org-agenda-skip-function are
>> meant primarily for agenda views, which are built around timestamps
>
> Which is exactly what I want - maybe I was not clear enough. I don't
> want tags search. I want agenda view without entries with given tags
> (or entries only with given tags).

Could you please clarify what you mean by an agenda view. Do you mean
the daily/weekly agenda?

None of the examples you provided have timestamps, so they would not
show up in the *daily/weekly* agenda view unless you had
org-agenda-include-all-todo set to t.

Best,
Matt

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Filtering agenda by tags.
  2011-04-20 13:12     ` Matt Lundin
@ 2011-04-20 13:16       ` Radosław Grzanka
  2011-04-20 14:02         ` Matt Lundin
  0 siblings, 1 reply; 7+ messages in thread
From: Radosław Grzanka @ 2011-04-20 13:16 UTC (permalink / raw)
  To: Org-mode ml

W dniu 2011-04-20 15:12, Matt Lundin pisze:
> Radosław Grzanka<radoslawg@gmail.com>  writes:
>
>> Hello,
>>
>> W dniu 2011-04-20 14:52, Matt Lundin pisze:
>>>> I'd like to have two agenda views:
>>>>
>>>> 1. should show things I can do at work and internet and untagged tasks
>>>> 2. should show things I can do at home and internet and untagged tasks
>>
>>> The simplest solution is just to use a query/match (as above). The
>>> variables org-agenda-filter-preset and org-agenda-skip-function are
>>> meant primarily for agenda views, which are built around timestamps
>>
>> Which is exactly what I want - maybe I was not clear enough. I don't
>> want tags search. I want agenda view without entries with given tags
>> (or entries only with given tags).
>
> Could you please clarify what you mean by an agenda view. Do you mean
> the daily/weekly agenda?
>
> None of the examples you provided have timestamps, so they would not
> show up in the *daily/weekly* agenda view unless you had
> org-agenda-include-all-todo set to t.

Hi,
   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.

Thanks for helping,
   Radek.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Filtering agenda by tags.
  2011-04-20 13:16       ` Radosław Grzanka
@ 2011-04-20 14:02         ` Matt Lundin
  2011-04-30 15:48           ` Mike McLean
  0 siblings, 1 reply; 7+ messages in thread
From: Matt Lundin @ 2011-04-20 14:02 UTC (permalink / raw)
  To: radoslawg; +Cc: Org-mode ml

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Filtering agenda by tags.
  2011-04-20 14:02         ` Matt Lundin
@ 2011-04-30 15:48           ` Mike McLean
  0 siblings, 0 replies; 7+ messages in thread
From: Mike McLean @ 2011-04-30 15:48 UTC (permalink / raw)
  To: emacs-orgmode

On 4/20/11 10:02 AM, Matt Lundin wrote:
> I believe the only option is to write a skip function that uses
> org-entry-get to get all the tags at point.
I have this in my org-setup and use it to generate agenda views that
skip certain tags, whether that tag is local or inherited.

#+begin_src emacs-lisp
  (defun mlm-skip-if-bill-pay()
    "Skip entries that are Tagged Bill_Pay taking into account inheritance"
    (let* ((entry-tags (org-get-tags-at (point))))
      (if (member "Bill_Pay" entry-tags)
          (progn (outline-next-heading) (point))
        nil
        )
      )
    )
#+end_src

And then the the custom agenda definiitions where I want to exclude
this, I have:

#+begin_src emacs-lisp
(org-agenda-skip-function 'mlm-skip-if-bill-pay)
#+end_src

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-04-30 15:48 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2011-04-30 15:48           ` Mike McLean

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