aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTino Calancha2016-09-13 04:28:42 +0900
committerTino Calancha2016-09-13 04:28:42 +0900
commit5d7433aba3893d9d5849b33b909dacc778ecd023 (patch)
treec29836ad8f14b5ff021203202d8f13b69ba99865
parent2675c79db5745d55d43b78019b1e6a4f84b168fa (diff)
downloademacs-5d7433aba3893d9d5849b33b909dacc778ecd023.tar.gz
emacs-5d7433aba3893d9d5849b33b909dacc778ecd023.zip
image-dired: Signal an error before calling a missing executable
Reverts commit ca473907 Add a defun to check if an executable exists, and call it on each function using an external program: when the executable is not available signal an error. See discussion on: https://lists.gnu.org/archive/html/emacs-devel/2016-09/msg00135.html * lisp/image-dired.el (image-dired--check-executable-exists): New defun. Throw and error when the executable arg is missing. (image-dired-display-image, image-dired-rotate-thumbnail) (image-dired-rotate-original, image-dired-set-exif-data) (image-dired-get-exif-data): Use it.
-rw-r--r--lisp/image-dired.el102
1 files changed, 50 insertions, 52 deletions
diff --git a/lisp/image-dired.el b/lisp/image-dired.el
index 5ac46008f4f..a55dd40c09a 100644
--- a/lisp/image-dired.el
+++ b/lisp/image-dired.el
@@ -224,7 +224,7 @@ expects to find pictures in this directory."
224 :group 'image-dired) 224 :group 'image-dired)
225 225
226(defcustom image-dired-cmd-create-thumbnail-program 226(defcustom image-dired-cmd-create-thumbnail-program
227 (executable-find "convert") 227 "convert"
228 "Executable used to create thumbnail. 228 "Executable used to create thumbnail.
229Used together with `image-dired-cmd-create-thumbnail-options'." 229Used together with `image-dired-cmd-create-thumbnail-options'."
230 :type 'string 230 :type 'string
@@ -242,7 +242,7 @@ which is replaced by the file name of the thumbnail file."
242 :group 'image-dired) 242 :group 'image-dired)
243 243
244(defcustom image-dired-cmd-create-temp-image-program 244(defcustom image-dired-cmd-create-temp-image-program
245 (executable-find "convert") 245 "convert"
246 "Executable used to create temporary image. 246 "Executable used to create temporary image.
247Used together with `image-dired-cmd-create-temp-image-options'." 247Used together with `image-dired-cmd-create-temp-image-options'."
248 :type 'string 248 :type 'string
@@ -308,7 +308,7 @@ with the information required by the Thumbnail Managing Standard."
308 :group 'image-dired) 308 :group 'image-dired)
309 309
310(defcustom image-dired-cmd-rotate-thumbnail-program 310(defcustom image-dired-cmd-rotate-thumbnail-program
311 (executable-find "mogrify") 311 "mogrify"
312 "Executable used to rotate thumbnail. 312 "Executable used to rotate thumbnail.
313Used together with `image-dired-cmd-rotate-thumbnail-options'." 313Used together with `image-dired-cmd-rotate-thumbnail-options'."
314 :type 'string 314 :type 'string
@@ -326,20 +326,14 @@ of the thumbnail file."
326 :group 'image-dired) 326 :group 'image-dired)
327 327
328(defcustom image-dired-cmd-rotate-original-program 328(defcustom image-dired-cmd-rotate-original-program
329 (cond ((executable-find "jpegtran")) 329 "jpegtran"
330 ((executable-find "convert")))
331 "Executable used to rotate original image. 330 "Executable used to rotate original image.
332Used together with `image-dired-cmd-rotate-original-options'." 331Used together with `image-dired-cmd-rotate-original-options'."
333 :type 'string 332 :type 'string
334 :group 'image-dired) 333 :group 'image-dired)
335 334
336(defcustom image-dired-cmd-rotate-original-options 335(defcustom image-dired-cmd-rotate-original-options
337 (when image-dired-cmd-rotate-original-program 336 "%p -rotate %d -copy all -outfile %t \"%o\""
338 (pcase image-dired-cmd-rotate-original-program
339 ((pred (lambda (x) (string-match-p "jpegtran" x)))
340 "%p -rotate %d -copy all -outfile %t \"%o\"")
341 ((pred (lambda (x) (string-match-p "convert" x)))
342 "%p -rotate %d \"%o\" %t")))
343 "Format of command used to rotate original image. 337 "Format of command used to rotate original image.
344Available options are %p which is replaced by 338Available options are %p which is replaced by
345`image-dired-cmd-rotate-original-program', %d which is replaced by the 339`image-dired-cmd-rotate-original-program', %d which is replaced by the
@@ -364,7 +358,7 @@ original file with `image-dired-temp-rotate-image-file'."
364 :group 'image-dired) 358 :group 'image-dired)
365 359
366(defcustom image-dired-cmd-write-exif-data-program 360(defcustom image-dired-cmd-write-exif-data-program
367 (executable-find "exiftool") 361 "exiftool"
368 "Program used to write EXIF data to image. 362 "Program used to write EXIF data to image.
369Used together with `image-dired-cmd-write-exif-data-options'." 363Used together with `image-dired-cmd-write-exif-data-options'."
370 :type 'string 364 :type 'string
@@ -381,7 +375,7 @@ which is replaced by the tag value."
381 :group 'image-dired) 375 :group 'image-dired)
382 376
383(defcustom image-dired-cmd-read-exif-data-program 377(defcustom image-dired-cmd-read-exif-data-program
384 (executable-find "exiftool") 378 "exiftool"
385 "Program used to read EXIF data to image. 379 "Program used to read EXIF data to image.
386Used together with `image-dired-cmd-read-exif-data-program-options'." 380Used together with `image-dired-cmd-read-exif-data-program-options'."
387 :type 'string 381 :type 'string
@@ -619,10 +613,14 @@ according to the Thumbnail Managing Standard."
619 (file-name-base f) 613 (file-name-base f)
620 (file-name-extension f)))))) 614 (file-name-extension f))))))
621 615
616(defun image-dired--check-executable-exists (executable)
617 (unless (executable-find (symbol-value executable))
618 (error "Executable %S not found" executable)))
619
622(defun image-dired-create-thumb (original-file thumbnail-file) 620(defun image-dired-create-thumb (original-file thumbnail-file)
623 "For ORIGINAL-FILE, create thumbnail image named THUMBNAIL-FILE." 621 "For ORIGINAL-FILE, create thumbnail image named THUMBNAIL-FILE."
624 (unless image-dired-cmd-create-thumbnail-program 622 (image-dired--check-executable-exists
625 (error "image-dired-cmd-create-thumbnail-program is nil")) 623 'image-dired-cmd-create-thumbnail-program)
626 (let* ((width (int-to-string image-dired-thumb-width)) 624 (let* ((width (int-to-string image-dired-thumb-width))
627 (height (int-to-string image-dired-thumb-height)) 625 (height (int-to-string image-dired-thumb-height))
628 (modif-time (format "%.0f" (float-time (nth 5 (file-attributes 626 (modif-time (format "%.0f" (float-time (nth 5 (file-attributes
@@ -1812,6 +1810,8 @@ should feel snappy enough.
1812 1810
1813If optional argument ORIGINAL-SIZE is non-nil, display image in its 1811If optional argument ORIGINAL-SIZE is non-nil, display image in its
1814original size." 1812original size."
1813 (image-dired--check-executable-exists
1814 'image-dired-cmd-create-temp-image-program)
1815 (let ((new-file (expand-file-name image-dired-temp-image-file)) 1815 (let ((new-file (expand-file-name image-dired-temp-image-file))
1816 width height command ret 1816 width height command ret
1817 (image-type 'jpeg)) 1817 (image-type 'jpeg))
@@ -1820,8 +1820,6 @@ original size."
1820 (progn 1820 (progn
1821 (setq width (image-dired-display-window-width)) 1821 (setq width (image-dired-display-window-width))
1822 (setq height (image-dired-display-window-height)) 1822 (setq height (image-dired-display-window-height))
1823 (unless image-dired-cmd-create-temp-image-program
1824 (error "image-dired-cmd-create-temp-image-program is nil"))
1825 (setq command 1823 (setq command
1826 (format-spec 1824 (format-spec
1827 image-dired-cmd-create-temp-image-options 1825 image-dired-cmd-create-temp-image-options
@@ -1878,8 +1876,8 @@ With prefix argument ARG, display image in its original size."
1878 1876
1879(defun image-dired-rotate-thumbnail (degrees) 1877(defun image-dired-rotate-thumbnail (degrees)
1880 "Rotate thumbnail DEGREES degrees." 1878 "Rotate thumbnail DEGREES degrees."
1881 (unless image-dired-cmd-rotate-thumbnail-program 1879 (image-dired--check-executable-exists
1882 (error "image-dired-cmd-rotate-thumbnail-program is nil")) 1880 'image-dired-cmd-rotate-thumbnail-program)
1883 (if (not (image-dired-image-at-point-p)) 1881 (if (not (image-dired-image-at-point-p))
1884 (message "No thumbnail at point") 1882 (message "No thumbnail at point")
1885 (let ((file (image-dired-thumb-name (image-dired-original-file-name))) 1883 (let ((file (image-dired-thumb-name (image-dired-original-file-name)))
@@ -1922,33 +1920,33 @@ overwritten. This confirmation can be turned off using
1922 1920
1923(defun image-dired-rotate-original (degrees) 1921(defun image-dired-rotate-original (degrees)
1924 "Rotate original image DEGREES degrees." 1922 "Rotate original image DEGREES degrees."
1925 (unless (image-dired-image-at-point-p) 1923 (image-dired--check-executable-exists
1926 (message "No image at point")) 1924 'image-dired-cmd-rotate-original-program)
1927 (unless image-dired-cmd-rotate-original-program 1925 (if (not (image-dired-image-at-point-p))
1928 (error "image-dired-cmd-rotate-original-program is nil")) 1926 (message "No image at point")
1929 (let ((file (image-dired-original-file-name)) 1927 (let ((file (image-dired-original-file-name))
1930 command) 1928 command)
1931 (unless (eq 'jpeg (image-type file)) 1929 (unless (eq 'jpeg (image-type file))
1932 (error "Only JPEG images can be rotated!")) 1930 (error "Only JPEG images can be rotated!"))
1933 (setq command (format-spec 1931 (setq command (format-spec
1934 image-dired-cmd-rotate-original-options 1932 image-dired-cmd-rotate-original-options
1935 (list 1933 (list
1936 (cons ?p image-dired-cmd-rotate-original-program) 1934 (cons ?p image-dired-cmd-rotate-original-program)
1937 (cons ?d degrees) 1935 (cons ?d degrees)
1938 (cons ?o (expand-file-name file)) 1936 (cons ?o (expand-file-name file))
1939 (cons ?t image-dired-temp-rotate-image-file)))) 1937 (cons ?t image-dired-temp-rotate-image-file))))
1940 (if (not (= 0 (call-process shell-file-name nil nil nil 1938 (if (not (= 0 (call-process shell-file-name nil nil nil
1941 shell-command-switch command))) 1939 shell-command-switch command)))
1942 (error "Could not rotate image") 1940 (error "Could not rotate image")
1943 (image-dired-display-image image-dired-temp-rotate-image-file) 1941 (image-dired-display-image image-dired-temp-rotate-image-file)
1944 (if (or (and image-dired-rotate-original-ask-before-overwrite 1942 (if (or (and image-dired-rotate-original-ask-before-overwrite
1945 (y-or-n-p 1943 (y-or-n-p
1946 "Rotate to temp file OK. Overwrite original image? ")) 1944 "Rotate to temp file OK. Overwrite original image? "))
1947 (not image-dired-rotate-original-ask-before-overwrite)) 1945 (not image-dired-rotate-original-ask-before-overwrite))
1948 (progn 1946 (progn
1949 (copy-file image-dired-temp-rotate-image-file file t) 1947 (copy-file image-dired-temp-rotate-image-file file t)
1950 (image-dired-refresh-thumb)) 1948 (image-dired-refresh-thumb))
1951 (image-dired-display-image file))))) 1949 (image-dired-display-image file))))))
1952 1950
1953(defun image-dired-rotate-original-left () 1951(defun image-dired-rotate-original-left ()
1954 "Rotate original image left (counter clockwise) 90 degrees." 1952 "Rotate original image left (counter clockwise) 90 degrees."
@@ -1995,15 +1993,15 @@ default value at the prompt."
1995 (old-value (image-dired-get-exif-data file "ImageDescription"))) 1993 (old-value (image-dired-get-exif-data file "ImageDescription")))
1996 (if (eq 0 1994 (if (eq 0
1997 (image-dired-set-exif-data file "ImageDescription" 1995 (image-dired-set-exif-data file "ImageDescription"
1998 (read-string "Value of ImageDescription: " 1996 (read-string "Value of ImageDescription: "
1999 old-value))) 1997 old-value)))
2000 (message "Successfully wrote ImageDescription tag.") 1998 (message "Successfully wrote ImageDescription tag.")
2001 (error "Could not write ImageDescription tag"))))) 1999 (error "Could not write ImageDescription tag")))))
2002 2000
2003(defun image-dired-set-exif-data (file tag-name tag-value) 2001(defun image-dired-set-exif-data (file tag-name tag-value)
2004 "In FILE, set EXIF tag TAG-NAME to value TAG-VALUE." 2002 "In FILE, set EXIF tag TAG-NAME to value TAG-VALUE."
2005 (unless image-dired-cmd-write-exif-data-program 2003 (image-dired--check-executable-exists
2006 (error "image-dired-cmd-write-exif-data-program is nil")) 2004 'image-dired-cmd-write-exif-data-program)
2007 (let (command) 2005 (let (command)
2008 (setq command (format-spec 2006 (setq command (format-spec
2009 image-dired-cmd-write-exif-data-options 2007 image-dired-cmd-write-exif-data-options
@@ -2016,8 +2014,8 @@ default value at the prompt."
2016 2014
2017(defun image-dired-get-exif-data (file tag-name) 2015(defun image-dired-get-exif-data (file tag-name)
2018 "From FILE, return EXIF tag TAG-NAME." 2016 "From FILE, return EXIF tag TAG-NAME."
2019 (unless image-dired-cmd-read-exif-data-program 2017 (image-dired--check-executable-exists
2020 (error "image-dired-cmd-read-exif-data-program is nil")) 2018 'image-dired-cmd-read-exif-data-program)
2021 (let ((buf (get-buffer-create "*image-dired-get-exif-data*")) 2019 (let ((buf (get-buffer-create "*image-dired-get-exif-data*"))
2022 command tag-value) 2020 command tag-value)
2023 (setq command (format-spec 2021 (setq command (format-spec