emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Searching for tags or todo keywords
@ 2008-08-22 13:21 Peter Westlake
  2008-09-13 19:10 ` Carsten Dominik
  0 siblings, 1 reply; 6+ messages in thread
From: Peter Westlake @ 2008-08-22 13:21 UTC (permalink / raw)
  To: emacs-orgmode

I only discovered org-mode a couple of weeks ago, so apologies if this
is a FAQ, or the patch is in the wrong format.

I would like to define an agenda command to show TODO items in the
context of the projects to which they belong, like this:

  todo:       .Widget project
  todo:       ..TODO Gather widget requirements
  todo:       .Gadget project
  todo:       ..TODO Plan the end of project party

That would be a search like:

  (LEVEL=2) | (/TODO)

But LEVEL=2|/TODO is interpreted as (LEVEL=2|) & (/TODO)
because / has the lowest precedence.

/TODO|LEVEL=2 treats LEVEL as a TODO word instead of a tag.

Is there any way around this, short of implementing parentheses?

One possibility might be to make operators that are like / but bind most
tightly, one to say "this is a todo keyword" and one to say "this is a
tag". For instance, if \ was like / but high precedence, and % was the
opposite of \, my query would become:

  \TODO | %LEVEL=2

Having looked at the code, that looks almost as hard as parens.

Next idea: since "/" means "and this TODO expression", add "\" meaning
"or this TODO expression". So my query becomes:

  LEVEL=2\TODO

This is a lot easier to implement. In fact, this patch does it:

diff -wu /usr/share/emacs/site-lisp/org-mode/org.el
/home/pwestlake/elisp/org.el
--- /usr/share/emacs/site-lisp/org-mode/org.el  2008-06-17
20:36:44.000000000 +0100
+++ /home/pwestlake/elisp/org.el        2008-08-22 14:13:44.031536000
+0100
@@ -9381,17 +9381,26 @@
        tagsmatch todomatch tagsmatcher todomatcher kwd matcher
        orterms term orlist re-p str-p level-p level-op
        prop-p pn pv po cat-p gv)
-    (if (string-match "/+" match)
+    (cond ((string-match "/+" match)
        ;; match contains also a todo-matching request
-       (progn
          (setq tagsmatch (substring match 0 (match-beginning 0))
                todomatch (substring match (match-end 0)))
          (if (string-match "^!" todomatch)
              (setq todo-only t todomatch (substring todomatch 1)))
          (if (string-match "^\\s-*$" todomatch)
-             (setq todomatch nil)))
+               (setq todomatch nil))
+           (setq todo-op 'and todo-op-default t))
+          ((string-match "\\\\+" match)
+           (setq tagsmatch (substring match 0 (match-beginning 0))
+                 todomatch (substring match (match-end 0)))
+           (if (string-match "^!" todomatch)
+               (setq todo-only t todomatch (substring todomatch 1)))
+           (if (string-match "^\\s-*$" todomatch)
+               (setq todomatch nil))
+           (setq todo-op 'or todo-op-default nil))
+
       ;; only matching tags
-      (setq tagsmatch match todomatch nil))
+          (t (setq tagsmatch match todomatch nil todo-op-default t
todo-op 'and)))

     ;; Make the tags matcher
     (if (or (not tagsmatch) (not (string-match "\\S-" tagsmatch)))
@@ -9447,7 +9456,7 @@
            (list 'progn '(setq org-cached-props nil) tagsmatcher)))
     ;; Make the todo matcher
     (if (or (not todomatch) (not (string-match "\\S-" todomatch)))
-       (setq todomatcher t)
+       (setq todomatcher todo-op-default)
       (setq orterms (org-split-string todomatch "|") orlist nil)
       (while (setq term (pop orterms))
        (while (string-match re term)
@@ -9471,7 +9480,7 @@

     ;; Return the string and lisp forms of the matcher
     (setq matcher (if todomatcher
-                     (list 'and tagsmatcher todomatcher)
+                     (list todo-op tagsmatcher todomatcher)
                    tagsmatcher))
     (cons match0 matcher)))


Regards,

Peter.

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

* Re: Searching for tags or todo keywords
  2008-08-22 13:21 Searching for tags or todo keywords Peter Westlake
@ 2008-09-13 19:10 ` Carsten Dominik
  2008-09-15 22:30   ` Peter Westlake
  2008-09-16  5:15   ` Samuel Wales
  0 siblings, 2 replies; 6+ messages in thread
From: Carsten Dominik @ 2008-09-13 19:10 UTC (permalink / raw)
  To: Peter Westlake; +Cc: emacs-orgmode

Hi Peter,

as you have seen, changing the logic is not easy, for a number of  
reasons.
I would like to have parenthesis, but since the parsing is done by  
string processing, any parenthesis in one of the search strings would  
be difficult to handle.

Some work-arounds:

1. Have you thought about using a sparse tree?  Or is you stuff in  
different files?

2. You could use categories to mark the entries.  Basically make each  
project its own category.

3. Have you tried follow mode in the agenda?  Then you will always  
see, in another window, the embedding of the entry you are looking at.


HTH

- Carsten

On Aug 22, 2008, at 3:21 PM, Peter Westlake wrote:

> I only discovered org-mode a couple of weeks ago, so apologies if this
> is a FAQ, or the patch is in the wrong format.
>
> I would like to define an agenda command to show TODO items in the
> context of the projects to which they belong, like this:
>
>  todo:       .Widget project
>  todo:       ..TODO Gather widget requirements
>  todo:       .Gadget project
>  todo:       ..TODO Plan the end of project party
>
> That would be a search like:
>
>  (LEVEL=2) | (/TODO)
>
> But LEVEL=2|/TODO is interpreted as (LEVEL=2|) & (/TODO)
> because / has the lowest precedence.
>
> /TODO|LEVEL=2 treats LEVEL as a TODO word instead of a tag.
>
> Is there any way around this, short of implementing parentheses?
>
> One possibility might be to make operators that are like / but bind  
> most
> tightly, one to say "this is a todo keyword" and one to say "this is a
> tag". For instance, if \ was like / but high precedence, and % was the
> opposite of \, my query would become:
>
>  \TODO | %LEVEL=2
>
> Having looked at the code, that looks almost as hard as parens.
>
> Next idea: since "/" means "and this TODO expression", add "\" meaning
> "or this TODO expression". So my query becomes:
>
>  LEVEL=2\TODO
>
> This is a lot easier to implement. In fact, this patch does it:
>
> diff -wu /usr/share/emacs/site-lisp/org-mode/org.el
> /home/pwestlake/elisp/org.el
> --- /usr/share/emacs/site-lisp/org-mode/org.el  2008-06-17
> 20:36:44.000000000 +0100
> +++ /home/pwestlake/elisp/org.el        2008-08-22 14:13:44.031536000
> +0100
> @@ -9381,17 +9381,26 @@
>        tagsmatch todomatch tagsmatcher todomatcher kwd matcher
>        orterms term orlist re-p str-p level-p level-op
>        prop-p pn pv po cat-p gv)
> -    (if (string-match "/+" match)
> +    (cond ((string-match "/+" match)
>        ;; match contains also a todo-matching request
> -       (progn
>          (setq tagsmatch (substring match 0 (match-beginning 0))
>                todomatch (substring match (match-end 0)))
>          (if (string-match "^!" todomatch)
>              (setq todo-only t todomatch (substring todomatch 1)))
>          (if (string-match "^\\s-*$" todomatch)
> -             (setq todomatch nil)))
> +               (setq todomatch nil))
> +           (setq todo-op 'and todo-op-default t))
> +          ((string-match "\\\\+" match)
> +           (setq tagsmatch (substring match 0 (match-beginning 0))
> +                 todomatch (substring match (match-end 0)))
> +           (if (string-match "^!" todomatch)
> +               (setq todo-only t todomatch (substring todomatch 1)))
> +           (if (string-match "^\\s-*$" todomatch)
> +               (setq todomatch nil))
> +           (setq todo-op 'or todo-op-default nil))
> +
>       ;; only matching tags
> -      (setq tagsmatch match todomatch nil))
> +          (t (setq tagsmatch match todomatch nil todo-op-default t
> todo-op 'and)))
>
>     ;; Make the tags matcher
>     (if (or (not tagsmatch) (not (string-match "\\S-" tagsmatch)))
> @@ -9447,7 +9456,7 @@
>            (list 'progn '(setq org-cached-props nil) tagsmatcher)))
>     ;; Make the todo matcher
>     (if (or (not todomatch) (not (string-match "\\S-" todomatch)))
> -       (setq todomatcher t)
> +       (setq todomatcher todo-op-default)
>       (setq orterms (org-split-string todomatch "|") orlist nil)
>       (while (setq term (pop orterms))
>        (while (string-match re term)
> @@ -9471,7 +9480,7 @@
>
>     ;; Return the string and lisp forms of the matcher
>     (setq matcher (if todomatcher
> -                     (list 'and tagsmatcher todomatcher)
> +                     (list todo-op tagsmatcher todomatcher)
>                    tagsmatcher))
>     (cons match0 matcher)))
>
>
> Regards,
>
> Peter.
>
>
>
>
> _______________________________________________
> Emacs-orgmode mailing list
> Remember: use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

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

* Re: Searching for tags or todo keywords
  2008-09-13 19:10 ` Carsten Dominik
@ 2008-09-15 22:30   ` Peter Westlake
  2008-09-16  4:06     ` Carsten Dominik
  2008-09-16  5:15   ` Samuel Wales
  1 sibling, 1 reply; 6+ messages in thread
From: Peter Westlake @ 2008-09-15 22:30 UTC (permalink / raw)
  To: Carsten Dominik; +Cc: emacs-orgmode


On Sat, 13 Sep 2008 21:10:15 +0200, "Carsten Dominik"
<dominik@science.uva.nl> said:
> Hi Peter,
>
> as you have seen, changing the logic is not easy, for a number of
> reasons. I would like to have parenthesis, but since the parsing is
> done by string processing, any parenthesis in one of the search
> strings would be difficult to handle.
>
> Some work-arounds:
>
> 1. Have you thought about using a sparse tree?  Or is you stuff in
>    different files?

All the things I'm interested in for this are in one file, so that would
work. It would need a regexp that duplicated some of the logic to match
todos and tags, I guess.

> 2. You could use categories to mark the entries.  Basically make each
>    project its own category.

Yes, that's a definite possibility.

> 3. Have you tried follow mode in the agenda?  Then you will always
>    see, in another window, the embedding of the entry you are
>    looking at.

Yes, or just hitting Space. This works nicely, thanks!

Another thing I've done is to add a TODO type called PROJECT. That also
makes it easy to put projects at different levels in the tree, which is
good because I have a huge file of things to do that I had been keeping
in outline-mode, and this is a lot easier than moving all the
project-type subtrees to level 2.

> HTH

It does, thanks!

Peter.

> - Carsten
>
> On Aug 22, 2008, at 3:21 PM, Peter Westlake wrote:
>
> > I only discovered org-mode a couple of weeks ago, so apologies if
> > this is a FAQ, or the patch is in the wrong format.
> >
> > I would like to define an agenda command to show TODO items in the
> > context of the projects to which they belong, like this:
> >
> >  todo:       .Widget project todo:       ..TODO Gather widget
> >  requirements todo:       .Gadget project todo:       ..TODO Plan
> >  the end of project party
> >
> > That would be a search like:
> >
> >  (LEVEL=2) | (/TODO)
> >
> > But LEVEL=2|/TODO is interpreted as (LEVEL=2|) & (/TODO) because /
> > has the lowest precedence.
> >
> > /TODO|LEVEL=2 treats LEVEL as a TODO word instead of a tag.
> >
> > Is there any way around this, short of implementing parentheses?
> >
> > One possibility might be to make operators that are like / but bind
> > most tightly, one to say "this is a todo keyword" and one to say
> > "this is a tag". For instance, if \ was like / but high precedence,
> > and % was the opposite of \, my query would become:
> >
> >  \TODO | %LEVEL=2
> >
> > Having looked at the code, that looks almost as hard as parens.
> >
> > Next idea: since "/" means "and this TODO expression", add "\"
> > meaning "or this TODO expression". So my query becomes:
> >
> >  LEVEL=2\TODO
> >
> > This is a lot easier to implement. In fact, this patch does it:
> >
> > diff -wu /usr/share/emacs/site-lisp/org-mode/org.el
> > /home/pwestlake/elisp/org.el --- /usr/share/emacs/site-lisp/org-
> > mode/org.el  2008-06-17 20:36:44.000000000 +0100 +++
> > /home/pwestlake/elisp/org.el        2008-08-22 14:13:44.031536000
> > +0100 @@ -9381,17 +9381,26 @@       tagsmatch todomatch tagsmatcher
> > todomatcher kwd matcher       orterms term orlist re-p str-p level-p
> > level-op       prop-p pn pv po cat-p gv)
> > -    (if (string-match "/+" match)
> > +    (cond ((string-match "/+" match)  ;; match contains also a todo-
> >      matching request
> > -       (progn (setq tagsmatch (substring match 0 (match-beginning
> >         0))       todomatch (substring match (match-end 0))) (if (string-
> >         match "^!" todomatch)     (setq todo-only t todomatch
> >         (substring todomatch 1))) (if (string-match "^\\s-*$"
> >         todomatch)
> > -             (setq todomatch nil)))
> > +               (setq todomatch nil))
> > +           (setq todo-op 'and todo-op-default t))
> > +          ((string-match "\\\\+" match)
> > +           (setq tagsmatch (substring match 0 (match-beginning 0))
> > +                 todomatch (substring match (match-end 0)))
> > +           (if (string-match "^!" todomatch)
> > +               (setq todo-only t todomatch (substring todomatch
> >                 1)))
> > +           (if (string-match "^\\s-*$" todomatch)
> > +               (setq todomatch nil))
> > +           (setq todo-op 'or todo-op-default nil)) + ;; only
> >             matching tags
> > -      (setq tagsmatch match todomatch nil))
> > +          (t (setq tagsmatch match todomatch nil todo-op-default t
> >            todo-op 'and)))
> >
> >     ;; Make the tags matcher (if (or (not tagsmatch) (not (string-
> >     match "\\S-" tagsmatch))) @@ -9447,7 +9456,7 @@       (list
> >     'progn '(setq org-cached-props nil) tagsmatcher))) ;; Make the
> >     todo matcher (if (or (not todomatch) (not (string-match "\\S-"
> >     todomatch)))
> > -       (setq todomatcher t)
> > +       (setq todomatcher todo-op-default) (setq orterms (org-split-
> >         string todomatch "|") orlist nil) (while (setq term (pop
> >         orterms)) (while (string-match re term) @@ -9471,7 +9480,7
> >         @@
> >
> >     ;; Return the string and lisp forms of the matcher (setq matcher
> >     (if todomatcher
> > -                     (list 'and tagsmatcher todomatcher)
> > +                     (list todo-op tagsmatcher todomatcher)
> >                       tagsmatcher)) (cons match0 matcher)))
> >
> >
> > Regards,
> >
> > Peter.
> >
> >
> >
> >
> > _______________________________________________
> > Emacs-orgmode mailing list Remember: use `Reply All' to send replies
> > to the list. Emacs-orgmode@gnu.org
> > http://lists.gnu.org/mailman/listinfo/emacs-orgmode
>

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

* Re: Searching for tags or todo keywords
  2008-09-15 22:30   ` Peter Westlake
@ 2008-09-16  4:06     ` Carsten Dominik
  0 siblings, 0 replies; 6+ messages in thread
From: Carsten Dominik @ 2008-09-16  4:06 UTC (permalink / raw)
  To: Peter Westlake; +Cc: emacs-orgmode


On Sep 16, 2008, at 12:30 AM, Peter Westlake wrote:

>
> On Sat, 13 Sep 2008 21:10:15 +0200, "Carsten Dominik"
> <dominik@science.uva.nl> said:
>> Hi Peter,
>>
>> as you have seen, changing the logic is not easy, for a number of
>> reasons. I would like to have parenthesis, but since the parsing is
>> done by string processing, any parenthesis in one of the search
>> strings would be difficult to handle.
>>
>> Some work-arounds:
>>
>> 1. Have you thought about using a sparse tree?  Or is you stuff in
>>   different files?
>
> All the things I'm interested in for this are in one file, so that  
> would
> work. It would need a regexp that duplicated some of the logic to  
> match
> todos and tags, I guess.

No, there are many ways to build a sparse tree, and one is a tags  
query.  This is
on `C-c / T' (or, if you have an old version, maybe on `C-c \'.

>
>
>> 2. You could use categories to mark the entries.  Basically make each
>>   project its own category.
>
> Yes, that's a definite possibility.
>
>> 3. Have you tried follow mode in the agenda?  Then you will always
>>   see, in another window, the embedding of the entry you are
>>   looking at.
>
> Yes, or just hitting Space. This works nicely, thanks!
>
> Another thing I've done is to add a TODO type called PROJECT. That  
> also
> makes it easy to put projects at different levels in the tree, which  
> is
> good because I have a huge file of things to do that I had been  
> keeping
> in outline-mode, and this is a lot easier than moving all the
> project-type subtrees to level 2.

Yes, I have the same thing in my setup.

- Carsten

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

* Re: Searching for tags or todo keywords
  2008-09-13 19:10 ` Carsten Dominik
  2008-09-15 22:30   ` Peter Westlake
@ 2008-09-16  5:15   ` Samuel Wales
  2008-09-16  8:00     ` Carsten Dominik
  1 sibling, 1 reply; 6+ messages in thread
From: Samuel Wales @ 2008-09-16  5:15 UTC (permalink / raw)
  To: Carsten Dominik; +Cc: emacs-orgmode

On Sat, Sep 13, 2008 at 12:10, Carsten Dominik <dominik@science.uva.nl> wrote:
> I would like to have parenthesis, but since the parsing is done by string
> processing, any parenthesis in one of the search strings would be difficult
> to handle.

Have you considered using Lisp syntax, perhaps as an alternate?

Benefits include: trivial to parse (no parsing at all -- let Lisp
parse and maybe even eval for you!), easier for the user to remember
(for some of us :)), orthogonal, easy to extend (even with
user-defined functions), easier to quote and escape, consistent,
standard, free of precedence lists, proven technology,
pretty-printable, print-readable, etc.

The old syntax can easily be converted to sexp, thus separating syntax
from semantics and ensuring that the behavior is the same -- without
making anybody have to switch.

Just a possibility.

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

* Re: Searching for tags or todo keywords
  2008-09-16  5:15   ` Samuel Wales
@ 2008-09-16  8:00     ` Carsten Dominik
  0 siblings, 0 replies; 6+ messages in thread
From: Carsten Dominik @ 2008-09-16  8:00 UTC (permalink / raw)
  To: Samuel Wales; +Cc: emacs-orgmode

Hi Samuel,

yes, a general Lisp syntax is certainly a good idea.  In fact,  
currently the match is also converted into a Lisp form.  However, it  
does not use simple variables that would be great to supply in a user  
form.  The reason is that I am trying to minimize parsing for  
properties and tags, so that these are only located if used.  Still, I  
guess you are right that this is a relatively simple extension to make  
- I will think about it.

- Carsten

On Sep 16, 2008, at 7:15 AM, Samuel Wales wrote:

> On Sat, Sep 13, 2008 at 12:10, Carsten Dominik  
> <dominik@science.uva.nl> wrote:
>> I would like to have parenthesis, but since the parsing is done by  
>> string
>> processing, any parenthesis in one of the search strings would be  
>> difficult
>> to handle.
>
> Have you considered using Lisp syntax, perhaps as an alternate?
>
> Benefits include: trivial to parse (no parsing at all -- let Lisp
> parse and maybe even eval for you!), easier for the user to remember
> (for some of us :)), orthogonal, easy to extend (even with
> user-defined functions), easier to quote and escape, consistent,
> standard, free of precedence lists, proven technology,
> pretty-printable, print-readable, etc.
>
> The old syntax can easily be converted to sexp, thus separating syntax
> from semantics and ensuring that the behavior is the same -- without
> making anybody have to switch.
>
> Just a possibility.

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

end of thread, other threads:[~2008-09-16  8:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-22 13:21 Searching for tags or todo keywords Peter Westlake
2008-09-13 19:10 ` Carsten Dominik
2008-09-15 22:30   ` Peter Westlake
2008-09-16  4:06     ` Carsten Dominik
2008-09-16  5:15   ` Samuel Wales
2008-09-16  8:00     ` Carsten Dominik

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