mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-08-26 05:02:53 +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:
parent
94dbeedd4a
commit
3bc8c9647a
|
@ -4622,26 +4622,40 @@ first element of current section."
|
||||||
(list (org-element-headline-parser (point-max) t))))
|
(list (org-element-headline-parser (point-max) t))))
|
||||||
;; Otherwise move at the beginning of the section containing
|
;; Otherwise move at the beginning of the section containing
|
||||||
;; point.
|
;; point.
|
||||||
(let ((origin (point))
|
(catch 'exit
|
||||||
(end (save-excursion
|
(let ((origin (point))
|
||||||
(org-with-limited-levels (outline-next-heading)) (point)))
|
(end (save-excursion
|
||||||
element type special-flag trail struct prevs parent)
|
(org-with-limited-levels (outline-next-heading)) (point)))
|
||||||
(org-with-limited-levels
|
element type special-flag trail struct prevs parent)
|
||||||
(if (org-before-first-heading-p) (goto-char (point-min))
|
(org-with-limited-levels
|
||||||
(org-back-to-heading)
|
(if (org-before-first-heading-p)
|
||||||
(forward-line)))
|
;; In empty lines at buffer's beginning, return nil.
|
||||||
(org-skip-whitespace)
|
(progn (goto-char (point-min))
|
||||||
(beginning-of-line)
|
(org-skip-whitespace)
|
||||||
;; Parse successively each element, skipping those ending
|
(when (or (eobp) (> (line-beginning-position) origin))
|
||||||
;; before original position.
|
(throw 'exit nil)))
|
||||||
(catch 'exit
|
(org-back-to-heading)
|
||||||
(while t
|
(forward-line)
|
||||||
(setq element
|
(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)
|
(org-element--current-element end 'element special-flag struct)
|
||||||
type (car element))
|
type (car element))
|
||||||
(org-element-put-property element :parent parent)
|
(org-element-put-property element :parent parent)
|
||||||
(when keep-trail (push element trail))
|
(when keep-trail (push element trail))
|
||||||
(cond
|
(cond
|
||||||
;; 1. Skip any element ending before point. Also skip
|
;; 1. Skip any element ending before point. Also skip
|
||||||
;; element ending at point when we're sure that another
|
;; element ending at point when we're sure that another
|
||||||
;; element has started.
|
;; element has started.
|
||||||
|
|
Loading…
Reference in a new issue