Closed ogdenwebb closed 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?
Oh, I see, they can both be nil.
Oh, your other PR changed it from checking the functions to checking the variables.
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.
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)
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.
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.
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.
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.
Oh, huh. That's exactly the same thing as the ignore-errors line.
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
Alright, that should probably resolve your issue, I think.
Yes, it's even clearly than other solutions here. :tada:
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 theprojectile-project-root
variable, but it's incorrect.As far as I can understand this part of projectile.
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: