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?

kvantour
  • 113
  • 4

1 Answers1

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)
NickD
  • 27,023
  • 3
  • 23
  • 42
  • 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 09:38
  • 1
    This might be related to [this bug](https://lists.gnu.org/archive/html/bug-gnu-emacs/2015-04/msg00133.html) – kvantour Oct 16 '20 at 09:45
  • Looks like it is, yes. – NickD Oct 16 '20 at 12:40