0
0
Fork 1
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-08-26 04:02:52 +00:00

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.
This commit is contained in:
Nicolas Goaziou 2013-02-15 16:00:16 +01:00
parent 94dbeedd4a
commit 3bc8c9647a

View file

@ -4622,19 +4622,33 @@ first element of current section."
(list (org-element-headline-parser (point-max) t))))
;; Otherwise move at the beginning of the section containing
;; point.
(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) (goto-char (point-min))
(org-back-to-heading)
(forward-line)))
(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.
(catch 'exit
(while t
(setq element
(org-element--current-element end 'element special-flag struct)