summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <n.goaziou@gmail.com>2013-02-15 15:00:16 (GMT)
committer Nicolas Goaziou <n.goaziou@gmail.com>2013-02-15 15:13:53 (GMT)
commit3bc8c9647a55decc6c27cfdb8267de14d54d86d3 (patch)
tree1e33cb501dad16a630760fd71488225bbcefc18c
parent94dbeedd4a259aaf8f644a9b65371452fc841e36 (diff)
downloadorg-mode-3bc8c9647a55decc6c27cfdb8267de14d54d86d3.zip
org-mode-3bc8c9647a55decc6c27cfdb8267de14d54d86d3.tar.gz
org-element: Fix error and infloop in `org-element-at-point'
* lisp/org-element.el (org-element-at-point): Return nil when in the first empty lines of the buffer. Return headline when in empty lines just after the headline.
-rw-r--r--lisp/org-element.el48
1 files changed, 31 insertions, 17 deletions
diff --git a/lisp/org-element.el b/lisp/org-element.el
index f4eb35d..f17273c 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -4622,26 +4622,40 @@ first element of current section."
(list (org-element-headline-parser (point-max) t))))
;; Otherwise move at the beginning of the section containing
;; point.
- (let ((origin (point))
- (end (save-excursion
- (org-with-limited-levels (outline-next-heading)) (point)))
- element type special-flag trail struct prevs parent)
- (org-with-limited-levels
- (if (org-before-first-heading-p) (goto-char (point-min))
- (org-back-to-heading)
- (forward-line)))
- (org-skip-whitespace)
- (beginning-of-line)
- ;; Parse successively each element, skipping those ending
- ;; before original position.
- (catch 'exit
- (while t
- (setq element
+ (catch 'exit
+ (let ((origin (point))
+ (end (save-excursion
+ (org-with-limited-levels (outline-next-heading)) (point)))
+ element type special-flag trail struct prevs parent)
+ (org-with-limited-levels
+ (if (org-before-first-heading-p)
+ ;; In empty lines at buffer's beginning, return nil.
+ (progn (goto-char (point-min))
+ (org-skip-whitespace)
+ (when (or (eobp) (> (line-beginning-position) origin))
+ (throw 'exit nil)))
+ (org-back-to-heading)
+ (forward-line)
+ (org-skip-whitespace)
+ (when (> (line-beginning-position) origin)
+ ;; In blank lines just after the headline, point still
+ ;; belongs to the headline.
+ (throw 'exit
+ (progn (org-back-to-heading)
+ (if (not keep-trail)
+ (org-element-headline-parser (point-max) t)
+ (list (org-element-headline-parser
+ (point-max) t))))))))
+ (beginning-of-line)
+ ;; Parse successively each element, skipping those ending
+ ;; before original position.
+ (while t
+ (setq element
(org-element--current-element end 'element special-flag struct)
- type (car element))
+ type (car element))
(org-element-put-property element :parent parent)
(when keep-trail (push element trail))
- (cond
+ (cond
;; 1. Skip any element ending before point. Also skip
;; element ending at point when we're sure that another
;; element has started.