tomtom / tcomment_vim

An extensible & universal comment vim-plugin that also handles embedded filetypes

Home Page:http://www.vim.org/scripts/script.php?script_id=1173

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

vim9script comments

lkjell opened this issue · comments

Is it possible to make tcomment vim9script aware?

                                                 vim9-mix

There is one way to use both legacy and Vim9 syntax in one script file:

         " comments may go here
         if !has('vim9script')
            " legacy script commands go here
            finish
         endif
         vim9script
         # Vim9 script commands go here

This allows for writing a script that takes advantage of the Vim9 script
syntax if possible, but will also work on a Vim version without it.

edit:
I see that tcomment does try to detect vim9scripts in the default.vim file, but does not work for .vimrc file.
The vim9scripts must not contain any "old" syntax e.g call FUNC otherwise it will think it is still in we are in vimscripts and not vim9scripts

I still use vim8 so I cannot check what is needed myself. What's the output of :call tcomment#debug#CollectInfo() with the cursor being placed on a vim9 line? (See also tcomment-new-filetype|.)

vim9script 
#vimscript9 is started use only new syntax!
syntax on # always enable syntax incase of early errors

var minpac_settings = {"progress_open": "vertical", "verbose": 3, "status_open": "vertical"}

def PackInit()
    packadd! minpac
    minpac#init(minpac_settings)

    minpac#add("k-takata/minpac", {"type": "opt"})

    minpac#add("tomtom/tcomment_vim")
enddef

Trying to comment var minpac_settings gives vim8 comments

TCOMMENT: &ft = vim => vim
TCOMMENT: stx = vimString => vimString
TCOMMENT: ct  = {'_args': {'beg': 5, 'fallbackFiletype': '', 'end': 5, 'filetype': 'vim', 'comment_mode': ''}, 'commentstring': '" %s', 'mode': '', 'filetype': 'vim'}

And for the other sections it swap back and forth between vim8 and vim9.

TCOMMENT: &ft = vim => vim
TCOMMENT: stx = vim9Comment => vim9Comment
TCOMMENT: ct  = {'if': 'getline(1) ==# ''vim9script'' ||getline(search(''^\%(fu\%[nction]\|def\)\>'', ''bcnWz'')) =~# ''^def\>'' && search(''^def\>'', ''bcnWz'') < line("''[")', '_args': {'beg': 25, 'fallbackFiletype': '', 'end': 25, 'filetype': 'vim', 'comment_mode': ''}, 'commentstring': '# %s', 'mode': '', 'filetype': 'vim'}

I did not understand what you meant by tcomment-new-filetype|.

2021-03-28.20-29-14.mp4

From what I gather vim8 and vim9 code share the same syntax names? This makes it difficult to determine the right comment syntax for mixed code.

Do I get you right that vim treats code as vim8 as soon as there is a :call command being used despite the use of the new :def command and the vim9script marker? This looks very confusing to me.

Would it help to support " and # comments for uncommenting and to use a user of per-file preference for commenting?

In any case, I'll change the definition so that the vim9script marker is allowed anywhere in the file.

@tomtom you just need to check that the magic word vim9script is at the beginning of the sentence. Everything under that line will be vim9script only. Everything above will be vim8 as now. It is not possible to comment with " in vim9.

I do not know how tcomment handle the logic. Sometimes I can switch from " to # but then tcomment remembers and does not switch back to ".

E1039: "vim9script" must be the first command in a script

Could you please check the previous commit if it improves the situation. I forgot to split the commit properly.

Which PR or commit you referring to?

In 7a9c1ea everything below the vim9script marker should be commented as vim9 code.

It works. I am unable to introduce the old behaviour.
Everything is using # as comment.
Cheers!

Tested with

" comments may go here
if !has('vim9script')
    " legacy script commands go here
    finish
endif
vim9script
# Vim9 script commands go here

and

vim9script 
#vimscript9 is started use only new syntax!
syntax on # always enable syntax incase of early errors

var minpac_settings = {"progress_open": "vertical", "verbose": 3, "status_open": "vertical"}

def PackInit()
    packadd! minpac
    minpac#init(minpac_settings)

    minpac#add("k-takata/minpac", {"type": "opt"})

    minpac#add("tomtom/tcomment_vim")
enddef