Fix string type error from doom-store API
Do to nil location.
This commit is contained in:
parent
a13639bde0
commit
ce22f75a57
1 changed files with 36 additions and 36 deletions
|
@ -38,13 +38,14 @@ name under `pcache-directory' (by default a subdirectory under
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
;; Library
|
;;; Library
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom-store-persist (location variables)
|
(defun doom-store-persist (location variables)
|
||||||
"Persist VARIABLES (list of symbols) in LOCATION (symbol).
|
"Persist VARIABLES (list of symbols) in LOCATION (symbol).
|
||||||
This populates these variables with cached values, if one exists, and saves them
|
This populates these variables with cached values, if one exists, and saves them
|
||||||
to file when Emacs quits. This cannot persist buffer-local variables."
|
to file when Emacs quits. This cannot persist buffer-local variables."
|
||||||
|
(cl-check-type location string)
|
||||||
(dolist (var variables)
|
(dolist (var variables)
|
||||||
(when (doom-store-member-p var location)
|
(when (doom-store-member-p var location)
|
||||||
(set var (doom-store-get var location))))
|
(set var (doom-store-get var location))))
|
||||||
|
@ -56,27 +57,29 @@ to file when Emacs quits. This cannot persist buffer-local variables."
|
||||||
"Unregisters VARIABLES (list of symbols) in LOCATION (symbol).
|
"Unregisters VARIABLES (list of symbols) in LOCATION (symbol).
|
||||||
Variables to persist are recorded in `doom-store-persist-alist'. Does not affect
|
Variables to persist are recorded in `doom-store-persist-alist'. Does not affect
|
||||||
the actual variables themselves or their values."
|
the actual variables themselves or their values."
|
||||||
|
(cl-check-type location string)
|
||||||
(if variables
|
(if variables
|
||||||
(setf (alist-get location doom-store-persist-alist)
|
(setf (alist-get location doom-store-persist-alist)
|
||||||
(cl-set-difference (cdr (assq location doom-store-persist-alist))
|
(cl-set-difference (cdr (assq location doom-store-persist-alist))
|
||||||
variables))
|
variables))
|
||||||
(delq! location doom-store-persist-alist 'assoc)))
|
(delq! location doom-store-persist-alist 'assoc)))
|
||||||
|
|
||||||
(defun doom--store-init (location)
|
(defun doom--store-init (&optional location)
|
||||||
(cl-check-type location (or null string))
|
(cl-check-type location (or null string))
|
||||||
(or (gethash location doom--store-table)
|
(let ((location (or location doom-store-location)))
|
||||||
(let* ((file-name-handler-alist nil)
|
(or (gethash location doom--store-table)
|
||||||
(location-path (expand-file-name location doom-store-dir)))
|
(let* ((file-name-handler-alist nil)
|
||||||
(if (file-exists-p location-path)
|
(location-path (expand-file-name location doom-store-dir)))
|
||||||
(puthash location
|
(if (file-exists-p location-path)
|
||||||
(with-temp-buffer
|
(puthash location
|
||||||
(set-buffer-multibyte nil)
|
(with-temp-buffer
|
||||||
(setq buffer-file-coding-system 'binary)
|
(set-buffer-multibyte nil)
|
||||||
(insert-file-contents-literally location-path)
|
(setq buffer-file-coding-system 'binary)
|
||||||
(read (current-buffer)))
|
(insert-file-contents-literally location-path)
|
||||||
doom--store-table)
|
(read (current-buffer)))
|
||||||
(puthash location (make-hash-table :test 'equal)
|
doom--store-table)
|
||||||
doom--store-table)))))
|
(puthash location (make-hash-table :test 'equal)
|
||||||
|
doom--store-table))))))
|
||||||
|
|
||||||
(defun doom--store-expired-p (key data)
|
(defun doom--store-expired-p (key data)
|
||||||
(let ((ttl (car data)))
|
(let ((ttl (car data)))
|
||||||
|
@ -90,20 +93,20 @@ the actual variables themselves or their values."
|
||||||
(let ((file-name-handler-alist nil)
|
(let ((file-name-handler-alist nil)
|
||||||
(coding-system-for-write 'binary)
|
(coding-system-for-write 'binary)
|
||||||
(write-region-annotate-functions nil)
|
(write-region-annotate-functions nil)
|
||||||
(write-region-post-annotation-function nil)
|
(write-region-post-annotation-function nil))
|
||||||
(data (doom--store-init location)))
|
(let* ((location (or location doom-store-location))
|
||||||
(make-directory doom-store-dir 'parents)
|
(data (doom--store-init location)))
|
||||||
(with-temp-file (expand-file-name location doom-store-dir)
|
(make-directory doom-store-dir 'parents)
|
||||||
(prin1 data (current-buffer)))
|
(with-temp-file (expand-file-name location doom-store-dir)
|
||||||
data))
|
(prin1 data (current-buffer)))
|
||||||
|
data)))
|
||||||
|
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom-store-get (key &optional location default-value noflush)
|
(defun doom-store-get (key &optional location default-value noflush)
|
||||||
"Retrieve KEY from LOCATION (defaults to `doom-store-location').
|
"Retrieve KEY from LOCATION (defaults to `doom-store-location').
|
||||||
If it doesn't exist or has expired, DEFAULT_VALUE is returned."
|
If it doesn't exist or has expired, DEFAULT_VALUE is returned."
|
||||||
(let ((location (or location doom-store-location))
|
(let ((data (gethash key (doom--store-init location) default-value)))
|
||||||
(data (gethash key (doom--store-init location) default-value)))
|
|
||||||
(if (not (or (eq data default-value)
|
(if (not (or (eq data default-value)
|
||||||
(doom--store-expired-p key data)))
|
(doom--store-expired-p key data)))
|
||||||
(cdr data)
|
(cdr data)
|
||||||
|
@ -118,22 +121,20 @@ KEY can be any lisp object that is comparable with `equal'. TTL is the duration
|
||||||
LOCATION is the super-key to store this cache item under. It defaults to
|
LOCATION is the super-key to store this cache item under. It defaults to
|
||||||
`doom-store-location'."
|
`doom-store-location'."
|
||||||
(cl-check-type ttl (or null integer function))
|
(cl-check-type ttl (or null integer function))
|
||||||
(let ((location (or location doom-store-location)))
|
(puthash key (cons (if (integerp ttl)
|
||||||
(puthash key (cons (if (integerp ttl)
|
(time-add (current-time) ttl)
|
||||||
(time-add (current-time) ttl)
|
ttl)
|
||||||
ttl)
|
value)
|
||||||
value)
|
(doom--store-init location))
|
||||||
(doom--store-init location))
|
(unless noflush
|
||||||
(unless noflush
|
(doom--store-flush location)))
|
||||||
(doom--store-flush location))))
|
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom-store-rem (key &optional location noflush)
|
(defun doom-store-rem (key &optional location noflush)
|
||||||
"Clear a cache LOCATION (defaults to `doom-store-location')."
|
"Clear a cache LOCATION (defaults to `doom-store-location')."
|
||||||
(let ((location (or location doom-store-location)))
|
(remhash key (doom--store-init location))
|
||||||
(remhash key (doom--store-init location))
|
(unless noflush
|
||||||
(unless noflush
|
(doom--store-flush location)))
|
||||||
(doom--store-flush location))))
|
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom-store-member-p (key &optional location)
|
(defun doom-store-member-p (key &optional location)
|
||||||
|
@ -146,7 +147,6 @@ LOCATION defaults to `doom-store-location'."
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom-store-clear (&optional location)
|
(defun doom-store-clear (&optional location)
|
||||||
"Clear the store at LOCATION (defaults to `doom-store-location')."
|
"Clear the store at LOCATION (defaults to `doom-store-location')."
|
||||||
(cl-check-type location (or null string))
|
|
||||||
(let* ((location (or location doom-store-location))
|
(let* ((location (or location doom-store-location))
|
||||||
(path (expand-file-name location doom-store-dir)))
|
(path (expand-file-name location doom-store-dir)))
|
||||||
(remhash location doom--store-table)
|
(remhash location doom--store-table)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue