... fire autocmds on :cd and :lcd family of commands.
This is intended to fix #868.
Note that it only responds to user-initiated changes (:cd, :lcd, and synonyms); are there other ways the working directory can change that we should look out for?
https://github.com/vim/vim/pull/888
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
I'd be happy to write unit tests for this, but would first like to know if the approach is reasonable.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, .
In src/ex_docmd.c:
> @@ -8928,6 +8928,10 @@ ex_cd(exarg_T *eap) > /* Echo the new current directory if the command was typed. */ > if (KeyTyped || p_verbose >= 5) > ex_pwd(eap); > + > +#ifdef FEAT_AUTOCMD > + apply_autocmds(EVENT_DIRCHANGED, new_dir, new_dir, FALSE, curbuf);
The event "pattern" should say "global" or "window". expand('<afile>')
can be used to get the directory name itself (though even that seems useless, because getcwd()
should serve that purpose anyway).
apply_autocmds(EVENT_DIRCHANGED, "global", new_dir, FALSE, curbuf);
Advantages:
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, .
In src/ex_docmd.c:
> @@ -8928,6 +8928,10 @@ ex_cd(exarg_T *eap) > /* Echo the new current directory if the command was typed. */ > if (KeyTyped || p_verbose >= 5) > ex_pwd(eap); > + > +#ifdef FEAT_AUTOCMD > + apply_autocmds(EVENT_DIRCHANGED, new_dir, new_dir, FALSE, curbuf);
Though I see you already removed DirChangedLocal, it could be useful for scripts to listen to only window-local directory changes. Though I cannot think of why.
autocmd DirChanged window ...
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, .
In src/ex_docmd.c:
> @@ -8928,6 +8928,10 @@ ex_cd(exarg_T *eap) > /* Echo the new current directory if the command was typed. */ > if (KeyTyped || p_verbose >= 5) > ex_pwd(eap); > + > +#ifdef FEAT_AUTOCMD > + apply_autocmds(EVENT_DIRCHANGED, new_dir, new_dir, FALSE, curbuf);
Hi, I don't think I agree that the pattern should be a keyword like "window" or "global". I find it more consistent with the other autocommands if it is a filename glob. Users can use '*' to match everything. Maybe we can think of another way to implement multiple event types if that's desired?
I'm also thinking that the third argument () should maybe just be NULL, because it's also confusing if is suddenly a directory.
And, I'm wondering if it should also check if the directory actually changed. Now it fires on each cd command, even if it didn't.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, .
In src/ex_docmd.c:
> @@ -8928,6 +8928,10 @@ ex_cd(exarg_T *eap) > /* Echo the new current directory if the command was typed. */ > if (KeyTyped || p_verbose >= 5) > ex_pwd(eap); > + > +#ifdef FEAT_AUTOCMD > + apply_autocmds(EVENT_DIRCHANGED, new_dir, new_dir, FALSE, curbuf);
I find it more consistent with the other autocommands if it is a filename glob.
The pattern is not always a filename (e.g. FileType
autocommand), and it would be useless for this use-case.
The autocmd pattern is the primary way of selecting a subset of event messages to listen to.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, .
I agree with Justin, using "global" or "window" works better.
I'l dropping the patch from the todo list until that's done and we have tests.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, .
@misterfish pushed 4 commits.
—
You are receiving this because you are subscribed to this thread.
@misterfish pushed 1 commit.
—
You are receiving this because you are subscribed to this thread.
@misterfish pushed 1 commit.
—
You are receiving this because you are subscribed to this thread.
@misterfish pushed 2 commits.
—
You are receiving this because you are subscribed to this thread.
@misterfish pushed 1 commit.
—
You are receiving this because you are subscribed to this thread.
@misterfish pushed 1 commit.
—
You are receiving this because you are subscribed to this thread.
@misterfish pushed 1 commit.
—
You are receiving this because you are subscribed to this thread.
This could probably use some squashing, but is there any other reason it isn't merged yet?
I cleaned up this PR and made some small changes (removed unnecessary validation on autocmd pattern) andymass/vim@4e24de9 .
It differs from neovim's implementation since it does not set v:event
. But their v:event
seems completely useless since it just tells you getcwd()
and global/window which is in <amatch>
.
Thanks for cleaning it up, Andy.
@misterfish If you can reset your branch to andymass/vim@4e24de9 and push it, that would update the PR. Otherwise a new one should be opened and this one closed I guess.
@misterfish pushed 2 commits.
—
You are receiving this because you are subscribed to this thread.
Done.