mirror of
https://github.com/preservim/nerdcommenter.git
synced 2025-01-23 01:40:44 +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.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*
|
||||
|
|
|
@ -329,6 +329,7 @@ let s:delimiterMap = {
|
|||
\ 'ps1': { 'left': '#' },
|
||||
\ 'psf': { 'left': '#' },
|
||||
\ 'ptcap': { 'left': '#' },
|
||||
\ 'pug': { 'left': '//-', 'leftAlt': '//' },
|
||||
\ 'puppet': { 'left': '#' },
|
||||
\ 'pyrex': { '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
|
||||
" 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 +589,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 +1159,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 +1267,11 @@ function! NERDComment(mode, type) range
|
|||
else
|
||||
silent! call repeat#set("\<Plug>NERDCommenter". a:type)
|
||||
endif
|
||||
|
||||
if exists('*NERDCommenter_after')
|
||||
exe "call NERDCommenter_after()"
|
||||
endif
|
||||
|
||||
endfunction
|
||||
|
||||
" Function: s:PlaceDelimitersAndInsBetween() function {{{2
|
||||
|
|
Loading…
Reference in New Issue
Block a user