dbordak / telephone-line

A new implementation of Powerline for Emacs
GNU General Public License v3.0
550 stars 51 forks source link

Fix projectile-buffer-segment to display root. #82

Closed ogdenwebb closed 6 years ago

ogdenwebb commented 6 years ago

Doh, today I've found that after my #81 projectile-buffer-segment doesn't display a project root, but it now works outside of a project. I though that the projectile-project-root function write a value into the projectile-project-root variable, but it's incorrect.

As far as I can understand this part of projectile.

(defvar-local projectile-project-root nil
  "Defines a custom Projectile project root.
This is intended to be used as a file local variable.")

The projectile-project-root variable will have nil value until a user specifies it manually, so projectile-buffer-segment fails to display a project root. Also, in the first place, the segment checks if projectile-mode is defined.

Finally it should work as expected. :clap:

dbordak commented 6 years ago

Why not just change it partially back to:

  (if (and (buffer-file-name)
           (fboundp 'projectile-project-root)
           (bound-and-true-p projectile-project-name))

if the problem is just that projectile-project-root is allowed to be nil?

dbordak commented 6 years ago

Oh, I see, they can both be nil.

dbordak commented 6 years ago

Oh, your other PR changed it from checking the functions to checking the variables.

ogdenwebb commented 6 years ago

Yes, the projectile-project-name variable also can return nil within a project.

Also if you check like that.

(fboundp 'projectile-project-root)

It will produce false result, because you can have this function from projectile, but the value of this function should be nil, so the segment won't work as expected.

dbordak commented 6 years ago

Yeah, figured that much out.

What would be best is if I could just see if (projectile-project-root) will work or not, but it either returns default or an error depending upon a global var (i.e. projectile-require-project-root) :/

(btw, if you set that global var to nil, you'll probably get the behavior you want)

dbordak commented 6 years ago

ok, kinda ugly, but I think I've got a solution for this

  (if (and (buffer-file-name)
           (fboundp 'projectile-project-name)
           (ignore-errors (projectile-project-root)))

That'll return nil whenever you'd get "You're not in a project" and collapse you into the false clause.

ogdenwebb commented 6 years ago

But what is the point to use this line? (ignore-errors (projectile-project-root)

Besides with (and (bound-and-true-p projectile-mode) it won't eval any other code without projectile.

dbordak commented 6 years ago

It doesn't matter if projectile-mode is true or not, you'll still get that "Not in a project" error if you're not in a project.

The ignore-errors line will return nil whenever a call to projectile-project-root would return that error.

ogdenwebb commented 6 years ago

It doesn't matter if projectile-mode is true or not, you'll still get that "Not in a project" error if you're not in a project.

Yeah, I got it. We can use projectile-project-p instead of ignore-errors.

dbordak commented 6 years ago

Oh, huh. That's exactly the same thing as the ignore-errors line.

dbordak commented 6 years ago

Actually, technically it saves a bit to use ignore-errors, since to use that function now we need to do

(and (fboundp 'projectile-project-p)
     (projectile-project-p))

:P

dbordak commented 6 years ago

Alright, that should probably resolve your issue, I think.

ogdenwebb commented 6 years ago

Yes, it's even clearly than other solutions here. :tada: