From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jean Louis Newsgroups: gmane.emacs.help Subject: Re: Better way to make sure external command exists in the system? Date: Thu, 25 Mar 2021 18:17:34 +0300 Message-ID: References: <87y2ego29q.fsf@zoho.eu> <87o8faxkfd.fsf@zoho.eu> <877dlvp9al.fsf@zoho.eu> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25666"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/2.0.6 (2021-03-06) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Thu Mar 25 16:22:34 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lPRof-0006aQ-Jh for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 25 Mar 2021 16:22:33 +0100 Original-Received: from localhost ([::1]:39086 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPRoe-00048g-JW for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 25 Mar 2021 11:22:32 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:38110) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPRlF-0001zq-6Y for help-gnu-emacs@gnu.org; Thu, 25 Mar 2021 11:19:01 -0400 Original-Received: from stw1.rcdrun.com ([217.170.207.13]:48321) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPRlC-0005WC-BN for help-gnu-emacs@gnu.org; Thu, 25 Mar 2021 11:19:00 -0400 Original-Received: from localhost ([::ffff:41.202.241.53]) (AUTH: PLAIN securesender, TLS: TLS1.3,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA id 0000000000027F30.00000000605CA9DF.00006A41; Thu, 25 Mar 2021 08:18:53 -0700 Mail-Followup-To: help-gnu-emacs@gnu.org Content-Disposition: inline In-Reply-To: <877dlvp9al.fsf@zoho.eu> Received-SPF: pass client-ip=217.170.207.13; envelope-from=bugs@gnu.support; helo=stw1.rcdrun.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:128567 Archived-At: * Emanuel Berg via Users list for the GNU Emacs text editor [2021-03-25 18:04]: > 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. Maybe yes, maybe not, but it does not matter neither for human or computer. Human sees the number at completion. > > 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. In general yes, but in this specific case, who cares, important is that it works. Numbers or strings are converted to string by using format. One can supply either integer or string, it does not matter, it works. See: (defun image-resize (file &optional size) "Resizes the JPG image with default SIZE. Argument FILE is image to be resized." (if (rcd-which-list '("mogrify")) (let ((extension (file-name-extension file))) (when (or (equal (downcase extension) "jpg") (equal (downcase extension) "png")) (let* ((file (shell-double-quote file)) (command (format "mogrify -resize %s \"%s\"" size file))) (message command) (call-process-shell-command command)))) (rcd-warning-message "RCD ERROR: `mogrify' not found in `$PATH'"))) > > (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. I want to be able to complete straight. `read-number' does not offer completion. This does not work: (completing-read "Number: " '(1 2 3)) This works: (completing-read "Number: " '("1" "2" "3")) Now you get it why they are strings in the completion list? They are not strings for the underlying function `image-resize' but only for the completion candidates. > Otherwise looks good, I don't have dired-get-marked-files, It is in dired. > rcd-warning-message, rcd-which-list, or shell-double-quote but > I suppose you do... I gave you recently if you need. > >> 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")))) That would mean if I change candidates list I would actually need to change the function. Not practical. 🙈 But interesting. > >> And, no need for globals if they are only used here. > >> Use let* for that as well. > > > > Which globals? > > The two global variables. I would not know which...