whonore / Coqtail

Interactive Coq Proofs in Vim
MIT License
274 stars 35 forks source link

Comment indentation and duplicated comment line when inputing "return" in edit mode. #231

Closed vsiles closed 2 years ago

vsiles commented 2 years ago

That might be a bad interaction with another plugin, but I don't know how to debug this: I often write multi-line comments, and when I hit "return" at the end of a line, the current line is duplicated. Also, the * indentation looks incorrect. If I'm in edit mode at the end of the line and I hit return, this

(* bla bla bla

becomes

(* bla bla bla
*

Note that the * is not aligned. Now If I do the same with

(* bla bla bla
* sdfsdf

I end up with

(* bla bla bla
* sdfsdf
* sdfsdf

Any idea how to debug this ? In the meantime I'll try to check which plugins might interfere. Here is my list:

 17 Plugin 'ctrlpvim/ctrlp.vim'
 18 Plugin 'godlygeek/tabular'
 19 Plugin 'jceb/vim-orgmode'
 20 Plugin 'let-def/ocp-indent-vim'
 21 Plugin 'let-def/vimbufsync'
 22 Plugin 'ludovicchabant/vim-lawrencium'
 23 Plugin 'majutsushi/tagbar'
 24 Plugin 'prabirshrestha/async.vim'
 25 Plugin 'prabirshrestha/asyncomplete-lsp.vim'
 26 Plugin 'prabirshrestha/asyncomplete.vim'
 27 Plugin 'prabirshrestha/vim-lsp'
 28 Plugin 'racer-rust/vim-racer'
 29 Plugin 'roxma/nvim-yarp'
 30 Plugin 'roxma/vim-hug-neovim-rpc'
 31 Plugin 'rust-lang/rust.vim'
 32 Plugin 'Shougo/deoplete.nvim'
 33 Plugin 'tpope/vim-speeddating'
 34 Plugin 'tpope/vim-commentary'
 35 Plugin 'tpope/vim-fugitive'
 36 Plugin 'vim-airline/vim-airline'
 37 Plugin 'vim-airline/vim-airline-themes'
 38 Plugin 'vim-scripts/a.vim'
 39 Plugin 'w0rp/ale'
 40 Plugin 'whonore/Coqtail'
 41 Plugin 'greymd/oscyank.vim'
 42 Plugin 'joom/latex-unicoder.vim'

loaded with Vundle

vsiles commented 2 years ago

I tried to comment them all and the issue is still here. But if I start with vim --clean it is no longer here. I see I have a .vim/pack/coq directory with coq.vim in it. If I remove this, the issue disappears too. I also try to only leave CoqTail enabled, and the issue is still here, so probably not a bad interaction with another plugin.

I don't remember installing coq.vim by hand (maybe, but really doesn't ring a bell). Is it installed as part of Coqtail ? Should I report the issue to them ?

tomtomjhj commented 2 years ago

Can you try removing coq.vim and and reinstall Coqtail? If that doesn't fix, can you check the result of verb set comments formatoptions indentexpr indentkeys?

vsiles commented 2 years ago

I removed the pack/coq directory, removed CoqTail and reinstall it. The issue has been removed and the pack/coq directory has not been restored.

However now indenting seems to not work at all. Should I run something to setup indenting ?

In case it is useful, here is the output of the command you asked:

  comments=srn:(*,mb:*,exn:*)
        Last set from ~/.vim/bundle/Coqtail/ftplugin/coq.vim line 16
  formatoptions=tcql
        Last set from ~/.vimrc line 186
  indentexpr=GetCoqIndent()
        Last set from ~/.vim/bundle/Coqtail/indent/coq.vim line 17
  indentkeys=o,O,0=end,0=End,0=in,0=|,0=Qed,0=Defined,0=Abort,0=Admitted,0},0),0-,0+,0<*>,0--,0++,0<*><*>,0---,0+++,0<*><*><*>
        Last set from ~/.vim/bundle/Coqtail/indent/coq.vim line 18

Line 186 is autocmd FileType coq setlocal formatoptions-=o. I get the same behavior with or without it

tomtomjhj commented 2 years ago

Do you have let g:coqtail_noindent_comment = 1 in your vimrc? This disables indentation in comments.

tomtomjhj commented 2 years ago

Can you try inserting *? The default option in Coqtail aligns the comment line when * is typed. For example, suppose the cursor is at the first column of the second line:

(*
|

If you type *, it will be automatically aligned.

(*
 *|
vsiles commented 2 years ago

Do you have let g:coqtail_noindent_comment = 1 in your vimrc?

No:

$ grep coq .vimrc
autocmd FileType coq setlocal commentstring=(*\ %s\ *)
" autocmd FileType coq setlocal formatoptions-=o
" let g:syntastic_coq_checkers = []

Ok. I tried what you explained and it seems to work that way. Not the way I was used to but I don't care, things work now :) Thanks for helping me with this issue !

dhilst commented 2 years ago

Hello all, I replaced comments in the ftplugin/coc.vim with setlocal comments=sO:*\ -,mO:*\ \ ,exO:*),s1:(*,mb:*,ex:*)

This will enable comments like, inserting the proper * in the beginning of the line automatically.

(* foo
 * bar
 * zar ... *)

I copied this from the C mode and adapted, not sure if this is the preferred commenting style though. I have set fo+=r in my .vimrc.

I didn't change any Coqtail settings in the .vimrc file.

Not sure how to do this on .vimrc without intruding on the Coqtail code though. Here is the full if block

if has('comments')
  setlocal commentstring=(*%s*)
  "setlocal comments=sr:(*\ ,mb:\ ,ex:*)
  "setlocal comments^=sr:(**,mb:\ \ ,ex:*)
  setlocal comments=sO:*\ -,mO:*\ \ ,exO:*),s1:(*,mb:*,ex:*)

  " NOTE: The 'r' and 'o' flags mistake the '*' bullet as a middle comment and
  " will automatically add an extra one after <Enter>, 'o' or 'O'.
  " setlocal formatoptions-=tro formatoptions+=cql
  " let b:undo_ftplugin = add(b:undo_ftplugin, 'setl cms< com< fo<')
endif
tomtomjhj commented 2 years ago

Not sure how to do this on .vimrc without intruding on the Coqtail code though.

One way to do that in .vimrc:

" NOTE: This should be executed before setting up the custom FileType autocmds.
filetype plugin indent on

augroup MyFileTypeSetup | autocmd!
    autocmd FileType coq call s:ft_coq()
augroup END

function! s:ft_coq() abort
    " Your settings here..
endfunction

Alternatively, you can create after/plugin/coq.vim file in your runtimepath (e.g. ~/.vim) and put your custom settings there.

dhilst commented 2 years ago

Thanks @tomtomjhj!