Function: kotl-mode:move-after

kotl-mode:move-after is an interactive and byte-compiled function defined in kotl-mode.el.

Signature

(kotl-mode:move-after FROM-CELL-REF TO-CELL-REF CHILD-P &optional COPY-FLAG FILL-P)

Documentation

Move tree rooted at FROM-CELL-REF to follow tree rooted at TO-CELL-REF.

If prefix arg CHILD-P is non-nil, make FROM-CELL-REF the first child of TO-CELL-REF, otherwise make it the sibling following 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-after (from-cell-ref to-cell-ref child-p
			     &optional copy-flag fill-p)
  "Move tree rooted at FROM-CELL-REF to follow tree rooted at TO-CELL-REF.
If prefix arg CHILD-P is non-nil, make FROM-CELL-REF the first child of
TO-CELL-REF, otherwise make it the sibling following 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 follow as %s of cell: "
		(if current-prefix-arg "child" "sibling")))
	  (list label label))
      (list current-prefix-arg))))
  (if (and (not copy-flag) (equal from-cell-ref to-cell-ref))
      (error "(kotl-mode:move-after): Can't move tree after 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)))
	 (id-label-flag (eq (kview:label-type kotl-kview) 'id))
	 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-after): 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 before deletion of tree-to-move from old
    ;; position, in case old position precedes new one.
    ;; Skip past either cell or tree at move-to-point.
    (goto-char move-to-point)
    (if child-p
	;; Move to insert position for first child of to-cell-ref.
	(progn (goto-char (kcell-view:end))
	       (setq to-label (klabel:child to-label)
		     to-indent (+ to-indent (kview:level-indent kotl-kview))))
      ;; Move to after to-cell-ref's tree for insertion as following sibling.
      (goto-char (kotl-mode:tree-end))
      (unless id-label-flag
	(setq to-label (klabel:increment to-label))))
    ;;
    ;; 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 cell with to-label.
    (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))