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

Buf{something} autocommand isn't always run #23

Closed
arp242 opened this issue Feb 11, 2016 · 4 comments
Closed

Buf{something} autocommand isn't always run #23

arp242 opened this issue Feb 11, 2016 · 4 comments
Labels

Comments

@arp242
Copy link

arp242 commented Feb 11, 2016

When I do: vim . the BufCreate autocommand isn't executed, but if I do vim -c ':e .' it is.

I see a lot of noau in the script; I'm not sure why you would ever need that? If I understand the intention of this plugin correct, it's designed to be "just a buffer", so stuff like running autocommands seems to be a part of that to me?

At any rate, both methods (vim . and :e .) should probably do the same.

@justinmk
Copy link
Owner

In the cases you mentioned, Vim creates the buffer before Dirvish ever sees it. Any autocmd you set up won't get triggered in the vim . case. Can be verified by adding au BufCreate * echom localtime() in vimrc and then compare vim foo to vim -c 'e foo', where foo is a non-existent file.

Note that :h BufCreate says it's for when a buffer is added to the buffer list. But dirvish buffers are 'nobuflisted', which I would think is generally preferable.

Regarding noau: it's in s:do_open to avoid infinite loop, though that's avoidable in other ways. The other noau are mostly when tickling the alternate buffer, and those cases could be avoided in Vim 7.4.7xx.

@arp242
Copy link
Author

arp242 commented Feb 12, 2016

Right. I picked the wrong example with BufCreate as I as I misremembered the subtle differences between the various autocmds :-/ I would expect some auto autocommand to be run; BufRead*? This can still be done manually with doautocmd btw.

The problem is that one of my plugins wants to create a b: variable for every buffer. I can use BufEnter, but that gets run every time a buffer is entered, so it's not exactly ideal...

@justinmk
Copy link
Owner

This can still be done manually with doautocmd btw.

Yep, that's what I will do if removing noau judiciously is unfeasible.

@justinmk justinmk changed the title BufCreate autocommand isn't always run Buf{something} autocommand isn't always run Mar 18, 2016
@justinmk justinmk added the bug label Mar 25, 2016
@justinmk
Copy link
Owner

Documentation of BufRead[Post] mentions that it will not be triggered for buftype=nofile ("Not used when the file doesn't exist").

After removing all cases of :noau, BufNew works for :edit <nothing> and :edit <directory>. But it never works for :Dirvish ... (nor do BufAdd, BufNewFile, BufReadPost, and BufFilePost, for either case).

So :noau doesn't seem to be the root cause of this problem. Vim considers directory-like paths an "error" (which is a Vim bug, IMO), maybe that's related.

Dirvish now fires BufNew when a directory is first visited. @Carpetsmoker let me know if you have any better insight or suggestions.

justinmk added a commit that referenced this issue Jan 10, 2018
Explicit `doautocmd BufEnter` causes Vim to again make love to the
buffer name, which cancels our effort to normalize the name.

Retreat from this micromanagemnt.

- Remove `:noautocmd` to allow implicit BufEnter/BufNew.
- Our BufEnter handlers are not marked `nested`, so they won't recurse.

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

No branches or pull requests

2 participants