Function: kview:move

kview:move is a byte-compiled function defined in kview.el.

Signature

(kview:move FROM-START FROM-END TO-START FROM-INDENT TO-INDENT &optional COPY-FLAG FILL-P)

Documentation

Move tree between FROM-START and FROM-END to TO-START.

Also change indentation from FROM-INDENT to TO-INDENT. Copy tree if optional COPY-FLAG is non-nil. Refill cells if optional FILL-P is non-nil. Leave point at TO-START.

Source Code

;; Defined in ~/.emacs.d/elpa/hyperbole-20260414.325/kotl/kview.el
(defun kview:move (from-start from-end to-start from-indent to-indent
                   &optional copy-flag fill-p)
  "Move tree between FROM-START and FROM-END to TO-START.
Also change indentation from FROM-INDENT to TO-INDENT.
Copy tree if optional COPY-FLAG is non-nil.  Refill cells if optional
FILL-P is non-nil.  Leave point at TO-START."
  (let ((region (buffer-substring from-start from-end))
	(new-start (set-marker (make-marker) to-start))
	(collapsed-cells (kview:get-cells-status kotl-kview from-start from-end))
	expr new-end space)

    ;;
    ;; Move or copy tree region to new location.
    (or copy-flag (delete-region from-start from-end))
    (goto-char new-start)
    (insert region)
    (setq new-end (point))
    ;;
    ;; Change indentation of tree cells.
    (if (/= from-indent to-indent)
	(save-restriction
	  (narrow-to-region new-start new-end)
	  ;; Expand all cells in the region to move.
	  (outline-flag-region new-start new-end nil)
	  ;;
	  (goto-char (point-min))
	  (if (< from-indent to-indent)
	      ;; Add indent
	      (progn
		(setq expr (concat (make-string (- to-indent from-indent) ?\ )
				   "\\&"))
		(while (re-search-forward "^[^\n\r\f]" nil t)
		  (replace-match expr t)
		  (kfill:forward-line 1)))
	    ;; Reduce indent in all but first cell lines.
	    (setq expr (concat "^" (make-string (- from-indent to-indent) ?\ )))
	    (while (re-search-forward expr nil t)
	      (replace-match "" t t)
	      (kfill:forward-line 1))
	    ;; Reduce indent in first cell lines which may have an
	    ;; autonumber or other cell delimiter.
	    (setq space (- from-indent to-indent
			   (kview:label-separator-length kotl-kview)
			   1))
	    (unless (zerop space)
	      (setq expr (concat "^" (make-string
				      (- from-indent to-indent
					 (kview:label-separator-length kotl-kview)
					 1)
				      ?\ )))
	      (kview:map-tree
	       (lambda (_view)
		 (save-excursion
		   (beginning-of-line)
		   (when (looking-at expr)
		     (replace-match "" t t))))
	       kotl-kview t)))
	  ;;
	  (when fill-p
	    ;; Refill cells lacking no-fill attribute.
	    (kview:map-tree (lambda (_view) (kotl-mode:fill-cell nil t))
			    kotl-kview t))))
    ;;
    (goto-char new-start)
    ;;
    ;; Restore status of temporarily expanded cells.
    (when (remq 0 collapsed-cells)
      (kview:set-cells-status kotl-kview new-start new-end collapsed-cells))
    ;;
    ;; Delete temporary markers.
    (set-marker new-start nil)))