]> git.eshelyaron.com Git - emacs.git/commitdiff
image-dired: Improve XDG compliance
authorStefan Kangas <stefan@marxist.se>
Mon, 25 Oct 2021 04:44:30 +0000 (06:44 +0200)
committerStefan Kangas <stefan@marxist.se>
Mon, 25 Oct 2021 05:54:11 +0000 (07:54 +0200)
* lisp/image-dired.el (xdg): Require.
(image-dired-main-image-directory): Prefer XDG_PICTURES_HOME.
(image-dired-thumb-name): Simplify by using 'xdg-cache-home'.

lisp/image-dired.el

index 210361f6038ce6d1ed1a638d48bac0f71b462fe6..77a35900e44fbba57200a3796058f0049ac465a2 100644 (file)
 (require 'exif)
 (require 'image-mode)
 (require 'widget)
+(require 'xdg)
 
 (eval-when-compile
   (require 'cl-lib)
@@ -551,10 +552,12 @@ Including parameters.  Used when displaying original image from
   :type '(choice string
                  (const :tag "Not Set" nil)))
 
-(defcustom image-dired-main-image-directory "~/pics/"
+(defcustom image-dired-main-image-directory
+  (or (xdg-user-dir "PICTURES") "~/pics/")
   "Name of main image directory, if any.
 Used by `image-dired-copy-with-exif-file-name'."
-  :type 'string)
+  :type 'string
+  :version "29.1")
 
 (defcustom image-dired-show-all-from-dir-max-files 100
   "Maximum number of files in directory before prompting.
@@ -647,18 +650,15 @@ file name of the thumbnail will vary:
 See also `image-dired-thumbnail-storage'."
   (cond ((memq image-dired-thumbnail-storage
                image-dired--thumbnail-standard-sizes)
-         (let* ((xdg (getenv "XDG_CACHE_HOME"))
-                (dir (if (and xdg (file-name-absolute-p xdg))
-                         xdg "~/.cache"))
-                (thumbdir (cl-case image-dired-thumbnail-storage
-                            (standard "thumbnails/normal")
-                            (standard-large "thumbnails/large")
-                            (standard-x-large "thumbnails/x-large")
-                            (standard-xx-large "thumbnails/xx-large"))))
+         (let ((thumbdir (cl-case image-dired-thumbnail-storage
+                           (standard "thumbnails/normal")
+                           (standard-large "thumbnails/large")
+                           (standard-x-large "thumbnails/x-large")
+                           (standard-xx-large "thumbnails/xx-large"))))
            (expand-file-name
             ;; MD5 is mandated by the Thumbnail Managing Standard.
             (concat (md5 (concat "file://" (expand-file-name file))) ".png")
-            (expand-file-name thumbdir dir))))
+            (expand-file-name thumbdir (xdg-cache-home)))))
         ((eq 'use-image-dired-dir image-dired-thumbnail-storage)
          (let* ((f (expand-file-name file))
                 (hash