From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yann Hodique Subject: [PATCH] Fix inconsistency in drawer handling Date: Sat, 15 Sep 2012 14:00:12 +0200 Message-ID: <1347710412-23188-2-git-send-email-yann.hodique@gmail.com> References: <1347710412-23188-1-git-send-email-yann.hodique@gmail.com> Return-path: Received: from eggs.gnu.org ([208.118.235.92]:44196) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TCr3W-0005bq-Ai for emacs-orgmode@gnu.org; Sat, 15 Sep 2012 08:01:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TCr3U-00039U-U7 for emacs-orgmode@gnu.org; Sat, 15 Sep 2012 08:01:02 -0400 Received: from mail-wi0-f177.google.com ([209.85.212.177]:55950) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TCr3U-00037P-NO for emacs-orgmode@gnu.org; Sat, 15 Sep 2012 08:01:00 -0400 Received: by mail-wi0-f177.google.com with SMTP id hn17so661653wib.12 for ; Sat, 15 Sep 2012 05:01:00 -0700 (PDT) In-Reply-To: <1347710412-23188-1-git-send-email-yann.hodique@gmail.com> 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: emacs-orgmode@gnu.org Cc: Yann Hodique * 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