emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Sacha Chua <sacha@sachachua.com>
To: emacs-orgmode@gnu.org
Subject: [PATCH] Recognize property blocks even after text
Date: Wed, 11 Feb 2015 20:39:03 -0500	[thread overview]
Message-ID: <86wq3nucw8.fsf@sachachua.com> (raw)

Hi! I noticed that the refactored org-get-property-block no longer
allows for any text (aside from the SCHEDULED / DEADLINE / CLOSED) text
between the heading and the property drawer, which gave me problems when
I accidentally added text or timestamps or things like that. Also, it
means org-gcal's default format (which puts the timestamp before the
property drawer) doesn't work, so maybe a bunch of other things rely on
the old behavior. If that part of the change was unintentional, would
you consider the patch below? It seems to be okay with my Org files, but
maybe that flexibility was removed for performance reasons. Hope this is
useful!


Subject: [PATCH] Recognize property blocks even after text

* lisp/org.el (org-get-property-block): Search for the property drawer
anywhere before the next heading or the end of the buffer.

* testing/lisp/test-org.el (test-org/property-blocks-are-flexible):
Check if property blocks can be defined after text.
---
 lisp/org.el              | 25 +++++++++++++++----------
 testing/lisp/test-org.el | 17 +++++++++++++++++
 2 files changed, 32 insertions(+), 10 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 64b546f..dac7390 100755
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -15422,16 +15422,21 @@ return nil."
 		      (t (org-with-limited-levels (org-back-to-heading t))))))
        (forward-line)
        (when (org-looking-at-p org-planning-line-re) (forward-line))
-       (cond ((looking-at org-property-drawer-re)
-	      (forward-line)
-	      (cons (point) (progn (goto-char (match-end 0))
-				   (line-beginning-position))))
-	     (force
-	      (goto-char beg)
-	      (org-insert-property-drawer)
-	      (let ((pos (save-excursion (search-forward ":END:")
-					 (line-beginning-position))))
-		(cons pos pos))))))))
+       (cond ((re-search-forward
+               org-property-drawer-re
+               (save-excursion (save-match-data (outline-next-heading))
+                               (point)) t)
+              (progn
+                (goto-char (match-beginning 0))
+                (forward-line)
+                (cons (point) (progn (goto-char (match-end 0))
+                                     (line-beginning-position)))))
+             (force
+              (goto-char beg)
+              (org-insert-property-drawer)
+              (let ((pos (save-excursion (search-forward ":END:")
+                                         (line-beginning-position))))
+                (cons pos pos))))))))
 
 (defun org-at-property-p ()
   "Non-nil when point is inside a property drawer.
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index ce1d519..800cffc 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -2618,6 +2618,23 @@ Text.
 	      "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
 	    (org-buffer-property-keys nil nil t)))))
 
+(ert-deftest test-org/property-blocks-are-flexible ()
+  "Test if properties can be specified with some information before them."
+  ;; Retrieve properties accross siblings.
+  (should
+   (equal '("A" "B")
+	  (org-test-with-temp-text "
+* H1
+Some text goes here.
+:PROPERTIES:
+:A: 1
+:END:
+* H2
+:PROPERTIES:
+:B: 1
+:END:"
+	    (org-buffer-property-keys)))))
+
 (ert-deftest test-org/property-values ()
   "Test `org-property-values' specifications."
   ;; Regular test.
-- 
2.1.4

             reply	other threads:[~2015-02-12  1:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-12  1:39 Sacha Chua [this message]
2015-02-12 10:12 ` [PATCH] Recognize property blocks even after text Rasmus
2015-02-13 17:49   ` Sacha Chua
2015-02-17 20:59     ` Rasmus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86wq3nucw8.fsf@sachachua.com \
    --to=sacha@sachachua.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).