Function: kfile:create
kfile:create is a byte-compiled function defined in kfile.el.
Signature
(kfile:create BUFFER)
Documentation
Create a new koutline file attached to BUFFER and return file's kview.
File is created with a single empty level 1 kotl cell.
Source Code
;; Defined in ~/.emacs.d/elpa/hyperbole-20260414.325/kotl/kfile.el
;;; ************************************************************************
;;; Public functions
;;; ************************************************************************
(defun kfile:create (buffer)
"Create a new koutline file attached to BUFFER and return file's kview.
File is created with a single empty level 1 kotl cell."
(or buffer (setq buffer (current-buffer)))
(unless (bufferp buffer)
(error "(kfile:create): Invalid buffer argument, %s" buffer))
(set-buffer buffer)
(barf-if-buffer-read-only)
(widen)
(let ((empty-flag (zerop (buffer-size)))
import-from view standard-output)
(unless empty-flag
;; This is a foreign file whose elements must be converted into
;; koutline cells.
(setq import-from (kimport:copy-and-set-buffer buffer))
(set-buffer buffer)
(erase-buffer)) ;; We copied the contents to `import-from'.
(setq view (kview:create (buffer-name buffer))
standard-output (current-buffer))
(goto-char (point-min))
(princ ";; -*- Mode: kotl -*- \n")
(prin1 kfile:version)
(princ " ;; file-format\n\^_\n")
(goto-char (point-max))
(princ "\^_\n")
(princ "\^_\n;; depth-first kcell attributes\n")
;; Ensure that display is narrowed to cell region only.
(kfile:narrow-to-kcells)
(goto-char (point-min))
(if empty-flag
;; This is a new koutline file. Always need at least one visible
;; cell within a view. Insert initial empty cell.
;; Ensure that last cell has two newlines after it so that
;; kfile:insert-attributes finds it.
(progn (kview:add-cell "1" 1)
;; Mark view unmodified, so if kill right away, there is no
;; prompt.
(set-buffer-modified-p nil)
;; Move to first cell.
(goto-char (point-min))
(goto-char (kcell-view:start)))
;; Import buffer. Next line is necessary or the importation will fail.
(delete-region (point-min) (point-max))
;; Import foreign buffer as koutline cells.
(kimport:file import-from (current-buffer))
;; If import buffer name starts with a space, kill it, as it is no
;; longer needed.
(when (eq ?\ (aref (buffer-name import-from) 0))
(kill-buffer import-from)))
view))