From 305f3f65c30880aefa8a16de241bcce1556df8da Mon Sep 17 00:00:00 2001 From: Hanh Le Date: Fri, 17 Jul 2020 16:57:40 +0700 Subject: [PATCH 1/3] Add syntax for reasonml config --- after/ftplugin/reason.vim | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 after/ftplugin/reason.vim diff --git a/after/ftplugin/reason.vim b/after/ftplugin/reason.vim new file mode 100644 index 0000000..33bd0d3 --- /dev/null +++ b/after/ftplugin/reason.vim @@ -0,0 +1,31 @@ +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" Vim ftplugin file +" +" Language: javascript.jsx +" Maintainer: MaxMEllon +" +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" + +" modified from html.vim +" For matchit plugin +if exists("loaded_matchit") + let b:match_ignorecase = 0 + let b:match_words = '(:),\[:\],{:},<:>,' . + \ '<\@<=\([^/][^ \t>]*\)[^>]*\%(>\|$\):<\@<=/\1>' +endif + +" For andymass/vim-matchup plugin +if exists("loaded_matchup") + setlocal matchpairs=(:),{:},[:],<:> + let b:match_words = '<\@<=\([^/][^ \t>]*\)\g{hlend}[^>]*\%(/\@\|$\):<\@<=/\1>' + let b:match_skip = 's:comment\|string' +endif + +let b:jsx_pretty_old_cms = &l:commentstring + +augroup jsx_comment + autocmd! CursorMoved + autocmd CursorMoved call jsx_pretty#comment#update_commentstring(b:jsx_pretty_old_cms) +augroup end + +setlocal suffixesadd+=.jsx From 868a2a31531851ec155734790b1d2dc908e8e143 Mon Sep 17 00:00:00 2001 From: Hanh Le Date: Mon, 22 Feb 2021 15:53:00 +0700 Subject: [PATCH 2/3] add jsx_pretty#comment#update_commentstring function --- after/ftplugin/reason.vim | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/after/ftplugin/reason.vim b/after/ftplugin/reason.vim index 33bd0d3..496429c 100644 --- a/after/ftplugin/reason.vim +++ b/after/ftplugin/reason.vim @@ -28,4 +28,42 @@ augroup jsx_comment autocmd CursorMoved call jsx_pretty#comment#update_commentstring(b:jsx_pretty_old_cms) augroup end +function! jsx_pretty#comment#update_commentstring(original) + let line = getline(".") + let col = col('.') + if line !~# '^\s*$' && line[: col - 1] =~# '^\s*$' " skip indent + let col = indent('.') + 1 + endif + let syn_start = s:syn_name(line('.'), col) + let save_cursor = getcurpos() + + if syn_start =~? '^jsx' + if line =~ '^\s*//' + let &l:commentstring = '// %s' + elseif s:syn_contains(line('.'), col, 'jsxTaggedRegion') + let &l:commentstring = '' + elseif syn_start =~? '^jsxAttrib' + let &l:commentstring = '// %s' + else + let &l:commentstring = '{/* %s */}' + endif + else + let &l:commentstring = a:original + endif + + " Restore the cursor position + call setpos('.', save_cursor) +endfunction + +function! s:syn_name(lnum, cnum) + let syn_id = get(synstack(a:lnum, a:cnum), -1) + return synIDattr(syn_id, "name") +endfunction + +function! s:syn_contains(lnum, cnum, syn_name) + let stack = synstack(a:lnum, a:cnum) + let syn_names = map(stack, 'synIDattr(v:val, "name")') + return index(syn_names, a:syn_name) >= 0 +endfunction + setlocal suffixesadd+=.jsx From bc032b0616ec2f152a7293bc9c95ba8d05e82567 Mon Sep 17 00:00:00 2001 From: Hanh Le Date: Mon, 22 Feb 2021 16:07:37 +0700 Subject: [PATCH 3/3] correct function name --- after/ftplugin/reason.vim | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/after/ftplugin/reason.vim b/after/ftplugin/reason.vim index 496429c..adbfa83 100644 --- a/after/ftplugin/reason.vim +++ b/after/ftplugin/reason.vim @@ -23,12 +23,7 @@ endif let b:jsx_pretty_old_cms = &l:commentstring -augroup jsx_comment - autocmd! CursorMoved - autocmd CursorMoved call jsx_pretty#comment#update_commentstring(b:jsx_pretty_old_cms) -augroup end - -function! jsx_pretty#comment#update_commentstring(original) +function! s:update_commentstring(original) let line = getline(".") let col = col('.') if line !~# '^\s*$' && line[: col - 1] =~# '^\s*$' " skip indent @@ -65,5 +60,9 @@ function! s:syn_contains(lnum, cnum, syn_name) let syn_names = map(stack, 'synIDattr(v:val, "name")') return index(syn_names, a:syn_name) >= 0 endfunction +augroup jsx_comment + autocmd! CursorMoved + autocmd CursorMoved call s:update_commentstring(b:jsx_pretty_old_cms) +augroup end setlocal suffixesadd+=.jsx