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

206 views Asked by At

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...

2

There are 2 answers

0
Rorschach On BEST ANSWER

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"))
0
Sivaram On

Perhaps a non projectile way would be to use bookmarks feature of emacs? For an already defined bookmark C-x r b would take you to the file and offset within it?