]> git.eshelyaron.com Git - emacs.git/commitdiff
Make `image-dired-thumb-(height|width)' obsolete
authorStefan Kangas <stefankangas@gmail.com>
Sat, 17 Sep 2022 19:27:38 +0000 (21:27 +0200)
committerStefan Kangas <stefankangas@gmail.com>
Sat, 17 Sep 2022 22:18:22 +0000 (00:18 +0200)
* lisp/image/image-dired.el (image-dired-thumb-width)
(image-dired-thumb-height): Make obsolete.
(image-dired-thumb-size): Clean up and improve docstring.
* lisp/image/image-dired-external.el (image-dired-thumb-size): Use
'image-dired-thumb-size' instead of above obsolete variables.
(image-dired-create-thumb-1): Support %s format specifier for size.
(image-dired-cmd-create-thumbnail-options): Document %s format
specifier.
(image-dired--thumb-size): Rename function from
'image-dired-thumb-size' and make old name into an obsolete alias.
Update all callers.

etc/NEWS
lisp/image/image-dired-external.el
lisp/image/image-dired.el

index cd14bcf69b5045a50162ebd89b6b416079170676..8382d171cadaf11a7c0e6dffee2aba25dcbaddb6 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2117,6 +2117,11 @@ thumbnails in the background in recent versions, this is not as
 important as it used to be.  You can now also customize this option to
 nil to disable this confirmation completely.
 
+---
+*** 'image-dired-thumb-(height|width)' are now obsolete.
+Customize 'image-dired-thumb-size' instead, which will set both the
+height and width.
+
 ---
 *** HTML image gallery generation is now obsolete.
 The 'image-dired-gallery-generate' command and these user options are
index 1fd3a5806cae3562b551a46db1ecaa4ab67b0681..4e38d14c8674fb0677b0a64f8cb04c1763d40638 100644 (file)
@@ -38,8 +38,6 @@
 (defvar image-dired-dir)
 (defvar image-dired-main-image-directory)
 (defvar image-dired-rotate-original-ask-before-overwrite)
-(defvar image-dired-thumb-height)
-(defvar image-dired-thumb-width)
 (defvar image-dired-thumbnail-storage)
 
 (defgroup image-dired-external nil
@@ -62,12 +60,12 @@ Used together with `image-dired-cmd-create-thumbnail-options'."
     (if (executable-find "gm") (cons "convert" opts) opts))
   "Options of command used to create thumbnail image.
 Used with `image-dired-cmd-create-thumbnail-program'.
-Available format specifiers are: %w which is replaced by
-`image-dired-thumb-width', %h which is replaced by `image-dired-thumb-height',
-%f which is replaced by the file name of the original image and %t
-which is replaced by the file name of the thumbnail file."
-  :version "29.1"
-  :type '(repeat (string :tag "Argument")))
+Available format specifiers are:
+    %s, %w and %h, which are replaced by `image-dired-thumb-size'
+    %f which is replaced by the file name of the original image and
+    %t which is replaced by the file name of the thumbnail file."
+  :type '(repeat (string :tag "Argument"))
+  :version "29.1")
 
 (defcustom image-dired-cmd-pngnq-program
   ;; Prefer pngquant to pngnq-s9 as it is faster on my machine.
@@ -193,17 +191,15 @@ which is replaced by the tag value."
 \f
 ;;; Creating thumbnails
 
-(defun image-dired-thumb-size (dimension)
-  "Return thumb size depending on `image-dired-thumbnail-storage'.
-DIMENSION should be either the symbol `width' or `height'."
-  (cond
-   ((eq 'standard image-dired-thumbnail-storage) 128)
-   ((eq 'standard-large image-dired-thumbnail-storage) 256)
-   ((eq 'standard-x-large image-dired-thumbnail-storage) 512)
-   ((eq 'standard-xx-large image-dired-thumbnail-storage) 1024)
-   (t (cl-ecase dimension
-        (width image-dired-thumb-width)
-        (height image-dired-thumb-height)))))
+(defun image-dired--thumb-size (&optional _)
+  "Return thumb size depending on `image-dired-thumbnail-storage'."
+  (declare (advertised-calling-convention () "29.1"))
+  (pcase image-dired-thumbnail-storage
+    ('standard 128)
+    ('standard-large 256)
+    ('standard-x-large 512)
+    ('standard-xx-large 1024)
+    (_ image-dired-thumb-size)))
 
 (defvar image-dired--generate-thumbs-start nil
   "Time when `display-thumbs' was called.")
@@ -289,21 +285,17 @@ and remove the cached thumbnail files between each trial run.")
   "For ORIGINAL-FILE, create thumbnail image named THUMBNAIL-FILE."
   (image-dired--check-executable-exists
    'image-dired-cmd-create-thumbnail-program)
-  (let* ((width (int-to-string (image-dired-thumb-size 'width)))
-         (height (int-to-string (image-dired-thumb-size 'height)))
+  (let* ((size (number-to-string (image-dired--thumb-size)))
          (modif-time (format-time-string
                       "%s" (file-attribute-modification-time
                             (file-attributes original-file))))
          (thumbnail-nq8-file (replace-regexp-in-string ".png\\'" "-nq8.png"
                                                        thumbnail-file))
-         (spec
-          (list
-           (cons ?w width)
-           (cons ?h height)
-           (cons ?m modif-time)
-           (cons ?f original-file)
-           (cons ?q thumbnail-nq8-file)
-           (cons ?t thumbnail-file)))
+         (spec `((?s ,size) (?w ,size) (?h ,size)
+                 (?m ,modif-time)
+                 (?f ,original-file)
+                 (?q ,thumbnail-nq8-file)
+                 (?t ,thumbnail-file)))
          (thumbnail-dir (file-name-directory thumbnail-file))
          process)
     (when (not (file-exists-p thumbnail-dir))
@@ -469,6 +461,8 @@ default value at the prompt."
            (mapcar (lambda (arg) (format-spec arg spec))
                    image-dired-cmd-write-exif-data-options))))
 
+(define-obsolete-function-alias 'image-dired-thumb-size #'image-dired--thumb-size "29.1")
+
 (provide 'image-dired-external)
 
 ;; Local Variables:
index 3bfb388db3cfca8b7b6fab944f2c6fdaa4ff93dc..33f10bdbb730cc73a3acd4fad19dda84b17c2546 100644 (file)
@@ -224,28 +224,20 @@ If non-nil, ask user for confirmation before overwriting the
 original file with `image-dired-temp-rotate-image-file'."
   :type 'boolean)
 
-(defcustom image-dired-thumb-size
-  (cond
-   ((eq 'standard image-dired-thumbnail-storage) 128)
-   ((eq 'standard-large image-dired-thumbnail-storage) 256)
-   ((eq 'standard-x-large image-dired-thumbnail-storage) 512)
-   ((eq 'standard-xx-large image-dired-thumbnail-storage) 1024)
-   (t 100))
-  "Size of thumbnails, in pixels.
-This is the default size for both `image-dired-thumb-width'
-and `image-dired-thumb-height'.
-
-The value of this option will be ignored if Image-Dired is
-customized to use the Thumbnail Managing Standard; the standard
-sizes will be used instead.  See `image-dired-thumbnail-storage'."
-  :type 'integer)
-
-(defcustom image-dired-thumb-width image-dired-thumb-size
-  "Width of thumbnails, in pixels."
-  :type 'integer)
-
-(defcustom image-dired-thumb-height image-dired-thumb-size
-  "Height of thumbnails, in pixels."
+(defcustom image-dired--thumb-size
+  ;; This is ignored when using the Thumbnail Managing Standard, but
+  ;; this provides a better default (e.g., when 'image-dired-thumbnail-storage'
+  ;; is `image-dired' in a directory local variables).
+  (pcase image-dired-thumbnail-storage
+    ('standard 128)
+    ('standard-large 256)
+    ('standard-x-large 512)
+    ('standard-xx-large 1024)
+    (_ 100))
+  "Default size of thumbnails in pixels.
+The value of this option is ignored if Image-Dired is customized
+to use the Thumbnail Managing Standard; the standard sizes will
+be used instead.  See `image-dired-thumbnail-storage'."
   :type 'integer)
 
 (defcustom image-dired-thumb-relief 2
@@ -1053,7 +1045,7 @@ See also `image-dired-line-up-dynamic'."
           (thumb-width-chars
            (ceiling (/ (+ (* 2 image-dired-thumb-relief)
                           (* 2 image-dired-thumb-margin)
-                          (image-dired-thumb-size 'width))
+                          (image-dired--thumb-size))
                        (float (frame-char-width))))))
       (while (not (eobp))
         (forward-char)
@@ -1080,7 +1072,7 @@ Calculate how many thumbnails fit."
           (/ width
              (+ (* 2 image-dired-thumb-relief)
                 (* 2 image-dired-thumb-margin)
-                (image-dired-thumb-size 'width)
+                (image-dired--thumb-size)
                 char-width))))
     (image-dired-line-up)))
 
@@ -1350,6 +1342,18 @@ Track this in associated Dired buffer if
 (define-obsolete-function-alias 'image-dired-setup-dired-keybindings
   #'image-dired-minor-mode "26.1")
 
+(make-obsolete-variable 'image-dired-thumb-width
+                        'image-dired-thumb-size "29.1")
+(defcustom image-dired-thumb-width image-dired-thumb-size
+  "Width of thumbnails, in pixels."
+  :type 'integer)
+
+(make-obsolete-variable 'image-dired-thumb-height
+                        'image-dired-thumb-size "29.1")
+(defcustom image-dired-thumb-height image-dired-thumb-size
+  "Height of thumbnails, in pixels."
+  :type 'integer)
+
 (defcustom image-dired-temp-image-file
   (expand-file-name ".image-dired_temp" image-dired-dir)
   "Name of temporary image file used by various commands."