Search for node containing point + misc
This commit is contained in:
parent
1eba276ad9
commit
2920f6ca1f
45
origami.el
45
origami.el
@ -64,7 +64,8 @@
|
|||||||
(vector beg end open sorted-children data)))))
|
(vector beg end open sorted-children data)))))
|
||||||
|
|
||||||
(defun origami-fold-top-level-node (&optional children)
|
(defun origami-fold-top-level-node (&optional children)
|
||||||
(origami-fold-node 0 0 t children))
|
;; TODO: fix min and max
|
||||||
|
(origami-fold-node 0 10000 t children))
|
||||||
|
|
||||||
(defun origami-fold-beg (node) (when node (aref node 0)))
|
(defun origami-fold-beg (node) (when node (aref node 0)))
|
||||||
|
|
||||||
@ -72,6 +73,15 @@
|
|||||||
|
|
||||||
(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)
|
||||||
|
(let* ((old-node (-last-item path))
|
||||||
|
(new-node (origami-fold-node (origami-fold-beg old-node)
|
||||||
|
(origami-fold-end old-node)
|
||||||
|
value
|
||||||
|
(origami-fold-children old-node)
|
||||||
|
(origami-fold-data old-node))))
|
||||||
|
(origami-fold-assoc path new-node)))
|
||||||
|
|
||||||
(defun origami-fold-children (node &optional children)
|
(defun origami-fold-children (node &optional children)
|
||||||
(when node
|
(when node
|
||||||
(if children
|
(if children
|
||||||
@ -90,15 +100,6 @@ used to nil out data. This mutates the node."
|
|||||||
(aset node 4 data)
|
(aset node 4 data)
|
||||||
(aref node 4))))
|
(aref node 4))))
|
||||||
|
|
||||||
(defun origami-fold-open-set (path value)
|
|
||||||
(let* ((old-node (-last-item path))
|
|
||||||
(new-node (origami-fold-node (origami-fold-beg old-node)
|
|
||||||
(origami-fold-end old-node)
|
|
||||||
value
|
|
||||||
(origami-fold-children old-node)
|
|
||||||
(origami-fold-data old-node))))
|
|
||||||
(origami-fold-assoc path new-node)))
|
|
||||||
|
|
||||||
(defun origami-fold-range-equal (a b)
|
(defun origami-fold-range-equal (a b)
|
||||||
(and (equal (origami-fold-beg a) (origami-fold-beg b))
|
(and (equal (origami-fold-beg a) (origami-fold-beg b))
|
||||||
(equal (origami-fold-end a) (origami-fold-end b))))
|
(equal (origami-fold-end a) (origami-fold-end b))))
|
||||||
@ -145,6 +146,21 @@ used to nil out data. This mutates the node."
|
|||||||
(-each (origami-fold-children node) f)
|
(-each (origami-fold-children node) f)
|
||||||
(funcall f node))
|
(funcall f node))
|
||||||
|
|
||||||
|
(defun origami-fold-find-node-containing (tree point)
|
||||||
|
"Return the path to the most specific (deepest) node that
|
||||||
|
contains point, or null."
|
||||||
|
(cl-labels
|
||||||
|
((node-contains? (point node)
|
||||||
|
(and (<= (origami-fold-beg node) point)
|
||||||
|
(>= (origami-fold-end node) point)))
|
||||||
|
(get-child-containing (children point)
|
||||||
|
(-first (lambda (n) (node-contains? point n)) children)))
|
||||||
|
(when tree
|
||||||
|
(when (node-contains? point tree)
|
||||||
|
(-if-let (child (get-child-containing (origami-fold-children tree) point))
|
||||||
|
(cons tree (origami-fold-find-node-containing child point))
|
||||||
|
(list tree))))))
|
||||||
|
|
||||||
;;; overlay manipulation
|
;;; overlay manipulation
|
||||||
|
|
||||||
(defun origami-create-overlay (beg end buffer text)
|
(defun origami-create-overlay (beg end buffer text)
|
||||||
@ -297,13 +313,16 @@ used to nil out data. This mutates the node."
|
|||||||
|
|
||||||
(defun origami-store-cached-tree (buffer tree)
|
(defun origami-store-cached-tree (buffer tree)
|
||||||
;; TODO:
|
;; TODO:
|
||||||
)
|
tree)
|
||||||
|
|
||||||
(defun origami-build-tree (buffer parser)
|
(defun origami-build-tree (buffer parser)
|
||||||
(when parser
|
(when parser
|
||||||
(with-current-buffer buffer
|
(with-current-buffer buffer
|
||||||
(let ((contents (buffer-string)))
|
(let ((contents (buffer-string)))
|
||||||
(origami-run-parser parser (origami-content 0 contents))))))
|
(-> parser
|
||||||
|
(origami-run-parser (origami-content 0 contents))
|
||||||
|
car
|
||||||
|
origami-fold-top-level-node)))))
|
||||||
|
|
||||||
(defun origami-get-parser (buffer)
|
(defun origami-get-parser (buffer)
|
||||||
;; TODO: remove hardcoding!
|
;; TODO: remove hardcoding!
|
||||||
@ -339,8 +358,10 @@ otherwise fetch cached tree."
|
|||||||
(defun origami-open-node (buffer point)
|
(defun origami-open-node (buffer point)
|
||||||
(interactive (list (current-buffer) (point)))
|
(interactive (list (current-buffer) (point)))
|
||||||
(let ((tree (origami-get-fold-tree buffer)))
|
(let ((tree (origami-get-fold-tree buffer)))
|
||||||
|
(debug-msg "tree: %s" tree)
|
||||||
(-when-let (path (origami-fold-find-node-containing tree point))
|
(-when-let (path (origami-fold-find-node-containing tree point))
|
||||||
;; TODO: don't actually compute + apply the diff
|
;; TODO: don't actually compute + apply the diff
|
||||||
|
(debug-msg "path: %s" path)
|
||||||
(origami-store-cached-tree buffer
|
(origami-store-cached-tree buffer
|
||||||
(origami-fold-open-set path t)))))
|
(origami-fold-open-set path t)))))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user