branch: externals/compat
commit e83e9a67fea13fc1087c918211206284c8e0cf7b
Author: Philip Kaludercic <[email protected]>
Commit: Philip Kaludercic <[email protected]>

    Add compat-executable-find
---
 MANUAL       |  3 +++
 compat-27.el | 21 +++++++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/MANUAL b/MANUAL
index 8115234d63..42168891f4 100644
--- a/MANUAL
+++ b/MANUAL
@@ -315,6 +315,9 @@ when ~compat-27~ is required:
 - Function: compat-assoc-delete-all :: See [[info:elisp#Association 
Lists][(elisp) Association Lists]].
 
   Handle the optional third (TESTFN) argument.
+- Function: compat-executable-find :: [[info:elisp#Locating Files][(elisp) 
Locating Files]].
+
+  Handle the optional second (REMOTE) argument.
 
 Compat does not provide support for the following Lisp features
 implemented in 27.1:
diff --git a/compat-27.el b/compat-27.el
index 6901870fcf..9b37f3c36a 100644
--- a/compat-27.el
+++ b/compat-27.el
@@ -464,6 +464,27 @@ in all cases, since that is the standard symbol for byte."
               (if (string= prefixed-unit "") "" (or space ""))
               prefixed-unit))))
 
+(declare-function compat--file-name-quote "compat-26"
+                  (name &optional top))
+
+;;;*UNTESTED
+(compat-defun executable-find (command &optional remote)
+  "Search for COMMAND in `exec-path' and return the absolute file name.
+Return nil if COMMAND is not found anywhere in `exec-path'.  If
+REMOTE is non-nil, search on the remote host indicated by
+`default-directory' instead."
+  :prefix t
+  (if (and remote (file-remote-p default-directory))
+      (let ((res (locate-file
+                  command
+                  (mapcar
+                   (apply-partially
+                    #'concat (file-remote-p default-directory))
+                   (exec-path))
+                  exec-suffixes 'file-executable-p)))
+        (when (stringp res) (file-local-name res)))
+    (executable-find command)))
+
 ;; TODO provide advice for directory-files-recursively
 
 ;;;; Defined in format-spec.el

Reply via email to