org-persist-register: New optional keyword to force immidiate write
* lisp/org-persist.el: Update commentary. (org-persist-register): Add new keyword `write-immediately' to write the newrly registerd container to disk immediately.
This commit is contained in:
parent
1bc8389871
commit
0526acd16f
|
@ -42,11 +42,9 @@
|
||||||
;; 3. Temporarily cache a file, including TRAMP path to disk:
|
;; 3. Temporarily cache a file, including TRAMP path to disk:
|
||||||
;; (org-persist-write '("file") "/path/to/file")
|
;; (org-persist-write '("file") "/path/to/file")
|
||||||
;; 4. Cache file or URL while some other file exists.
|
;; 4. Cache file or URL while some other file exists.
|
||||||
;; (org-persist-register '("url" "https://static.fsf.org/common/img/logo-new.png") '(:file "/path to the other file") :expiry 'never)
|
;; (org-persist-register '("url" "https://static.fsf.org/common/img/logo-new.png") '(:file "/path to the other file") :expiry 'never :write-immediately t)
|
||||||
;; (org-persist-write '("url" "https://static.fsf.org/common/img/logo-new.png") '(:file "/path to the other file"))
|
|
||||||
;; or, if the other file is current buffer file
|
;; or, if the other file is current buffer file
|
||||||
;; (org-persist-register '("url" "https://static.fsf.org/common/img/logo-new.png") (current-buffer) :expiry 'never)
|
;; (org-persist-register '("url" "https://static.fsf.org/common/img/logo-new.png") (current-buffer) :expiry 'never :write-immediately t)
|
||||||
;; (org-persist-write '("url" "https://static.fsf.org/common/img/logo-new.png") (current-buffer))
|
|
||||||
;; 5. Cache value of a Elisp variable to disk. The value will be
|
;; 5. Cache value of a Elisp variable to disk. The value will be
|
||||||
;; saved and restored automatically (except buffer-local
|
;; saved and restored automatically (except buffer-local
|
||||||
;; variables).
|
;; variables).
|
||||||
|
@ -674,7 +672,11 @@ COLLECTION is the plist holding data collectin."
|
||||||
|
|
||||||
;;;; Public API
|
;;;; Public API
|
||||||
|
|
||||||
(cl-defun org-persist-register (container &optional associated &rest misc &key inherit &key (expiry org-persist-default-expiry) &allow-other-keys)
|
(cl-defun org-persist-register (container &optional associated &rest misc
|
||||||
|
&key inherit
|
||||||
|
&key (expiry org-persist-default-expiry)
|
||||||
|
&key (write-immediately nil)
|
||||||
|
&allow-other-keys)
|
||||||
"Register CONTAINER in ASSOCIATED to be persistent across Emacs sessions.
|
"Register CONTAINER in ASSOCIATED to be persistent across Emacs sessions.
|
||||||
Optional key INHERIT makes CONTAINER dependent on another container.
|
Optional key INHERIT makes CONTAINER dependent on another container.
|
||||||
Such dependency means that data shared between variables will be
|
Such dependency means that data shared between variables will be
|
||||||
|
@ -683,6 +685,8 @@ Optional key EXPIRY will set the expiry condition of the container.
|
||||||
It can be `never', nil - until end of session, a number of days since
|
It can be `never', nil - until end of session, a number of days since
|
||||||
last access, or a function accepting a single argument - collection.
|
last access, or a function accepting a single argument - collection.
|
||||||
EXPIRY key has no effect when INHERIT is non-nil.
|
EXPIRY key has no effect when INHERIT is non-nil.
|
||||||
|
Optional key WRITE-IMMEDIATELY controls whether to save the container
|
||||||
|
data immediately.
|
||||||
MISC will be appended to CONTAINER."
|
MISC will be appended to CONTAINER."
|
||||||
(unless org-persist--index (org-persist--load-index))
|
(unless org-persist--index (org-persist--load-index))
|
||||||
(setq container (org-persist--normalize-container container))
|
(setq container (org-persist--normalize-container container))
|
||||||
|
@ -699,6 +703,7 @@ MISC will be appended to CONTAINER."
|
||||||
(let ((collection (org-persist--get-collection container associated misc)))
|
(let ((collection (org-persist--get-collection container associated misc)))
|
||||||
(when (and expiry (not inherit))
|
(when (and expiry (not inherit))
|
||||||
(when expiry (plist-put collection :expiry expiry))))
|
(when expiry (plist-put collection :expiry expiry))))
|
||||||
|
(when write-immediately (org-persist-write container associated))
|
||||||
(when (or (bufferp associated) (bufferp (plist-get associated :buffer)))
|
(when (or (bufferp associated) (bufferp (plist-get associated :buffer)))
|
||||||
(with-current-buffer (if (bufferp associated)
|
(with-current-buffer (if (bufferp associated)
|
||||||
associated
|
associated
|
||||||
|
|
Loading…
Reference in New Issue