diff --git a/autoload/tcomment.vim b/autoload/tcomment.vim index 64b5866..aead64c 100644 --- a/autoload/tcomment.vim +++ b/autoload/tcomment.vim @@ -2,8 +2,8 @@ " @Website: http://www.vim.org/account/profile.php?user_id=4037 " @License: GPL (see http://www.gnu.org/licenses/gpl.txt) " @Created: 2007-09-17. -" @Last Change: 2019-03-17. -" @Revision: 2036 +" @Last Change: 2020-03-14. +" @Revision: 2039 scriptencoding utf-8 @@ -279,6 +279,16 @@ endf " postprocess_uncomment .. Run a |printf()| expression with 2 " placeholders on uncommented lines, e.g. " 'norm! %sgg=%sgg'. +" choose ... A list of commend definitions (a +" dictionary as defined above) that may +" contain an `if` key referring to an +" expression; if this condition evaluates +" to true, the item will be selected; the +" last item in the list will be selected +" anyway (see the bib definition for an +" example) +" if ... an |eval()|able expression (only valid +" within a choose list, see above) " 2. 1-2 values for: ?commentPrefix, ?commentPostfix " 3. a dictionary (internal use only) " diff --git a/autoload/tcomment/type.vim b/autoload/tcomment/type.vim index 0c45f98..e9f7a8b 100644 --- a/autoload/tcomment/type.vim +++ b/autoload/tcomment/type.vim @@ -2,8 +2,8 @@ " @Website: http://www.vim.org/account/profile.php?user_id=4037 " @License: GPL (see http://www.gnu.org/licenses/gpl.txt) " @Created: 2007-09-17. -" @Last Change: 2018-09-03. -" @Revision: 33 +" @Last Change: 2020-03-12. +" @Revision: 42 if exists(':Tlibtrace') != 2 command! -nargs=+ -bang Tlibtrace : @@ -90,11 +90,36 @@ endf " Return b:tcomment_def_{NAME} if the variable exists. Otherwise return " the comment definition as set with |tcomment#type#Define|. function! tcomment#type#GetDefinition(name, ...) abort + Tlibtrace 'tcomment', a:name if exists('b:tcomment_def_'. a:name) - return b:tcomment_def_{a:name} + let def = b:tcomment_def_{a:name} else - return get(s:definitions, a:name, a:0 >= 1 ? a:1 : '') + let def = get(s:definitions, a:name, a:0 >= 1 ? a:1 : '') endif + Tlibtrace 'tcomment', def + if has_key(def, 'choose') + let def = copy(def) + let defs = def.choose + let ndefs = len(defs) + Tlibtrace 'tcomment', ndefs + for idef in range(ndefs) + let cdef = defs[idef] + Tlibtrace 'tcomment', idef, cdef + if idef == ndefs - 1 + let choose = 1 + else + let choose = eval(cdef.if) + endif + Tlibtrace 'tcomment', choose + if choose + call remove(def, 'choose') + let def = extend(def, cdef) + break + endif + endfor + endif + Tlibtrace 'tcomment', def + return def endf diff --git a/autoload/tcomment/types/default.vim b/autoload/tcomment/types/default.vim index e42ba4d..6cc1705 100644 --- a/autoload/tcomment/types/default.vim +++ b/autoload/tcomment/types/default.vim @@ -1,8 +1,8 @@ " @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim]) " @Website: https://github.com/tomtom " @License: GPL (see http://www.gnu.org/licenses/gpl.txt) -" @Last Change: 2019-03-17 -" @Revision: 18 +" @Last Change: 2020-03-12 +" @Revision: 23 call tcomment#type#Define('aap', '# %s' ) call tcomment#type#Define('ada', '-- %s' ) @@ -14,7 +14,7 @@ call tcomment#type#Define('applescript_inline','# %s' ) call tcomment#type#Define('asciidoc', '// %s' ) call tcomment#type#Define('asm', '; %s' ) call tcomment#type#Define('asterisk', '; %s' ) -call tcomment#type#Define('bib', '%% %s' ) +call tcomment#type#Define('bib', {'choose': [{'if': 'col(".") <= 1', 'commentstring': '@Comment{%s}'}, {'commentstring': '%% %s'}]}) call tcomment#type#Define('blade', '{{-- %s --}}' ) call tcomment#type#Define('blade_block', '{{--%s--}}' ) call tcomment#type#Define('blade_inline', '{{-- %s --}}' ) diff --git a/doc/tcomment.txt b/doc/tcomment.txt index a7cc627..9d1f43c 100644 --- a/doc/tcomment.txt +++ b/doc/tcomment.txt @@ -479,6 +479,16 @@ tcomment#Comment(beg, end, ...) postprocess_uncomment .. Run a |printf()| expression with 2 placeholders on uncommented lines, e.g. 'norm! %sgg=%sgg'. + choose ... A list of commend definitions (a + dictionary as defined above) that may + contain an `if` key referring to an + expression; if this condition evaluates + to true, the item will be selected; the + last item in the list will be selected + anyway (see the bib definition for an + example) + if ... an |eval()|able expression (only valid + within a choose list, see above) 2. 1-2 values for: ?commentPrefix, ?commentPostfix 3. a dictionary (internal use only)