Browse Source

org-element: Fix first section parsing

* contrib/lisp/org-element.el (org-element-current-element): Use a new
  special mode symbol to treat section before first headline
  differently.  In this case, its boundaries must be computed since it
  has not been limited by headline container.
(org-element-parse-elements): Use new special mode symbol.
Nicolas Goaziou 13 years ago
parent
commit
17b865ddd0
1 changed files with 13 additions and 7 deletions
  1. 13 7
      contrib/lisp/org-element.el

+ 13 - 7
contrib/lisp/org-element.el

@@ -3195,8 +3195,8 @@ CONTENTS is nil."
 ;; `org-element-current-element' makes use of special modes.  They are
 ;; `org-element-current-element' makes use of special modes.  They are
 ;; activated for fixed element chaining (i.e. `plain-list' > `item')
 ;; activated for fixed element chaining (i.e. `plain-list' > `item')
 ;; or fixed conditional element chaining (i.e. `headline' >
 ;; or fixed conditional element chaining (i.e. `headline' >
-;; `section'). Special modes are: `section', `quote-section', `item'
-;; and `table-row'.
+;; `section'). Special modes are: `first-section', `section',
+;; `quote-section', `item' and `table-row'.
 
 
 (defun org-element-current-element
 (defun org-element-current-element
   (limit &optional granularity special structure)
   (limit &optional granularity special structure)
@@ -3216,8 +3216,9 @@ recursion.  Allowed values are `headline', `greater-element',
 nil), secondary values will not be parsed, since they only
 nil), secondary values will not be parsed, since they only
 contain objects.
 contain objects.
 
 
-Optional argument SPECIAL, when non-nil, can be either `section',
-`quote-section', `table-row' and `item'.
+Optional argument SPECIAL, when non-nil, can be either
+`first-section', `section', `quote-section', `table-row' and
+`item'.
 
 
 If STRUCTURE isn't provided but SPECIAL is set to `item', it will
 If STRUCTURE isn't provided but SPECIAL is set to `item', it will
 be computed.
 be computed.
@@ -3250,6 +3251,10 @@ element it has to parse."
         (org-element-headline-parser limit raw-secondary-p))
         (org-element-headline-parser limit raw-secondary-p))
        ;; Section (must be checked after headline).
        ;; Section (must be checked after headline).
        ((eq special 'section) (org-element-section-parser limit))
        ((eq special 'section) (org-element-section-parser limit))
+       ((eq special 'first-section)
+	(org-element-section-parser
+	 (or (save-excursion (org-with-limited-levels (outline-next-heading)))
+	     limit)))
        ;; Planning and Clock.
        ;; Planning and Clock.
        ((and (looking-at org-planning-or-clock-line-re))
        ((and (looking-at org-planning-or-clock-line-re))
 	(if (equal (match-string 1) org-clock-string)
 	(if (equal (match-string 1) org-clock-string)
@@ -3466,9 +3471,9 @@ Assume buffer is in Org mode."
     (org-skip-whitespace)
     (org-skip-whitespace)
     (org-element-parse-elements
     (org-element-parse-elements
      (point-at-bol) (point-max)
      (point-at-bol) (point-max)
-     ;; Start in `section' mode so text before the first
+     ;; Start in `first-section' mode so text before the first
      ;; headline belongs to a section.
      ;; headline belongs to a section.
-     'section nil granularity visible-only (list 'org-data nil))))
+     'first-section nil granularity visible-only (list 'org-data nil))))
 
 
 (defun org-element-parse-secondary-string (string restriction &optional parent)
 (defun org-element-parse-secondary-string (string restriction &optional parent)
   "Recursively parse objects in STRING and return structure.
   "Recursively parse objects in STRING and return structure.
@@ -3606,7 +3611,8 @@ Nil values returned from FUN do not appear in the results."
   "Parse elements between BEG and END positions.
   "Parse elements between BEG and END positions.
 
 
 SPECIAL prioritize some elements over the others.  It can be set
 SPECIAL prioritize some elements over the others.  It can be set
-to `quote-section', `section' `item' or `table-row'.
+to `first-section', `quote-section', `section' `item' or
+`table-row'.
 
 
 When value is `item', STRUCTURE will be used as the current list
 When value is `item', STRUCTURE will be used as the current list
 structure.
 structure.