Function: kimport:text

kimport:text is an autoloaded, interactive and byte-compiled function defined in kimport.el.

Signature

(kimport:text IMPORT-FROM OUTPUT-TO &optional CHILDREN-FLAG)

Documentation

Insert text paragraphs from IMPORT-FROM into koutline OUTPUT-TO.

Display and leave point in OUTPUT-TO. See documentation for kimport:initialize for valid values of IMPORT-FROM and OUTPUT-TO and for an explanation of where imported cells are placed.

Import Koutlines with their structure intact. Import text paragraphs as a sequence of same level cells. The variable, paragraph-start, is used to determine paragraphs.

Key Bindings

Source Code

;; Defined in ~/.emacs.d/elpa/hyperbole-20260414.325/kotl/kimport.el
;;;
;;; Generic text file import or koutline insertion.
;;;

;;;###autoload
(defun kimport:text (import-from output-to &optional children-flag)
  "Insert text paragraphs from IMPORT-FROM into koutline OUTPUT-TO.
Display and leave point in OUTPUT-TO.  See documentation for
`kimport:initialize' for valid values of IMPORT-FROM and
OUTPUT-TO and for an explanation of where imported cells are
placed.

Import Koutlines with their structure intact.  Import text
paragraphs as a sequence of same level cells.  The variable,
`paragraph-start,' is used to determine paragraphs."
  (interactive "FImport from text/koutline buffer/file: \nFInsert cells into koutline buffer/file: \nP")
  (when (and (hypb:buffer-file-name) (directory-name-p import-from))
    (setq import-from (hypb:buffer-file-name)))
  (when (and (hypb:buffer-file-name) (directory-name-p output-to))
    (setq output-to (concat (file-name-sans-extension (hypb:buffer-file-name)) ".kotl")))
  (let ((output-level 1) (klabel "1") (count 0)
        initially-empty-output no-renumber orig-point total)
    ;; Don't change the order of import-from and output-to inits here.
    (setq import-from (kimport:copy-and-set-buffer import-from)
	  ;; Set current buffer to output-to
	  output-to (kimport:initialize output-to t)
	  orig-point (point)
	  initially-empty-output (zerop (- (point-max) (point-min)))
	  no-renumber (or initially-empty-output
			  (not (if children-flag
				   (kcell-view:child-p)
				 (kcell-view:sibling-p)))))

    (when (eq import-from output-to)
      (error "(kimport:text): Import and output buffers may not be the same"))

    (set-buffer import-from)
    (let ((kotl-import (derived-mode-p 'kotl-mode))
	  visible-cells)
      (save-excursion
	(goto-char (point-min))
	(unless initially-empty-output
	  ;; Insert first cell as sibling of current cell.
	  (set-buffer output-to)
	  (cond (children-flag
		 ;; Insert as children.
		 (setq klabel (klabel:child (kcell-view:label))
		       output-level (klabel:level klabel))
		 ;; Move to end of this cell since cell insertion will
		 ;; occur at point.
		 (goto-char (kcell-view:end)))
		((string-empty-p (kcell-view:contents))
		 ;; This is an unused cell, fill in from here.
		 (setq klabel (kcell-view:label)
		       output-level (klabel:level klabel))
		 (goto-char (kcell-view:start)))
		(t ;; Insert as successors.
		 (setq klabel (klabel:increment (kcell-view:label))
		       output-level (klabel:level klabel))
		 ;; Move to start of line of next tree since cell insertion
		 ;; will occur at point.
		 (goto-char (kotl-mode:tree-end))))))

      (if kotl-import
	  ;; Importing from a koutline, so handle specially.
	  (progn (kotl-mode:beginning-of-buffer)
		 ;; Total number of cells.
		 (setq total (count-matches "[\n\r][\n\r]")
		       visible-cells (count-matches "\n\n")
		       count (save-excursion
			       ;; Incredible non-local exit to ensure that
			       ;; recursion ends at the right time.
			       (catch 'end
				 (kimport:kcells import-from output-to klabel
						 output-level 1
						 count total)))))
	(outline-show-all)
	(goto-char (point-min))
	;; Total number of paragraphs.
	(setq total (kimport:count-paragraphs)
	      count (kimport:text-paragraphs import-from output-to klabel
					     output-level count total)))
      (pop-to-buffer output-to)
      (kfile:narrow-to-kcells)
      (unless no-renumber
	(klabel-type:update-labels klabel))
      (goto-char orig-point)
      (unless (kotl-mode:buffer-empty-p)
	(kotl-mode:to-valid-position))
      (if kotl-import
	  (message "Imported %d of %d visible cells from a %d cell outline."
		   count visible-cells total)
	(message "Imported %d of %d paragraphs." count total)))))