-
Notifications
You must be signed in to change notification settings - Fork 8
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
Conversation
sesman.el
Outdated
:group 'sesman | ||
:type 'boolean | ||
:package-version '(sesman . "0.3.2")) | ||
(put 'sesman-follow-symlinks 'safe-local-variable (lambda (x) (booleanp x))) |
There was a problem hiding this comment.
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'. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@vspinu How about that ? |
Don't know if |
Also it simplifies: ((nil . ((find-file-visit-truename . nil)
(vc-follow-symlinks . nil)))) I asked Emacs dudes to white-list |
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 How about the following. Keep both I think the vc and file-find variables should be referenced clearly in |
Should |
BTW, when set to
I would think so. BTW, I think |
With |
Yeah https://github.com/emacs-mirror/emacs/blob/emacs-26/lisp/vc/vc-hooks.el#L824 🤔 And the |
@vspinu I think this is how they do it 🤔 |
I'm done |
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)) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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))) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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))
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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 😺
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vspinu Cool thx 👍
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.el
Outdated
(vc-backend truename)))))) | ||
|
||
(defvar sesman--file-truename-cache (make-hash-table :test #'equal)) | ||
(defun sesman--file-truename (filepath) |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Often actually.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 😄
btw TravisCI reports Ok. Now I'm gone gone. |
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. |
That's Great! Thanks @vspinu ❤️ |
Fix clojure-emacs/cider#2505
This works for me with
.dir-locals.el
: