org-element: Small refactoring

* lisp/org-element.el (org-element-at-point): Refactor code.  Fixing
  structure in cached plain lists is no longer required since
  4423d750a4.
This commit is contained in:
Nicolas Goaziou 2013-12-30 14:05:38 +01:00
parent fde42c5303
commit 4dbbbe5b01
1 changed files with 16 additions and 25 deletions

View File

@ -5284,29 +5284,20 @@ first row."
(while t (while t
(unless element (unless element
(setq element (setq element
(let* ((pos (if (and (memq special-flag '(item table-row)) (let ((pos (if (and (memq special-flag '(item table-row))
(memq type '(plain-list table))) (memq type '(plain-list table)))
;; First item (resp. row) in ;; First item (resp. row) in plain
;; plain list (resp. table) gets ;; list (resp. table) gets
;; a special key in cache. ;; a special key in cache.
(1+ (point)) (1+ (point))
(point))) (point))))
(cached (org-element-cache-get pos 'element))) (or (org-element-cache-get pos 'element)
(cond
((not cached)
(let ((element (org-element--current-element (let ((element (org-element--current-element
end 'element special-flag struct))) end 'element special-flag struct)))
(when (derived-mode-p 'org-mode) (when (derived-mode-p 'org-mode)
(org-element-cache-put pos (cons element nil))) (org-element-cache-put pos (cons element nil)))
(org-element-put-property element :parent parent))) (org-element-put-property element
;; When changes happened in the middle of :parent parent))))))
;; a list, its structure ends up being
;; invalid. Therefore, we make sure to use
;; a valid one.
((and struct (memq (org-element-type cached)
'(item plain-list)))
(org-element-put-property cached :structure struct))
(t cached)))))
(setq type (org-element-type element)) (setq type (org-element-type element))
(cond (cond
;; 1. Skip any element ending before point. Also skip ;; 1. Skip any element ending before point. Also skip
@ -5317,8 +5308,8 @@ first row."
(and (= elem-end origin) (/= elem-end end))) (and (= elem-end origin) (/= elem-end end)))
(goto-char elem-end))) (goto-char elem-end)))
(setq element nil)) (setq element nil))
;; 2. An element containing point is always the element at ;; 2. An element containing point is always the element
;; point. ;; at point.
((not (memq type org-element-greater-elements)) ((not (memq type org-element-greater-elements))
(throw 'exit element)) (throw 'exit element))
;; 3. At any other greater element type, if point is ;; 3. At any other greater element type, if point is