Function: org-persist--normalize-associated
org-persist--normalize-associated is a byte-compiled function defined
in org-persist.el.gz.
Signature
(org-persist--normalize-associated ASSOCIATED)
Documentation
Normalize ASSOCIATED representation into (:type value).
Source Code
;; Defined in /usr/src/emacs/lisp/org/org-persist.el.gz
(defun org-persist--normalize-associated (associated)
"Normalize ASSOCIATED representation into (:type value)."
(pcase associated
((or (pred stringp) `(:file ,_))
(unless (stringp associated)
(setq associated (cadr associated)))
(let* ((rtn `(:file ,associated))
(inode (and
;; Do not store :inode for remote files - it may
;; be time-consuming on slow connections or even
;; fail completely when ssh connection is closed.
(not (file-remote-p associated))
(fboundp 'file-attribute-inode-number)
(file-attribute-inode-number
(file-attributes associated)))))
(when inode (plist-put rtn :inode inode))
rtn))
((or (pred bufferp) `(:buffer ,_))
(unless (bufferp associated)
(setq associated (cadr associated)))
(let ((cached (gethash associated org-persist--associated-buffer-cache))
file inode hash)
(if (and cached (eq (buffer-modified-tick associated)
(car cached)))
(progn
(setq file (nth 1 cached)
inode (nth 2 cached)
hash (nth 3 cached)))
(setq file (buffer-file-name
(or (buffer-base-buffer associated)
associated)))
(setq inode (when (and file
;; Do not store :inode for remote files - it may
;; be time-consuming on slow connections or even
;; fail completely when ssh connection is closed.
(not (file-remote-p file))
(fboundp 'file-attribute-inode-number))
(file-attribute-inode-number
(file-attributes file))))
(setq hash (secure-hash 'md5 associated))
(puthash associated
(list (buffer-modified-tick associated)
file inode hash)
org-persist--associated-buffer-cache))
(let ((rtn `(:hash ,hash)))
(when file (setq rtn (plist-put rtn :file file)))
(when inode (setq rtn (plist-put rtn :inode inode)))
rtn)))
((pred listp)
associated)
(_ (error "Unknown associated object %S" associated))))