Function: org-persist-register

org-persist-register is a byte-compiled function defined in org-persist.el.gz.

Signature

(org-persist-register CONTAINER &optional ASSOCIATED &rest MISC &key INHERIT &key (EXPIRY org-persist-default-expiry) &key (WRITE-IMMEDIATELY nil) &allow-other-keys)

Documentation

Register CONTAINER in ASSOCIATED to be persistent across Emacs sessions.

Optional key INHERIT makes CONTAINER dependent on another container. Such dependency means that data shared between variables will be preserved (see elisp#Circular Objects). 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 last access, or a function accepting a single argument - collection. 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 the collection. It must be alternating :KEY VALUE pairs. When WRITE-IMMEDIATELY is non-nil, the return value will be the same with org-persist-write.

Source Code

;; Defined in /usr/src/emacs/lisp/org/org-persist.el.gz
;;;; Public API

(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.
Optional key INHERIT makes CONTAINER dependent on another container.
Such dependency means that data shared between variables will be
preserved (see elisp#Circular Objects).
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
last access, or a function accepting a single argument - collection.
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 the collection.  It must be alternating :KEY
VALUE pairs.
When WRITE-IMMEDIATELY is non-nil, the return value will be the same
with `org-persist-write'."
  (unless org-persist--index (org-persist--load-index))
  (setq container (org-persist--normalize-container container))
  (when inherit
    (setq inherit (org-persist--normalize-container inherit))
    (let ((inherited-collection (org-persist--get-collection inherit associated))
          new-collection)
      (unless (member container (plist-get inherited-collection :container))
        (setq new-collection
              (plist-put (copy-sequence inherited-collection) :container
                         (cons container (plist-get inherited-collection :container))))
        (org-persist--remove-from-index inherited-collection)
        (org-persist--add-to-index new-collection))))
  (let ((collection (org-persist--get-collection container associated misc)))
    (when (and expiry (not inherit))
      (when expiry (plist-put collection :expiry expiry))))
  (when (or (bufferp associated) (bufferp (plist-get associated :buffer)))
    (with-current-buffer (if (bufferp associated)
                             associated
                           (plist-get associated :buffer))
      (add-hook 'kill-buffer-hook #'org-persist-write-all-buffer nil 'local)))
  (when write-immediately (org-persist-write container associated)))