Add more interactive movement commands

This commit is contained in:
Greg Sexton 2016-07-09 17:50:23 +01:00
parent 714fba2a9c
commit 1a957be171
2 changed files with 71 additions and 7 deletions

View File

@ -123,7 +123,22 @@ buffer - those in bold are particularly useful:
<tr> <tr>
<td>origami-next-fold</td> <td>origami-next-fold</td>
<td>Move to the next fold.</td> <td>Move to the end of the next fold.</td>
</tr>
<tr>
<td>origami-forward-fold</td>
<td>Move to the start of the next fold.</td>
</tr>
<tr>
<td>origami-forward-fold-same-level</td>
<td>Move to the start of the next fold that is a sibling of the current fold.</td>
</tr>
<tr>
<td>origami-backward-fold-same-level</td>
<td>Move to the start of the previous fold that is a sibling of the current fold.</td>
</tr> </tr>
<tr> <tr>

View File

@ -386,6 +386,20 @@ with the current state and the current node at each iteration."
(origami-fold-add-child leaf node)))) (origami-fold-add-child leaf node))))
tree1 (origami-fold-children tree2))) tree1 (origami-fold-children tree2)))
(defun origami-fold-parent (path)
(-last-item (-butlast path)))
(defun origami-fold-prev-sibling (siblings node)
(->> siblings
(-partition-in-steps 2 1)
(-drop-while (lambda (pair) (not (equal (cadr pair) node))))
caar))
(defun origami-fold-next-sibling (siblings node)
(->> siblings
(-drop-while (lambda (n) (not (equal n node))))
cadr))
;;; linear history structure ;;; linear history structure
(defun origami-h-new (present) (defun origami-h-new (present)
@ -691,6 +705,41 @@ a fold, move to the end of the fold that POINT is in."
(->> (-last (lambda (pos) (> pos point)))) (->> (-last (lambda (pos) (> pos point))))
goto-char))) goto-char)))
(defun origami-forward-fold (buffer point)
"Move point to the beginning of the first fold in the BUFFER
after POINT."
(interactive (list (current-buffer) (point)))
(-when-let (tree (origami-get-fold-tree buffer))
(-> tree
(origami-fold-preorder-reduce (lambda (state n)
(cons (origami-fold-beg n) state)) nil)
(->> (-last (lambda (pos) (> pos point))))
goto-char)))
(defun origami-forward-fold-same-level (buffer point)
"Move point to the beginning of the next fold in the buffer
that is a sibling of the fold the point is currently in."
(interactive (list (current-buffer) (point)))
(-when-let (tree (origami-get-fold-tree buffer))
(-when-let (path (origami-fold-find-path-containing tree point))
(when-let (c (-> (origami-fold-next-sibling (origami-fold-children
(origami-fold-parent path))
(-last-item path))
origami-fold-beg))
(goto-char c)))))
(defun origami-backward-fold-same-level (buffer point)
"Move point to the beginning of the previous fold in the buffer
that is a sibling of the fold the point is currently in."
(interactive (list (current-buffer) (point)))
(-when-let (tree (origami-get-fold-tree buffer))
(-when-let (path (origami-fold-find-path-containing tree point))
(-when-let (c (-> (origami-fold-prev-sibling (origami-fold-children
(origami-fold-parent path))
(-last-item path))
origami-fold-beg))
(goto-char c)))))
(defun origami-undo (buffer) (defun origami-undo (buffer)
"Undo the last folding operation applied to BUFFER. Undo "Undo the last folding operation applied to BUFFER. Undo
history is linear. If you undo some fold operations and then history is linear. If you undo some fold operations and then