org-element: Simplify request processing

* lisp/org-element.el (org-element--cache-process-request): Do not try
  to find orphans for now.  Remove useless comments.  Refactor code.
This commit is contained in:
Nicolas Goaziou 2014-06-30 17:39:21 +02:00
parent ba9c43fc81
commit 1a9b074d9f
1 changed files with 14 additions and 32 deletions

View File

@ -5083,24 +5083,15 @@ request."
;; Delete all elements starting after BEG, but not after buffer ;; Delete all elements starting after BEG, but not after buffer
;; position END or past element with key NEXT. ;; position END or past element with key NEXT.
;; ;;
;; As an exception, also delete elements starting after
;; modifications but included in an element altered by
;; modifications (orphans).
;;
;; At each iteration, we start again at tree root since ;; At each iteration, we start again at tree root since
;; a deletion modifies structure of the balanced tree. ;; a deletion modifies structure of the balanced tree.
(catch 'end-phase (catch 'end-phase
(let ((beg (aref request 0)) (let ((beg (aref request 0))
(end (aref request 2)) (end (aref request 2)))
(deleted-parent (aref request 4)))
(while t (while t
(when (org-element--cache-interrupt-p time-limit) (when (org-element--cache-interrupt-p time-limit)
(aset request 4 deleted-parent)
(throw 'interrupt nil)) (throw 'interrupt nil))
;; Find first element in cache with key BEG or after it. ;; Find first element in cache with key BEG or after it.
;; We don't use `org-element--cache-find' because it
;; couldn't reach orphaned elements past NEXT. Moreover,
;; BEG is a key, not a buffer position.
(let ((node (org-element--cache-root)) data data-key) (let ((node (org-element--cache-root)) data data-key)
(while node (while node
(let* ((element (avl-tree--node-data node)) (let* ((element (avl-tree--node-data node))
@ -5115,28 +5106,19 @@ request."
(t (setq data element (t (setq data element
data-key key data-key key
node nil))))) node nil)))))
(if (not data) (throw 'quit t) (if data
(let ((pos (org-element-property :begin data))) (let ((pos (org-element-property :begin data)))
(cond (if (and (<= pos end)
;; Remove orphaned elements. (or (not next)
((and deleted-parent (org-element--cache-key-less-p data-key next)))
(let ((up data)) (org-element--cache-remove data)
(while (and (aset request 0 data-key)
(setq up (org-element-property :parent up)) (aset request 1 pos)
(not (eq up deleted-parent)))) (aset request 5 1)
up)) (throw 'end-phase nil)))
(org-element--cache-remove data)) ;; No element starting after modifications left in
((or (and next ;; cache: further processing is futile.
(not (org-element--cache-key-less-p data-key (throw 'quit t)))))))
next)))
(> pos end))
(aset request 0 data-key)
(aset request 2 pos)
(aset request 5 1)
(throw 'end-phase nil))
(t (org-element--cache-remove data)
(when (= (org-element-property :end data) end)
(setq deleted-parent data)))))))))))
(when (= (aref request 5) 1) (when (= (aref request 5) 1)
;; Phase 2. ;; Phase 2.
;; ;;