From mboxrd@z Thu Jan 1 00:00:00 1970 From: Samuel Loury Subject: Re: org-expiry not compatible with the new drawer syntax Date: Fri, 30 Jan 2015 11:28:13 +0100 Message-ID: <87wq44h8aq.fsf@konixwork.incubateur.ens-lyon.fr> References: <87lhkkg2bx.fsf@konixwork.incubateur.ens-lyon.fr> <877fw4r4yq.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:53776) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YH8oL-0003o0-S4 for emacs-orgmode@gnu.org; Fri, 30 Jan 2015 05:28:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YH8oI-0003Ih-JZ for emacs-orgmode@gnu.org; Fri, 30 Jan 2015 05:28:25 -0500 Received: from mail-wi0-x22f.google.com ([2a00:1450:400c:c05::22f]:49156) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YH8oI-0003Ic-8E for emacs-orgmode@gnu.org; Fri, 30 Jan 2015 05:28:22 -0500 Received: by mail-wi0-f175.google.com with SMTP id fb4so1983738wid.2 for ; Fri, 30 Jan 2015 02:28:21 -0800 (PST) In-Reply-To: <877fw4r4yq.fsf@nicolasgoaziou.fr> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Nicolas Goaziou Cc: OrgMode ML --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain Thank you for taking into account this problem. Nicolas Goaziou writes: > Samuel Loury 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. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Fix-org-agenda-insert-diary-as-top-level.patch Content-Transfer-Encoding: quoted-printable From=20d826e7b8d4208a2cd9129c0b9f411aa662e6d67d Mon Sep 17 00:00:00 2001 From: Konubinix 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. =2D-- 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 =2D-- 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) =2D (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))) =20 (defun org-agenda-insert-diary-make-new-entry (text) =2D-=20 2.1.4 --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable >> 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 :-)): =2D-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))) =2D-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 :-), =2D-=20 Konubinix GPG Key : 7439106A Fingerprint: 5993 BE7A DA65 E2D9 06CE 5C36 75D2 3CED 7439 106A --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJUy1y9AAoJEHXSPO10ORBqRUgH/jKhlGeIISqvYzm6xvO+qIYe d/EC0kb7g5jRoZYXh8yABFtbaFUoR+jddcdSXuXZZ/z4QfkFSw5tWSiNvYbu3z1X W5b2UYPXBIz9SdGUB/aWhC/wp3cro3oBYFApfSJ1rKjFpJOiEw4Fore+zhhSWc9T dHnZnzde13sV3J0p2TV2qt/C1H8jtanpXIwoGAavX3MvcIoyQpdmZBC40z0BJQWb U2mcK+NNGFloiDK7l7biAXSuyKk2ZWzyEfBflB0I/5z3U4a5T9X1hoDDq/DiZKYu yWODhL26FKA1ZF9yJBkQVhyt797efumbHRliUU3n6PYfCkg5PfVT0LfBJ0TBkaE= =WLkq -----END PGP SIGNATURE----- --==-=-=--