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

Run __mundo__ autocmds earlier #92

Open
BlueDrink9 opened this issue Feb 21, 2020 · 4 comments
Open

Run __mundo__ autocmds earlier #92

BlueDrink9 opened this issue Feb 21, 2020 · 4 comments

Comments

@BlueDrink9
Copy link

BlueDrink9 commented Feb 21, 2020

I use some autocmds to set the default filetype for new buffers:

autocmd myVimrc BufNewFile * filetype detect | if &filetype == "" | setlocal ft=scratch | endif
" No names
autocmd myVimrc BufEnter {} if &filetype == "" | setlocal ft=scratch | endif
autocmd myVimrc BufEnter * if &filetype == "" | setlocal ft=conf

For some reason, the combination of the first and last autocmd in that list breaks mundo, causing the __mundo__ files to be opened as actual non-hidden new files, with ft=scratch.

Changing the MundoAug groups to BufNewFile instead of BufEnter fixes this:

autocmd BufNewFile __Mundo__ call s:MundoSettingsGraph()
autocmd BufNewFile __Mundo_Preview__ call s:MundoSettingsPreview()

This would mean re-entering an existing Mundo window wouldn't reapply the autocmd. That's potentially a benefit, since it is marginally more efficient if they only set local settings anyway (which can't be changed unless within the buffer), and wouldn't override user changes to buffer settings each time they re-enter it.

It also makes Mundo's ft setup etc more robust, since it's happening earlier in the setup process. It stops buggy vimrc or plugins from modifying the buffer if their autocmds fire first, for example.

@BlueDrink9
Copy link
Author

@simnalamburt do you have any thoughts on this?

simnalamburt added a commit that referenced this issue May 9, 2020
We used `BufNewFile` in long time ago and changed it into `BufEnter`
intensionally. But someone wanted it to be executed little bit earlier.

So I hereby made `__Mundo__`, `__Mundo_Preview__` be executed at both
`BufNewFile` and `BufEnter`.

References:
  #74
  #92
@simnalamburt
Copy link
Owner

@BlueDrink9 OMG sorry to keep you extremely late.

We used BufNewFile in long time ago and changed it into BufEnter intensionally: #74

Well.. Since s:MundoSettingsGraph() and s:MundoSettingsPreview() is not that expensive function, fixing autoload/mundo.vim like this will both keep #74 and fix your issue:

diff --git a/autoload/mundo.vim b/autoload/mundo.vim
index 18009d9..3c437fe 100644
--- a/autoload/mundo.vim
+++ b/autoload/mundo.vim
@@ -533,8 +533,8 @@ augroup MundoAug
                     \ call s:MundoRenderPreview() |
                     \ call s:MundoStopRefreshTimer() |
                 \ endif |
-    autocmd BufEnter __Mundo__ call s:MundoSettingsGraph()
-    autocmd BufEnter __Mundo_Preview__ call s:MundoSettingsPreview()
+    autocmd BufNewFile,BufEnter __Mundo__ call s:MundoSettingsGraph()
+    autocmd BufNewFile,BufEnter __Mundo_Preview__ call s:MundoSettingsPreview()
     autocmd CursorHold,CursorMoved,TextChanged,InsertLeave *
                 \ call s:MundoRefresh()
 augroup END

But well.. I'm not sure if it's really a big deal to Execute __Mundo__ and __Mundo_Preview__ little bit early. Is it common practice to reload syntax highlightings and keymaps on both BufNewFile and BufEnter?

I made a draft PR of this patch, but I want to listen @dsummersl's opinion first. :)

@BlueDrink9
Copy link
Author

I see. #74 is definitely a reason to keep using bufenter. For me, the only thing that actually affects me is when the buffer filetype is set, so if you wanted to make the smallest possible change, separating out setting the filetype and only having that set with bufnewfile would work. I can't imagine a world where setting it on bufenter would be needed for anything.

@BlueDrink9
Copy link
Author

Alternatively, if it's just s:MundoSyntaxGraph() that #74 needs on bufenter, maybe that could be called separately on bufenter

simnalamburt added a commit that referenced this issue Mar 26, 2024
We used `BufNewFile` in long time ago and changed it into `BufEnter`
intensionally. But someone wanted it to be executed little bit earlier.

So I hereby made `__Mundo__`, `__Mundo_Preview__` be executed at both
`BufNewFile` and `BufEnter`.

References:
  #74
  #92
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

No branches or pull requests

2 participants