Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sesman-follow-symlinks defcustom #13

Closed
wants to merge 1 commit into from
Closed

Add sesman-follow-symlinks defcustom #13

wants to merge 1 commit into from

Conversation

JAremko
Copy link
Contributor

@JAremko JAremko commented Nov 5, 2018

Fix clojure-emacs/cider#2505

This works for me with .dir-locals.el:

((nil . ((find-file-visit-truename . nil)
         (vc-follow-symlinks       . nil)
         (sesman-follow-symlinks   . nil))))

sesman.el Outdated
:group 'sesman
:type 'boolean
:package-version '(sesman . "0.3.2"))
(put 'sesman-follow-symlinks 'safe-local-variable (lambda (x) (booleanp x)))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vspinu I don't see negative repercussions of this.

sesman.el Outdated
@@ -72,6 +72,14 @@ sessions running in dependent projects."
:type 'boolean
:package-version '(sesman . "0.3.2"))

(defcustom sesman-follow-symlinks t
"If non-nil expand file paths and follow symlinks using `file-truename'.
Copy link
Owner

@vspinu vspinu Nov 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a bit uncomfortable that this goes against the default value of find-file-visit-truename. What are your thoughts regarding this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vspinu Agree. But it will be confusing either way. When you use something like ranger it suppresses prompt from vc-follow-symlinks ask so vc fallbacks to vc-follow-symlinks t and since projects are usually under version control the value of find-file-visit-truename doesn't really meter.

I have another idea. I'll update PR.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. I think it's best to keep it simple and following vc here is the right choice. Unless you really have something uniformly better than this simple solution I would rather stick to this boolean setting.

@JAremko
Copy link
Contributor Author

JAremko commented Nov 6, 2018

@vspinu How about that ?

@JAremko
Copy link
Contributor Author

JAremko commented Nov 6, 2018

Don't know if vc-backend is too slow or not. Mb it also needs caching 🤔

@JAremko
Copy link
Contributor Author

JAremko commented Nov 6, 2018

Also it simplifies: .dir-locals.el

((nil . ((find-file-visit-truename . nil)
         (vc-follow-symlinks       . nil))))

I asked Emacs dudes to white-list vc-follow-symlinks https://debbugs.gnu.org/cgi/bugreport.cgi?bug=33264

@vspinu
Copy link
Owner

vspinu commented Nov 6, 2018

Not sure. The semantics is considerably more complex. It defaults to nil when not in VC projects and to t within. The users will have to be aware of those two variables and how they interplay for the purpose of sesman. I think the most common use case is to simlink a directory outside of a project and the new setup will fail for that use case. The advantage of the new proposal is that it is consistent with how find-file works and it's not to us to fix that.

Maybe sesman-follow-symlinks could be set to auto in order to achieve this new behavior? I don't like this new -fn. I think if users want to change that -fn they can overwrite or advice sesman-follow-symlink-p directly.

How about the following. Keep both sesman-follow-symlinks and a version of sesman-follow-symlink-p which will be triggered when sesman-follow-symlink is auto? Then users can have the freedom to set all 3 variables as they want and to revert to the old behavior by setting it to t.

I think the vc and file-find variables should be referenced clearly in sesman-follow-symlinks docstring. I have been with emacs for more than 10 years and was not aware of those.

@JAremko
Copy link
Contributor Author

JAremko commented Nov 6, 2018

Should auto be default for sesman-follow-symlinks ?

@vspinu
Copy link
Owner

vspinu commented Nov 6, 2018

BTW, when set to auto sesman can go a bit further and fallback on the project in the true path if there is no project in symlinked path. But it's getting crazy.

Should auto be default for sesman-follow-symlinks ?

I would think so.

BTW, I think (vc-backend ...) is not representative if vc follows links or not. It follows if the truename is in the VCed dir. For example if you have a link from outside of project into a project file then you will be redirected but vc-backend will return nil on the original path. This behavior would be consistent with what clojure-emacs/cider#2433 was about.

@JAremko
Copy link
Contributor Author

JAremko commented Nov 6, 2018

BTW, when set to auto sesman can go a bit further and fallback on the project in the true path if there is no project in symlinked path. But it's getting crazy.

With polylith the both paths have project files. But it's getting kinda too complicated to even thing about it 🤔

@JAremko
Copy link
Contributor Author

JAremko commented Nov 6, 2018

BTW, I think (vc-backend ...) is not representative if vc follows links or not. It follows if the truename is in the VCed dir.

Yeah https://github.com/emacs-mirror/emacs/blob/emacs-26/lisp/vc/vc-hooks.el#L824 🤔

And the truename isn't file-truename but expand-file-name 🤔

@JAremko
Copy link
Contributor Author

JAremko commented Nov 6, 2018

@vspinu I think this is how they do it 🤔

@JAremko
Copy link
Contributor Author

JAremko commented Nov 6, 2018

I'm done :shipit:

sesman.el Outdated
:group 'sesman
:type '(choice (const :tag "Behave like `find-file'" auto)
(const :tag "Don't fallow symlinks" nil)
(const :tag "fallow symlinks" t))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, "follow" and capitalized ;)

sesman.el Outdated
"This variable determines whether symlinks should be followed.
nil - Don't fallow symlinks - use `expand-file-name' for expanding file paths.
t - Fallow symlinks - us `file-truename' for expanding file paths.
'auto - Don't fallow symlink unless it's under version control and
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fallow -> "follow", "us" -> "use".

sesman.el Outdated
@@ -319,6 +332,16 @@ If SORT is non-nil, sort in relevance order."
(defun sesman--lnk-value (lnk)
(nth 2 lnk))

(defun sesman--follow-symlink-p (filename)
"FILENAME predicate that tries to predict whether `find-file' will
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am afraid this doesn't do it. With default settings, If am about to open a symlink into a VCed project from outside the VC context I am redirected into the real file, but sesman--follow-symlink-p returns nil on that symlink.

(puthash path (file-truename path) sesman--path-cache)))
(if (or (eq sesman-follow-symlinks t)
(and (eq sesman-follow-symlinks 'auto)
(sesman--follow-symlink-p path)))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it should be true name instead of path. I think this caching of file-names is not necessary either. There is a buffer local variable buffer-file-truename which could be used instead.

Copy link
Contributor Author

@JAremko JAremko Nov 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

think this caching of file-names is not necessary either.

You mean basically remove sesman--expand-path and use something like (file-name-directory buffer-file-truename) instead of (sesman--expand-path default-directory)

Got it. Sry multitasking. You mean instead (sesman--expand-path default-directory) do (sesman--expand-path (file-name-directory buffer-file-truename))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about (sesman--expand-path dir)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. I meant that that entire caching mechanism of truenames is not needed. I was not aware about buffer-file-truename before.

The sesman-relevant-context-p for project should first sesman--expand-path on buffer true name, then use that as default-directory and call sesman-project and root-dir.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sesman-relevant-context-p for project should first sesman--expand-path on buffer true name, then use that as default-directory and call sesman-project and root-dir.

@vspinu I don't think that I have sesman expertise required for a refactoring of such scale 😺

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Let me take over from here. This part turned to be much stuffier than expected. Thanks for all the effort!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vspinu Cool thx 👍

@vspinu
Copy link
Owner

vspinu commented Nov 6, 2018

I would really appreciate if you could squeeze a few tests here. Basically 4 cases, VCed -> Non-VCed, VCed -> VCed, Non-VC-ed -> VC-ed, Non-VC-ed-> Non-VCed replicated for two possible values of sesman-follow-symlinks variables.

sesman.el Outdated
(vc-backend truename))))))

(defvar sesman--file-truename-cache (make-hash-table :test #'equal))
(defun sesman--file-truename (filepath)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vspinu Can we use something like this ?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That dynamic buffer-file-truename will surely screw things up when called with filepath which is not from current buffer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't know that it can be called in such way... Not a good idea anyway.

sesman.el Outdated
"Optimizing `file-truename' wrapper."
(let ((exp-fp (expand-file-name filepath)))
(cond
((string= exp-fp default-directory)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can default-directory be not expanded?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Often actually.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vspinu thx.

(const :tag "Don't follow symlinks" nil)
(const :tag "Follow symlinks" t))
:package-version '(sesman . "0.3.2"))
(put 'sesman-follow-symlinks
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vspinu White-listed sesman-follow-symlinks.

Now I'm gone fore real. Good luck and thanks for the package 😄

@JAremko
Copy link
Contributor Author

JAremko commented Nov 6, 2018

btw TravisCI reports sesman.el:69: Some lines are over 80 columns wide

Ok. Now I'm gone gone. :shipit:

@vspinu
Copy link
Owner

vspinu commented Nov 9, 2018

I have built on top of this and merged locally. The issues should be fixed. Only vc-follow-symblinks is honored. I think it's simpler and more consistent this way.

@vspinu vspinu closed this Nov 9, 2018
@JAremko
Copy link
Contributor Author

JAremko commented Nov 9, 2018

That's Great! Thanks @vspinu ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants