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'.
This commit is contained in:
parent
2db3307e8a
commit
ca47390727
1 changed files with 56 additions and 36 deletions
|
@ -224,7 +224,7 @@ expects to find pictures in this directory."
|
||||||
:group 'image-dired)
|
:group 'image-dired)
|
||||||
|
|
||||||
(defcustom image-dired-cmd-create-thumbnail-program
|
(defcustom image-dired-cmd-create-thumbnail-program
|
||||||
"convert"
|
(executable-find "convert")
|
||||||
"Executable used to create thumbnail.
|
"Executable used to create thumbnail.
|
||||||
Used together with `image-dired-cmd-create-thumbnail-options'."
|
Used together with `image-dired-cmd-create-thumbnail-options'."
|
||||||
:type 'string
|
:type 'string
|
||||||
|
@ -242,7 +242,7 @@ which is replaced by the file name of the thumbnail file."
|
||||||
:group 'image-dired)
|
:group 'image-dired)
|
||||||
|
|
||||||
(defcustom image-dired-cmd-create-temp-image-program
|
(defcustom image-dired-cmd-create-temp-image-program
|
||||||
"convert"
|
(executable-find "convert")
|
||||||
"Executable used to create temporary image.
|
"Executable used to create temporary image.
|
||||||
Used together with `image-dired-cmd-create-temp-image-options'."
|
Used together with `image-dired-cmd-create-temp-image-options'."
|
||||||
:type 'string
|
:type 'string
|
||||||
|
@ -308,7 +308,7 @@ with the information required by the Thumbnail Managing Standard."
|
||||||
:group 'image-dired)
|
:group 'image-dired)
|
||||||
|
|
||||||
(defcustom image-dired-cmd-rotate-thumbnail-program
|
(defcustom image-dired-cmd-rotate-thumbnail-program
|
||||||
"mogrify"
|
(executable-find "mogrify")
|
||||||
"Executable used to rotate thumbnail.
|
"Executable used to rotate thumbnail.
|
||||||
Used together with `image-dired-cmd-rotate-thumbnail-options'."
|
Used together with `image-dired-cmd-rotate-thumbnail-options'."
|
||||||
:type 'string
|
:type 'string
|
||||||
|
@ -326,14 +326,20 @@ of the thumbnail file."
|
||||||
:group 'image-dired)
|
:group 'image-dired)
|
||||||
|
|
||||||
(defcustom image-dired-cmd-rotate-original-program
|
(defcustom image-dired-cmd-rotate-original-program
|
||||||
"jpegtran"
|
(cond ((executable-find "jpegtran"))
|
||||||
|
((executable-find "convert")))
|
||||||
"Executable used to rotate original image.
|
"Executable used to rotate original image.
|
||||||
Used together with `image-dired-cmd-rotate-original-options'."
|
Used together with `image-dired-cmd-rotate-original-options'."
|
||||||
:type 'string
|
:type 'string
|
||||||
:group 'image-dired)
|
:group 'image-dired)
|
||||||
|
|
||||||
(defcustom image-dired-cmd-rotate-original-options
|
(defcustom image-dired-cmd-rotate-original-options
|
||||||
"%p -rotate %d -copy all -outfile %t \"%o\""
|
(when image-dired-cmd-rotate-original-program
|
||||||
|
(pcase image-dired-cmd-rotate-original-program
|
||||||
|
((pred (lambda (x) (string-match-p "jpegtran" x)))
|
||||||
|
"%p -rotate %d -copy all -outfile %t \"%o\"")
|
||||||
|
((pred (lambda (x) (string-match-p "convert" x)))
|
||||||
|
"%p -rotate %d \"%o\" %t")))
|
||||||
"Format of command used to rotate original image.
|
"Format of command used to rotate original image.
|
||||||
Available options are %p which is replaced by
|
Available options are %p which is replaced by
|
||||||
`image-dired-cmd-rotate-original-program', %d which is replaced by the
|
`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'."
|
||||||
:group 'image-dired)
|
:group 'image-dired)
|
||||||
|
|
||||||
(defcustom image-dired-cmd-write-exif-data-program
|
(defcustom image-dired-cmd-write-exif-data-program
|
||||||
"exiftool"
|
(executable-find "exiftool")
|
||||||
"Program used to write EXIF data to image.
|
"Program used to write EXIF data to image.
|
||||||
Used together with `image-dired-cmd-write-exif-data-options'."
|
Used together with `image-dired-cmd-write-exif-data-options'."
|
||||||
:type 'string
|
:type 'string
|
||||||
|
@ -375,7 +381,7 @@ which is replaced by the tag value."
|
||||||
:group 'image-dired)
|
:group 'image-dired)
|
||||||
|
|
||||||
(defcustom image-dired-cmd-read-exif-data-program
|
(defcustom image-dired-cmd-read-exif-data-program
|
||||||
"exiftool"
|
(executable-find "exiftool")
|
||||||
"Program used to read EXIF data to image.
|
"Program used to read EXIF data to image.
|
||||||
Used together with `image-dired-cmd-read-exif-data-program-options'."
|
Used together with `image-dired-cmd-read-exif-data-program-options'."
|
||||||
:type 'string
|
:type 'string
|
||||||
|
@ -615,6 +621,8 @@ according to the Thumbnail Managing Standard."
|
||||||
|
|
||||||
(defun image-dired-create-thumb (original-file thumbnail-file)
|
(defun image-dired-create-thumb (original-file thumbnail-file)
|
||||||
"For ORIGINAL-FILE, create thumbnail image named THUMBNAIL-FILE."
|
"For ORIGINAL-FILE, create thumbnail image named THUMBNAIL-FILE."
|
||||||
|
(unless image-dired-cmd-create-thumbnail-program
|
||||||
|
(error "image-dired-cmd-create-thumbnail-program is nil"))
|
||||||
(let* ((width (int-to-string image-dired-thumb-width))
|
(let* ((width (int-to-string image-dired-thumb-width))
|
||||||
(height (int-to-string image-dired-thumb-height))
|
(height (int-to-string image-dired-thumb-height))
|
||||||
(modif-time (format "%.0f" (float-time (nth 5 (file-attributes
|
(modif-time (format "%.0f" (float-time (nth 5 (file-attributes
|
||||||
|
@ -1144,7 +1152,8 @@ image."
|
||||||
"Move to next line and display properties."
|
"Move to next line and display properties."
|
||||||
(interactive)
|
(interactive)
|
||||||
(let ((goal-column (current-column)))
|
(let ((goal-column (current-column)))
|
||||||
(next-line))
|
(forward-line 1)
|
||||||
|
(move-to-column goal-column))
|
||||||
;; If we end up in an empty spot, back up to the next thumbnail.
|
;; If we end up in an empty spot, back up to the next thumbnail.
|
||||||
(if (not (image-dired-image-at-point-p))
|
(if (not (image-dired-image-at-point-p))
|
||||||
(image-dired-backward-image))
|
(image-dired-backward-image))
|
||||||
|
@ -1157,7 +1166,8 @@ image."
|
||||||
"Move to previous line and display properties."
|
"Move to previous line and display properties."
|
||||||
(interactive)
|
(interactive)
|
||||||
(let ((goal-column (current-column)))
|
(let ((goal-column (current-column)))
|
||||||
(previous-line))
|
(forward-line -1)
|
||||||
|
(move-to-column goal-column))
|
||||||
;; If we end up in an empty spot, back up to the next
|
;; If we end up in an empty spot, back up to the next
|
||||||
;; thumbnail. This should only happen if the user deleted a
|
;; thumbnail. This should only happen if the user deleted a
|
||||||
;; thumbnail and did not refresh, so it is not very common. But we
|
;; thumbnail and did not refresh, so it is not very common. But we
|
||||||
|
@ -1810,6 +1820,8 @@ original size."
|
||||||
(progn
|
(progn
|
||||||
(setq width (image-dired-display-window-width))
|
(setq width (image-dired-display-window-width))
|
||||||
(setq height (image-dired-display-window-height))
|
(setq height (image-dired-display-window-height))
|
||||||
|
(unless image-dired-cmd-create-temp-image-program
|
||||||
|
(error "image-dired-cmd-create-temp-image-program is nil"))
|
||||||
(setq command
|
(setq command
|
||||||
(format-spec
|
(format-spec
|
||||||
image-dired-cmd-create-temp-image-options
|
image-dired-cmd-create-temp-image-options
|
||||||
|
@ -1866,6 +1878,8 @@ With prefix argument ARG, display image in its original size."
|
||||||
|
|
||||||
(defun image-dired-rotate-thumbnail (degrees)
|
(defun image-dired-rotate-thumbnail (degrees)
|
||||||
"Rotate thumbnail DEGREES degrees."
|
"Rotate thumbnail DEGREES degrees."
|
||||||
|
(unless image-dired-cmd-rotate-thumbnail-program
|
||||||
|
(error "image-dired-cmd-rotate-thumbnail-program is nil"))
|
||||||
(if (not (image-dired-image-at-point-p))
|
(if (not (image-dired-image-at-point-p))
|
||||||
(message "No thumbnail at point")
|
(message "No thumbnail at point")
|
||||||
(let ((file (image-dired-thumb-name (image-dired-original-file-name)))
|
(let ((file (image-dired-thumb-name (image-dired-original-file-name)))
|
||||||
|
@ -1908,31 +1922,33 @@ overwritten. This confirmation can be turned off using
|
||||||
|
|
||||||
(defun image-dired-rotate-original (degrees)
|
(defun image-dired-rotate-original (degrees)
|
||||||
"Rotate original image DEGREES degrees."
|
"Rotate original image DEGREES degrees."
|
||||||
(if (not (image-dired-image-at-point-p))
|
(unless (image-dired-image-at-point-p)
|
||||||
(message "No image at point")
|
(message "No image at point"))
|
||||||
(let ((file (image-dired-original-file-name))
|
(unless image-dired-cmd-rotate-original-program
|
||||||
command)
|
(error "image-dired-cmd-rotate-original-program is nil"))
|
||||||
(unless (eq 'jpeg (image-type file))
|
(let ((file (image-dired-original-file-name))
|
||||||
(error "Only JPEG images can be rotated!"))
|
command)
|
||||||
(setq command (format-spec
|
(unless (eq 'jpeg (image-type file))
|
||||||
image-dired-cmd-rotate-original-options
|
(error "Only JPEG images can be rotated!"))
|
||||||
(list
|
(setq command (format-spec
|
||||||
(cons ?p image-dired-cmd-rotate-original-program)
|
image-dired-cmd-rotate-original-options
|
||||||
(cons ?d degrees)
|
(list
|
||||||
(cons ?o (expand-file-name file))
|
(cons ?p image-dired-cmd-rotate-original-program)
|
||||||
(cons ?t image-dired-temp-rotate-image-file))))
|
(cons ?d degrees)
|
||||||
(if (not (= 0 (call-process shell-file-name nil nil nil
|
(cons ?o (expand-file-name file))
|
||||||
shell-command-switch command)))
|
(cons ?t image-dired-temp-rotate-image-file))))
|
||||||
(error "Could not rotate image")
|
(if (not (= 0 (call-process shell-file-name nil nil nil
|
||||||
(image-dired-display-image image-dired-temp-rotate-image-file)
|
shell-command-switch command)))
|
||||||
(if (or (and image-dired-rotate-original-ask-before-overwrite
|
(error "Could not rotate image")
|
||||||
(y-or-n-p
|
(image-dired-display-image image-dired-temp-rotate-image-file)
|
||||||
"Rotate to temp file OK. Overwrite original image? "))
|
(if (or (and image-dired-rotate-original-ask-before-overwrite
|
||||||
(not image-dired-rotate-original-ask-before-overwrite))
|
(y-or-n-p
|
||||||
(progn
|
"Rotate to temp file OK. Overwrite original image? "))
|
||||||
(copy-file image-dired-temp-rotate-image-file file t)
|
(not image-dired-rotate-original-ask-before-overwrite))
|
||||||
(image-dired-refresh-thumb))
|
(progn
|
||||||
(image-dired-display-image file))))))
|
(copy-file image-dired-temp-rotate-image-file file t)
|
||||||
|
(image-dired-refresh-thumb))
|
||||||
|
(image-dired-display-image file)))))
|
||||||
|
|
||||||
(defun image-dired-rotate-original-left ()
|
(defun image-dired-rotate-original-left ()
|
||||||
"Rotate original image left (counter clockwise) 90 degrees."
|
"Rotate original image left (counter clockwise) 90 degrees."
|
||||||
|
@ -1979,13 +1995,15 @@ default value at the prompt."
|
||||||
(old-value (image-dired-get-exif-data file "ImageDescription")))
|
(old-value (image-dired-get-exif-data file "ImageDescription")))
|
||||||
(if (eq 0
|
(if (eq 0
|
||||||
(image-dired-set-exif-data file "ImageDescription"
|
(image-dired-set-exif-data file "ImageDescription"
|
||||||
(read-string "Value of ImageDescription: "
|
(read-string "Value of ImageDescription: "
|
||||||
old-value)))
|
old-value)))
|
||||||
(message "Successfully wrote ImageDescription tag.")
|
(message "Successfully wrote ImageDescription tag.")
|
||||||
(error "Could not write ImageDescription tag")))))
|
(error "Could not write ImageDescription tag")))))
|
||||||
|
|
||||||
(defun image-dired-set-exif-data (file tag-name tag-value)
|
(defun image-dired-set-exif-data (file tag-name tag-value)
|
||||||
"In FILE, set EXIF tag TAG-NAME to value TAG-VALUE."
|
"In FILE, set EXIF tag TAG-NAME to value TAG-VALUE."
|
||||||
|
(unless image-dired-cmd-write-exif-data-program
|
||||||
|
(error "image-dired-cmd-write-exif-data-program is nil"))
|
||||||
(let (command)
|
(let (command)
|
||||||
(setq command (format-spec
|
(setq command (format-spec
|
||||||
image-dired-cmd-write-exif-data-options
|
image-dired-cmd-write-exif-data-options
|
||||||
|
@ -1998,6 +2016,8 @@ default value at the prompt."
|
||||||
|
|
||||||
(defun image-dired-get-exif-data (file tag-name)
|
(defun image-dired-get-exif-data (file tag-name)
|
||||||
"From FILE, return EXIF tag TAG-NAME."
|
"From FILE, return EXIF tag TAG-NAME."
|
||||||
|
(unless image-dired-cmd-read-exif-data-program
|
||||||
|
(error "image-dired-cmd-read-exif-data-program is nil"))
|
||||||
(let ((buf (get-buffer-create "*image-dired-get-exif-data*"))
|
(let ((buf (get-buffer-create "*image-dired-get-exif-data*"))
|
||||||
command tag-value)
|
command tag-value)
|
||||||
(setq command (format-spec
|
(setq command (format-spec
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue