Function: kimport:initialize

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

Signature

(kimport:initialize OUTPUT-TO &optional ERASE-FLAG)

Documentation

Setup to import elements into koutline OUTPUT-TO.

Return OUTPUT-TO buffer and set current buffer for the current command to OUTPUT-TO.

With optional ERASE-FLAG non-nil, erase OUTPUT-TO before importing elements (don't append them).

OUTPUT-TO may be a buffer, buffer-name or file name. If OUTPUT-TO exists already, it must be a koutline or an error will be signaled. For an existing OUTPUT-TO, the text cells are inserted after the cell at point or after the first cell for a newly loaded koutline. If OUTPUT-TO is nil, the current buffer is used.

If OUTPUT-TO is an existing koutline, the first cell imported will be added as the successor of the current cell. If an existing file is read in as OUTPUT-TO within this function, point is left at the end of this buffer so that imported cells will be appended to the buffer. For a new file, this means the first cell imported will become the first outline cell.

If a non-nil third argument, CHILDREN-FLAG, is given to the caller of this function and OUTPUT-TO contains at least one cell, then the imported cells will be added as children of the cell where this function leaves point
(either the current cell or for a newly read in outline, the last cell).

Source Code

;; Defined in ~/.emacs.d/elpa/hyperbole-20260414.325/kotl/kimport.el
(defun kimport:initialize (output-to &optional erase-flag)
  "Setup to import elements into koutline OUTPUT-TO.
Return OUTPUT-TO buffer and set current buffer for the current command
to OUTPUT-TO.

With optional ERASE-FLAG non-nil, erase OUTPUT-TO before importing
elements (don't append them).

OUTPUT-TO may be a buffer, `buffer-name' or file name.  If OUTPUT-TO exists
already, it must be a koutline or an error will be signaled.  For an existing
OUTPUT-TO, the text cells are inserted after the cell at point or after the
first cell for a newly loaded koutline.  If OUTPUT-TO is nil, the current
buffer is used.

If OUTPUT-TO is an existing koutline, the first cell imported will be added
as the successor of the current cell.  If an existing file is read in as
OUTPUT-TO within this function, point is left at the end of this buffer so
that imported cells will be appended to the buffer.  For a new file, this
means the first cell imported will become the first outline cell.

If a non-nil third argument, CHILDREN-FLAG, is given to the caller of this
function and OUTPUT-TO contains at least one cell, then the imported cells
will be added as children of the cell where this function leaves point
\(either the current cell or for a newly read in outline, the last cell)."
  (let* ((output-existing-buffer-p
	  (when output-to
	    (or (get-buffer output-to) (get-file-buffer output-to))))
	 (output-exists-p
	  (if output-to
	      (or output-existing-buffer-p (file-exists-p output-to))
	    ;; current buffer will be used for output and it exists.
	    t)))
    (setq output-to (if output-to
			(or (get-buffer output-to)
			    (find-file-noselect output-to))
		      (current-buffer)))
    (set-buffer output-to)
    (if (and output-exists-p (not erase-flag))
	(if (eq major-mode 'kotl-mode)
	    (unless (kotl-mode:buffer-empty-p)
	      ;; Make imported cells be appended if the output buffer was
	      ;; just read in.
	      (unless output-existing-buffer-p
		(goto-char (point-max)))
	      (kotl-mode:to-valid-position))
	  (error
	   "(kimport:initialize): Second arg, %s, must be a koutline file"
	   (buffer-name output-to)))
      (when erase-flag
	(widen)
	(delete-region (point-min) (point-max)))
      (unless (kfile:is-p)
	(setq kotl-kview nil)
	(kotl-mode))))
  output-to)