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?

Trevoke
  • 2,375
  • 21
  • 34
  • 7
    Is `executable-find` what you're looking for? – legoscia Sep 26 '14 at 18:04
  • 2
    Do you want the executable or the lisp library file? Cask has both. – shosti Sep 26 '14 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 '14 at 22:22

3 Answers3

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))
Clément
  • 3,924
  • 1
  • 22
  • 37
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.

Sigma
  • 4,510
  • 21
  • 27
  • 3
    For executables specifically you should rather use `executable-find`. –  Aug 06 '16 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)
gavenkoa
  • 3,352
  • 19
  • 36