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

Question: Why the ocamlformat plugin for vim stop me from storing me code? #2561

Open
VON0000 opened this issue Jun 26, 2024 · 6 comments
Open

Comments

@VON0000
Copy link

VON0000 commented Jun 26, 2024

i am running Linux Mint
My ocaml version is 4.13.1
My ocamlformat version is 0.26.2
My vim version is 9.1

i add this to my vimrc
'''
call plug#begin('~/.vim/plugged')

Plug 'rgrinberg/vim-ocaml'

call plug#end()

autocmd BufWritePre .ml,.mli execute ':silent !ocamlformat % --inplace' | execute 'edit!'
'''
But after that, if i do sth like ':w' or ':wq', any new code i write that is not saved will be deleted. And the file is saved as the last version before coding.

ocamlformat works well in terminal.

@Julow
Copy link
Collaborator

Julow commented Jun 26, 2024

BufWritePre is called before the file is saved to disk. Ocamlformat operates on the old file and the edit! overwrite any new change.
Did you find these instructions somewhere ?

This should work with BufWritePost instead. Though, a dedicated formatter plugin for vim would work better as it will handle different languages and errors.

@VON0000
Copy link
Author

VON0000 commented Jun 26, 2024

sorry for bothering you, but I have tried this one "autocmd BufWritePost .ml,.mli execute ':silent !ocamlformat % --inplace' | execute 'edit!'"
It can store my change now but it could not format the code.

@Julow
Copy link
Collaborator

Julow commented Jun 26, 2024

Is here an error? Having a nice display of the errors is hard to do in Vim, you'd probably have more luck with a formatter plugin.
I do not have formatting-on-save in my setup so I cannot suggest a specific plugin.

@VON0000
Copy link
Author

VON0000 commented Jun 26, 2024

There is no error or warning in terminal. I tried to print the log of vim.
ah0IeT4wwb
It seems that no log connected to ocamlformat is printed.

I also will try to find some formatter plugin for vim.

@Julow
Copy link
Collaborator

Julow commented Jun 26, 2024

You can run :!ocamlformat % --inplace, which should show the same errors if any.

@VON0000
Copy link
Author

VON0000 commented Jun 26, 2024

:!ocamlformat % --inplace works well in vim

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

No branches or pull requests

2 participants