From 59c79279b5a59bba68046da895341f5bb45903cb Mon Sep 17 00:00:00 2001 From: Sebastian Witte Date: Fri, 25 Jul 2014 17:14:56 +0200 Subject: [PATCH] Implement functionality to configure alternate comment style (fixes #145) The change requires the variable to have global scope which is also updated in the documentation. --- doc/NERD_commenter.txt | 4 ++-- plugin/NERD_commenter.vim | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/doc/NERD_commenter.txt b/doc/NERD_commenter.txt index 151ea29..7314af2 100644 --- a/doc/NERD_commenter.txt +++ b/doc/NERD_commenter.txt @@ -714,11 +714,11 @@ again. If you want the NERD commenter to use the alternative delimiters for a specific filetype by default then put a line of this form into your vimrc: > - let NERD__alt_style=1 + let g:NERD__alt_style=1 < Example: java uses // style comments by default, but you want it to default to /* */ style comments instead. You would put this line in your vimrc: > - let NERD_java_alt_style=1 + let g:NERD_java_alt_style=1 < See |NERDComAltDelim| for switching commenting styles at runtime. diff --git a/plugin/NERD_commenter.vim b/plugin/NERD_commenter.vim index b7ba977..612a9e1 100644 --- a/plugin/NERD_commenter.vim +++ b/plugin/NERD_commenter.vim @@ -462,6 +462,10 @@ function s:SetUpForNewFiletype(filetype, forceReset) let b:NERDCommenterDelims[i] = '' endif endfor + " if g:NERD__alt_style is defined, use the alternate style + if exists('g:NERD_'.ft.'_alt_style') && eval('g:NERD_'.ft.'_alt_style') + call s:SwitchToAlternativeDelimiters(0) + endif else let b:NERDCommenterDelims = s:CreateDelimMapFromCms() endif @@ -2379,7 +2383,7 @@ endfunction function s:Left(...) let params = a:0 ? a:1 : {} - let delim = has_key(params, 'alt') ? b:NERDCommenterDelims['leftAlt'] : b:NERDCommenterDelims['left'] + let delim = has_key(params, 'alt') ? b:NERDCommenterDelims['leftAlt'] : b:NERDCommenterDelims['left'] if delim == '' return '' @@ -2558,7 +2562,7 @@ endfunction function s:Right(...) let params = a:0 ? a:1 : {} - let delim = has_key(params, 'alt') ? b:NERDCommenterDelims['rightAlt'] : b:NERDCommenterDelims['right'] + let delim = has_key(params, 'alt') ? b:NERDCommenterDelims['rightAlt'] : b:NERDCommenterDelims['right'] if delim == '' return ''