Function: kotl-mode:move-before
kotl-mode:move-before is an interactive and byte-compiled function
defined in kotl-mode.el.
Signature
(kotl-mode:move-before FROM-CELL-REF TO-CELL-REF PARENT-P &optional COPY-FLAG FILL-P)
Documentation
Move tree rooted at FROM-CELL-REF to precede tree rooted at TO-CELL-REF.
If prefix arg PARENT-P is non-nil, make FROM-CELL-REF the first child of TO-CELL-REF's parent, otherwise make it the preceding sibling of TO-CELL-REF. With optional COPY-FLAG, copies tree rather than moving it.
Leave point at original location but return the tree's new start point.
Key Bindings
Source Code
;; Defined in ~/.emacs.d/elpa/hyperbole-20260414.325/kotl/kotl-mode.el
(defun kotl-mode:move-before (from-cell-ref to-cell-ref parent-p
&optional copy-flag fill-p)
"Move tree rooted at FROM-CELL-REF to precede tree rooted at TO-CELL-REF.
If prefix arg PARENT-P is non-nil, make FROM-CELL-REF the first child of
TO-CELL-REF's parent, otherwise make it the preceding sibling of TO-CELL-REF.
With optional COPY-FLAG, copies tree rather than moving it.
Leave point at original location but return the tree's new start point."
(interactive
(let* ((label (kcell-view:label)))
(append
(hargs:iform-read
(list 'interactive
(format "*+KMove tree: \n+KMove tree <%%s> to be %s of cell: "
(if current-prefix-arg "first child of parent"
"preceding sibling")))
(list label label))
(list current-prefix-arg))))
(when (and (not copy-flag) (equal from-cell-ref to-cell-ref))
(error "(kotl-mode:move-before): Can't move tree before itself"))
(let* ((lbl-sep-len (kview:label-separator-length kotl-kview))
(move-to-point (set-marker
(make-marker)
(kotl-mode:goto-cell to-cell-ref t)))
(to-label (kcell-view:label))
(to-indent (kcell-view:indent nil lbl-sep-len))
(from-label (progn (kotl-mode:goto-cell from-cell-ref t)
(kcell-view:label)))
(from-indent (kcell-view:indent nil lbl-sep-len))
(start (kotl-mode:tree-start))
(end (kotl-mode:tree-end))
(sib-id (when (= 0 (kotl-mode:forward-cell 1))
(kcell-view:idstamp)))
new-tree-start)
;;
;; We can't move a tree to a point within itself, so if that is the case
;; and this is not a copy operation, signal an error.
(when (and (not copy-flag) (>= move-to-point start) (<= move-to-point end))
(error "(kotl-mode:move-before): Can't move tree <%s> to within itself"
from-label))
;;
;; If tree to move has a sibling, point is now at the start of the
;; sibling cell. Mark its label with a property which will be deleted
;; whenever the cell label is renumbered. This tells us whether or not
;; to renumber the sibling separately from the tree to move.
(when sib-id
;; Move to middle of label and insert klabel-original temp property.
(goto-char (- (point) lbl-sep-len 3))
(kproperty:set 'klabel-original t))
;;
;; Position for insertion at succeeding-tree, before deletion of
;; tree-to-move from old position, in case old position precedes new one.
(goto-char move-to-point)
(if parent-p
;; Move to insert position for first child of to-cell-ref's parent.
(if (kcell-view:parent nil lbl-sep-len)
(progn (setq to-label (klabel:child (kcell-view:label)))
(goto-char (kcell-view:end)))
(error "(kotl-mode:move-before): to-cell-ref's parent not in current view"))
;; Move to before to-cell-ref for insertion as preceding sibling.
(goto-char (kotl-mode:tree-start)))
;;
;; Insert tree-to-move at new location
;;
(kview:move start end (point) from-indent to-indent copy-flag
(or fill-p kotl-mode:refill-flag))
;;
;; Ensure that point is within editable region of root of tree just moved.
(kotl-mode:to-valid-position)
(setq new-tree-start (point))
;;
;; Update current cell and new siblings' labels within view.
(klabel-type:update-labels to-label)
;;
(unless copy-flag
;;
;; Move to sibling of tree-to-move within view and update labels within
;; view of tree-to-move's original siblings.
(when sib-id
(kotl-mode:goto-cell sib-id t)
;; Sibling labels may have already been updated if tree was
;; moved somewhere preceding its siblings.
(let ((label-middle (- (point) lbl-sep-len 2)))
(when (kproperty:get label-middle 'klabel-original)
(klabel-type:update-labels from-label)))))
;;
(goto-char new-tree-start)
;;
;; Ensure that point is within editable region of a cell.
(kotl-mode:to-valid-position)
;;
(set-marker move-to-point nil)
new-tree-start))