Question: is there a way to convince ffap to perform variable substitution on environment variables before attempting to resolve the file path?

I often have lines in shell scripts that read:


When I use ffap on the above, it is unaware of what ${ENV_VAR} means. Assume ENV_VAR is properly defined via

export ENV_VAR="/path/to/dir"

in one of the shell's init-files and it can be found in the output of env. Is there a way we can trick ffap to do the variable substitution?


You can redefine ffap-file-finder. This is normally set to find-file, which doesn't do env variable expansion. So define a function like find-file that does do env variable expansion:

(defun find-file-env (fname)
   (find-file (substitute-in-file-name fname)))

and assign it to ffap-file-finder:

(setq ffap-file-finder #'find-file-env)
  • Thanks for the help. I've done the above, and it works "partially". When having a string like "${INCL_PATH}/path/to/foo", it will now recognize ${INCL_PATH} and it will recognize /path/to/foo (depending on the location of the cursor), but it will not recognize both combined. It does work when removing the braces.
    – kvantour
    Oct 16 '20 at 9:38
  • 1
    This might be related to this bug
    – kvantour
    Oct 16 '20 at 9:45
  • Looks like it is, yes.
    – NickD
    Oct 16 '20 at 12:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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