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)?
Asked
Active
Viewed 987 times
9

Name
- 7,689
- 4
- 38
- 84
1 Answers
14
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:
-
The program name that was used to run Emacs.
Any directory names are omitted. -
The directory in which the Emacs executable was found, to run it.
The value is nil if that directory's name is not known.

Malabarba
- 22,878
- 6
- 78
- 163