Implement forward versions for open and close
This already exists for the toggle methods and it's quite convenient. This commit reproduce this behavior for: - `origami-open-node' - `origami-open-node-recursively' - `origami-close-node' - `origami-close-node-recursively'
This commit is contained in:
parent
1f38085c8f
commit
d58014d81b
61
origami.el
61
origami.el
@ -533,6 +533,19 @@ will be the deepest nested at POINT."
|
|||||||
(origami-fold-assoc path (lambda (node)
|
(origami-fold-assoc path (lambda (node)
|
||||||
(origami-fold-open-set node t))))))))
|
(origami-fold-open-set node t))))))))
|
||||||
|
|
||||||
|
(defun origami-forward-open-node (buffer point)
|
||||||
|
"Like `origami-open-node' but search forward in BUFFER for a
|
||||||
|
fold node. If a closed fold node is found after POINT and before
|
||||||
|
the next line break, it will be opened. Otherwise, behave exactly
|
||||||
|
as `origami-open-node'."
|
||||||
|
(interactive (list (current-buffer) (point)))
|
||||||
|
(-when-let (tree (origami-get-fold-tree buffer))
|
||||||
|
(-when-let (path (origami-search-forward-for-path buffer point))
|
||||||
|
(origami-apply-new-tree buffer tree (origami-store-cached-tree
|
||||||
|
buffer
|
||||||
|
(origami-fold-assoc path (lambda (node)
|
||||||
|
(origami-fold-open-set node t))))))))
|
||||||
|
|
||||||
(defun origami-open-node-recursively (buffer point)
|
(defun origami-open-node-recursively (buffer point)
|
||||||
"Open the fold node and all of its children at POINT in BUFFER.
|
"Open the fold node and all of its children at POINT in BUFFER.
|
||||||
The fold node opened will be the deepest nested at POINT."
|
The fold node opened will be the deepest nested at POINT."
|
||||||
@ -548,6 +561,23 @@ The fold node opened will be the deepest nested at POINT."
|
|||||||
(origami-fold-open-set node t))
|
(origami-fold-open-set node t))
|
||||||
node))))))))
|
node))))))))
|
||||||
|
|
||||||
|
(defun origami-forward-open-node-recursively (buffer point)
|
||||||
|
"Like `origami-open-node-recursively' but search forward in BUFFER
|
||||||
|
for a fold node. If a closed fold node is found after POINT and before
|
||||||
|
the next line break, it will be opened and its children as well.
|
||||||
|
Otherwise, behave exactly as `origami-open-node-recursively'."
|
||||||
|
(interactive (list (current-buffer) (point)))
|
||||||
|
(-when-let (tree (origami-get-fold-tree buffer))
|
||||||
|
(-when-let (path (origami-search-forward-for-path buffer point))
|
||||||
|
(origami-apply-new-tree
|
||||||
|
buffer tree (origami-store-cached-tree
|
||||||
|
buffer
|
||||||
|
(origami-fold-assoc path
|
||||||
|
(lambda (node)
|
||||||
|
(origami-fold-map (lambda (node)
|
||||||
|
(origami-fold-open-set node t))
|
||||||
|
node))))))))
|
||||||
|
|
||||||
(defun origami-show-node (buffer point)
|
(defun origami-show-node (buffer point)
|
||||||
"Like `origami-open-node' but also opens parent fold nodes
|
"Like `origami-open-node' but also opens parent fold nodes
|
||||||
recursively so as to ensure the position where POINT is is
|
recursively so as to ensure the position where POINT is is
|
||||||
@ -574,6 +604,20 @@ will be the deepest nested at POINT."
|
|||||||
path (lambda (node)
|
path (lambda (node)
|
||||||
(origami-fold-open-set node nil))))))))
|
(origami-fold-open-set node nil))))))))
|
||||||
|
|
||||||
|
(defun origami-forward-close-node (buffer point)
|
||||||
|
"Like `origami-close-node' but search forward in BUFFER for a
|
||||||
|
fold node. If an opened fold node is found after POINT and before
|
||||||
|
the next line break, it will be closed. Otherwise, behave exactly
|
||||||
|
as `origami-close-node'."
|
||||||
|
(interactive (list (current-buffer) (point)))
|
||||||
|
(-when-let (tree (origami-get-fold-tree buffer))
|
||||||
|
(-when-let (path (origami-search-forward-for-path buffer point))
|
||||||
|
(origami-apply-new-tree buffer tree (origami-store-cached-tree
|
||||||
|
buffer
|
||||||
|
(origami-fold-assoc
|
||||||
|
path (lambda (node)
|
||||||
|
(origami-fold-open-set node nil))))))))
|
||||||
|
|
||||||
(defun origami-close-node-recursively (buffer point)
|
(defun origami-close-node-recursively (buffer point)
|
||||||
"Close the fold node and all of its children at POINT in BUFFER.
|
"Close the fold node and all of its children at POINT in BUFFER.
|
||||||
The fold node closed will be the deepest nested at POINT."
|
The fold node closed will be the deepest nested at POINT."
|
||||||
@ -589,6 +633,23 @@ The fold node closed will be the deepest nested at POINT."
|
|||||||
(origami-fold-open-set node nil))
|
(origami-fold-open-set node nil))
|
||||||
node))))))))
|
node))))))))
|
||||||
|
|
||||||
|
(defun origami-forward-close-node-recursively (buffer point)
|
||||||
|
"Like `origami-close-node-recursively' but search forward in BUFFER
|
||||||
|
for a fold node. If an opened fold node is found after POINT and before
|
||||||
|
the next line break, it will be opened and its children as well.
|
||||||
|
Otherwise, behave exactly as `origami-close-node-recursively'."
|
||||||
|
(interactive (list (current-buffer) (point)))
|
||||||
|
(-when-let (tree (origami-get-fold-tree buffer))
|
||||||
|
(-when-let (path (origami-search-forward-for-path buffer point))
|
||||||
|
(origami-apply-new-tree
|
||||||
|
buffer tree (origami-store-cached-tree
|
||||||
|
buffer
|
||||||
|
(origami-fold-assoc path
|
||||||
|
(lambda (node)
|
||||||
|
(origami-fold-map (lambda (node)
|
||||||
|
(origami-fold-open-set node nil))
|
||||||
|
node))))))))
|
||||||
|
|
||||||
(defun origami-toggle-node (buffer point)
|
(defun origami-toggle-node (buffer point)
|
||||||
"Toggle the fold node at POINT in BUFFER open or closed. The
|
"Toggle the fold node at POINT in BUFFER open or closed. The
|
||||||
fold node opened or closed will be the deepest nested at POINT."
|
fold node opened or closed will be the deepest nested at POINT."
|
||||||
|
Loading…
Reference in New Issue
Block a user