Browse Source

org-element: Preserve Emacs 23 compatibility

* lisp/org-element.el (org-element--cache-mapc): New function.
(org-element--cache-sync): Use new function.

`avl-tree-mapc' exists in Emacs 24's "avl-tree" but not in Emacs
23's. The new function implements it.
Nicolas Goaziou 11 years ago
parent
commit
34edfd846f
1 changed files with 12 additions and 2 deletions
  1. 12 2
      lisp/org-element.el

+ 12 - 2
lisp/org-element.el

@@ -5436,6 +5436,16 @@ Properties are modified by side-effect.  Return ELEMENT."
 	(and value (plist-put properties key (+ offset value))))))
   element)
 
+(defun org-element--cache-mapc (__map-function__ &optional reverse)
+  "Apply FUNCTION to all elements in cache.
+FUNCTION is applied to the elements in ascending order, or
+descending order if REVERSE is non-nil."
+  (avl-tree--mapc
+   #'(lambda (node)
+       (funcall __map-function__ (avl-tree--node-data node)))
+   (org-element--cache-root)
+   (if reverse 1 0)))
+
 (defun org-element--cache-sync (buffer)
   "Synchronize cache with recent modification in BUFFER.
 Elements ending before modification area are kept in cache.
@@ -5553,7 +5563,7 @@ removed from the cache."
 	    ;; before END.
 	    (unless (zerop offset)
 	      (catch 'exit
-		(avl-tree-mapc
+		(org-element--cache-mapc
 		 #'(lambda (data)
 		     (if (<= (org-element-property :begin data) end)
 			 (throw 'exit t)
@@ -5568,7 +5578,7 @@ removed from the cache."
 			 (dolist (object (cddr object-data))
 			   (org-element--cache-shift-positions
 			    object offset)))))
-		 org-element--cache 'reverse)))))
+		 'reverse)))))
 	;; Eventually signal cache as up-to-date.
 	(org-element--cache-cancel-changes)))))