Function: org-persist-write

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

Signature

(org-persist-write CONTAINER &optional ASSOCIATED IGNORE-RETURN)

Documentation

Save CONTAINER according to ASSOCIATED.

ASSOCIATED can be a plist, a buffer, or a string. A buffer is treated as (:buffer ASSOCIATED). A string is treated as (:file ASSOCIATED). The return value is nil when writing fails and the written value (as returned by org-persist-read) on success. When IGNORE-RETURN is non-nil, just return t on success without calling org-persist-read.

Source Code

;; Defined in /usr/src/emacs/lisp/org/org-persist.el.gz
(defun org-persist-write (container &optional associated ignore-return)
  "Save CONTAINER according to ASSOCIATED.
ASSOCIATED can be a plist, a buffer, or a string.
A buffer is treated as (:buffer ASSOCIATED).
A string is treated as (:file ASSOCIATED).
The return value is nil when writing fails and the written value (as
returned by `org-persist-read') on success.
When IGNORE-RETURN is non-nil, just return t on success without calling
`org-persist-read'."
  (setq associated (org-persist--normalize-associated associated))
  ;; Update hash
  (when (and (plist-get associated :file)
             (plist-get associated :hash)
             (get-file-buffer (plist-get associated :file)))
    (setq associated (org-persist--normalize-associated (get-file-buffer (plist-get associated :file)))))
  (let ((collection (org-persist--get-collection container associated)))
    (setf collection (plist-put collection :associated associated))
    (unless (or
             ;; Prevent data leakage from encrypted files.
             ;; We do it in somewhat paranoid manner and do not
             ;; allow anything related to encrypted files to be
             ;; written.
             (and (plist-get associated :file)
                  (string-match-p epa-file-name-regexp (plist-get associated :file)))
             (seq-find (lambda (v)
                         (run-hook-with-args-until-success 'org-persist-before-write-hook v associated))
                       (plist-get collection :container)))
      (when (or (file-exists-p org-persist-directory) (org-persist--save-index))
        (let ((file (org-file-name-concat org-persist-directory (plist-get collection :persist-file)))
              (data (mapcar (lambda (c) (cons c (org-persist-write:generic c collection)))
                            (plist-get collection :container))))
          (puthash file data org-persist--write-cache)
          (org-persist--write-elisp-file file data)
          (or ignore-return (org-persist-read container associated)))))))