From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: 2QdxY4RzWzUUiLuE@potatochowder.com Newsgroups: gmane.emacs.help Subject: Re: Better way to make sure external command exists in the system? Date: Fri, 19 Mar 2021 07:16:00 -0700 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="36235"; mail-complaints-to="usenet@ciao.gmane.io" To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Fri Mar 19 15:17:51 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 1lNFwk-0009J7-R0 for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 19 Mar 2021 15:17:50 +0100 Original-Received: from localhost ([::1]:35550 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lNFwj-0001Fw-Sc for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 19 Mar 2021 10:17:49 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46358) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <2QdxY4RzWzUUiLuE@potatochowder.com>) id 1lNFvC-0000TD-ET for help-gnu-emacs@gnu.org; Fri, 19 Mar 2021 10:16:14 -0400 Original-Received: from www458.your-server.de ([136.243.165.62]:36176) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <2QdxY4RzWzUUiLuE@potatochowder.com>) id 1lNFvA-0007Qr-79 for help-gnu-emacs@gnu.org; Fri, 19 Mar 2021 10:16:14 -0400 Original-Received: from sslproxy03.your-server.de ([88.198.220.132]) by www458.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92.3) (envelope-from <2QdxY4RzWzUUiLuE@potatochowder.com>) id 1lNFv2-0006nS-31 for help-gnu-emacs@gnu.org; Fri, 19 Mar 2021 15:16:04 +0100 Original-Received: from [2607:fb90:a68c:f73b:d461:19e2:14d4:61ec] (helo=localhost) by sslproxy03.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from <2QdxY4RzWzUUiLuE@potatochowder.com>) id 1lNFv1-000FV2-5f for help-gnu-emacs@gnu.org; Fri, 19 Mar 2021 15:16:03 +0100 Mail-Followup-To: help-gnu-emacs@gnu.org Content-Disposition: inline In-Reply-To: X-Authenticated-Sender: 2QdxY4RzWzUUiLuE@potatochowder.com X-Virus-Scanned: Clear (ClamAV 0.102.4/26113/Fri Mar 19 12:14:45 2021) Received-SPF: pass client-ip=136.243.165.62; envelope-from=2QdxY4RzWzUUiLuE@potatochowder.com; helo=www458.your-server.de 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_NONE=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:128453 Archived-At: On 2021-03-19 at 14:57:34 +0100, Daniel Martín wrote: > Jean Louis writes: > > > I have changed the OS on one computer and noticed that my Emacs Lisp > > programs use external commands like: mailutils, mail, pandoc, > > markdown, and others. Sometimes I was hard coding the path names like > > /usr/local/bin and now some commands changed to /usr/bin > > > > And some functions should not even run if external command does not > > exist. I would even like to stop loading the .el program if necessary > > external programs do not exist in the system. > > > > For that reason I would do some changes: > > > > - instead of hard coding the program name within quotes, I will use > > variable. Instead of (shell-command "mogrify ...") I will rather use > > something like (shell-command (format "%s ..." mogrify-command)) > > > > - variables for commands I would place at beginning of programs > > > > Yes, I think that using a variable instead of a hardcoded string is > recommended. > > > - before variables get defined, I would use `executable-find' but I > > would like for the program loading to fail if those external > > programs cannot be found. > > Why do you think that checking for the existence of programs on load is > better? I think it would slow down loading the module, and the benefits > are not clear to me. For example, the Elisp module may still be useful > even if it cannot call external programs. > > Why is it better than simply calling `executable-find' when invoking a > command that depends on an external program? Using executable-find at load time is better because modules are only loaded once, but the functionality inside the modules is executed repeatedly. Personally, my emacs.el loads lots of stuff unconditionally, because I usually only start Emacs when I start my X session, which is already time consuming. Anything I don't load at that time only delays me later. And if every function in a module is a wrapper around, say, mogrify, then why shouldn't I verfiy that mogrify exists before I load the module? (Obviously, there are a number of user- and application- interface questions to be answered, but there are definitely modules that can't do anything (except report failure) without their associated external dependencies.)