From 71c3322cefb1645d71c2a4ec3d854e867136026d Mon Sep 17 00:00:00 2001 From: David Briscoe Date: Tue, 20 Jul 2021 14:58:01 -0700 Subject: [PATCH 1/2] Add some locals to make surroundings() decipherable --- plugin/commentary.vim | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/plugin/commentary.vim b/plugin/commentary.vim index 079bce1..720ecdf 100644 --- a/plugin/commentary.vim +++ b/plugin/commentary.vim @@ -9,8 +9,11 @@ endif let g:loaded_commentary = 1 function! s:surroundings() abort - return split(get(b:, 'commentary_format', substitute(substitute(substitute( - \ &commentstring, '^$', '%s', ''), '\S\zs%s',' %s', '') ,'%s\ze\S', '%s ', '')), '%s', 1) + " Get commentstring with %s and whitespace padding. + let cms = substitute(substitute(substitute( + \ &commentstring, '^$', '%s', ''), '\S\zs%s',' %s', '') ,'%s\ze\S', '%s ', '') + let fmt = get(b:, 'commentary_format', cms) + return split(fmt, '%s', 1) endfunction function! s:strip_white_space(l,r,line) abort From 5348669c606937577d7775baaab02eb85aace5b0 Mon Sep 17 00:00:00 2001 From: David Briscoe Date: Tue, 16 May 2017 10:39:25 -0700 Subject: [PATCH 2/2] Add a string that marks inserted comments This marker is inserted immediately after the comment string. Useful if commentary is only used to disable code (rather than inserting explanatory comments). For example, let g:commentary_marker = '~' will comment f(); into //~ f(); Support a b: version because some filetypes (like dosbatch or python's black) require whitespace after their commentstring. --- doc/commentary.txt | 16 ++++++++++++++++ plugin/commentary.vim | 7 +++++++ 2 files changed, 23 insertions(+) diff --git a/doc/commentary.txt b/doc/commentary.txt index 01f73da..b7a1b09 100644 --- a/doc/commentary.txt +++ b/doc/commentary.txt @@ -29,6 +29,22 @@ gcu *:Commentary* :[range]Commentary Comment or uncomment [range] lines + + *g:commentary_marker* +g:commentary_marker A string that marks comments inserted by commentary. + This marker is inserted immediately after the comment + string. Useful if commentary is only used to disable + code (rather than inserting explanatory comments). + + For example, > + let g:commentary_marker = '~' +< will comment > + f(); +< into > + //~ f(); +< + Use |b:commentary_marker| for a buffer-local override. + The |User| CommentaryPost autocommand fires after a successful operation and can be used for advanced customization. diff --git a/plugin/commentary.vim b/plugin/commentary.vim index 720ecdf..e56a9b0 100644 --- a/plugin/commentary.vim +++ b/plugin/commentary.vim @@ -8,10 +8,17 @@ if exists("g:loaded_commentary") || v:version < 703 endif let g:loaded_commentary = 1 +if !exists("g:commentary_marker") + let g:commentary_marker = '' +endif + function! s:surroundings() abort " Get commentstring with %s and whitespace padding. let cms = substitute(substitute(substitute( \ &commentstring, '^$', '%s', ''), '\S\zs%s',' %s', '') ,'%s\ze\S', '%s ', '') + " Postfix comment leader with marker to make auto commented code easier to find. + let marker = get(b:, 'commentary_marker', g:commentary_marker) + let cms = substitute(cms, '\S\zs\s*%s', marker ..'&','') let fmt = get(b:, 'commentary_format', cms) return split(fmt, '%s', 1) endfunction