[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Better way to make sure external command exists in the system?
From: |
Emanuel Berg |
Subject: |
Re: Better way to make sure external command exists in the system? |
Date: |
Thu, 25 Mar 2021 16:01:06 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
Jean Louis wrote:
> Now it is:
>
> (defvar image-default-resize-size "1536")
> (defvar image-resize-sizes '("1536" "1024" "800" "1200" "640"))
Well, the width of a computer image is not a string but
an integer.
>> The *common-lisp-convention* for global variables is
>> disencourage in Elisp.
>
> Yes, those functions are old. Who knows what I knew
> back then.
Yeah, it is always like that...
>> Also, why the strings?
>
> Maybe it works with numbers, but now I changed it to
> completing-read, maybe that is why I placed it as strings.
Don't do that, data should be in its natural, sound state,
then it is up to functions and/or users who use it to convert
it to fit their purposes. And the better everything is, the
less of that is required.
> (defun image-resize-dired ()
> "Resizes images."
> (interactive)
> (let ((files (dired-get-marked-files))
> (size (completing-read "Size: " image-resize-sizes nil t
> image-default-resize-size)))
> (dolist (file files)
> (image-resize file size))
> (revert-buffer)))
>
> That way is better, my choice of 1536 is offered, but if
> I delete it, I can complete it with some of other default
> choices. It is very handy to mark files and resize them how
> one wants.
OK, not sure that's the way it is supposed to work but if you
want to innovate, no problem.
> (defun optimize-image-jpg (file)
> "Optimizes the JPG image with quality 70%"
> (if (rcd-which-list '("mogrify"))
> (let ((extension (file-name-extension file)))
> (when (equal (downcase extension) "jpg")
> (let* ((file (shell-double-quote file))
> (command (format "mogrify -sampling-factor 4:2:0 -strip
> -interlace JPEG -colorspace RGB -quality 70 \"%s\"" file)))
> (message command)
> (shell-command command))))
> (rcd-warning-message "RCD ERROR: `mogrify' not found in $PATH")))
>
> (defun optimize-jpg-images-dired ()
> "Optimizes JPG images inside of Dired"
> (interactive)
> (let ((files (dired-get-marked-files)))
> (dolist (file files)
> (optimize-image-jpg file))
> (revert-buffer)))
geh.el:281: First sentence should end with punctuation
geh.el:281: Argument ‘file’ should appear (as FILE) in the doc string
geh.el:292: First sentence should end with punctuation
Otherwise looks good, I don't have dired-get-marked-files,
rcd-warning-message, rcd-which-list, or shell-double-quote but
I suppose you do...
>>> (equal (downcase extension) "png"))
>>
>> Same thing twice, instead do let*.
>
> There I wanted to test first for extension and then to proceed.
Yes, but put (downcase extension) in a let* and so you don't
have to do it twice. Now you seem to have removed the PNG so
it isn't an issue anymore.
>> Also, why `read-number' and not in interactive?
>
> I often use `completing-read', maybe that may be implemented in
> `interactive' but I don't find it nice that way.
Yes, compare:
(interactive
`(,(string-to-number
(completing-read "Digit: " '("11" "12" "13") nil t "11"))))
>> And, no need for globals if they are only used here.
>> Use let* for that as well.
>
> Which globals?
The two global variables.
--
underground experts united
https://dataswamp.org/~incal
- Better way to make sure external command exists in the system?, Jean Louis, 2021/03/18
- Re: Better way to make sure external command exists in the system?, Daniel Martín, 2021/03/19
- Re: Better way to make sure external command exists in the system?, Jean Louis, 2021/03/21
- Re: Better way to make sure external command exists in the system?, Emanuel Berg, 2021/03/21
- Re: Better way to make sure external command exists in the system?, Jean Louis, 2021/03/23
- Re: Better way to make sure external command exists in the system?, Emanuel Berg, 2021/03/23
- Re: Better way to make sure external command exists in the system?, Jean Louis, 2021/03/23
- Re: Better way to make sure external command exists in the system?,
Emanuel Berg <=
- Re: Better way to make sure external command exists in the system?, Jean Louis, 2021/03/25
- Re: Better way to make sure external command exists in the system?, Emanuel Berg, 2021/03/25
- Re: Better way to make sure external command exists in the system?, Jean Louis, 2021/03/25
- Re: Better way to make sure external command exists in the system?, Emanuel Berg, 2021/03/25