emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] [PATCH] Recognize property blocks even after text


From: Sacha Chua
Subject: [O] [PATCH] Recognize property blocks even after text
Date: Wed, 11 Feb 2015 20:39:03 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (windows-nt)

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 via email to

[Prev in Thread] Current Thread [Next in Thread]