diff options
| author | Lars Ingebrigtsen | 2019-09-30 06:29:27 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2019-09-30 06:29:27 +0200 |
| commit | 150bf03107791cd413fa635665401a808b015b4f (patch) | |
| tree | 2cf17968aff726fe798ea46830a245400031ba7b | |
| parent | 88250102707799bf961c3f1a3d80607b99502704 (diff) | |
| download | emacs-150bf03107791cd413fa635665401a808b015b4f.tar.gz emacs-150bf03107791cd413fa635665401a808b015b4f.zip | |
Change the commands in image-converter--converters to lists
* lisp/image/image-converter.el (image-converter--converters):
Change format of the commands to lists.
(image-converter--probe, image-converter--convert): Adjust usages.
| -rw-r--r-- | lisp/image/image-converter.el | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/lisp/image/image-converter.el b/lisp/image/image-converter.el index e91d87af40d..f251d5ca590 100644 --- a/lisp/image/image-converter.el +++ b/lisp/image/image-converter.el | |||
| @@ -43,9 +43,9 @@ installed on the system." | |||
| 43 | "A regexp that matches the file name suffixes that can be converted.") | 43 | "A regexp that matches the file name suffixes that can be converted.") |
| 44 | 44 | ||
| 45 | (defvar image-converter--converters | 45 | (defvar image-converter--converters |
| 46 | '((graphicsmagick :command "gm convert" :probe "-list format") | 46 | '((graphicsmagick :command ("gm" "convert") :probe ("-list" "format")) |
| 47 | (ffmpeg :command "ffmpeg" :probe "-decoders") | 47 | (ffmpeg :command "ffmpeg" :probe "-decoders") |
| 48 | (imagemagick :command "convert" :probe "-list format")) | 48 | (imagemagick :command "convert" :probe ("-list" "format"))) |
| 49 | "List of supported image converters to try.") | 49 | "List of supported image converters to try.") |
| 50 | 50 | ||
| 51 | (defun image-convert-p (file) | 51 | (defun image-convert-p (file) |
| @@ -90,17 +90,19 @@ where created with DATA-P nil (i.e., it has to refer to a file)." | |||
| 90 | 90 | ||
| 91 | (defun image-converter--value (type elem) | 91 | (defun image-converter--value (type elem) |
| 92 | "Return the value of ELEM of image converter TYPE." | 92 | "Return the value of ELEM of image converter TYPE." |
| 93 | (plist-get (cdr (assq type image-converter--converters)) elem)) | 93 | (let ((value (plist-get (cdr (assq type image-converter--converters)) elem))) |
| 94 | (if (stringp value) | ||
| 95 | (list value) | ||
| 96 | value))) | ||
| 94 | 97 | ||
| 95 | (cl-defmethod image-converter--probe ((type (eql graphicsmagick))) | 98 | (cl-defmethod image-converter--probe ((type (eql graphicsmagick))) |
| 96 | "Check whether the system has GraphicsMagick installed." | 99 | "Check whether the system has GraphicsMagick installed." |
| 97 | (with-temp-buffer | 100 | (with-temp-buffer |
| 98 | (let ((command (split-string (image-converter--value type :command) " ")) | 101 | (let ((command (image-converter--value type :command)) |
| 99 | formats) | 102 | formats) |
| 100 | (when (zerop (apply #'call-process (car command) nil '(t nil) nil | 103 | (when (zerop (apply #'call-process (car command) nil '(t nil) nil |
| 101 | (append (cdr command) | 104 | (append (cdr command) |
| 102 | (split-string | 105 | (image-converter--value type :probe)))) |
| 103 | (image-converter--value type :probe) " ")))) | ||
| 104 | (goto-char (point-min)) | 106 | (goto-char (point-min)) |
| 105 | (when (re-search-forward "^-" nil t) | 107 | (when (re-search-forward "^-" nil t) |
| 106 | (forward-line 1) | 108 | (forward-line 1) |
| @@ -113,13 +115,12 @@ where created with DATA-P nil (i.e., it has to refer to a file)." | |||
| 113 | (cl-defmethod image-converter--probe ((type (eql imagemagick))) | 115 | (cl-defmethod image-converter--probe ((type (eql imagemagick))) |
| 114 | "Check whether the system has ImageMagick installed." | 116 | "Check whether the system has ImageMagick installed." |
| 115 | (with-temp-buffer | 117 | (with-temp-buffer |
| 116 | (let ((command (split-string (image-converter--value type :command) " ")) | 118 | (let ((command (image-converter--value type :command)) |
| 117 | formats) | 119 | formats) |
| 118 | ;; Can't check return value; ImageMagick convert usually returns | 120 | ;; Can't check return value; ImageMagick convert usually returns |
| 119 | ;; a non-zero result on "-list format". | 121 | ;; a non-zero result on "-list format". |
| 120 | (apply #'call-process (car command) nil '(t nil) nil | 122 | (apply #'call-process (car command) nil '(t nil) nil |
| 121 | (append (cdr command) | 123 | (append (cdr command) (image-converter--value type :probe))) |
| 122 | (split-string (image-converter--value type :probe) " "))) | ||
| 123 | (goto-char (point-min)) | 124 | (goto-char (point-min)) |
| 124 | (when (re-search-forward "^-" nil t) | 125 | (when (re-search-forward "^-" nil t) |
| 125 | (forward-line 1) | 126 | (forward-line 1) |
| @@ -134,8 +135,9 @@ where created with DATA-P nil (i.e., it has to refer to a file)." | |||
| 134 | (with-temp-buffer | 135 | (with-temp-buffer |
| 135 | (let ((command (image-converter--value type :command)) | 136 | (let ((command (image-converter--value type :command)) |
| 136 | formats) | 137 | formats) |
| 137 | (when (zerop (call-process command nil '(t nil) nil | 138 | (when (zerop (apply #'call-process (car command) nil '(t nil) nil |
| 138 | (image-converter--value type :probe))) | 139 | (append (cdr command) |
| 140 | (image-converter--value type :probe)))) | ||
| 139 | (goto-char (point-min)) | 141 | (goto-char (point-min)) |
| 140 | (when (re-search-forward "^ *-" nil t) | 142 | (when (re-search-forward "^ *-" nil t) |
| 141 | (forward-line 1) | 143 | (forward-line 1) |
| @@ -161,7 +163,7 @@ where created with DATA-P nil (i.e., it has to refer to a file)." | |||
| 161 | (image-converter--convert-magick type file)) | 163 | (image-converter--convert-magick type file)) |
| 162 | 164 | ||
| 163 | (defun image-converter--convert-magick (type file) | 165 | (defun image-converter--convert-magick (type file) |
| 164 | (let ((command (split-string (image-converter--value type :command) " "))) | 166 | (let ((command (image-converter--value type :command))) |
| 165 | (unless (zerop (apply #'call-process (car command) | 167 | (unless (zerop (apply #'call-process (car command) |
| 166 | nil t nil | 168 | nil t nil |
| 167 | (append (cdr command) | 169 | (append (cdr command) |
| @@ -172,11 +174,14 @@ where created with DATA-P nil (i.e., it has to refer to a file)." | |||
| 172 | 174 | ||
| 173 | (cl-defmethod image-converter--convert ((type (eql ffmpeg)) file) | 175 | (cl-defmethod image-converter--convert ((type (eql ffmpeg)) file) |
| 174 | "Convert using ffmpeg." | 176 | "Convert using ffmpeg." |
| 175 | (unless (zerop (call-process (image-converter--value type :command) | 177 | (let ((command (image-converter--value type :command))) |
| 176 | nil '(t nil) nil | 178 | (unless (zerop (apply #'call-process |
| 177 | "-i" (expand-file-name file) | 179 | (car command) |
| 178 | "-c:v" "png" "-f" "image2pipe" "-")) | 180 | nil '(t nil) nil |
| 179 | "ffmpeg error when converting")) | 181 | (append (cdr command) |
| 182 | (list "-i" (expand-file-name file) | ||
| 183 | "-c:v" "png" "-f" "image2pipe" "-")))) | ||
| 184 | "ffmpeg error when converting"))) | ||
| 180 | 185 | ||
| 181 | (provide 'image-converter) | 186 | (provide 'image-converter) |
| 182 | 187 | ||