Search code examples
emacsprojectileemacs-helm

Open a fixed file from a project (in Emacs Projectile)


How can I code a function to open the same relative file (for example, server/logfile.txt) from a project? So, this should be relative to the project I'm in.

projectile-find-file list all of them, not only the one which we're interested to open...


Solution

  • You can use the projectile-project-root function to expand paths relative to your projectile project's base directory, eg.

    (when-let ((root (projectile-project-root)))
      (find-file-other-window (expand-file-name "server/logfile.txt" root)))
    

    or (the when-let, if-let macros are from subr-x included in recent emacses)

    (if-let ((root (projectile-project-root)))
        (find-file-other-window (expand-file-name "server/logfilt.txt" root))
      (user-error "not projectile project found"))