Add origami-recursively-toggle-node command
This commit is contained in:
parent
3de4a8513b
commit
26037d8a99
58
origami.el
58
origami.el
@ -261,6 +261,14 @@ with the current state and the current node at each iteration."
|
|||||||
(origami-fold-children tree))
|
(origami-fold-children tree))
|
||||||
tree))
|
tree))
|
||||||
|
|
||||||
|
(defun origami-fold-node-recursively-closed? (node)
|
||||||
|
(origami-fold-postorder-reduce node (lambda (acc node)
|
||||||
|
(and acc (not (origami-fold-open? node)))) t))
|
||||||
|
|
||||||
|
(defun origami-fold-node-recursively-open? (node)
|
||||||
|
(origami-fold-postorder-reduce node (lambda (acc node)
|
||||||
|
(and acc (origami-fold-open? node))) t))
|
||||||
|
|
||||||
;;; interactive utils
|
;;; interactive utils
|
||||||
|
|
||||||
;;; TODO: create functions for accessing/setting the local vars and
|
;;; TODO: create functions for accessing/setting the local vars and
|
||||||
@ -325,6 +333,20 @@ otherwise fetch cached tree."
|
|||||||
'origami-show-overlay-from-fold-tree-fn
|
'origami-show-overlay-from-fold-tree-fn
|
||||||
'origami-change-overlay-from-fold-node-fn)))
|
'origami-change-overlay-from-fold-node-fn)))
|
||||||
|
|
||||||
|
(defun origami-search-forward-for-path (buffer point)
|
||||||
|
(let (end)
|
||||||
|
(with-current-buffer buffer
|
||||||
|
(save-excursion
|
||||||
|
(goto-char point)
|
||||||
|
(setq end (line-end-position))))
|
||||||
|
(-when-let (tree (origami-get-fold-tree buffer))
|
||||||
|
(-when-let (path (origami-fold-find-path-containing tree point))
|
||||||
|
(let ((forward-node (-first (lambda (node)
|
||||||
|
(and (>= (origami-fold-beg node) point)
|
||||||
|
(<= (origami-fold-beg node) end)))
|
||||||
|
(origami-fold-children (-last-item path)))))
|
||||||
|
(if forward-node (append path (list forward-node)) path))))))
|
||||||
|
|
||||||
;;; commands
|
;;; commands
|
||||||
|
|
||||||
;;; TODO: document all commands
|
;;; TODO: document all commands
|
||||||
@ -389,23 +411,25 @@ as to ensure seeing where POINT is."
|
|||||||
|
|
||||||
(defun origami-forward-toggle-node (buffer point)
|
(defun origami-forward-toggle-node (buffer point)
|
||||||
(interactive (list (current-buffer) (point)))
|
(interactive (list (current-buffer) (point)))
|
||||||
(let (end)
|
(-when-let (tree (origami-get-fold-tree buffer))
|
||||||
(with-current-buffer buffer
|
(-when-let (path (origami-search-forward-for-path buffer point))
|
||||||
(save-excursion
|
(origami-apply-new-tree buffer tree (origami-fold-assoc
|
||||||
(goto-char point)
|
path (lambda (node)
|
||||||
(setq end (line-end-position))))
|
(origami-fold-open-set
|
||||||
(-when-let (tree (origami-get-fold-tree buffer))
|
node (not (origami-fold-open?
|
||||||
(-when-let (path (origami-fold-find-path-containing tree point))
|
(-last-item path))))))))))
|
||||||
(let ((forward-node (-first (lambda (node)
|
|
||||||
(and (>= (origami-fold-beg node) point)
|
(defun origami-recursively-toggle-node (buffer point)
|
||||||
(<= (origami-fold-beg node) end)))
|
(interactive (list (current-buffer) (point)))
|
||||||
(origami-fold-children (-last-item path)))))
|
(-when-let (path (origami-search-forward-for-path buffer point))
|
||||||
(let ((path (if forward-node (append path (list forward-node)) path)))
|
(let ((node (-last-item path)))
|
||||||
(origami-apply-new-tree buffer tree (origami-fold-assoc
|
(if (eq last-command 'origami-recursively-toggle-node)
|
||||||
path (lambda (node)
|
(cond ((origami-fold-node-recursively-open? node)
|
||||||
(origami-fold-open-set
|
(origami-close-node-recursively buffer (origami-fold-beg node)))
|
||||||
node (not (origami-fold-open?
|
((origami-fold-node-recursively-closed? node)
|
||||||
(-last-item path)))))))))))))
|
(origami-toggle-node buffer (origami-fold-beg node)))
|
||||||
|
(t (origami-open-node-recursively buffer (origami-fold-beg node))))
|
||||||
|
(origami-forward-toggle-node buffer point)))))
|
||||||
|
|
||||||
(defun origami-open-all-nodes (buffer)
|
(defun origami-open-all-nodes (buffer)
|
||||||
(interactive (list (current-buffer)))
|
(interactive (list (current-buffer)))
|
||||||
|
Loading…
Reference in New Issue
Block a user