Implement show only

This commit is contained in:
Greg Sexton 2014-04-21 21:32:04 +01:00
parent 3cb65b2912
commit 3650c604b5

View File

@ -76,15 +76,17 @@
(defun origami-fold-open-p (node) (when node (aref node 2))) (defun origami-fold-open-p (node) (when node (aref node 2)))
(defun origami-fold-open-set (path value) (defun origami-fold-open-set (path value)
(let* ((old-node (-last-item path)) "Set all nodes in PATH to VALUE. This operation only really
(new-node (origami-fold-node (origami-fold-beg old-node) makes sense to do for a path from the root node."
(origami-fold-end old-node) (origami-fold-path-map (lambda (node)
(if (origami-fold-is-root-node? node)
node
(origami-fold-node (origami-fold-beg node)
(origami-fold-end node)
value value
(origami-fold-children old-node) (origami-fold-children node)
(origami-fold-data old-node)))) (origami-fold-data node))))
(if (origami-fold-is-root-node? old-node) ;can't change the state of the root node path))
old-node
(origami-fold-assoc path new-node))))
(defun origami-fold-children (node) (when node (aref node 3))) (defun origami-fold-children (node) (when node (aref node 3)))
@ -116,7 +118,8 @@ used to nil out data. This mutates the node."
(cons new (remove old (origami-fold-children node))))) (cons new (remove old (origami-fold-children node)))))
(defun origami-fold-assoc (path new-node) (defun origami-fold-assoc (path new-node)
"Rewrite the tree, replacing the node referenced by path with NEW-NODE" "Rewrite the tree, replacing the node referenced by PATH with
NEW-NODE"
(cdr (cdr
(-reduce-r-from (lambda (node acc) (-reduce-r-from (lambda (node acc)
(destructuring-bind (old-node . new-node) acc (destructuring-bind (old-node . new-node) acc
@ -160,6 +163,15 @@ the state of each node."
(-map (lambda (node) (origami-fold-map f node)) (-map (lambda (node) (origami-fold-map f node))
(origami-fold-children tree)))) (origami-fold-children tree))))
(defun origami-fold-path-map (f path)
"Map F over the nodes in path. As with `origami-fold-map',
children cannot be manipulated."
(cond ((null path) nil)
((cdr path) (funcall f (origami-fold-replace-child (car path)
(cadr path)
(origami-fold-path-map f (cdr path)))))
(t (funcall f (car path)))))
(defun origami-fold-find-deepest (tree pred) (defun origami-fold-find-deepest (tree pred)
(when tree (when tree
(when (funcall pred tree) (when (funcall pred tree)
@ -371,9 +383,14 @@ consumed count."
(origami-parser-consume-while (lambda (x) (and (not (equal x "}")) (origami-parser-consume-while (lambda (x) (and (not (equal x "}"))
(not (equal x "{"))))) (not (equal x "{")))))
(origami-parser-1? (origami-parser-1?
(origami-parser-paired (origami-parser-char "{") (origami-parser-paired
(origami-parser-char "{")
(origami-parser-char "}") (origami-parser-char "}")
(origami-parser-zero) is-open data))) (origami-do
(origami-parser-consume-while (lambda (x) (and (not (equal x "}"))
(not (equal x "{")))))
(origami-parser-return nil))
is-open data)))
is-open data)))) is-open data))))
(defun origami-was-previously-open? (tree) (defun origami-was-previously-open? (tree)
@ -464,6 +481,11 @@ otherwise fetch cached tree."
(origami-delete-overlay-from-fold-tree-fn buffer) (origami-delete-overlay-from-fold-tree-fn buffer)
(origami-change-overlay-from-fold-node-fn buffer)))) (origami-change-overlay-from-fold-node-fn buffer))))
(defun origami-show-only-node (buffer point)
(interactive (list (current-buffer) (point)))
(origami-close-all-nodes buffer)
(origami-open-node buffer point))
(defun origami-reset (buffer) (defun origami-reset (buffer)
(interactive (list (current-buffer))) (interactive (list (current-buffer)))
(let ((tree (origami-get-fold-tree buffer))) (let ((tree (origami-get-fold-tree buffer)))