From: Yann Hodique <yann.hodique@gmail.com>
To: emacs-orgmode@gnu.org
Cc: Yann Hodique <yann.hodique@gmail.com>
Subject: [PATCH] Fix inconsistency in drawer handling
Date: Sat, 15 Sep 2012 14:00:12 +0200 [thread overview]
Message-ID: <1347710412-23188-2-git-send-email-yann.hodique@gmail.com> (raw)
In-Reply-To: <1347710412-23188-1-git-send-email-yann.hodique@gmail.com>
* lisp/org.el (org-drawer-end-re): Introduce new constant.
(org-clock-drawer-start-re): Fix docstring.
(org-clock-drawer-end-re): Fix docstring.
(org-flag-drawer): Make use of `org-drawer-end-re'.
(org-end-of-meta-data-and-drawers): Make use of `org-drawer-end-re'.
* lisp/org-element.el (org-element-drawer-parser): Make use of
`org-drawer-end-re'.
(org-element-property-drawer-parser): Make use of `org-drawer-end-re'.
Subtle differences in the definition of drawers delimiters were leading
to inconsistencies. For example, the following drawer:
:PROPERTIES:
:start: now
:end: then
:END:
was interpreted by `org-entry-properties' as containing properties
"start" and "end", whereas the cycling code would hide at the
first :end:, and `org-element-drawer-parser' would also consider the
black to end at the first :end:.
---
lisp/org-element.el | 8 ++++----
lisp/org.el | 18 ++++++++++++------
2 files changed, 16 insertions(+), 10 deletions(-)
diff --git a/lisp/org-element.el b/lisp/org-element.el
index bcdd336..9822045 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -529,7 +529,7 @@ Return a list whose CAR is `drawer' and CDR is a plist containing
Assume point is at beginning of drawer."
(let ((case-fold-search t))
- (if (not (save-excursion (re-search-forward "^[ \t]*:END:" limit t)))
+ (if (not (save-excursion (re-search-forward org-drawer-end-re limit t)))
;; Incomplete drawer: parse it as a paragraph.
(org-element-paragraph-parser limit)
(let ((drawer-end-line (match-beginning 0)))
@@ -1895,7 +1895,7 @@ Assume point is at the beginning of the property drawer."
(hidden (org-invisible-p2))
(properties
(let (val)
- (while (not (looking-at "^[ \t]*:END:"))
+ (while (not (looking-at org-property-end-re))
(when (looking-at "[ \t]*:\\([A-Za-z][-_A-Za-z0-9]*\\):")
(push (cons (org-match-string-no-properties 1)
(org-trim
@@ -1904,7 +1904,7 @@ Assume point is at the beginning of the property drawer."
val))
(forward-line))
val))
- (prop-end (progn (re-search-forward "^[ \t]*:END:" limit t)
+ (prop-end (progn (re-search-forward org-property-end-re limit t)
(point-at-bol)))
(pos-before-blank (progn (forward-line) (point)))
(end (progn (skip-chars-forward " \r\t\n" limit)
@@ -3395,7 +3395,7 @@ element it has to parse."
(let ((name (match-string 1)))
(cond
((not (save-excursion
- (re-search-forward "^[ \t]*:END:[ \t]*$" nil t)))
+ (re-search-forward org-drawer-end-re nil t)))
(org-element-paragraph-parser limit))
((equal "PROPERTIES" name)
(org-element-property-drawer-parser limit))
diff --git a/lisp/org.el b/lisp/org.el
index 1c18d70..f62bde6 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -6768,6 +6768,9 @@ open and agenda-wise Org files."
(while (re-search-forward org-drawer-regexp end t)
(org-flag-drawer t))))))
+(eval-when-compile
+ (defvar org-drawer-end-re))
+
(defun org-flag-drawer (flag)
"When FLAG is non-nil, hide the drawer we are within.
Otherwise make it visible."
@@ -6776,7 +6779,7 @@ Otherwise make it visible."
(when (looking-at "^[ \t]*:[a-zA-Z][a-zA-Z0-9]*:")
(let ((b (match-end 0)))
(if (re-search-forward
- "^[ \t]*:END:"
+ org-drawer-end-re
(save-excursion (outline-next-heading) (point)) t)
(outline-flag-region b (point-at-eol) flag)
(error ":END: line missing at position %s" b))))))
@@ -14308,17 +14311,20 @@ but in some other way.")
"Some properties that are used by Org-mode for various purposes.
Being in this list makes sure that they are offered for completion.")
+(defconst org-drawer-end-re "^[ \t]*:END:[ \t]*$"
+ "Regular expression matching the last line of a drawer.")
+
(defconst org-property-start-re "^[ \t]*:PROPERTIES:[ \t]*$"
"Regular expression matching the first line of a property drawer.")
-(defconst org-property-end-re "^[ \t]*:END:[ \t]*$"
+(defconst org-property-end-re org-drawer-end-re
"Regular expression matching the last line of a property drawer.")
(defconst org-clock-drawer-start-re "^[ \t]*:CLOCK:[ \t]*$"
- "Regular expression matching the first line of a property drawer.")
+ "Regular expression matching the first line of a clock drawer.")
-(defconst org-clock-drawer-end-re "^[ \t]*:END:[ \t]*$"
- "Regular expression matching the first line of a property drawer.")
+(defconst org-clock-drawer-end-re org-drawer-end-re
+ "Regular expression matching the first line of a clock drawer.")
(defconst org-property-drawer-re
(concat "\\(" org-property-start-re "\\)[^\000]*\\("
@@ -22080,7 +22086,7 @@ clocking lines, and drawers."
;; empty or planning line
(forward-line 1)
;; a drawer, find the end
- (re-search-forward "^[ \t]*:END:" end 'move)
+ (re-search-forward org-drawer-end-re end 'move)
(forward-line 1)))
(and (re-search-forward "[^\n]" nil t) (backward-char 1))
(point)))
--
1.7.12
next prev parent reply other threads:[~2012-09-15 12:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-15 12:00 [PATCH] Fix inconsistency in drawer handling Yann Hodique
2012-09-15 12:00 ` Yann Hodique [this message]
2012-09-15 12:36 ` Nicolas Goaziou
2012-09-16 17:03 ` Yann Hodique
2012-09-19 14:02 ` Nicolas Goaziou
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=1347710412-23188-2-git-send-email-yann.hodique@gmail.com \
--to=yann.hodique@gmail.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).