1

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:

variable="${ENV_VAR}/path/to/file"

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?

1 Answer 1

2

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)
3
  • 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. Commented Oct 16, 2020 at 9:38
  • 1
    This might be related to this bug Commented Oct 16, 2020 at 9:45
  • Looks like it is, yes. Commented Oct 16, 2020 at 12:40

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.