20

My current use case is to find where the Cask executable is (it can be installed in at least two places, and there's an issue open about this).

I need to require cask this way:

(require 'cask "~/.cask/cask.el")

But I need to find the correct path to that cask.el, and as far as I know, the easiest way to do that is through locating the executable.

How can I do this?

3
  • 7
    Is executable-find what you're looking for?
    – legoscia
    Sep 26, 2014 at 18:04
  • 2
    Do you want the executable or the lisp library file? Cask has both.
    – shosti
    Sep 26, 2014 at 18:26
  • It looks you're asking two different things. Do you want to locate the cask executable? Or the cask.el library file (which is not an executable)? Please amend your question and title accordingly.
    – Malabarba
    Sep 26, 2014 at 22:22

3 Answers 3

22

@Sigma's answer is a good start, but it doesn't filter by executability, nor does it allow for extra suffixes. On windows, for example, running a can invoke a.exe, if that's what's in your path.

So use executable-find; here's the definition (taken from Emacs' sources), if you're curious:

(defun executable-find (command)
  "Search for COMMAND in `exec-path' and return the absolute file name.
Return nil if COMMAND is not found anywhere in `exec-path'."
  ;; Use 1 rather than file-executable-p to better match the behavior of
  ;; call-process.
  (locate-file command exec-path exec-suffixes 1))
3

Not sure I understand completely (I'm not using Cask myself), but would the following put you on the right track ?

(locate-file "cask" exec-path)

That seems to be the answer to your general question.

1
  • 3
    For executables specifically you should rather use executable-find.
    – user227
    Aug 6, 2016 at 14:44
0

Paths to executable on partial prefix:

(locate-file-completion-table
   exec-path
   exec-suffixes
   ;; here is prefix like "emacs" gives "emacs21"/"emacs22"/"emacs-nox"
   (thing-at-point 'filename)
   'identity
   t)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.