I'm using Projectile, and after seeing the really awesome .emacs file I decided to copy the lines that set the mode-line to display the project name, like so:

  (projectile-global-mode 1)
  (setq-default ;; <snip>
   projectile-mode-line '(:eval (projectile-project-name))))

I've got this included in my init.el and it almost works - the only problem is that the variable projectile-project-name is nil, so it doesn't actually show the name of the project (and this is even after I've done C-C p p and chosen a project.

How is projectile-project-name set and/or where is that information stored? (Maybe in the .projectile file?)

  • 1
    As per your code, you're calling the projectile-project-name function which does not purely depend on the variable of the same name (but does use that value by preference, when it's non-nil). – phils Aug 30 '18 at 7:18
  • It seems that projectile already sets projectile-mode-line to a value which includes the project name. Or at least the current version does. If you weren't already seeing that, your problem is probably that you have a custom mode line which isn't displaying projectile-mode-line at all. – phils Aug 30 '18 at 7:20
  • (:eval (format " Projectile[%s]" (projectile-project-name))) is the value I'm seeing for projectile-mode-line – phils Aug 30 '18 at 7:21
  • I'm using smart-mode-line, which seems to embed the projectile-mode-line into the mode line at the bottom of the screen. – MikeTheTall Aug 30 '18 at 15:57
  • Thanks for the tip about projectile-project-name being a function - I hadn't caught that. When I call it interactively (using M-:) it returns '-'..... because that particular file wasn't part of a project. It returns something reasonable when the file (buffer) that's open is part of the project – MikeTheTall Aug 30 '18 at 16:04

Much thanks to @phils for helping me to realize that Projectile displays the project name when the buffer that has the focus is in a project. If that buffer's file isn't in a project then it displays '-'

Thinking about this, this makes perfect sense - the error is clearly on my end :)

I think I was confused because Visual Studio / Eclipse / etc do it the opposite way - once you've got a project open you're always 'in' that project, even if you open unrelated files.

Both ways seems reasonable, and now I know how Projectile works :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.