Function: kimport:star-entries

kimport:star-entries is a byte-compiled function defined in kimport.el.

Signature

(kimport:star-entries IMPORT-FROM OUTPUT-TO KLABEL OUTPUT-LEVEL IMPORT-LEVEL COUNT TOTAL MAX-POS)

Documentation

Insert visible star outline entries from IMPORT-FROM into existing OUTPUT-TO.

KLABEL is the label to use for the first imported entry. OUTPUT-LEVEL is the level at which to insert the first entry. IMPORT-LEVEL is the depth of the current entry in the import file,
(initially 1).

COUNT of inserted entries starts at 0. TOTAL is the total number of entries in IMPORT-FROM, used to show a running tally of the imported entries. MAX-POS is the furthest position searched in IMPORT-FROM so far (initially 0).

Return a cons of MAX-POS and COUNT.

Source Code

;; Defined in ~/.emacs.d/elpa/hyperbole-20260414.325/kotl/kimport.el
(defun kimport:star-entries (import-from output-to klabel output-level
                             import-level count total max-pos)
  "Insert visible star outline entries from IMPORT-FROM into existing OUTPUT-TO.

KLABEL is the label to use for the first imported entry.
OUTPUT-LEVEL is the level at which to insert the first entry.
IMPORT-LEVEL is the depth of the current entry in the import file,
\(initially 1).

COUNT of inserted entries starts at 0.  TOTAL is the total number
of entries in IMPORT-FROM, used to show a running tally of the
imported entries.  MAX-POS is the furthest position searched in
IMPORT-FROM so far (initially 0).

Return a cons of MAX-POS and COUNT."
  (set-buffer import-from)
  (let ((start (point))
	(hyrolo-hdr-and-entry-regexp kimport:star-heading)
	(case-fold-search)
	max-pos-and-count
	subtree-p end contents node-level child-label)
    ;; While find cells at import-level or deeper ...
    (while (and (re-search-forward hyrolo-hdr-and-entry-regexp nil t)
		(<= import-level
		    (setq node-level
			  (length (match-string 1)))))
      (skip-chars-forward " \t")
      (setq start (point)
	    end (hyrolo-to-entry-end)
	    subtree-p (if (looking-at hyrolo-hdr-and-entry-regexp)
			  (< node-level
			     (length (match-string 1)))))
      (skip-chars-backward "\n\r")
      (setq contents (kimport:unindent-region start (point)))
      (with-current-buffer output-to
	(if (and (zerop count) (string-empty-p (kcell-view:contents)))
	    ;; Reuse this initial empty cell in koutline
	    (progn (kview:insert-contents (kcell-view:cell) contents 'no-fill
					  (make-string (kcell-view:indent) ?\ ))
		   (goto-char (kcell-view:end)))
	  ;; Add the cell starting at point.
	  (kview:add-cell klabel output-level contents nil t))
	(if subtree-p (setq child-label (klabel:child klabel)))
	(message "%d of %d trees converted..."
		 (if (= node-level 1) (setq count (1+ count)) count)
		 total)
	(setq klabel (klabel:increment klabel)))
      ;;
      ;; Current buffer returns to `import-from' here.
      (goto-char end)

      ;;
      ;; Handle each sub-level through recursion.
      (when subtree-p
	;; Subtree exists so insert its cells.
	(setq max-pos-and-count
	      (kimport:star-entries import-from output-to child-label
				    (1+ output-level) (1+ import-level)
				    count total max-pos)
	      max-pos (car max-pos-and-count)
	      count (cdr max-pos-and-count))))
    (goto-char (setq max-pos (max end max-pos))))
  (cons max-pos count))