diff options
| author | Tino Calancha | 2016-09-04 22:41:12 +0900 |
|---|---|---|
| committer | Tino Calancha | 2016-09-04 22:41:12 +0900 |
| commit | ca47390727c55a40a54d0dea3b15bd094ea9cde2 (patch) | |
| tree | 60ed6add266767136393431ee810c685acb0f67e | |
| parent | 2db3307e8a966a8f652a210d8f8eb83daddd7d9f (diff) | |
| download | emacs-ca47390727c55a40a54d0dea3b15bd094ea9cde2.tar.gz emacs-ca47390727c55a40a54d0dea3b15bd094ea9cde2.zip | |
image-dired: Report when a necessary executable is not found
See discussion on:
https://lists.gnu.org/archive/html/emacs-devel/2016-08/msg00552.html
* lisp/image-dired.el (image-dired-cmd-rotate-original-program)
(image-dired-cmd-create-thumbnail-program)
(image-dired-cmd-create-temp-image-program)
(image-dired-cmd-rotate-thumbnail-program)
(image-dired-cmd-write-exif-data-program)
(image-dired-cmd-read-exif-data-program):
Use executable-find to set the defaut value of this option.
(image-dired-cmd-rotate-original-program): Idem.
Search for program 'convert' if 'jpegtran' is not available.
(image-dired-cmd-rotate-original-options):
Set the default value consistent with the executable in
image-dired-cmd-rotate-original-program.
(image-dired-create-thumb, image-dired-display-image)
(image-dired-rotate-thumbnail, image-dired-rotate-original)
(image-dired-set-exif-data, image-dired-get-exif-data):
Throw and error when the executable used in the function is missing.
(image-dired-next-line, image-dired-previous-line):
Use 'forward-line'.
| -rw-r--r-- | lisp/image-dired.el | 92 |
1 files changed, 56 insertions, 36 deletions
diff --git a/lisp/image-dired.el b/lisp/image-dired.el index 34e4eaefbc1..5ac46008f4f 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 | "convert" | 227 | (executable-find "convert") |
| 228 | "Executable used to create thumbnail. | 228 | "Executable used to create thumbnail. |
| 229 | Used together with `image-dired-cmd-create-thumbnail-options'." | 229 | Used 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 | "convert" | 245 | (executable-find "convert") |
| 246 | "Executable used to create temporary image. | 246 | "Executable used to create temporary image. |
| 247 | Used together with `image-dired-cmd-create-temp-image-options'." | 247 | Used 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 | "mogrify" | 311 | (executable-find "mogrify") |
| 312 | "Executable used to rotate thumbnail. | 312 | "Executable used to rotate thumbnail. |
| 313 | Used together with `image-dired-cmd-rotate-thumbnail-options'." | 313 | Used together with `image-dired-cmd-rotate-thumbnail-options'." |
| 314 | :type 'string | 314 | :type 'string |
| @@ -326,14 +326,20 @@ 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 | "jpegtran" | 329 | (cond ((executable-find "jpegtran")) |
| 330 | ((executable-find "convert"))) | ||
| 330 | "Executable used to rotate original image. | 331 | "Executable used to rotate original image. |
| 331 | Used together with `image-dired-cmd-rotate-original-options'." | 332 | Used together with `image-dired-cmd-rotate-original-options'." |
| 332 | :type 'string | 333 | :type 'string |
| 333 | :group 'image-dired) | 334 | :group 'image-dired) |
| 334 | 335 | ||
| 335 | (defcustom image-dired-cmd-rotate-original-options | 336 | (defcustom image-dired-cmd-rotate-original-options |
| 336 | "%p -rotate %d -copy all -outfile %t \"%o\"" | 337 | (when image-dired-cmd-rotate-original-program |
| 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"))) | ||
| 337 | "Format of command used to rotate original image. | 343 | "Format of command used to rotate original image. |
| 338 | Available options are %p which is replaced by | 344 | Available options are %p which is replaced by |
| 339 | `image-dired-cmd-rotate-original-program', %d which is replaced by the | 345 | `image-dired-cmd-rotate-original-program', %d which is replaced by the |
| @@ -358,7 +364,7 @@ original file with `image-dired-temp-rotate-image-file'." | |||
| 358 | :group 'image-dired) | 364 | :group 'image-dired) |
| 359 | 365 | ||
| 360 | (defcustom image-dired-cmd-write-exif-data-program | 366 | (defcustom image-dired-cmd-write-exif-data-program |
| 361 | "exiftool" | 367 | (executable-find "exiftool") |
| 362 | "Program used to write EXIF data to image. | 368 | "Program used to write EXIF data to image. |
| 363 | Used together with `image-dired-cmd-write-exif-data-options'." | 369 | Used together with `image-dired-cmd-write-exif-data-options'." |
| 364 | :type 'string | 370 | :type 'string |
| @@ -375,7 +381,7 @@ which is replaced by the tag value." | |||
| 375 | :group 'image-dired) | 381 | :group 'image-dired) |
| 376 | 382 | ||
| 377 | (defcustom image-dired-cmd-read-exif-data-program | 383 | (defcustom image-dired-cmd-read-exif-data-program |
| 378 | "exiftool" | 384 | (executable-find "exiftool") |
| 379 | "Program used to read EXIF data to image. | 385 | "Program used to read EXIF data to image. |
| 380 | Used together with `image-dired-cmd-read-exif-data-program-options'." | 386 | Used together with `image-dired-cmd-read-exif-data-program-options'." |
| 381 | :type 'string | 387 | :type 'string |
| @@ -615,6 +621,8 @@ according to the Thumbnail Managing Standard." | |||
| 615 | 621 | ||
| 616 | (defun image-dired-create-thumb (original-file thumbnail-file) | 622 | (defun image-dired-create-thumb (original-file thumbnail-file) |
| 617 | "For ORIGINAL-FILE, create thumbnail image named THUMBNAIL-FILE." | 623 | "For ORIGINAL-FILE, create thumbnail image named THUMBNAIL-FILE." |
| 624 | (unless image-dired-cmd-create-thumbnail-program | ||
| 625 | (error "image-dired-cmd-create-thumbnail-program is nil")) | ||
| 618 | (let* ((width (int-to-string image-dired-thumb-width)) | 626 | (let* ((width (int-to-string image-dired-thumb-width)) |
| 619 | (height (int-to-string image-dired-thumb-height)) | 627 | (height (int-to-string image-dired-thumb-height)) |
| 620 | (modif-time (format "%.0f" (float-time (nth 5 (file-attributes | 628 | (modif-time (format "%.0f" (float-time (nth 5 (file-attributes |
| @@ -1144,7 +1152,8 @@ image." | |||
| 1144 | "Move to next line and display properties." | 1152 | "Move to next line and display properties." |
| 1145 | (interactive) | 1153 | (interactive) |
| 1146 | (let ((goal-column (current-column))) | 1154 | (let ((goal-column (current-column))) |
| 1147 | (next-line)) | 1155 | (forward-line 1) |
| 1156 | (move-to-column goal-column)) | ||
| 1148 | ;; If we end up in an empty spot, back up to the next thumbnail. | 1157 | ;; If we end up in an empty spot, back up to the next thumbnail. |
| 1149 | (if (not (image-dired-image-at-point-p)) | 1158 | (if (not (image-dired-image-at-point-p)) |
| 1150 | (image-dired-backward-image)) | 1159 | (image-dired-backward-image)) |
| @@ -1157,7 +1166,8 @@ image." | |||
| 1157 | "Move to previous line and display properties." | 1166 | "Move to previous line and display properties." |
| 1158 | (interactive) | 1167 | (interactive) |
| 1159 | (let ((goal-column (current-column))) | 1168 | (let ((goal-column (current-column))) |
| 1160 | (previous-line)) | 1169 | (forward-line -1) |
| 1170 | (move-to-column goal-column)) | ||
| 1161 | ;; If we end up in an empty spot, back up to the next | 1171 | ;; If we end up in an empty spot, back up to the next |
| 1162 | ;; thumbnail. This should only happen if the user deleted a | 1172 | ;; thumbnail. This should only happen if the user deleted a |
| 1163 | ;; thumbnail and did not refresh, so it is not very common. But we | 1173 | ;; thumbnail and did not refresh, so it is not very common. But we |
| @@ -1810,6 +1820,8 @@ original size." | |||
| 1810 | (progn | 1820 | (progn |
| 1811 | (setq width (image-dired-display-window-width)) | 1821 | (setq width (image-dired-display-window-width)) |
| 1812 | (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")) | ||
| 1813 | (setq command | 1825 | (setq command |
| 1814 | (format-spec | 1826 | (format-spec |
| 1815 | image-dired-cmd-create-temp-image-options | 1827 | image-dired-cmd-create-temp-image-options |
| @@ -1866,6 +1878,8 @@ With prefix argument ARG, display image in its original size." | |||
| 1866 | 1878 | ||
| 1867 | (defun image-dired-rotate-thumbnail (degrees) | 1879 | (defun image-dired-rotate-thumbnail (degrees) |
| 1868 | "Rotate thumbnail DEGREES degrees." | 1880 | "Rotate thumbnail DEGREES degrees." |
| 1881 | (unless image-dired-cmd-rotate-thumbnail-program | ||
| 1882 | (error "image-dired-cmd-rotate-thumbnail-program is nil")) | ||
| 1869 | (if (not (image-dired-image-at-point-p)) | 1883 | (if (not (image-dired-image-at-point-p)) |
| 1870 | (message "No thumbnail at point") | 1884 | (message "No thumbnail at point") |
| 1871 | (let ((file (image-dired-thumb-name (image-dired-original-file-name))) | 1885 | (let ((file (image-dired-thumb-name (image-dired-original-file-name))) |
| @@ -1908,31 +1922,33 @@ overwritten. This confirmation can be turned off using | |||
| 1908 | 1922 | ||
| 1909 | (defun image-dired-rotate-original (degrees) | 1923 | (defun image-dired-rotate-original (degrees) |
| 1910 | "Rotate original image DEGREES degrees." | 1924 | "Rotate original image DEGREES degrees." |
| 1911 | (if (not (image-dired-image-at-point-p)) | 1925 | (unless (image-dired-image-at-point-p) |
| 1912 | (message "No image at point") | 1926 | (message "No image at point")) |
| 1913 | (let ((file (image-dired-original-file-name)) | 1927 | (unless image-dired-cmd-rotate-original-program |
| 1914 | command) | 1928 | (error "image-dired-cmd-rotate-original-program is nil")) |
| 1915 | (unless (eq 'jpeg (image-type file)) | 1929 | (let ((file (image-dired-original-file-name)) |
| 1916 | (error "Only JPEG images can be rotated!")) | 1930 | command) |
| 1917 | (setq command (format-spec | 1931 | (unless (eq 'jpeg (image-type file)) |
| 1918 | image-dired-cmd-rotate-original-options | 1932 | (error "Only JPEG images can be rotated!")) |
| 1919 | (list | 1933 | (setq command (format-spec |
| 1920 | (cons ?p image-dired-cmd-rotate-original-program) | 1934 | image-dired-cmd-rotate-original-options |
| 1921 | (cons ?d degrees) | 1935 | (list |
| 1922 | (cons ?o (expand-file-name file)) | 1936 | (cons ?p image-dired-cmd-rotate-original-program) |
| 1923 | (cons ?t image-dired-temp-rotate-image-file)))) | 1937 | (cons ?d degrees) |
| 1924 | (if (not (= 0 (call-process shell-file-name nil nil nil | 1938 | (cons ?o (expand-file-name file)) |
| 1925 | shell-command-switch command))) | 1939 | (cons ?t image-dired-temp-rotate-image-file)))) |
| 1926 | (error "Could not rotate image") | 1940 | (if (not (= 0 (call-process shell-file-name nil nil nil |
| 1927 | (image-dired-display-image image-dired-temp-rotate-image-file) | 1941 | shell-command-switch command))) |
| 1928 | (if (or (and image-dired-rotate-original-ask-before-overwrite | 1942 | (error "Could not rotate image") |
| 1929 | (y-or-n-p | 1943 | (image-dired-display-image image-dired-temp-rotate-image-file) |
| 1930 | "Rotate to temp file OK. Overwrite original image? ")) | 1944 | (if (or (and image-dired-rotate-original-ask-before-overwrite |
| 1931 | (not image-dired-rotate-original-ask-before-overwrite)) | 1945 | (y-or-n-p |
| 1932 | (progn | 1946 | "Rotate to temp file OK. Overwrite original image? ")) |
| 1933 | (copy-file image-dired-temp-rotate-image-file file t) | 1947 | (not image-dired-rotate-original-ask-before-overwrite)) |
| 1934 | (image-dired-refresh-thumb)) | 1948 | (progn |
| 1935 | (image-dired-display-image file)))))) | 1949 | (copy-file image-dired-temp-rotate-image-file file t) |
| 1950 | (image-dired-refresh-thumb)) | ||
| 1951 | (image-dired-display-image file))))) | ||
| 1936 | 1952 | ||
| 1937 | (defun image-dired-rotate-original-left () | 1953 | (defun image-dired-rotate-original-left () |
| 1938 | "Rotate original image left (counter clockwise) 90 degrees." | 1954 | "Rotate original image left (counter clockwise) 90 degrees." |
| @@ -1979,13 +1995,15 @@ default value at the prompt." | |||
| 1979 | (old-value (image-dired-get-exif-data file "ImageDescription"))) | 1995 | (old-value (image-dired-get-exif-data file "ImageDescription"))) |
| 1980 | (if (eq 0 | 1996 | (if (eq 0 |
| 1981 | (image-dired-set-exif-data file "ImageDescription" | 1997 | (image-dired-set-exif-data file "ImageDescription" |
| 1982 | (read-string "Value of ImageDescription: " | 1998 | (read-string "Value of ImageDescription: " |
| 1983 | old-value))) | 1999 | old-value))) |
| 1984 | (message "Successfully wrote ImageDescription tag.") | 2000 | (message "Successfully wrote ImageDescription tag.") |
| 1985 | (error "Could not write ImageDescription tag"))))) | 2001 | (error "Could not write ImageDescription tag"))))) |
| 1986 | 2002 | ||
| 1987 | (defun image-dired-set-exif-data (file tag-name tag-value) | 2003 | (defun image-dired-set-exif-data (file tag-name tag-value) |
| 1988 | "In FILE, set EXIF tag TAG-NAME to value TAG-VALUE." | 2004 | "In FILE, set EXIF tag TAG-NAME to value TAG-VALUE." |
| 2005 | (unless image-dired-cmd-write-exif-data-program | ||
| 2006 | (error "image-dired-cmd-write-exif-data-program is nil")) | ||
| 1989 | (let (command) | 2007 | (let (command) |
| 1990 | (setq command (format-spec | 2008 | (setq command (format-spec |
| 1991 | image-dired-cmd-write-exif-data-options | 2009 | image-dired-cmd-write-exif-data-options |
| @@ -1998,6 +2016,8 @@ default value at the prompt." | |||
| 1998 | 2016 | ||
| 1999 | (defun image-dired-get-exif-data (file tag-name) | 2017 | (defun image-dired-get-exif-data (file tag-name) |
| 2000 | "From FILE, return EXIF tag TAG-NAME." | 2018 | "From FILE, return EXIF tag TAG-NAME." |
| 2019 | (unless image-dired-cmd-read-exif-data-program | ||
| 2020 | (error "image-dired-cmd-read-exif-data-program is nil")) | ||
| 2001 | (let ((buf (get-buffer-create "*image-dired-get-exif-data*")) | 2021 | (let ((buf (get-buffer-create "*image-dired-get-exif-data*")) |
| 2002 | command tag-value) | 2022 | command tag-value) |
| 2003 | (setq command (format-spec | 2023 | (setq command (format-spec |