Function: hywiki-cache-save

hywiki-cache-save is a byte-compiled function defined in hywiki.el.

Signature

(hywiki-cache-save &optional SAVE-FILE)

Documentation

Save hywiki-directory lookup data to a file.

The file is given by optional SAVE-FILE or hywiki-cache-file. Also save and potentially set hywiki--directory-mod-time and hywiki--directory-checksum.

Source Code

;; Defined in ~/.emacs.d/elpa/hyperbole-20261030.2317/hywiki.el
(defun hywiki-cache-save (&optional save-file)
  "Save `hywiki-directory' lookup data to a file.
The file is given by optional SAVE-FILE or `hywiki-cache-file'.  Also
save and potentially set `hywiki--directory-mod-time' and
`hywiki--directory-checksum'."
  (when (or (not (stringp save-file)) (equal save-file ""))
    (setq save-file (hywiki-cache-default-file)))
  (setq save-file (expand-file-name save-file hywiki-directory))
  (unless (file-writable-p save-file)
    (error "(hywiki-cache-save): Non-writable Environment file, \"%s\"" save-file))
  (let ((buf (get-file-buffer save-file)))
    (when buf
      (if (buffer-modified-p buf)
          (with-current-buffer buf
	    (hypb:save-buffer-silently))
	;; (error "(hywiki-cache-save): HyWiki cache file failed to save: \"%s\"" save-file)
	(kill-buffer buf))))
  (let ((dir (or (file-name-directory save-file)
		 default-directory)))
    (unless (file-writable-p dir)
      (error "(hywiki-cache-save): Non-writable Environment directory, \"%s\"" dir)))
  (save-excursion
    (let ((output-buffer (hywiki-cache-edit save-file))
          marker
          standard-output)
      (with-current-buffer output-buffer
        ;; Need to use a marker here or point will not always advance
        ;; after the print calls
        (unwind-protect
            (progn (setq marker (copy-marker (point) t)
                         standard-output marker)
                   (set-marker-insertion-type standard-output t)
                   (erase-buffer)
                   (princ ";; -*- mode:lisp-data; coding: utf-8-emacs; -*-\n")

                   ;; Save these next two values only as comments for reference.
                   ;; Otherwise, they would improperly override the current values.
                   ;; -- RSW 2026-10-19
                   (terpri)
                   (princ (format ";; hyperb:version: %S\n" hyperb:version))
                   (princ (format ";; hywiki-directory: %S\n" hywiki-directory))

                   ;; Save last `hywiki-directory' mod time and checksum, nil if none.
                   (princ (format "\n(setq\nhywiki--directory-mod-time '%S\n"
                                  (hywiki-directory-set-mod-time)))

                   (princ (format "\nhywiki--directory-checksum %S\n"
                                  (hywiki-directory-set-checksum)))

                   (princ "\nhywiki--referent-alist\n'")
                   (hash-prin1 (hywiki-get-referent-hasht) nil t)
                   (princ ")\n")

                   (hypb:save-buffer-silently))
          (set-marker marker nil)
	  (if (buffer-modified-p)
	      (error "(hywiki-cache-save): HyWiki cache file failed to save: \"%s\"" save-file)
	    (kill-buffer output-buffer))
          save-file)))))