emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* org-expiry not compatible with the new drawer syntax
@ 2015-01-30  7:22 Samuel Loury
  2015-01-30  9:30 ` Nicolas Goaziou
  0 siblings, 1 reply; 8+ messages in thread
From: Samuel Loury @ 2015-01-30  7:22 UTC (permalink / raw)
  To: OrgMode ML

[-- Attachment #1: Type: text/plain, Size: 2112 bytes --]

Dear All,

I am running the version cd6fa4c15e8e35afa6beb9e89ad3723fb82df091 (git
sha) of org-mode.

I just realized that when creating a new entry in my org-diary
(`org-agenda-add-entry-to-org-agenda-diary-file'), the entry looks like:

--8<---------------cut here---------------start------------->8---
** test
  <2015-01-30 Fri>
   :PROPERTIES:
   :CREATED:  [2015-01-30 Fri 08:00]
   :END:
--8<---------------cut here---------------end--------------->8---

The property is added by an call to `org-expiry-insert-created' in the
`org-insert-heading-hook'. see in contrib/lisp/org-expiry.el:179

With more details:

In the process in inserting the diary entry,
`org-agenda-add-entry-to-org-agenda-diary-file'
calls (lisp/org-agenda.el:9460)
`org-agenda-insert-diary-as-top-level' (lisp/org-agenda.el:9479).

The later then calls `org-insert-heading' (calling the org-expiry hook
that creates the property drawer), and inserts the text of the heading
followed by a new line, resulting in the insertion of:
--8<---------------cut here---------------start------------->8---
** test

   :PROPERTIES:
   :CREATED:  [2015-01-30 Fri 08:00]
   :END:
--8<---------------cut here---------------end--------------->8---

Then `org-agenda-add-entry-to-org-agenda-diary-file' inserts the
timestamp, resulting in:
--8<---------------cut here---------------start------------->8---
** test
  <2015-01-30 Fri>
   :PROPERTIES:
   :CREATED:  [2015-01-30 Fri 08:00]
   :END:
--8<---------------cut here---------------end--------------->8---

This is not compatible with the new drawer syntax (see
http://article.gmane.org/gmane.emacs.orgmode/91752).

My opinion is that we should either consider that adding a property in
`org-insert-heading-hook' is a bad practice or change the functions that
create entries to make sure they move beyond a potentially created
properties drawer before adding extra information such as timestamps.

What is your opinion?

Best regards,
-- 
Konubinix
GPG Key    : 7439106A
Fingerprint: 5993 BE7A DA65 E2D9 06CE  5C36 75D2 3CED 7439 106A

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

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

* Re: org-expiry not compatible with the new drawer syntax
  2015-01-30  7:22 org-expiry not compatible with the new drawer syntax Samuel Loury
@ 2015-01-30  9:30 ` Nicolas Goaziou
  2015-01-30 10:28   ` Samuel Loury
  0 siblings, 1 reply; 8+ messages in thread
From: Nicolas Goaziou @ 2015-01-30  9:30 UTC (permalink / raw)
  To: Samuel Loury; +Cc: OrgMode ML

Hello,

Samuel Loury <konubinix@gmail.com> writes:

> I just realized that when creating a new entry in my org-diary
> (`org-agenda-add-entry-to-org-agenda-diary-file'), the entry looks like:
>
> ** test
>   <2015-01-30 Fri>
>    :PROPERTIES:
>    :CREATED:  [2015-01-30 Fri 08:00]
>    :END:
>
> The property is added by an call to `org-expiry-insert-created' in the
> `org-insert-heading-hook'. see in contrib/lisp/org-expiry.el:179
>
> With more details:
>
> In the process in inserting the diary entry,
> `org-agenda-add-entry-to-org-agenda-diary-file'
> calls (lisp/org-agenda.el:9460)
> `org-agenda-insert-diary-as-top-level' (lisp/org-agenda.el:9479).
>
> The later then calls `org-insert-heading' (calling the org-expiry hook
> that creates the property drawer), and inserts the text of the heading
> followed by a new line, resulting in the insertion of:

Actually, AFAICT, the sole function calling `org-insert-heading' in
"org-agenda.el" is `org-agenda-insert-diary-make-new-entry'. I fixed it
so it properly puts point on the right spot in the entry.

Does it fix your issue?

> My opinion is that we should either consider that adding a property in
> `org-insert-heading-hook' is a bad practice or change the functions that
> create entries to make sure they move beyond a potentially created
> properties drawer before adding extra information such as timestamps.
>
> What is your opinion?

If a function calls on `org-insert-heading' and puts point in some
position for further processing, it should take into consideration
meta-data (i.e., planning info and properties drawer).


Regards,

-- 
Nicolas Goaziou

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

* Re: org-expiry not compatible with the new drawer syntax
  2015-01-30  9:30 ` Nicolas Goaziou
@ 2015-01-30 10:28   ` Samuel Loury
  2015-01-30 10:35     ` Samuel Loury
  2015-01-30 18:46     ` Nicolas Goaziou
  0 siblings, 2 replies; 8+ messages in thread
From: Samuel Loury @ 2015-01-30 10:28 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: OrgMode ML


[-- Attachment #1.1: Type: text/plain, Size: 1483 bytes --]

Thank you for taking into account this problem.

Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

> Samuel Loury <konubinix@gmail.com> writes:
>
>> I just realized that when creating a new entry in my org-diary
>> (`org-agenda-add-entry-to-org-agenda-diary-file'), the entry looks like:
>>
>> ** test
>>   <2015-01-30 Fri>
>>    :PROPERTIES:
>>    :CREATED:  [2015-01-30 Fri 08:00]
>>    :END:
>>
>> The property is added by an call to `org-expiry-insert-created' in the
>> `org-insert-heading-hook'. see in contrib/lisp/org-expiry.el:179
>>
>> With more details:
>>
>> In the process in inserting the diary entry,
>> `org-agenda-add-entry-to-org-agenda-diary-file'
>> calls (lisp/org-agenda.el:9460)
>> `org-agenda-insert-diary-as-top-level' (lisp/org-agenda.el:9479).
>>
>> The later then calls `org-insert-heading' (calling the org-expiry hook
>> that creates the property drawer), and inserts the text of the heading
>> followed by a new line, resulting in the insertion of:
>
> Actually, AFAICT, the sole function calling `org-insert-heading' in
> "org-agenda.el" is `org-agenda-insert-diary-make-new-entry'. I fixed it
> so it properly puts point on the right spot in the entry.

The function `org-agenda-insert-diary-as-top-level' is a few line above
the one you patched.

I copied the code you've written in
`org-agenda-insert-diary-make-new-entry' and I've put it in
`org-agenda-insert-diary-as-top-level'. This fixes my problem. Please
find attached the associated patch.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: 0001-Fix-org-agenda-insert-diary-as-top-level.patch --]
[-- Type: text/x-diff, Size: 1181 bytes --]

From d826e7b8d4208a2cd9129c0b9f411aa662e6d67d Mon Sep 17 00:00:00 2001
From: Konubinix <konubinix@gmail.com>
Date: Fri, 30 Jan 2015 11:19:45 +0100
Subject: [PATCH] Fix `org-agenda-insert-diary-as-top-level'

* lisp/org-agenda.el (org-agenda-insert-diary-as-top-level): Ensure
  point is at a real body line and not in front of meta data, so
  regular contents can be inserted safely after a call to this
  function.
---
 lisp/org-agenda.el | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index e719c00..ed882ae 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -9489,7 +9489,13 @@ a timestamp can be added there."
   (goto-char (point-max))
   (or (bolp) (insert "\n"))
   (org-insert-heading)
-  (insert text "\n")
+  (insert text)
+  (forward-line)
+  (when (org-looking-at-p org-planning-line-re) (forward-line))
+  (when (looking-at org-property-drawer-re)
+    (goto-char (match-end 0))
+    (forward-line))
+  (unless (bolp) (insert "\n"))
   (if org-adapt-indentation (org-indent-to-column 2)))
 
 (defun org-agenda-insert-diary-make-new-entry (text)
-- 
2.1.4


[-- Attachment #1.3: Type: text/plain, Size: 1327 bytes --]


>> My opinion is that we should either consider that adding a property in
>> `org-insert-heading-hook' is a bad practice or change the functions that
>> create entries to make sure they move beyond a potentially created
>> properties drawer before adding extra information such as timestamps.
>>
>> What is your opinion?
>
> If a function calls on `org-insert-heading' and puts point in some
> position for further processing, it should take into consideration
> meta-data (i.e., planning info and properties drawer).
I suggest to provide a helper that would move point after the meta-data
part to avoid code duplication. Something like (no surprise :-)):
--8<---------------cut here---------------start------------->8---
(defun org-goto-after-metadata-part ()
  (when (org-looking-at-p org-planning-line-re) (forward-line))
  (when (looking-at org-property-drawer-re)
    (goto-char (match-end 0))
    (forward-line)))
--8<---------------cut here---------------end--------------->8---

I would have gladly provided a patch myself but I couldn't find neither
a good name for the function nor a correct location to store it. Should
it be in org.el? It is already 24850 lines long...

My best :-),
-- 
Konubinix
GPG Key    : 7439106A
Fingerprint: 5993 BE7A DA65 E2D9 06CE  5C36 75D2 3CED 7439 106A

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

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

* Re: org-expiry not compatible with the new drawer syntax
  2015-01-30 10:28   ` Samuel Loury
@ 2015-01-30 10:35     ` Samuel Loury
  2015-01-30 18:46     ` Nicolas Goaziou
  1 sibling, 0 replies; 8+ messages in thread
From: Samuel Loury @ 2015-01-30 10:35 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: OrgMode ML


[-- Attachment #1.1: Type: text/plain, Size: 1738 bytes --]

Samuel Loury <konubinix@gmail.com> writes:

> Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
>
>> Samuel Loury <konubinix@gmail.com> writes:
>>
>>> I just realized that when creating a new entry in my org-diary
>>> (`org-agenda-add-entry-to-org-agenda-diary-file'), the entry looks like:
>>>
>>> ** test
>>>   <2015-01-30 Fri>
>>>    :PROPERTIES:
>>>    :CREATED:  [2015-01-30 Fri 08:00]
>>>    :END:
>>>
>>> The property is added by an call to `org-expiry-insert-created' in the
>>> `org-insert-heading-hook'. see in contrib/lisp/org-expiry.el:179
>>>
>>> With more details:
>>>
>>> In the process in inserting the diary entry,
>>> `org-agenda-add-entry-to-org-agenda-diary-file'
>>> calls (lisp/org-agenda.el:9460)
>>> `org-agenda-insert-diary-as-top-level' (lisp/org-agenda.el:9479).
>>>
>>> The later then calls `org-insert-heading' (calling the org-expiry hook
>>> that creates the property drawer), and inserts the text of the heading
>>> followed by a new line, resulting in the insertion of:
>>
>> Actually, AFAICT, the sole function calling `org-insert-heading' in
>> "org-agenda.el" is `org-agenda-insert-diary-make-new-entry'. I fixed it
>> so it properly puts point on the right spot in the entry.
>
> The function `org-agenda-insert-diary-as-top-level' is a few line above
> the one you patched.
>
> I copied the code you've written in
> `org-agenda-insert-diary-make-new-entry' and I've put it in
> `org-agenda-insert-diary-as-top-level'. This fixes my problem. Please
> find attached the associated patch.

I just realized that the call to `org-insert-heading' was into one of my
local patches.

Actually, I think this patch may be worth applying to prior to the one I
just sent.

Please, find it attached to this email.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: 0001-Make-use-of-org-insert-heading-instead-of-inserting-.patch --]
[-- Type: text/x-diff, Size: 1014 bytes --]

From b975ff7630dcf289a795a9eb0ec6f449d0efd621 Mon Sep 17 00:00:00 2001
From: Konubinix <konubinix@gmail.com>
Date: Thu, 6 Nov 2014 11:02:23 +0100
Subject: [PATCH] Make use of `org-insert-heading' instead of inserting the *
 character

* lisp/org-agenda.el (org-agenda-insert-diary-as-top-level): Make
  use of `org-insert-heading' instead of inserting the * character

Therefore, the hooks associated to the insertion of a heading will
be triggered.
---
 lisp/org-agenda.el | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index b83c331..e719c00 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -9488,7 +9488,8 @@ a timestamp can be added there."
   (widen)
   (goto-char (point-max))
   (or (bolp) (insert "\n"))
-  (insert "* " text "\n")
+  (org-insert-heading)
+  (insert text "\n")
   (if org-adapt-indentation (org-indent-to-column 2)))
 
 (defun org-agenda-insert-diary-make-new-entry (text)
-- 
2.1.4


[-- Attachment #1.3: Type: text/plain, Size: 333 bytes --]


It makes sure the `org-insert-heading' is called instead of hard-coding
its behavior by inserting the "*" character. I initially made this patch
to make sure the org-expiry hook is called whenever I create diary
entries.

-- 
Konubinix
GPG Key    : 7439106A
Fingerprint: 5993 BE7A DA65 E2D9 06CE  5C36 75D2 3CED 7439 106A

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

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

* Re: org-expiry not compatible with the new drawer syntax
  2015-01-30 10:28   ` Samuel Loury
  2015-01-30 10:35     ` Samuel Loury
@ 2015-01-30 18:46     ` Nicolas Goaziou
  2015-02-02  7:31       ` Samuel Loury
  1 sibling, 1 reply; 8+ messages in thread
From: Nicolas Goaziou @ 2015-01-30 18:46 UTC (permalink / raw)
  To: Samuel Loury; +Cc: OrgMode ML

Samuel Loury <konubinix@gmail.com> writes:

> I suggest to provide a helper that would move point after the meta-data
> part to avoid code duplication. Something like (no surprise :-)):
> (defun org-goto-after-metadata-part ()
>   (when (org-looking-at-p org-planning-line-re) (forward-line))
>   (when (looking-at org-property-drawer-re)
>     (goto-char (match-end 0))
>     (forward-line)))

Indeed.

> I would have gladly provided a patch myself but I couldn't find neither
> a good name for the function nor a correct location to store it. Should
> it be in org.el? It is already 24850 lines long...

I changed `org-end-of-meta-data-and-drawers' into
`org-end-of-meta-data'.

Could you merge your other patch and the use of this function?

Thanks,

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

* Re: org-expiry not compatible with the new drawer syntax
  2015-01-30 18:46     ` Nicolas Goaziou
@ 2015-02-02  7:31       ` Samuel Loury
  2015-02-02 12:26         ` Nicolas Goaziou
  0 siblings, 1 reply; 8+ messages in thread
From: Samuel Loury @ 2015-02-02  7:31 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: OrgMode ML


[-- Attachment #1.1: Type: text/plain, Size: 877 bytes --]

Hi,
Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

> Samuel Loury <konubinix@gmail.com> writes:
>
>> I suggest to provide a helper that would move point after the meta-data
>> part to avoid code duplication. Something like (no surprise :-)):
>> (defun org-goto-after-metadata-part ()
>>   (when (org-looking-at-p org-planning-line-re) (forward-line))
>>   (when (looking-at org-property-drawer-re)
>>     (goto-char (match-end 0))
>>     (forward-line)))
>
> Indeed.
>
>> I would have gladly provided a patch myself but I couldn't find neither
>> a good name for the function nor a correct location to store it. Should
>> it be in org.el? It is already 24850 lines long...
>
> I changed `org-end-of-meta-data-and-drawers' into
> `org-end-of-meta-data'.
>
> Could you merge your other patch and the use of this function?
Please find attached the merged patch, as asked for.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: 0001-Make-use-of-org-insert-heading-instead-of-inserting-.patch --]
[-- Type: text/x-diff, Size: 1175 bytes --]

From 02dd79b12d6f19551d1d9648a3a84e53c4cee984 Mon Sep 17 00:00:00 2001
From: Konubinix <konubinix@gmail.com>
Date: Thu, 6 Nov 2014 11:02:23 +0100
Subject: [PATCH] Make use of `org-insert-heading' instead of inserting the *
 character

* lisp/org-agenda.el (org-agenda-insert-diary-as-top-level): Make
  use of `org-insert-heading' instead of inserting the * character

Therefore, the hooks associated to the insertion of a heading will be
triggered. Since those hooks may cause the creation of some
metadata. `org-end-of-meta-data' is used afterward.
---
 lisp/org-agenda.el | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index 5f7c9ac..164e2d5 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -9488,7 +9488,10 @@ a timestamp can be added there."
   (widen)
   (goto-char (point-max))
   (or (bolp) (insert "\n"))
-  (insert "* " text "\n")
+  (org-insert-heading)
+  (insert text)
+  (org-end-of-meta-data)
+  (unless (bolp) (insert "\n"))
   (if org-adapt-indentation (org-indent-to-column 2)))
 
 (defun org-agenda-insert-diary-make-new-entry (text)
-- 
2.1.4


[-- Attachment #1.3: Type: text/plain, Size: 134 bytes --]


Thank you for you support.
-- 
Konubinix
GPG Key    : 7439106A
Fingerprint: 5993 BE7A DA65 E2D9 06CE  5C36 75D2 3CED 7439 106A

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

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

* Re: org-expiry not compatible with the new drawer syntax
  2015-02-02  7:31       ` Samuel Loury
@ 2015-02-02 12:26         ` Nicolas Goaziou
  2015-02-02 12:45           ` Samuel Loury
  0 siblings, 1 reply; 8+ messages in thread
From: Nicolas Goaziou @ 2015-02-02 12:26 UTC (permalink / raw)
  To: Samuel Loury; +Cc: OrgMode ML

Samuel Loury <konubinix@gmail.com> writes:

> Please find attached the merged patch, as asked for.

Applied, thank you.

> Therefore, the hooks associated to the insertion of a heading will be
> triggered. Since those hooks may cause the creation of some
> metadata. `org-end-of-meta-data' is used afterward.

Note that two spaces are required after full stop in commit messages.


Regards,

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

* Re: org-expiry not compatible with the new drawer syntax
  2015-02-02 12:26         ` Nicolas Goaziou
@ 2015-02-02 12:45           ` Samuel Loury
  0 siblings, 0 replies; 8+ messages in thread
From: Samuel Loury @ 2015-02-02 12:45 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: OrgMode ML

[-- Attachment #1: Type: text/plain, Size: 586 bytes --]

Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

> Samuel Loury <konubinix@gmail.com> writes:
>
>> Please find attached the merged patch, as asked for.
>
> Applied, thank you.
>
>> Therefore, the hooks associated to the insertion of a heading will be
>> triggered. Since those hooks may cause the creation of some
>> metadata. `org-end-of-meta-data' is used afterward.
>
> Note that two spaces are required after full stop in commit messages.
Noted, Thank you :-).

-- 
Konubinix
GPG Key    : 7439106A
Fingerprint: 5993 BE7A DA65 E2D9 06CE  5C36 75D2 3CED 7439 106A

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

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

end of thread, other threads:[~2015-02-02 12:45 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-30  7:22 org-expiry not compatible with the new drawer syntax Samuel Loury
2015-01-30  9:30 ` Nicolas Goaziou
2015-01-30 10:28   ` Samuel Loury
2015-01-30 10:35     ` Samuel Loury
2015-01-30 18:46     ` Nicolas Goaziou
2015-02-02  7:31       ` Samuel Loury
2015-02-02 12:26         ` Nicolas Goaziou
2015-02-02 12:45           ` Samuel Loury

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