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

problem with undojoin snippet #134

Open
hoschi opened this issue Nov 27, 2017 · 3 comments
Open

problem with undojoin snippet #134

hoschi opened this issue Nov 27, 2017 · 3 comments
Labels

Comments

@hoschi
Copy link

hoschi commented Nov 27, 2017

With the snippet

augroup fmt
  autocmd!
  autocmd BufWritePre * undojoin | Neoformat
augroup END

I get an error when writing the buffer again after undoing a change:

E790: undojoin is not allowed after undo
@hoschi
Copy link
Author

hoschi commented Nov 27, 2017

I found this https://vi.stackexchange.com/a/13401
and modified it into:

augroup fmt
  autocmd!
  au BufWritePre * try | undojoin | Neoformat | catch /^Vim\%((\a\+)\)\=:E790/ | finally | silent Neoformat | endtry
augroup END
  • catches error above
  • formats code when error catched
  • other errors (e.g. file was changed since last write) are still shown

Only "downside" is that you must hit enter when the file changed outside of vim and you selected "y" to overwrite it and Neoformat is run after that.

@sbdchd sbdchd added the bug label Nov 28, 2017
Boelensman1 added a commit to Boelensman1/dotfiles that referenced this issue Jun 15, 2019
sbdchd/neoformat#134
Signed-off-by: Boelensman1 <me@wiggerboelens.com>
@barraponto
Copy link

Can we have this in the README?

huntie added a commit to huntie/dotfiles that referenced this issue Apr 28, 2020
At present, Neoformat is unable to resolve the local Prettier version. Also would surface occasional errors on save (sbdchd/neoformat#134).
huntie added a commit to huntie/dotfiles that referenced this issue Apr 28, 2020
At present, Neoformat is unable to resolve the local Prettier version. Also would surface occasional errors on save (sbdchd/neoformat#134).
bachhh added a commit to bachhh/neoformat that referenced this issue Sep 12, 2021
@hoschi proposed a nice fix for issue sbdchd#134, I hope it can be put on the front page, in README.md.
ymcagodme pushed a commit to ymcagodme/dotfiles that referenced this issue Dec 21, 2021
@iamFIREcracker
Copy link
Contributor

I found this https://vi.stackexchange.com/a/13401 and modified it into:

augroup fmt
  autocmd!
  au BufWritePre * try | undojoin | Neoformat | catch /^Vim\%((\a\+)\)\=:E790/ | finally | silent Neoformat | endtry
augroup END
  • catches error above
  • formats code when error catched
  • other errors (e.g. file was changed since last write) are still shown

Only "downside" is that you must hit enter when the file changed outside of vim and you selected "y" to overwrite it and Neoformat is run after that.

Hey, thanks for this. What's the deal with the double call to :Neoformat by the way? One right after :undojoin, and inside the :finally block? I am not entirely sure what's the edge case that it's trying to catch.

I suspect the following to do just fine, right?

  • If :undojoin does not fail, :Neoformat (the one inside the :try block is executed just fine)
  • If :undojoin does fail, then the :Neoformat from within the :catch block is run
  • If something else happens, we give up and let the user deal with it without running :Neoformat
au BufWritePre * try | undojoin | Neoformat | catch /E790/ | Neoformat | endtry

ryanisaacg added a commit to ryanisaacg/neoformat that referenced this issue Mar 29, 2022
I'm just copying the snippet from sbdchd#134, because I've run into the same issue and the proposed fix worked for me
marjacob added a commit to marjacob/dotfiles that referenced this issue Jun 22, 2022
The error "E790: undojoin is not allowed after undo" appears when writing a file
with :w right after performing an undo operation.

See the following URLs for more information:
* sbdchd/neoformat#134
* https://vi.stackexchange.com/a/10326
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

4 participants