org-element: Fix `org-element-at-point' function

* lisp/org-element.el (org-element-at-point): Fix function when buffer
  starts with an inlinetask.  Also fix it when called on the last
  element in a greater element or the buffer.
This commit is contained in:
Nicolas Goaziou 2012-07-28 23:23:10 +02:00
parent e7397fda3f
commit 4b9aaf60d1
1 changed files with 16 additions and 6 deletions

View File

@ -4068,10 +4068,12 @@ first element of current section."
;; Otherwise move at the beginning of the section containing
;; point.
(let ((origin (point))
(end (save-excursion (outline-next-heading) (point)))
(end (save-excursion
(org-with-limited-levels (outline-next-heading)) (point)))
element type special-flag trail struct prevs)
(org-with-limited-levels
(if (org-before-first-heading-p) (goto-char (point-min))
(if (org-with-limited-levels (org-before-first-heading-p))
(goto-char (point-min))
(org-back-to-heading)
(forward-line)))
(org-skip-whitespace)
@ -4085,9 +4087,13 @@ first element of current section."
type (car element))
(push element trail)
(cond
;; 1. Skip any element ending before point or at point.
;; 1. Skip any element ending before point or at point
;; because the following element has started. On the
;; other hand, if the element ends at point and that
;; point is also the end of the buffer, do not skip it.
((let ((end (org-element-property :end element)))
(when (<= end origin)
(when (or (< end origin)
(and (= end origin) (/= (point-max) end)))
(if (> (point-max) end) (goto-char end)
(throw 'exit (if keep-trail trail element))))))
;; 2. An element containing point is always the element at
@ -4096,11 +4102,15 @@ first element of current section."
(throw 'exit (if keep-trail trail element)))
;; 3. At any other greater element type, if point is
;; within contents, move into it. Otherwise, return
;; that element.
;; that element. As a special case, when ORIGIN is
;; contents end and is also the end of the buffer, try
;; to move inside the greater element to find the end
;; of the innermost element.
(t
(let ((cbeg (org-element-property :contents-begin element))
(cend (org-element-property :contents-end element)))
(if (or (not cbeg) (not cend) (> cbeg origin) (<= cend origin)
(if (or (not cbeg) (not cend) (> cbeg origin) (< cend origin)
(and (= cend origin) (/= (point-max) origin))
(and (= cbeg origin) (memq type '(plain-list table))))
(throw 'exit (if keep-trail trail element))
(case type