Suppose that I have two identical emacs (of the same version) on my system. One is placed at C:\Program Files\Gnu Emacs and the other one at different place, say C:\Program Files\New Gnu Emacs. Can a running Emacs detect which one is? For example, can it give the path of its executable (i.e., the path where emacs.exe or emacs.bin can be found)?


1 Answer 1


Assuming Emacs knows how it was started, you can access the full path of the executable file by doing:

(expand-file-name invocation-name invocation-directory)

In my system, for instance, this returns "/usr/local/bin/emacs" on my regular session and returns "~/.evm/bin/emacs" on my evm test session. If you want to get fancy, you can also wrap that in a file-truename to resolve any symlinks.

The two variables used above, as described by their doc strings:

  • invocation-name

    The program name that was used to run Emacs.
    Any directory names are omitted.

  • invocation-directory

    The directory in which the Emacs executable was found, to run it.
    The value is nil if that directory's name is not known.

Your Answer

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

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