From 7f07dcde28ed312b6eb5fc067c4e1aa8b95293f5 Mon Sep 17 00:00:00 2001 From: Hsiaoyi Hsu Date: Tue, 31 May 2016 14:28:56 +0800 Subject: [PATCH 1/3] Add hook functions for NERDComment and SwitchToAlternativeDelimiters --- plugin/NERD_commenter.vim | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/plugin/NERD_commenter.vim b/plugin/NERD_commenter.vim index 3e96847..3c854e7 100644 --- a/plugin/NERD_commenter.vim +++ b/plugin/NERD_commenter.vim @@ -555,6 +555,9 @@ endfunction " -printMsgs: if this is 1 then a message is echoed to the user telling them " if this function changed the delimiters or not function s:SwitchToAlternativeDelimiters(printMsgs) + if exists('*NERDCommenter_before') + exe "call NERDCommenter_before()" + endif "if both of the alternative delimiters are empty then there is no "alternative comment style so bail out if b:NERDCommenterDelims['leftAlt'] == '' && b:NERDCommenterDelims['rightAlt'] == '' @@ -585,6 +588,10 @@ function s:SwitchToAlternativeDelimiters(printMsgs) call s:NerdEcho("Now using " . s:Left() . " " . s:Right() . " to delimit comments", 1) endif + if exists('*NERDCommenter_after') + exe "call NERDCommenter_after()" + endif + return 1 endfunction @@ -1151,6 +1158,10 @@ endfunction " 'Minimal', 'Toggle', 'AlignLeft', 'AlignBoth', 'Comment', " 'Nested', 'ToEOL', 'Append', 'Insert', 'Uncomment', 'Yank' function! NERDComment(mode, type) range + if exists('*NERDCommenter_before') + exe "call NERDCommenter_before()" + endif + let isVisual = a:mode =~ '[vsx]' if !exists("g:did_load_ftplugin") || g:did_load_ftplugin != 1 @@ -1255,6 +1266,11 @@ function! NERDComment(mode, type) range else silent! call repeat#set("\NERDCommenter". a:type) endif + + if exists('*NERDCommenter_after') + exe "call NERDCommenter_after()" + endif + endfunction " Function: s:PlaceDelimitersAndInsBetween() function {{{2 From dde288a9cccc3722a494c29e81147afc2d6045d2 Mon Sep 17 00:00:00 2001 From: Hsiaoyi Hsu Date: Tue, 31 May 2016 22:27:10 +0800 Subject: [PATCH 2/3] Add doc for NERDComHooks and fix doc of NERDComSexyComments and NERDComNERDComment --- doc/NERD_commenter.txt | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/doc/NERD_commenter.txt b/doc/NERD_commenter.txt index ea03c08..9da1ec8 100644 --- a/doc/NERD_commenter.txt +++ b/doc/NERD_commenter.txt @@ -28,8 +28,9 @@ CONTENTS *NERDCommenterContents* 3.2.11 Use alternate delims map...|NERDComAltDelim| 3.2.12 Comment aligned maps.......|NERDComAlignedComment| 3.2.13 Uncomment line map.........|NERDComUncommentLine| - 3.4 Sexy Comments.....................|NERDComSexyComments| - 3.5 The NERDComment function..........|NERDComNERDComment| + 3.3 Sexy Comments.....................|NERDComSexyComments| + 3.4 The NERDComment function..........|NERDComNERDComment| + 3.5 The Hooks.........................|NERDComHooks| 4.Options.................................|NERDComOptions| 4.1 Options summary...................|NERDComOptionsSummary| 4.2 Options details...................|NERDComOptionsDetails| @@ -391,6 +392,35 @@ For example, if you typed > < then the script would do a sexy comment on the last visual selection. +------------------------------------------------------------------------------ +3.5 The hooks *NERDComHooks* +|fu! NERDCommenter_before()| Before NERDComment/SwitchToAlternativeDelimiters +|fu! NERDCommenter_after()| After NERDComment/SwitchToAlternativeDelimiters + +For example, in order to handle different language blocks embedded in the same +file such as |vim-vue|, you can change the filetype, comment something and +change the filetype back: > + let g:ft = '' + fu! NERDCommenter_before() + if &ft == 'vue' + let g:ft = 'vue' + let stack = synstack(line('.'), col('.')) + if len(stack) > 0 + let syn = synIDattr((stack)[0], 'name') + if len(syn) > 0 + let syn = tolower(syn) + exe 'setf '.syn + endif + endif + endif + endfu + fu! NERDCommenter_after() + if g:ft == 'vue' + setf vue + let g:ft = '' + endif + endfu +< ============================================================================== 4. Options *NERDComOptions* From ce414bf62264c23e4baa1d67cfb7ef819abfce73 Mon Sep 17 00:00:00 2001 From: Hsiaoyi Hsu Date: Tue, 31 May 2016 22:30:37 +0800 Subject: [PATCH 3/3] Add filetype pug. Jade has been renamed to pug. --- plugin/NERD_commenter.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin/NERD_commenter.vim b/plugin/NERD_commenter.vim index 3c854e7..985a27f 100644 --- a/plugin/NERD_commenter.vim +++ b/plugin/NERD_commenter.vim @@ -329,6 +329,7 @@ let s:delimiterMap = { \ 'ps1': { 'left': '#' }, \ 'psf': { 'left': '#' }, \ 'ptcap': { 'left': '#' }, + \ 'pug': { 'left': '//-', 'leftAlt': '//' }, \ 'puppet': { 'left': '#' }, \ 'pyrex': { 'left': '# ', 'leftAlt': '#' }, \ 'python': { 'left': '# ', 'leftAlt': '#' },