[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/org ec787fb218 19/31: org-persist: Implement "file" and
From: |
ELPA Syncer |
Subject: |
[elpa] externals/org ec787fb218 19/31: org-persist: Implement "file" and "url" containers linked to other file |
Date: |
Sat, 29 Jan 2022 04:58:10 -0500 (EST) |
branch: externals/org
commit ec787fb218dab5eb30e8f004638078c70d5846b0
Author: Ihor Radchenko <yantar92@gmail.com>
Commit: Ihor Radchenko <yantar92@gmail.com>
org-persist: Implement "file" and "url" containers linked to other file
* lisp/org-persist.el: Update commentary.
(org-persist--storage-version): Bump storage version.
(org-persist-write:file):
(org-persist-write:url): Support optional container setting.
---
lisp/org-persist.el | 41 ++++++++++++++++++++++++++---------------
1 file changed, 26 insertions(+), 15 deletions(-)
diff --git a/lisp/org-persist.el b/lisp/org-persist.el
index f80a8e2c18..98d2f11afb 100644
--- a/lisp/org-persist.el
+++ b/lisp/org-persist.el
@@ -41,7 +41,13 @@
;; has been removed.
;; 3. Temporarily cache a file, including TRAMP path to disk:
;; (org-persist-write '("file") "/path/to/file")
-;; 4. Cache value of a Elisp variable to disk. The value will be
+;; 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-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
+;; (org-persist-register '("url"
"https://static.fsf.org/common/img/logo-new.png") (current-buffer) :expiry
'never)
+;; (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
;; saved and restored automatically (except buffer-local
;; variables).
;; ;; Until `org-persist-default-expiry'
@@ -54,11 +60,11 @@
;; ;; Save buffer-local variable preserving circular links:
;; (org-persist-register 'org-element--headline-cache (current-buffer)
;; :inherit 'org-element--cache)
-;; 5. Load variable by side effects assigning variable symbol:
+;; 6. Load variable by side effects assigning variable symbol:
;; (org-persist-load 'variable-symbol (current-buffer))
-;; 6. Version variable value:
+;; 7. Version variable value:
;; (org-persist-register '(("elisp" variable-symbol) (version "2.0")))
-;; 7. Cancel variable persistence:
+;; 8. Cancel variable persistence:
;; (org-persist-unregister 'variable-symbol 'all) ; in all buffers
;; (org-persist-unregister 'variable-symbol) ;; global variable
;; (org-persist-unregister 'variable-symbol (current-buffer)) ;;
buffer-local
@@ -120,6 +126,7 @@
;; elisp variable data.
;; 2. ("file") :: Store a copy of the associated file preserving the
;; extension.
+;; ("file" "/path/to/a/file") :: Store a copy of the file in path.
;; 3. ("version" "version number") :: Version the data collection.
;; If the stored collection has different version than "version
;; number", disregard it.
@@ -153,7 +160,7 @@
(declare-function org-at-heading-p "org" (&optional invisible-not-ok))
-(defconst org-persist--storage-version "2.2"
+(defconst org-persist--storage-version "2.3"
"Persistent storage layout version.")
(defgroup org-persist nil
@@ -603,35 +610,39 @@ COLLECTION is the plist holding data collectin."
(defalias 'org-persist-write:version #'ignore)
-(defun org-persist-write:file (_ collection)
- "Write file container according to COLLECTION."
+(defun org-persist-write:file (c collection)
+ "Write file container C according to COLLECTION."
(org-persist-collection-let collection
- (when (and path (file-exists-p path))
+ (when (or (and path (file-exists-p path))
+ (and (stringp (cadr c)) (file-exists-p (cadr c))))
+ (when (and (stringp (cadr c)) (file-exists-p (cadr c)))
+ (setq path (cadr c)))
(let* ((persist-file (plist-get collection :persist-file))
(ext (file-name-extension path))
(file-copy (org-file-name-concat
org-persist-directory
- (format "%s-file.%s" persist-file ext))))
+ (format "%s-%s.%s" persist-file (md5 path) ext))))
(unless (file-exists-p (file-name-directory file-copy))
(make-directory (file-name-directory file-copy) t))
(unless (file-exists-p file-copy)
(copy-file path file-copy 'overwrite))
- (format "%s-file.%s" persist-file ext)))))
+ (format "%s-%s.%s" persist-file (md5 path) ext)))))
-(defun org-persist-write:url (_ collection)
- "Write url container according to COLLECTION."
+(defun org-persist-write:url (c collection)
+ "Write url container C according to COLLECTION."
(org-persist-collection-let collection
- (when path
+ (when (or path (cadr c))
+ (when (cadr c) (setq path (cadr c)))
(let* ((persist-file (plist-get collection :persist-file))
(ext (file-name-extension path))
(file-copy (org-file-name-concat
org-persist-directory
- (format "%s-file.%s" persist-file ext))))
+ (format "%s-%s.%s" persist-file (md5 path) ext))))
(unless (file-exists-p (file-name-directory file-copy))
(make-directory (file-name-directory file-copy) t))
(unless (file-exists-p file-copy)
(url-copy-file path file-copy 'overwrite))
- (format "%s-file.%s" persist-file ext)))))
+ (format "%s-%s.%s" persist-file (md5 path) ext)))))
(defun org-persist-write:index (container _)
"Write index CONTAINER."
- [elpa] externals/org dc52c0fe99 17/31: Fix native-comp warnings, (continued)
- [elpa] externals/org dc52c0fe99 17/31: Fix native-comp warnings, ELPA Syncer, 2022/01/29
- [elpa] externals/org f3bd1dcb77 20/31: org-persist: Fix compiler warnings, ELPA Syncer, 2022/01/29
- [elpa] externals/org 1bc8389871 21/31: org-persist-read: Check expiry, ELPA Syncer, 2022/01/29
- [elpa] externals/org 6b175fb227 27/31: org-persist-register: Make return value meaningful with :write-immidiately, ELPA Syncer, 2022/01/29
- [elpa] externals/org f0e0716f54 28/31: org-element: Use new cache container format, ELPA Syncer, 2022/01/29
- [elpa] externals/org 19a383d9f4 29/31: org-persist-write-all: Speed up writing, ELPA Syncer, 2022/01/29
- [elpa] externals/org ac5742f296 31/31: Merge branch 'feature/org-persist-new-tidy', ELPA Syncer, 2022/01/29
- [elpa] externals/org 38a681fdae 05/31: org-element-cache-reset: Do not persist caches for non-file buffers, ELPA Syncer, 2022/01/29
- [elpa] externals/org 8821ff5811 09/31: org-persist-read: Do not try to read non-existing containers, ELPA Syncer, 2022/01/29
- [elpa] externals/org 4ec57a9453 16/31: org-persist: Update commentary, ELPA Syncer, 2022/01/29
- [elpa] externals/org ec787fb218 19/31: org-persist: Implement "file" and "url" containers linked to other file,
ELPA Syncer <=
- [elpa] externals/org 6a5874bb26 25/31: org-persist-write: Overwrite existing copy if write is requested, ELPA Syncer, 2022/01/29
- [elpa] externals/org 0e18c617cf 24/31: org-persist-write:index: Return index path on write, ELPA Syncer, 2022/01/29
- [elpa] externals/org eca678195b 23/31: org-persist-write: Return the written value on success, ELPA Syncer, 2022/01/29
- [elpa] externals/org 0526acd16f 22/31: org-persist-register: New optional keyword to force immidiate write, ELPA Syncer, 2022/01/29
- [elpa] externals/org caccec2c54 26/31: org-persist: Use symbols as container names, ELPA Syncer, 2022/01/29
- [elpa] externals/org 7014675226 30/31: org-mode: Fix cache loading order, ELPA Syncer, 2022/01/29
- [elpa] externals/org 1c79af13df 04/31: org-persist-gc: Fix when expiry is days and data is freshly created, ELPA Syncer, 2022/01/29