emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/svg-lib a1bfa49 15/32: Add svg-lib-icons-dir


From: ELPA Syncer
Subject: [elpa] externals/svg-lib a1bfa49 15/32: Add svg-lib-icons-dir
Date: Mon, 27 Sep 2021 16:57:48 -0400 (EDT)

branch: externals/svg-lib
commit a1bfa49a5365605f765bd82c76b15f14b25c5ad8
Author: Damon Chan <damon.chan@freshup.com.hk>
Commit: Damon Chan <damon.chan@freshup.com.hk>

    Add svg-lib-icons-dir
    
    Icons are downloaded to `svg-lib-icons-dir` rather than cache by 
`url-cache`.
    
    Cache by url-cache is not an ideal way for multiple platforms, since the
    md5 of same icon on different platform is different.
    
    This commit is downloading the icons to `svg-lib-icons-dir`.
---
 svg-lib.el | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/svg-lib.el b/svg-lib.el
index 7a06071..682916a 100644
--- a/svg-lib.el
+++ b/svg-lib.el
@@ -103,6 +103,10 @@ collection (there are way too many to store them)."
                 :value-type (string :tag "URL"))
   :group 'svg-lib)
 
+(defcustom svg-lib-icons-dir "~/Downloads"
+  "svg-lib icons directory."
+  :group 'svg-lib
+  :type 'directory)
 
 ;; Default style for all objects
 ;; ---------------------------------------------------------------------
@@ -310,13 +314,16 @@ Cached version is returned if it exists unless 
FORCE-RELOAD is t."
   ;; Build url from collection and name without checking for error
   (let ((url (format (cdr (assoc collection svg-lib-icon-collections)) name)))
     ;; Get data from cache
-    (let ((buffer (if (or force-reload (not (url-is-cached url)))
-                      (let ((url-automatic-caching t)
-                            (filename (url-cache-create-filename url)))
-                        (with-current-buffer (url-retrieve-synchronously url)
-                          (write-region (point-min) (point-max) filename)
-                          (current-buffer)))
-                      (url-fetch-from-cache url))))
+    (let* ((filename (expand-file-name (format "%s_%s.svg" collection name) 
svg-lib-icons-dir))
+           (buffer (if (or force-reload (not (file-exists-p filename)))
+                       (with-current-buffer (url-retrieve-synchronously url)
+                         (goto-char (point-min))
+                         (search-forward "\n\n")
+                         (write-region (point) (point-max) filename)
+                         (current-buffer))
+                     (with-current-buffer (generate-new-buffer " *temp*")
+                       (insert-file-contents filename)
+                       (current-buffer)))))
       (with-current-buffer buffer
         (xml-parse-region (point-min) (point-max))))))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]