emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Headline generation as in diary?
@ 2020-09-01 14:34 Michael Heerdegen
  2020-09-01 15:10 ` Eric S Fraga
  2020-10-28 17:12 ` Michael Heerdegen
  0 siblings, 2 replies; 25+ messages in thread
From: Michael Heerdegen @ 2020-09-01 14:34 UTC (permalink / raw)
  To: emacs-orgmode

Hi,

I am mainly using the org agenda for day planning.  But there is a
functionality I seem to miss I know from diary:

With diary, I can use arbitrary Lisp expressions to generate dates, and
those expressions can also return a string to use as non-nil return
value to generate non-constant headlines including certain numbers for
example.  I can use that to implement when the next garbage
collection will come (rules for that are complicated since there are
exceptions etc), add reminders for certain important stuff, etc.

I would like to use my org file to specify those things instead of
maintaining a second file (the diary file).  But AFAIK the dynamically
created headline part is tricky: what appears in the agenda is always
the org headline as it appears in the file, right?

Or do I miss something?  How to other people deal with things
like...garbage collection?


TIA,

Michael.


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

* Re: Headline generation as in diary?
  2020-09-01 14:34 Headline generation as in diary? Michael Heerdegen
@ 2020-09-01 15:10 ` Eric S Fraga
  2020-09-01 15:18   ` Michael Heerdegen
  2020-10-28 17:12 ` Michael Heerdegen
  1 sibling, 1 reply; 25+ messages in thread
From: Eric S Fraga @ 2020-09-01 15:10 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: emacs-orgmode

On Tuesday,  1 Sep 2020 at 16:34, Michael Heerdegen wrote:
> I would like to use my org file to specify those things instead of
> maintaining a second file (the diary file).  But AFAIK the dynamically
> created headline part is tricky: what appears in the agenda is always
> the org headline as it appears in the file, right?

No, not necessarily.  I have entries like this:

%%(diary-anniversary 1981 03 17) Somebody's birthday (%d years)

and the agenda view shows "Somebody's birthday (19 years)"; the actual
heading for this entry is ignored.  In fact, I have a large number of
such entries all in the same headline.

However, I don't know if other diary- functions work the same way.

> Or do I miss something?  How to other people deal with things
> like...garbage collection?

I use the org-recur [1] package for this.  Very nice for repeating
events.

HTH,
eric


Footnotes:
[1]  https://github.com/m-cat/org-recur

-- 
: Eric S Fraga via Emacs 28.0.50, Org release_9.3.7-725-g7bc18e


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

* Re: Headline generation as in diary?
  2020-09-01 15:10 ` Eric S Fraga
@ 2020-09-01 15:18   ` Michael Heerdegen
  2020-09-01 15:28     ` Michael Heerdegen
  2020-09-01 16:10     ` Robert Pluim
  0 siblings, 2 replies; 25+ messages in thread
From: Michael Heerdegen @ 2020-09-01 15:18 UTC (permalink / raw)
  To: emacs-orgmode

Eric S Fraga <e.fraga@ucl.ac.uk> writes:

> No, not necessarily.  I have entries like this:
>
> %%(diary-anniversary 1981 03 17) Somebody's birthday (%d years)
>
> and the agenda view shows "Somebody's birthday (19 years)"; the actual
> heading for this entry is ignored.

Where in an entry do you specify such specifications?

> However, I don't know if other diary- functions work the same way.

Yes, the interesting part then is: when does org behave like this, and
can this behavior be forced?

> > Or do I miss something?  How to other people deal with things
> > like...garbage collection?
>
> I use the org-recur [1] package for this.  Very nice for repeating
> events.

> Footnotes:
> [1]  https://github.com/m-cat/org-recur

Thanks for the hint, I'll have a look.


Michael.


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

* Re: Headline generation as in diary?
  2020-09-01 15:18   ` Michael Heerdegen
@ 2020-09-01 15:28     ` Michael Heerdegen
  2020-09-01 16:10     ` Robert Pluim
  1 sibling, 0 replies; 25+ messages in thread
From: Michael Heerdegen @ 2020-09-01 15:28 UTC (permalink / raw)
  To: emacs-orgmode

Michael Heerdegen <michael_heerdegen@web.de> writes:

> > [1]  https://github.com/m-cat/org-recur
>
> Thanks for the hint, I'll have a look.

Nice to have definitely.

I want to stick to diary sexp expressions for some complicated dates.  I
have already extended the diary language to fit my needs to specify the
dates of garbage collection here.  That looks like this:

#+begin_src emacs-lisp
     (dg-let-date (dg-tomorrow)
       (dg-except-for*
        (and (dg-friday-p) (cl-evenp (dg-iso-week)))
        (cl-some #'dg-holiday-p (dg-the-days-between (dg-days-before 2)))
        +1))
#+end_src

It means: warn me one day before garbage collection happens, and that
is: every Friday in any week with even week number, unless it has been a
holiday up to two days before that, then they collect one day later.

I guess I always want Lisp to specify something like this.

Michael.


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

* Re: Headline generation as in diary?
  2020-09-01 15:18   ` Michael Heerdegen
  2020-09-01 15:28     ` Michael Heerdegen
@ 2020-09-01 16:10     ` Robert Pluim
  2020-09-01 16:17       ` Eric S Fraga
  2020-09-01 21:56       ` Michael Heerdegen
  1 sibling, 2 replies; 25+ messages in thread
From: Robert Pluim @ 2020-09-01 16:10 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: emacs-orgmode

>>>>> On Tue, 01 Sep 2020 17:18:42 +0200, Michael Heerdegen <michael_heerdegen@web.de> said:

    Michael> Eric S Fraga <e.fraga@ucl.ac.uk> writes:
    >> No, not necessarily.  I have entries like this:
    >> 
    >> %%(diary-anniversary 1981 03 17) Somebody's birthday (%d years)
    >> 
    >> and the agenda view shows "Somebody's birthday (19 years)"; the actual
    >> heading for this entry is ignored.

    Michael> Where in an entry do you specify such specifications?

Below the headline, after the properties.

    >> However, I don't know if other diary- functions work the same way.

They do, although there are org- versions of most (all?) of them that
you should use, since they consistently use ISO8601 date order,
unlike the diary functions. The manual is a bit lacking in this area,
I think.

    Michael> Yes, the interesting part then is: when does org behave like this, and
    Michael> can this behavior be forced?

Itʼs triggered by the %%(, I believe, but not in headlines. You can
use them in timestamps as well, which is useful for weird time periods

**  Just before midnight on a few days 23:00-24:00
<%%(org-block 2020 8 31 2020 9 2)>
<%%(org-block 2020 9 10 2020 9 12)>

Robert


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

* Re: Headline generation as in diary?
  2020-09-01 16:10     ` Robert Pluim
@ 2020-09-01 16:17       ` Eric S Fraga
  2020-09-01 16:51         ` Robert Horn
  2020-09-01 21:56       ` Michael Heerdegen
  1 sibling, 1 reply; 25+ messages in thread
From: Eric S Fraga @ 2020-09-01 16:17 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: emacs-orgmode

On Tuesday,  1 Sep 2020 at 18:10, Robert Pluim wrote:
>>>>>> On Tue, 01 Sep 2020 17:18:42 +0200, Michael Heerdegen <michael_heerdegen@web.de> said:
>     Michael> Where in an entry do you specify such specifications?
>
> Below the headline, after the properties.

Yes, exactly.  I have one headline which says something along the lines
of:

* Birthdays

and then a number of %%(diary-anniversary ...) entries all under this
headline.

I could have done these with a +1y repeat but, like Michael, like the %d
capability of diary entries.

I use org-recur for most other repeat items and
org-clone-subtree-with-time-shift for setting up repeats with end dates
(e.g. lectures in a term).

-- 
: Eric S Fraga via Emacs 28.0.50, Org release_9.3.7-725-g7bc18e


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

* Re: Headline generation as in diary?
  2020-09-01 16:17       ` Eric S Fraga
@ 2020-09-01 16:51         ` Robert Horn
  0 siblings, 0 replies; 25+ messages in thread
From: Robert Horn @ 2020-09-01 16:51 UTC (permalink / raw)
  To: Eric S Fraga; +Cc: Michael Heerdegen, emacs-orgmode


Eric S Fraga writes:

> On Tuesday,  1 Sep 2020 at 18:10, Robert Pluim wrote:
> * Birthdays
>
> and then a number of %%(diary-anniversary ...) entries all under this
> headline.
>

Note that you can also use %%(org-anniversary ...) with slightly
different dependencies.

I also use modifications of diary to insert sunrise and sunset.

But I think that these %% functiotns only show up as part of agenda processing.

-- 
Robert Horn
rjhorn@alum.mit.edu


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

* Re: Headline generation as in diary?
  2020-09-01 16:10     ` Robert Pluim
  2020-09-01 16:17       ` Eric S Fraga
@ 2020-09-01 21:56       ` Michael Heerdegen
  2020-09-02  6:54         ` Robert Pluim
  1 sibling, 1 reply; 25+ messages in thread
From: Michael Heerdegen @ 2020-09-01 21:56 UTC (permalink / raw)
  To: Robert Pluim; +Cc: emacs-orgmode

Robert Pluim <rpluim@gmail.com> writes:

> Itʼs triggered by the %%(, I believe, but not in headlines.

Yes, I see that in the code.

But actually I seem to have the opposite problem: I can't make the
original headline appear in the agenda.  When the sexp doesn't return a
string the agenda will contain a line saying "SEXP entry returned empty
string" instead of showing the headline.

> You can use them in timestamps as well, which is useful for weird time
> periods
>
> **  Just before midnight on a few days 23:00-24:00
> <%%(org-block 2020 8 31 2020 9 2)>
> <%%(org-block 2020 9 10 2020 9 12)>

But it seems those time stamps are not allowed to span multiple lines
(at least I don't get it work).  Seems org doesn't recognize them as
such?


Michael.


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

* Re: Headline generation as in diary?
  2020-09-01 21:56       ` Michael Heerdegen
@ 2020-09-02  6:54         ` Robert Pluim
  2020-09-02 13:45           ` Michael Heerdegen
  0 siblings, 1 reply; 25+ messages in thread
From: Robert Pluim @ 2020-09-02  6:54 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: emacs-orgmode

>>>>> On Tue, 01 Sep 2020 23:56:55 +0200, Michael Heerdegen <michael_heerdegen@web.de> said:

    Michael> Robert Pluim <rpluim@gmail.com> writes:
    >> Itʼs triggered by the %%(, I believe, but not in headlines.

    Michael> Yes, I see that in the code.

    Michael> But actually I seem to have the opposite problem: I can't make the
    Michael> original headline appear in the agenda.  When the sexp doesn't return a
    Michael> string the agenda will contain a line saying "SEXP entry returned empty
    Michael> string" instead of showing the headline.

It seems `org-anniversary' supports %d for year and thatʼs about it,
which is not surprising, since itʼs just a wrapper around
`diary-anniversary'.

How about:

diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index 78fe13303..9049b3a42 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -5772,7 +5772,7 @@ displayed in agenda view."
 		    r (replace-match "" nil nil r)))
 	    (if (string-match "\\S-" r)
 		(setq txt r)
-	      (setq txt "SEXP entry returned empty string"))
+	      (setq txt (org-no-properties (org-get-heading t t t t))))
 	    (setq txt (org-agenda-format-item extra txt level category tags 'time))
 	    (org-add-props txt props 'org-marker marker
 			   'date date 'todo-state todo-state

(Iʼm guessing yet-another-config-variable is unnecessary)

    >> You can use them in timestamps as well, which is useful for weird time
    >> periods
    >> 
    >> **  Just before midnight on a few days 23:00-24:00
    >> <%%(org-block 2020 8 31 2020 9 2)>
    >> <%%(org-block 2020 9 10 2020 9 12)>

    Michael> But it seems those time stamps are not allowed to span multiple lines
    Michael> (at least I don't get it work).  Seems org doesn't recognize them as
    Michael> such?

Itʼs working fine for me in org-9.3.6. Note that I have my default
agenda view set to a fortnight, and those dates span two different
weeks.

Robert


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

* Re: Headline generation as in diary?
  2020-09-02  6:54         ` Robert Pluim
@ 2020-09-02 13:45           ` Michael Heerdegen
  2020-09-02 15:00             ` Robert Pluim
  0 siblings, 1 reply; 25+ messages in thread
From: Michael Heerdegen @ 2020-09-02 13:45 UTC (permalink / raw)
  To: Robert Pluim; +Cc: emacs-orgmode

Robert Pluim <rpluim@gmail.com> writes:

> How about:
>
> diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
> index 78fe13303..9049b3a42 100644
> --- a/lisp/org-agenda.el
> +++ b/lisp/org-agenda.el
> @@ -5772,7 +5772,7 @@ displayed in agenda view."
>  		    r (replace-match "" nil nil r)))
>  	    (if (string-match "\\S-" r)
>  		(setq txt r)
> -	      (setq txt "SEXP entry returned empty string"))
> +	      (setq txt (org-no-properties (org-get-heading t t t t))))
>  	    (setq txt (org-agenda-format-item extra txt level category tags 'time))
>  	    (org-add-props txt props 'org-marker marker
>  			   'date date 'todo-state todo-state

Thanks for looking at this.

Ok - That gives me a headline in the agenda, but a wrong one (more or
less, a random headline in the same file, at a seemingly unrelated
location).

> (Iʼm guessing yet-another-config-variable is unnecessary)

I think so toom yes.

>     >> You can use them in timestamps as well, which is useful for
>     >> weird time
>     >> periods
>     >> 
>     >> **  Just before midnight on a few days 23:00-24:00
>     >> <%%(org-block 2020 8 31 2020 9 2)>
>     >> <%%(org-block 2020 9 10 2020 9 12)>
>
>     Michael> But it seems those time stamps are not allowed to span
>     Michael> multiple lines
>     Michael> (at least I don't get it work).  Seems org doesn't
>     Michael> recognize them as
>     Michael> such?
>
> Itʼs working fine for me in org-9.3.6. Note that I have my default
> agenda view set to a fortnight, and those dates span two different
> weeks.

I didn't mean time spans.  What doesn't work for me are time _stamps_
that span multiple text lines.


Thanks,

Michael.


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

* Re: Headline generation as in diary?
  2020-09-02 13:45           ` Michael Heerdegen
@ 2020-09-02 15:00             ` Robert Pluim
  2020-09-02 22:51               ` Michael Heerdegen
  0 siblings, 1 reply; 25+ messages in thread
From: Robert Pluim @ 2020-09-02 15:00 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: emacs-orgmode

>>>>> On Wed, 02 Sep 2020 15:45:36 +0200, Michael Heerdegen <michael_heerdegen@web.de> said:

    Michael> Robert Pluim <rpluim@gmail.com> writes:
    >> How about:
    >> 
    >> diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
    >> index 78fe13303..9049b3a42 100644
    >> --- a/lisp/org-agenda.el
    >> +++ b/lisp/org-agenda.el
    >> @@ -5772,7 +5772,7 @@ displayed in agenda view."
    >> r (replace-match "" nil nil r)))
    >> (if (string-match "\\S-" r)
    >> (setq txt r)
    >> -	      (setq txt "SEXP entry returned empty string"))
    >> +	      (setq txt (org-no-properties (org-get-heading t t t t))))
    >> (setq txt (org-agenda-format-item extra txt level category tags 'time))
    >> (org-add-props txt props 'org-marker marker
    >> 'date date 'todo-state todo-state

    Michael> Thanks for looking at this.

    Michael> Ok - That gives me a headline in the agenda, but a wrong one (more or
    Michael> less, a random headline in the same file, at a seemingly unrelated
    Michael> location).

OK. Thatʼs as far as my org-hacking knowledge goes, so perhaps someone
else here has an idea of the right way to invoke "tell me what heading
Iʼm in, as a string".

    >> >> **  Just before midnight on a few days 23:00-24:00
    >> >> <%%(org-block 2020 8 31 2020 9 2)>
    >> >> <%%(org-block 2020 9 10 2020 9 12)>
    >> 
    Michael> But it seems those time stamps are not allowed to span
    Michael> multiple lines
    Michael> (at least I don't get it work).  Seems org doesn't
    Michael> recognize them as
    Michael> such?
    >> 
    >> Itʼs working fine for me in org-9.3.6. Note that I have my default
    >> agenda view set to a fortnight, and those dates span two different
    >> weeks.

    Michael> I didn't mean time spans.  What doesn't work for me are time _stamps_
    Michael> that span multiple text lines.

You've lost me. Can you show me an example?

Robert


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

* Re: Headline generation as in diary?
  2020-09-02 15:00             ` Robert Pluim
@ 2020-09-02 22:51               ` Michael Heerdegen
  2020-09-03  7:14                 ` Robert Pluim
  0 siblings, 1 reply; 25+ messages in thread
From: Michael Heerdegen @ 2020-09-02 22:51 UTC (permalink / raw)
  To: Robert Pluim; +Cc: emacs-orgmode

Robert Pluim <rpluim@gmail.com> writes:

> OK. Thatʼs as far as my org-hacking knowledge goes, so perhaps someone
> else here has an idea of the right way to invoke "tell me what heading
> Iʼm in, as a string".

The situation is actually like this: the empty string issue doesn't
happen with time stamps <%%(...)>, this always uses the correct
headline.  Seems %%() entries are expected to return a string OTOH since
the headline seems to be ignored.  I guess this is reasonable.  Dunno if
there is something to change here at all in the code.

Ok, the other thing: broken time stamps with line breaks:

> You've lost me. Can you show me an example?

The difference here is only a line break:

This doesn't work:

| ** APPT 17:00 Test
| SCHEDULED: <%%(and (or (diary-date 03 09 2020)
|                        (diary-date 04 09 2020)))>

But this works:

| ** APPT 17:00 Test
| SCHEDULED: <%%(and (or (diary-date 03 09 2020) (diary-date 04 09 2020)))>


Michael.


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

* Re: Headline generation as in diary?
  2020-09-02 22:51               ` Michael Heerdegen
@ 2020-09-03  7:14                 ` Robert Pluim
  2020-09-03 13:14                   ` Michael Heerdegen
  0 siblings, 1 reply; 25+ messages in thread
From: Robert Pluim @ 2020-09-03  7:14 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: emacs-orgmode

>>>>> On Thu, 03 Sep 2020 00:51:04 +0200, Michael Heerdegen <michael_heerdegen@web.de> said:

    Michael> Robert Pluim <rpluim@gmail.com> writes:
    >> OK. Thatʼs as far as my org-hacking knowledge goes, so perhaps someone
    >> else here has an idea of the right way to invoke "tell me what heading
    >> Iʼm in, as a string".

    Michael> The situation is actually like this: the empty string issue doesn't
    Michael> happen with time stamps <%%(...)>, this always uses the correct
    Michael> headline.  Seems %%() entries are expected to return a string OTOH since
    Michael> the headline seems to be ignored.  I guess this is reasonable.  Dunno if
    Michael> there is something to change here at all in the code.

OK.

I can push my change to org, but Iʼm not a regular org contributor, so
Iʼd prefer to hear from one of the maintainers first.

    Michael> Ok, the other thing: broken time stamps with line breaks:

    >> You've lost me. Can you show me an example?

    Michael> The difference here is only a line break:

    Michael> This doesn't work:

    Michael> | ** APPT 17:00 Test
    Michael> | SCHEDULED: <%%(and (or (diary-date 03 09 2020)
    Michael> |                        (diary-date 04 09 2020)))>

    Michael> But this works:

    Michael> | ** APPT 17:00 Test
    Michael> | SCHEDULED: <%%(and (or (diary-date 03 09 2020) (diary-date 04 09 2020)))>

I think thatʼs just a consequence of timestamps not being allowed to
span multiple lines in org, unlike diary.

Robert


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

* Re: Headline generation as in diary?
  2020-09-03  7:14                 ` Robert Pluim
@ 2020-09-03 13:14                   ` Michael Heerdegen
  2020-09-03 13:35                     ` Ihor Radchenko
  0 siblings, 1 reply; 25+ messages in thread
From: Michael Heerdegen @ 2020-09-03 13:14 UTC (permalink / raw)
  To: Robert Pluim; +Cc: emacs-orgmode

Robert Pluim <rpluim@gmail.com> writes:

> I can push my change to org, but Iʼm not a regular org contributor, so
> Iʼd prefer to hear from one of the maintainers first.

Sorry - I meant, I see no reason to touch the existing code.  No need to
change anything for what I want.

>     Michael> This doesn't work:
>
>     Michael> | ** APPT 17:00 Test
>     Michael> | SCHEDULED: <%%(and (or (diary-date 03 09 2020)
>     Michael> |                        (diary-date 04 09 2020)))>

> I think thatʼs just a consequence of timestamps not being allowed to
> span multiple lines in org, unlike diary.

This is bad.  Why is that?  Can it be changed?

When dealing with complicated date rules it can likely happen that a
diary sexp doesn't fit into one line.

Regards,

Michael.


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

* Re: Headline generation as in diary?
  2020-09-03 13:14                   ` Michael Heerdegen
@ 2020-09-03 13:35                     ` Ihor Radchenko
  2020-09-03 14:01                       ` Michael Heerdegen
  2020-09-03 14:06                       ` Robert Pluim
  0 siblings, 2 replies; 25+ messages in thread
From: Ihor Radchenko @ 2020-09-03 13:35 UTC (permalink / raw)
  To: Michael Heerdegen, Robert Pluim; +Cc: emacs-orgmode

> When dealing with complicated date rules it can likely happen that a
> diary sexp doesn't fit into one line.

Diary sexp can be a user-defined function. If your sexp needs to span
multiple lines, it is probably worth defining a function and simply
using <%%(your-function)> as a timestamp.

Best,
Ihor

Michael Heerdegen <michael_heerdegen@web.de> writes:

> Robert Pluim <rpluim@gmail.com> writes:
>
>> I can push my change to org, but Iʼm not a regular org contributor, so
>> Iʼd prefer to hear from one of the maintainers first.
>
> Sorry - I meant, I see no reason to touch the existing code.  No need to
> change anything for what I want.
>
>>     Michael> This doesn't work:
>>
>>     Michael> | ** APPT 17:00 Test
>>     Michael> | SCHEDULED: <%%(and (or (diary-date 03 09 2020)
>>     Michael> |                        (diary-date 04 09 2020)))>
>
>> I think thatʼs just a consequence of timestamps not being allowed to
>> span multiple lines in org, unlike diary.
>
> This is bad.  Why is that?  Can it be changed?
>
> When dealing with complicated date rules it can likely happen that a
> diary sexp doesn't fit into one line.
>
> Regards,
>
> Michael.


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

* Re: Headline generation as in diary?
  2020-09-03 13:35                     ` Ihor Radchenko
@ 2020-09-03 14:01                       ` Michael Heerdegen
  2020-09-03 15:31                         ` Ihor Radchenko
  2020-09-03 14:06                       ` Robert Pluim
  1 sibling, 1 reply; 25+ messages in thread
From: Michael Heerdegen @ 2020-09-03 14:01 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Robert Pluim, emacs-orgmode

Ihor Radchenko <yantar92@gmail.com> writes:

> > When dealing with complicated date rules it can likely happen that a
> > diary sexp doesn't fit into one line.
>
> Diary sexp can be a user-defined function. If your sexp needs to span
> multiple lines, it is probably worth defining a function and simply
> using <%%(your-function)> as a timestamp.

I think this is inconvenient.  Ok, only a bit.  But it would be nicer if
I could specify my dates in only one file.  Jumping around in my org
file + my emacs init file is what I used to do.

Multi-line sexps in time stamps work would just be nice to have.  Would
it be hard to achieve?  I mean, since multi-line %%(...) entries already
work...


Thanks,

Michael.


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

* Re: Headline generation as in diary?
  2020-09-03 13:35                     ` Ihor Radchenko
  2020-09-03 14:01                       ` Michael Heerdegen
@ 2020-09-03 14:06                       ` Robert Pluim
  2020-09-03 14:46                         ` Michael Heerdegen
  2020-09-03 15:34                         ` Ihor Radchenko
  1 sibling, 2 replies; 25+ messages in thread
From: Robert Pluim @ 2020-09-03 14:06 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Michael Heerdegen, emacs-orgmode

>>>>> On Thu, 03 Sep 2020 21:35:54 +0800, Ihor Radchenko <yantar92@gmail.com> said:

    >> When dealing with complicated date rules it can likely happen that a
    >> diary sexp doesn't fit into one line.

    Ihor> Diary sexp can be a user-defined function. If your sexp needs to span
    Ihor> multiple lines, it is probably worth defining a function and simply
    Ihor> using <%%(your-function)> as a timestamp.

It can? Thatʼs not documented, as far as I can tell.

Robert


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

* Re: Headline generation as in diary?
  2020-09-03 14:06                       ` Robert Pluim
@ 2020-09-03 14:46                         ` Michael Heerdegen
  2020-09-03 15:17                           ` Robert Pluim
  2020-09-03 15:34                         ` Ihor Radchenko
  1 sibling, 1 reply; 25+ messages in thread
From: Michael Heerdegen @ 2020-09-03 14:46 UTC (permalink / raw)
  To: Robert Pluim; +Cc: emacs-orgmode, Ihor Radchenko

Robert Pluim <rpluim@gmail.com> writes:

> It can? Thatʼs not documented, as far as I can tell.

As a user, I read "Diary-style expression entries" in the org manual as
including my own defined diary sexps - excluding them would be a
surprise that should be documented (no, I don't want that to happen!).

Michael.


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

* Re: Headline generation as in diary?
  2020-09-03 14:46                         ` Michael Heerdegen
@ 2020-09-03 15:17                           ` Robert Pluim
  0 siblings, 0 replies; 25+ messages in thread
From: Robert Pluim @ 2020-09-03 15:17 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: emacs-orgmode, Ihor Radchenko

>>>>> On Thu, 03 Sep 2020 16:46:48 +0200, Michael Heerdegen <michael_heerdegen@web.de> said:

    Michael> Robert Pluim <rpluim@gmail.com> writes:
    >> It can? Thatʼs not documented, as far as I can tell.

    Michael> As a user, I read "Diary-style expression entries" in the org manual as
    Michael> including my own defined diary sexps - excluding them would be a
    Michael> surprise that should be documented (no, I don't want that to happen!).

Ah, I wasnʼt aware that "diary-style expression entries" and "lisp
expression with %% prepended" were the same thing.

And itʼs not likely to go away: org just runs those expressions
through `eval'.

Robert


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

* Re: Headline generation as in diary?
  2020-09-03 14:01                       ` Michael Heerdegen
@ 2020-09-03 15:31                         ` Ihor Radchenko
  2020-09-03 17:01                           ` Michael Heerdegen
  0 siblings, 1 reply; 25+ messages in thread
From: Ihor Radchenko @ 2020-09-03 15:31 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: Robert Pluim, emacs-orgmode

> Multi-line sexps in time stamps work would just be nice to have.  Would
> it be hard to achieve?  I mean, since multi-line %%(...) entries already
> work...

The problem is that org-mode assumes that planning line must be a single
line and a lot of internal logic hard-code this assumption.

For example, below is a fragment of org-get-property-block:

     ;; Move point to its position according to its positional rules.
     (cond ((org-before-first-heading-p)
	    (while (and (org-at-comment-p) (bolp)) (forward-line)))
	   (t (forward-line)
	      (when (looking-at-p org-planning-line-re) (forward-line))))

The last line clearly assumes that planning line is always a single
line. The same assumption is made in many other places in org-mode
internals. Though one may write a patch to make multi-line sexps work in
org-mode, there is also a problem with external tools working with org.
I do not think there is support of multi-line planning everywhere.

> I think this is inconvenient.  Ok, only a bit.  But it would be nicer if
> I could specify my dates in only one file.  Jumping around in my org
> file + my emacs init file is what I used to do.

You can always use file-local definition at the beginning or end of your
org file. Below is an example of local definition at the end of an org
file. 

# Local Variables:
# eval: (defun your-function () (sexp))

Best,
Ihor

Michael Heerdegen <michael_heerdegen@web.de> writes:

> Ihor Radchenko <yantar92@gmail.com> writes:
>
>> > When dealing with complicated date rules it can likely happen that a
>> > diary sexp doesn't fit into one line.
>>
>> Diary sexp can be a user-defined function. If your sexp needs to span
>> multiple lines, it is probably worth defining a function and simply
>> using <%%(your-function)> as a timestamp.
>
> I think this is inconvenient.  Ok, only a bit.  But it would be nicer if
> I could specify my dates in only one file.  Jumping around in my org
> file + my emacs init file is what I used to do.
>
> Multi-line sexps in time stamps work would just be nice to have.  Would
> it be hard to achieve?  I mean, since multi-line %%(...) entries already
> work...
>
>
> Thanks,
>
> Michael.


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

* Re: Headline generation as in diary?
  2020-09-03 14:06                       ` Robert Pluim
  2020-09-03 14:46                         ` Michael Heerdegen
@ 2020-09-03 15:34                         ` Ihor Radchenko
  1 sibling, 0 replies; 25+ messages in thread
From: Ihor Radchenko @ 2020-09-03 15:34 UTC (permalink / raw)
  To: Robert Pluim; +Cc: Michael Heerdegen, emacs-orgmode

> It can? Thatʼs not documented, as far as I can tell.

It is literally called "diary sexp". You can use any elisp sexp there,
like (let ...) or (or ...) or (function-name ...)

Robert Pluim <rpluim@gmail.com> writes:

>>>>>> On Thu, 03 Sep 2020 21:35:54 +0800, Ihor Radchenko <yantar92@gmail.com> said:
>
>     >> When dealing with complicated date rules it can likely happen that a
>     >> diary sexp doesn't fit into one line.
>
>     Ihor> Diary sexp can be a user-defined function. If your sexp needs to span
>     Ihor> multiple lines, it is probably worth defining a function and simply
>     Ihor> using <%%(your-function)> as a timestamp.
>
> It can? Thatʼs not documented, as far as I can tell.
>
> Robert


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

* Re: Headline generation as in diary?
  2020-09-03 15:31                         ` Ihor Radchenko
@ 2020-09-03 17:01                           ` Michael Heerdegen
  2020-09-03 18:04                             ` Ihor Radchenko
  0 siblings, 1 reply; 25+ messages in thread
From: Michael Heerdegen @ 2020-09-03 17:01 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Robert Pluim, emacs-orgmode

Ihor Radchenko <yantar92@gmail.com> writes:

> I do not think there is support of multi-line planning everywhere.

I see.

> You can always use file-local definition at the beginning or end of your
> org file. Below is an example of local definition at the end of an org
> file.
>
> # Local Variables:
> # eval: (defun your-function () (sexp))

I didn't know that eval specs support multi-line sexps, but seems that
works, so I can indeed use this.  Thanks for the suggestion.

Michael.


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

* Re: Headline generation as in diary?
  2020-09-03 17:01                           ` Michael Heerdegen
@ 2020-09-03 18:04                             ` Ihor Radchenko
  2020-09-03 18:37                               ` Michael Heerdegen
  0 siblings, 1 reply; 25+ messages in thread
From: Ihor Radchenko @ 2020-09-03 18:04 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: Robert Pluim, emacs-orgmode

> I didn't know that eval specs support multi-line sexps, but seems that
> works, so I can indeed use this.  Thanks for the suggestion.

Hmm. According to manual, it should support multi-line string. Not sure
about sexps.

In the worst case when you absolutely want multi-line sexp to be really
multi-line and that is also not possible in file-local eval, you can
define your sexp in a named src block. Then, you can execute the named
block using file-local eval statement calling the following function:

(defun org-link-babel-follow (name &optional return-info)
  "Run src block NAME.
The NAME is parsed as in #+CALL: specification.
The src block should be in the same org file."
  (let* ((call (with-temp-buffer
		 (interactive)
		 (org-mode)
		 (insert "#+CALL: " (format "%s" (org-link-unescape name)) "\n")
		 (beginning-of-buffer)
		 (org-element-babel-call-parser (point-max) (list (point-min)))
		 ))
	 (info (org-babel-lob-get-info call)))
    (if return-info
	info
      (flet ((org-babel-insert-result (result &optional result-params info hash lang) nil))
	(org-babel-execute-src-block nil info)))))

Michael Heerdegen <michael_heerdegen@web.de> writes:

> Ihor Radchenko <yantar92@gmail.com> writes:
>
>> I do not think there is support of multi-line planning everywhere.
>
> I see.
>
>> You can always use file-local definition at the beginning or end of your
>> org file. Below is an example of local definition at the end of an org
>> file.
>>
>> # Local Variables:
>> # eval: (defun your-function () (sexp))
>
> I didn't know that eval specs support multi-line sexps, but seems that
> works, so I can indeed use this.  Thanks for the suggestion.
>
> Michael.


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

* Re: Headline generation as in diary?
  2020-09-03 18:04                             ` Ihor Radchenko
@ 2020-09-03 18:37                               ` Michael Heerdegen
  0 siblings, 0 replies; 25+ messages in thread
From: Michael Heerdegen @ 2020-09-03 18:37 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Robert Pluim, emacs-orgmode

Ihor Radchenko <yantar92@gmail.com> writes:

> > I didn't know that eval specs support multi-line sexps, but seems that
> > works, so I can indeed use this.  Thanks for the suggestion.
>
> Hmm. According to manual, it should support multi-line string. Not sure
> about sexps.

AFAIR it didn't work in the past.  I guess it has been fixed in master
not long ago.

Michael.


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

* Re: Headline generation as in diary?
  2020-09-01 14:34 Headline generation as in diary? Michael Heerdegen
  2020-09-01 15:10 ` Eric S Fraga
@ 2020-10-28 17:12 ` Michael Heerdegen
  1 sibling, 0 replies; 25+ messages in thread
From: Michael Heerdegen @ 2020-10-28 17:12 UTC (permalink / raw)
  To: emacs-orgmode

I <michael_heerdegen@web.de> wrote:

> With diary, I can use arbitrary Lisp expressions to generate dates, and
> those expressions can also return a string to use as non-nil return
> value to generate non-constant headlines including certain numbers for
> example. [...]

My solution so far: I've set up my `org-capture-templates' so that when
I hit T (instead of t) I am prompted for time+headline and optionally a
number of days for a reminder, and, for example, when I enter "21:00
Test" and a "2" I get an entry like

| ** TODO Special entry: "21:00 Test"
| %%(diary-remind
|    '(and
|      (dg-it-is "[2020-10-31 Sa]")
|      "TODO 21:00 Test")
|    2)

`dg-it-is' is a function that tests whether "it is" the given date
specified as an inactive org time stamp.  The nice thing about this is
that org recognizes the stamp and I can click on it with the mouse to
change it etc.

And I can freely edit the whole expression.  The entry gets listed in
the agenda correctly (also the reminder) and I get two appt.el
appointments (or rather, my substitution for it).

Cons: The headline is ignored, I use a dummy headline.  I don't have
emacs-lisp bindings to edit the expression in the Capture or Org buffer,
so if I want something more complicated I probably need to use *scratch*
as intermediate step  (I tried to use a source block, but then the %%()
expression is not recognized any more, and the time stamps are not
clickable any more).

And for whatever reason, the agenda doesn't fontify the word "TODO".

If anyone has ideas for improvements, I'm curious!


Regards,

Michael.


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

end of thread, other threads:[~2020-10-28 17:14 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-09-01 14:34 Headline generation as in diary? Michael Heerdegen
2020-09-01 15:10 ` Eric S Fraga
2020-09-01 15:18   ` Michael Heerdegen
2020-09-01 15:28     ` Michael Heerdegen
2020-09-01 16:10     ` Robert Pluim
2020-09-01 16:17       ` Eric S Fraga
2020-09-01 16:51         ` Robert Horn
2020-09-01 21:56       ` Michael Heerdegen
2020-09-02  6:54         ` Robert Pluim
2020-09-02 13:45           ` Michael Heerdegen
2020-09-02 15:00             ` Robert Pluim
2020-09-02 22:51               ` Michael Heerdegen
2020-09-03  7:14                 ` Robert Pluim
2020-09-03 13:14                   ` Michael Heerdegen
2020-09-03 13:35                     ` Ihor Radchenko
2020-09-03 14:01                       ` Michael Heerdegen
2020-09-03 15:31                         ` Ihor Radchenko
2020-09-03 17:01                           ` Michael Heerdegen
2020-09-03 18:04                             ` Ihor Radchenko
2020-09-03 18:37                               ` Michael Heerdegen
2020-09-03 14:06                       ` Robert Pluim
2020-09-03 14:46                         ` Michael Heerdegen
2020-09-03 15:17                           ` Robert Pluim
2020-09-03 15:34                         ` Ihor Radchenko
2020-10-28 17:12 ` Michael Heerdegen

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