This commit is contained in:
Greg Sexton 2014-08-10 15:29:44 +01:00
parent 29618c96de
commit 8a2d0388f6

View File

@ -76,7 +76,7 @@
;;; fold structure ;;; fold structure
(defun origami-fold-node-raw (beg end open &optional children data) (defun origami-fold-node (beg end open &optional children data)
(let ((sorted-children (-sort (lambda (a b) (let ((sorted-children (-sort (lambda (a b)
(or (< (origami-fold-beg a) (origami-fold-beg b)) (or (< (origami-fold-beg a) (origami-fold-beg b))
(and (= (origami-fold-beg a) (origami-fold-beg b)) (and (= (origami-fold-beg a) (origami-fold-beg b))
@ -104,7 +104,7 @@
(defun origami-fold-root-node (&optional children) (defun origami-fold-root-node (&optional children)
;; TODO: fix min and max ;; TODO: fix min and max
(origami-fold-node-raw 1 100000 t children 'root)) (origami-fold-node 1 100000 t children 'root))
(defun origami-fold-is-root-node? (node) (eq (origami-fold-data node) 'root)) (defun origami-fold-is-root-node? (node) (eq (origami-fold-data node) 'root))
@ -127,7 +127,7 @@
(when node (when node
(if (origami-fold-is-root-node? node) (if (origami-fold-is-root-node? node)
node node
(origami-fold-node-raw (origami-fold-beg node) (origami-fold-node (origami-fold-beg node)
(origami-fold-end node) (origami-fold-end node)
value value
(origami-fold-children node) (origami-fold-children node)
@ -137,7 +137,7 @@
(defun origami-fold-children-set (node children) (defun origami-fold-children-set (node children)
(when node (when node
(origami-fold-node-raw (origami-fold-beg node) (origami-fold-node (origami-fold-beg node)
(origami-fold-end node) (origami-fold-end node)
(origami-fold-open? node) (origami-fold-open? node)
children children
@ -255,17 +255,6 @@ with the current state and the current node at each iteration."
(origami-fold-children tree)) (origami-fold-children tree))
tree)) tree))
;;; TODO: why does this own copying data over? should it own copying over open status?
;;; TODO: not happy with this signature. Breaks abstraction layering.
(defun origami-fold-node (beg end open buffer &optional children previous-tree)
;; TODO: beg and end are superfluous
;; TODO: previous-tree is always true and this isn't guaranteed to produce an overlay
(let ((overlay (or (-> (origami-fold-find-path-with-range previous-tree beg end)
-last-item
origami-fold-data)
(origami-create-overlay beg end buffer))))
(origami-fold-node-raw beg end open children overlay)))
;;; interactive utils ;;; interactive utils
;;; TODO: create functions for accessing/setting the local vars and ;;; TODO: create functions for accessing/setting the local vars and
@ -290,11 +279,6 @@ was last built."
(not (= (buffer-local-value 'origami-tree-tick buffer) (not (= (buffer-local-value 'origami-tree-tick buffer)
(buffer-modified-tick buffer)))) (buffer-modified-tick buffer))))
(defun origami-was-previously-open? (tree beg end)
(-if-let (node (-last-item (origami-fold-find-path-with-range tree beg end)))
(origami-fold-open? node)
t))
(defun origami-build-tree (buffer parser) (defun origami-build-tree (buffer parser)
(when parser (when parser
(with-current-buffer buffer (with-current-buffer buffer
@ -305,12 +289,17 @@ was last built."
origami-fold-root-node))))) origami-fold-root-node)))))
(defun origami-get-parser (buffer) (defun origami-get-parser (buffer)
(let ((create (lambda (beg end children) (let* ((cached-tree (origami-get-cached-tree buffer))
(create (lambda (beg end children)
(let ((previous-fold (-last-item (origami-fold-find-path-with-range cached-tree beg end))))
(origami-fold-node beg end (origami-fold-node beg end
(origami-was-previously-open? (origami-get-cached-tree buffer) beg end) (if previous-fold (origami-fold-open? previous-fold) t)
buffer
children children
(origami-get-cached-tree buffer))))) (or (-> (origami-fold-find-path-with-range
(origami-get-cached-tree buffer) beg end)
-last-item
origami-fold-data)
(origami-create-overlay beg end buffer)))))))
(-when-let (parser-gen (cdr (assoc (buffer-local-value 'major-mode buffer) (-when-let (parser-gen (cdr (assoc (buffer-local-value 'major-mode buffer)
origami-parser-alist))) origami-parser-alist)))
(funcall parser-gen create)))) (funcall parser-gen create))))