Function: kimport:copy-and-set-buffer

kimport:copy-and-set-buffer is an autoloaded and byte-compiled function defined in kimport.el.

Signature

(kimport:copy-and-set-buffer SOURCE)

Documentation

Copy and untabify SOURCE.

Set copy buffer as current buffer for this command and return the copy buffer. SOURCE may be a buffer name, a buffer or a file name. If SOURCE buffer name begins with a space, it is not copied under the assumption that it already has been. If SOURCE is a koutline, it is not copied since there is no need to copy it to import it.

Source Code

;; Defined in ~/.emacs.d/elpa/hyperbole-20260414.325/kotl/kimport.el
;;;###autoload
(defun kimport:copy-and-set-buffer (source)
  "Copy and untabify SOURCE.
Set copy buffer as current buffer for this command and return the
copy buffer.  SOURCE may be a buffer name, a buffer or a file
name.  If SOURCE buffer name begins with a space, it is not
copied under the assumption that it already has been.  If SOURCE
is a koutline, it is not copied since there is no need to copy it
to import it."
  (setq source (set-buffer (or (get-buffer source)
			       (find-file-noselect source))))
  (let ((mode (or (if (boundp 'kotl-previous-mode) kotl-previous-mode)
		  major-mode))
	copy)
    (if (or (eq mode 'kotl-mode)
	    (eq ?\ (aref (buffer-name source) 0)))
	source
      ;; This buffer name format is used so that we can easily
      ;; extract any file name suffix from the buffer name.
      (setq copy (get-buffer-create
		  (concat " " (if (string-match ".+[|<]" (buffer-name))
				  (substring (buffer-name)
					     0 (1- (match-end 0)))
				(buffer-name)))))
      (set-buffer copy)
      ;; fundamental-mode can have an unusable value of paragraph-start so
      ;; use text-mode in such instances instead.
      (if (eq mode 'fundamental-mode)
	  (text-mode)
	(funcall mode))
      (setq buffer-read-only nil)
      (erase-buffer)
      (insert-buffer-substring source)
      (untabify (point-min) (point-max))
      ;; Ensure buffer ends with a newline so that we don't miss the last
      ;; element during the import.
      (goto-char (point-max))
      (unless (eq (preceding-char) ?\n)
	(insert "\n"))
      (set-buffer-modified-p nil)
      copy)))