Q:  Assuming that we open Emacs with a path to ../Emacs.app/Contents/MacOS/Emacs, how can we programmatically extract the path to etags located at ../Emacs.app/Contents/MacOS/bin/etags. [The location of Emacs.app will vary.]

I want to build my own TAGS index for certain files from the Emacs source code that I am tinkering with in a project directory containing only those files. Here is link to the draft function that I am using to build tags: find-tag: Build a new TAGS file if it does not already exist

OSX comes with an outdated version of etags located at /usr/bin/etags. I have recently learned that the outdated version of etags fails to index a ton of stuff in the current source code used to build Emacs. That discovery, combined by a lesson from Eli Z. over on reddit (i.e., calling make tags), led me to the command line ../emacs/lib-src/etags. The etags executable that is used in Emacs 26 and the current version of the master branch is superior in terms of its ability to properly index the source code. When calling make install (assuming Emacs was configured --with-ns), a packaged Emacs is created with a folder/package called Emacs.app. I am making a leap by assuming that the executable located at ../Emacs.app/Contents/MacOS/bin/etags is the same as found in the source code tree ../emacs/lib-src/etags. [If that assumption is wrong, please let me know.]

While the normal location of packaged applications ending in .app (on OSX) is in /Applications, I place them in other locations. And, I have several versions of Emacs strewn about on my hard drive that I use periodically for different reasons.

1 Answer 1


The variable invocation-directory contains the directory in which the Emacs executable was found, so you can use

(file-truename (expand-file-name "bin/etags" invocation-directory))

See also the question Can Emacs detect the path of its executable?.

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.