mirror of
https://github.com/preservim/nerdcommenter.git
synced 2025-01-23 05:02:17 +08:00
Merge pull request #249 from xream/master
Add hook functions for NERDComment and SwitchToAlternativeDelimiters
This commit is contained in:
commit
06c3184b2e
|
@ -28,8 +28,9 @@ CONTENTS *NERDCommenterContents*
|
||||||
3.2.11 Use alternate delims map...|NERDComAltDelim|
|
3.2.11 Use alternate delims map...|NERDComAltDelim|
|
||||||
3.2.12 Comment aligned maps.......|NERDComAlignedComment|
|
3.2.12 Comment aligned maps.......|NERDComAlignedComment|
|
||||||
3.2.13 Uncomment line map.........|NERDComUncommentLine|
|
3.2.13 Uncomment line map.........|NERDComUncommentLine|
|
||||||
3.4 Sexy Comments.....................|NERDComSexyComments|
|
3.3 Sexy Comments.....................|NERDComSexyComments|
|
||||||
3.5 The NERDComment function..........|NERDComNERDComment|
|
3.4 The NERDComment function..........|NERDComNERDComment|
|
||||||
|
3.5 The Hooks.........................|NERDComHooks|
|
||||||
4.Options.................................|NERDComOptions|
|
4.Options.................................|NERDComOptions|
|
||||||
4.1 Options summary...................|NERDComOptionsSummary|
|
4.1 Options summary...................|NERDComOptionsSummary|
|
||||||
4.2 Options details...................|NERDComOptionsDetails|
|
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.
|
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*
|
4. Options *NERDComOptions*
|
||||||
|
|
|
@ -329,6 +329,7 @@ let s:delimiterMap = {
|
||||||
\ 'ps1': { 'left': '#' },
|
\ 'ps1': { 'left': '#' },
|
||||||
\ 'psf': { 'left': '#' },
|
\ 'psf': { 'left': '#' },
|
||||||
\ 'ptcap': { 'left': '#' },
|
\ 'ptcap': { 'left': '#' },
|
||||||
|
\ 'pug': { 'left': '//-', 'leftAlt': '//' },
|
||||||
\ 'puppet': { 'left': '#' },
|
\ 'puppet': { 'left': '#' },
|
||||||
\ 'pyrex': { 'left': '# ', 'leftAlt': '#' },
|
\ 'pyrex': { 'left': '# ', 'leftAlt': '#' },
|
||||||
\ 'python': { 'left': '# ', 'leftAlt': '#' },
|
\ 'python': { 'left': '# ', 'leftAlt': '#' },
|
||||||
|
@ -555,6 +556,9 @@ endfunction
|
||||||
" -printMsgs: if this is 1 then a message is echoed to the user telling them
|
" -printMsgs: if this is 1 then a message is echoed to the user telling them
|
||||||
" if this function changed the delimiters or not
|
" if this function changed the delimiters or not
|
||||||
function s:SwitchToAlternativeDelimiters(printMsgs)
|
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
|
"if both of the alternative delimiters are empty then there is no
|
||||||
"alternative comment style so bail out
|
"alternative comment style so bail out
|
||||||
if b:NERDCommenterDelims['leftAlt'] == '' && b:NERDCommenterDelims['rightAlt'] == ''
|
if b:NERDCommenterDelims['leftAlt'] == '' && b:NERDCommenterDelims['rightAlt'] == ''
|
||||||
|
@ -585,6 +589,10 @@ function s:SwitchToAlternativeDelimiters(printMsgs)
|
||||||
call s:NerdEcho("Now using " . s:Left() . " " . s:Right() . " to delimit comments", 1)
|
call s:NerdEcho("Now using " . s:Left() . " " . s:Right() . " to delimit comments", 1)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
if exists('*NERDCommenter_after')
|
||||||
|
exe "call NERDCommenter_after()"
|
||||||
|
endif
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
@ -1151,6 +1159,10 @@ endfunction
|
||||||
" 'Minimal', 'Toggle', 'AlignLeft', 'AlignBoth', 'Comment',
|
" 'Minimal', 'Toggle', 'AlignLeft', 'AlignBoth', 'Comment',
|
||||||
" 'Nested', 'ToEOL', 'Append', 'Insert', 'Uncomment', 'Yank'
|
" 'Nested', 'ToEOL', 'Append', 'Insert', 'Uncomment', 'Yank'
|
||||||
function! NERDComment(mode, type) range
|
function! NERDComment(mode, type) range
|
||||||
|
if exists('*NERDCommenter_before')
|
||||||
|
exe "call NERDCommenter_before()"
|
||||||
|
endif
|
||||||
|
|
||||||
let isVisual = a:mode =~ '[vsx]'
|
let isVisual = a:mode =~ '[vsx]'
|
||||||
|
|
||||||
if !exists("g:did_load_ftplugin") || g:did_load_ftplugin != 1
|
if !exists("g:did_load_ftplugin") || g:did_load_ftplugin != 1
|
||||||
|
@ -1255,6 +1267,11 @@ function! NERDComment(mode, type) range
|
||||||
else
|
else
|
||||||
silent! call repeat#set("\<Plug>NERDCommenter". a:type)
|
silent! call repeat#set("\<Plug>NERDCommenter". a:type)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
if exists('*NERDCommenter_after')
|
||||||
|
exe "call NERDCommenter_after()"
|
||||||
|
endif
|
||||||
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Function: s:PlaceDelimitersAndInsBetween() function {{{2
|
" Function: s:PlaceDelimitersAndInsBetween() function {{{2
|
||||||
|
|
Loading…
Reference in New Issue
Block a user