`Helm’ can detect a file name at point. The file name can be absolute or relative path. However, it does not have the ability to identify a shell variable. If you have a path like `$(FOAM_TUTORIAL)/some/path/' you will not able to find the file correctly.

Here is what I do to solve this problem:

First setup some constants:

1
(setq wr/project-root-path "/PATH/TO/PROJ/")

Now you can `M-x wr/find-file-in-project-at-point’ to find file path in this case.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
(defun wr/project-root (filename)
  "Return the root directory of the project containing FILENAME."
  (let ((root (file-name-directory filename)))
    (while (and (not (file-exists-p (expand-file-name ".git" root)))
                (not (equal root (file-truename (file-name-directory (file-name-directory root))))))
      (setq root (file-name-directory (directory-file-name root))))
    (if (file-exists-p (expand-file-name ".git" root))
        root)))

(defun wr/find-file-in-project-at-point (&optional open-another-window)
  "Find file name in a simulation project. Replace root according
to the location of the current machine."
  (interactive "P")
  (let* ((filename (or
                    (thing-at-point 'filename)
                    (thing-at-point 'symbol)
                    (ffap-file-at-point)))
         (project-root-dir (wr/project-root (buffer-file-name)))
         (ffip-match-path-instead-of-filename t))
    (cond
     (filename
      (setq filename
            (setq wr/test-filename
                  (replace-regexp-in-string "$(FOAM_TUTORIAL)"
                                            (concat wr/project-root-path
                                                    (car (last
                                                          (split-string
                                                           (locate-dominating-file
                                                            (buffer-file-name)
                                                            ".git")
                                                           "/" t))))
                                            filename)))
      (find-file filename))
     (t
      (message "No file name is provided.")))))

Happy find file!