|
|
|
|
@@ -15,6 +15,7 @@ let s:delimiterMap = {
|
|
|
|
|
\ 'ada': { 'left': '--', 'leftAlt': '-- ' },
|
|
|
|
|
\ 'ahdl': { 'left': '--' },
|
|
|
|
|
\ 'ahk': { 'left': ';', 'leftAlt': '/*', 'rightAlt': '*/' },
|
|
|
|
|
\ 'alloy': { 'left': '/*', 'right': '*/', 'leftAlt': '//' },
|
|
|
|
|
\ 'amiga': { 'left': ';' },
|
|
|
|
|
\ 'aml': { 'left': '/*' },
|
|
|
|
|
\ 'ampl': { 'left': '#' },
|
|
|
|
|
@@ -23,6 +24,7 @@ let s:delimiterMap = {
|
|
|
|
|
\ 'apachestyle': { 'left': '#' },
|
|
|
|
|
\ 'apdl': { 'left': '!' },
|
|
|
|
|
\ 'applescript': { 'left': '--', 'leftAlt': '(*', 'rightAlt': '*)' },
|
|
|
|
|
\ 'aptconf': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
|
|
|
|
\ 'armasm': { 'left': ';' },
|
|
|
|
|
\ 'asciidoc': { 'left': '//' },
|
|
|
|
|
\ 'asm': { 'left': ';', 'leftAlt': '#' },
|
|
|
|
|
@@ -33,6 +35,7 @@ let s:delimiterMap = {
|
|
|
|
|
\ 'asterisk': { 'left': ';' },
|
|
|
|
|
\ 'asy': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
|
|
|
|
\ 'atlas': { 'left': 'C', 'right': '$' },
|
|
|
|
|
\ 'ats': { 'left': '//', 'leftAlt': '(*', 'rightAlt': '*)' },
|
|
|
|
|
\ 'augeas': { 'left': '(*', 'right': '*)' },
|
|
|
|
|
\ 'autohotkey': { 'left': ';', 'leftAlt': '/*', 'rightAlt': '*/' },
|
|
|
|
|
\ 'autoit': { 'left': ';' },
|
|
|
|
|
@@ -49,9 +52,11 @@ let s:delimiterMap = {
|
|
|
|
|
\ 'btm': { 'left': '::' },
|
|
|
|
|
\ 'c': { 'left': '/*', 'right': '*/', 'leftAlt': '//' },
|
|
|
|
|
\ 'cabal': { 'left': '--' },
|
|
|
|
|
\ 'cairo': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
|
|
|
|
\ 'calibre': { 'left': '//' },
|
|
|
|
|
\ 'caos': { 'left': '*' },
|
|
|
|
|
\ 'catalog': { 'left': '--', 'right': '--' },
|
|
|
|
|
\ 'cel': { 'left': '//' },
|
|
|
|
|
\ 'cf': { 'left': '<!---', 'right': '--->' },
|
|
|
|
|
\ 'cfg': { 'left': '#' },
|
|
|
|
|
\ 'cg': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
|
|
|
|
@@ -78,6 +83,7 @@ let s:delimiterMap = {
|
|
|
|
|
\ 'cython': { 'left': '# ', 'leftAlt': '#' },
|
|
|
|
|
\ 'd': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
|
|
|
|
\ 'dakota': { 'left': '#' },
|
|
|
|
|
\ 'dart': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
|
|
|
|
\ 'dcl': { 'left': '$!' },
|
|
|
|
|
\ 'debcontrol': { 'left': '#' },
|
|
|
|
|
\ 'debsources': { 'left': '#' },
|
|
|
|
|
@@ -85,11 +91,12 @@ let s:delimiterMap = {
|
|
|
|
|
\ 'desktop': { 'left': '#' },
|
|
|
|
|
\ 'dhcpd': { 'left': '#' },
|
|
|
|
|
\ 'diff': { 'left': '#' },
|
|
|
|
|
\ 'dts': { 'left': '/*', 'right': '*/', 'leftAlt': '//' },
|
|
|
|
|
\ 'django': { 'left': '{% comment %}', 'right': '{% endcomment %}', 'leftAlt': '{#', 'rightAlt': '#}' },
|
|
|
|
|
\ 'dns': { 'left': ';' },
|
|
|
|
|
\ 'docbk': { 'left': '<!--', 'right': '-->' },
|
|
|
|
|
\ 'dockerfile': { 'left': '#' },
|
|
|
|
|
\ 'dosbatch': { 'left': 'REM ', 'leftAlt': '::' },
|
|
|
|
|
\ 'dosbatch': { 'left': 'REM ', 'nested': 1, 'leftAlt': 'REM ', 'nestedAlt': 1 },
|
|
|
|
|
\ 'dosini': { 'left': ';' },
|
|
|
|
|
\ 'dot': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
|
|
|
|
\ 'dracula': { 'left': ';' },
|
|
|
|
|
@@ -114,6 +121,7 @@ let s:delimiterMap = {
|
|
|
|
|
\ 'exports': { 'left': '#' },
|
|
|
|
|
\ 'factor': { 'left': '! ', 'leftAlt': '!# ' },
|
|
|
|
|
\ 'fancy': { 'left': '#' },
|
|
|
|
|
\ 'fasm': { 'left': ';' },
|
|
|
|
|
\ 'faust': { 'left': '//' },
|
|
|
|
|
\ 'fgl': { 'left': '#' },
|
|
|
|
|
\ 'fluent': { 'left': '#', 'leftAlt': '##' },
|
|
|
|
|
@@ -152,10 +160,11 @@ let s:delimiterMap = {
|
|
|
|
|
\ 'h': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
|
|
|
|
\ 'haml': { 'left': '-#', 'leftAlt': '/' },
|
|
|
|
|
\ 'handlebars': { 'left': '{{!-- ', 'right': ' --}}' },
|
|
|
|
|
\ 'haskell': { 'left': '--', 'nested': 0, 'leftAlt': '{-', 'rightAlt': '-}', 'nestedAlt': 1 },
|
|
|
|
|
\ 'haskell': { 'left': '-- ', 'nested': 0, 'leftAlt': '{-', 'rightAlt': '-}', 'nestedAlt': 1 },
|
|
|
|
|
\ 'haxe': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
|
|
|
|
\ 'hb': { 'left': '#' },
|
|
|
|
|
\ 'hbs': { 'left': '{{!-- ', 'right': ' --}}' },
|
|
|
|
|
\ 'hcl': { 'left': '#', 'leftAlt': '/*', 'rightAlt': '*/' },
|
|
|
|
|
\ 'hercules': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
|
|
|
|
\ 'hive': { 'left': '-- ' },
|
|
|
|
|
\ 'hocon': { 'left': '//', 'leftAlt': '#' },
|
|
|
|
|
@@ -187,16 +196,20 @@ let s:delimiterMap = {
|
|
|
|
|
\ 'jgraph': { 'left': '(*', 'right': '*)' },
|
|
|
|
|
\ 'jinja': { 'left': '{#', 'right': '#}', 'leftAlt': '<!--', 'rightAlt': '-->' },
|
|
|
|
|
\ 'jproperties': { 'left': '#' },
|
|
|
|
|
\ 'jq': { 'left': '#' },
|
|
|
|
|
\ 'json5': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
|
|
|
|
\ 'jsonc': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
|
|
|
|
\ 'jsonnet': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
|
|
|
|
\ 'jsp': { 'left': '<%--', 'right': '--%>' },
|
|
|
|
|
\ 'julia': { 'left': '# ', 'leftAlt': '#=', 'rightAlt': '=#' },
|
|
|
|
|
\ 'just' : { 'left': '#' },
|
|
|
|
|
\ 'kivy': { 'left': '#' },
|
|
|
|
|
\ 'kix': { 'left': ';' },
|
|
|
|
|
\ 'kscript': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
|
|
|
|
\ 'lace': { 'left': '--' },
|
|
|
|
|
\ 'laravel': { 'left': '{{--', 'right': '--}}' },
|
|
|
|
|
\ 'ldif': { 'left': '#' },
|
|
|
|
|
\ 'lean': { 'left': '--', 'leftAlt': '/-', 'rightAlt': '-/' },
|
|
|
|
|
\ 'ledger': { 'left': '#', 'leftAlt': ';' },
|
|
|
|
|
\ 'less': { 'left': '/*', 'right': '*/' },
|
|
|
|
|
\ 'lhaskell': { 'left': '>{-', 'right': '-}', 'leftAlt': '>-- ' },
|
|
|
|
|
@@ -269,6 +282,7 @@ let s:delimiterMap = {
|
|
|
|
|
\ 'ox': { 'left': '//' },
|
|
|
|
|
\ 'paludis-use-conf': { 'left': '#' },
|
|
|
|
|
\ 'pandoc': { 'left': '<!--', 'right': '-->' },
|
|
|
|
|
\ 'pamenv': { 'left': '#' },
|
|
|
|
|
\ 'pascal': { 'left': '{', 'right': '}', 'leftAlt': '(*', 'rightAlt': '*)' },
|
|
|
|
|
\ 'patran': { 'left': '$', 'leftAlt': '/*', 'rightAlt': '*/' },
|
|
|
|
|
\ 'pcap': { 'left': '#' },
|
|
|
|
|
@@ -340,7 +354,7 @@ let s:delimiterMap = {
|
|
|
|
|
\ 'sh': { 'left': '#' },
|
|
|
|
|
\ 'shader_test': { 'left': '#' },
|
|
|
|
|
\ 'sicad': { 'left': '*' },
|
|
|
|
|
\ 'sile': { 'left': '%' },
|
|
|
|
|
\ 'sile': { 'left': '%', 'leftAlt': '--' },
|
|
|
|
|
\ 'simula': { 'left': '%', 'leftAlt': '--' },
|
|
|
|
|
\ 'sinda': { 'left': '$' },
|
|
|
|
|
\ 'skill': { 'left': ';' },
|
|
|
|
|
@@ -377,6 +391,7 @@ let s:delimiterMap = {
|
|
|
|
|
\ 'stan': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
|
|
|
|
\ 'stp': { 'left': '/*', 'right': '*/', 'leftAlt': '//' },
|
|
|
|
|
\ 'supercollider': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
|
|
|
|
\ 'svelte': { 'left': '<!--', 'right': '-->' },
|
|
|
|
|
\ 'swift': { 'left': '/*', 'right': '*/', 'leftAlt': '//' },
|
|
|
|
|
\ 'systemverilog': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
|
|
|
|
\ 'tads': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
|
|
|
|
@@ -391,6 +406,7 @@ let s:delimiterMap = {
|
|
|
|
|
\ 'texmf': { 'left': '%' },
|
|
|
|
|
\ 'tf': { 'left': '#' },
|
|
|
|
|
\ 'tidy': { 'left': '#' },
|
|
|
|
|
\ 'tla': { 'left': '\\*', 'leftAlt': '(*', 'rightAlt': '*)' },
|
|
|
|
|
\ 'tli': { 'left': '#' },
|
|
|
|
|
\ 'tmux': { 'left': '#' },
|
|
|
|
|
\ 'toml': { 'left': '#' },
|
|
|
|
|
@@ -405,6 +421,7 @@ let s:delimiterMap = {
|
|
|
|
|
\ 'txt2tags': { 'left': '%' },
|
|
|
|
|
\ 'typescript': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
|
|
|
|
\ 'typescriptreact': { 'left': '//', 'leftAlt': '{/*', 'rightAlt': '*/}' },
|
|
|
|
|
\ 'typst': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
|
|
|
|
\ 'uc': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
|
|
|
|
\ 'uc4': { 'left': '!' },
|
|
|
|
|
\ 'uil': { 'left': '!' },
|
|
|
|
|
@@ -412,6 +429,7 @@ let s:delimiterMap = {
|
|
|
|
|
\ 'vala': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
|
|
|
|
\ 'vasp': { 'left': '!' },
|
|
|
|
|
\ 'vb': { 'left': "'" },
|
|
|
|
|
\ 'vcl': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
|
|
|
|
\ 'velocity': { 'left': '##', 'right': '', 'leftAlt': '#*', 'rightAlt': '*#' },
|
|
|
|
|
\ 'vera': { 'left': '/*', 'right': '*/', 'leftAlt': '//' },
|
|
|
|
|
\ 'verilog': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
|
|
|
|
@@ -434,7 +452,8 @@ let s:delimiterMap = {
|
|
|
|
|
\ 'xpm2': { 'left': '!' },
|
|
|
|
|
\ 'xquery': { 'left': '(:', 'right': ':)' },
|
|
|
|
|
\ 'yaml': { 'left': '#' },
|
|
|
|
|
\ 'z8a': { 'left': ';' }
|
|
|
|
|
\ 'z8a': { 'left': ';' },
|
|
|
|
|
\ 'zig': { 'left': '//' }
|
|
|
|
|
\ }
|
|
|
|
|
|
|
|
|
|
let g:NERDDelimiterMap = s:delimiterMap
|
|
|
|
|
@@ -451,10 +470,6 @@ endif
|
|
|
|
|
" This function is responsible for setting up buffer scoped variables for the
|
|
|
|
|
" current buffer.
|
|
|
|
|
function! nerdcommenter#SetUp() abort
|
|
|
|
|
if exists('b:NERDCommenterDelims')
|
|
|
|
|
return
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
let filetype = &filetype
|
|
|
|
|
|
|
|
|
|
"for compound filetypes, if we don't know how to handle the full filetype
|
|
|
|
|
@@ -472,7 +487,7 @@ function! nerdcommenter#SetUp() abort
|
|
|
|
|
let b:NERDSexyComMarker = ''
|
|
|
|
|
|
|
|
|
|
if has_key(s:delimiterMap, filetype)
|
|
|
|
|
let b:NERDCommenterDelims = s:delimiterMap[filetype]
|
|
|
|
|
let b:NERDCommenterDelims = copy(s:delimiterMap[filetype])
|
|
|
|
|
for i in ['left', 'leftAlt', 'right', 'rightAlt']
|
|
|
|
|
if !has_key(b:NERDCommenterDelims, i)
|
|
|
|
|
let b:NERDCommenterDelims[i] = ''
|
|
|
|
|
@@ -484,10 +499,10 @@ function! nerdcommenter#SetUp() abort
|
|
|
|
|
endif
|
|
|
|
|
endfor
|
|
|
|
|
" if g:NERD_<filetype>_alt_style is defined, use the alternate style
|
|
|
|
|
let b:NERDCommenterFirstInit = getbufvar(1,'NERDCommenterFirstInit')
|
|
|
|
|
let b:NERDCommenterFirstInit = getbufvar(bufnr('%'),'NERDCommenterFirstInit')
|
|
|
|
|
if exists('g:NERDAltDelims_'.filetype) && eval('g:NERDAltDelims_'.filetype) && !b:NERDCommenterFirstInit
|
|
|
|
|
call nerdcommenter#SwitchToAlternativeDelimiters(0)
|
|
|
|
|
let b:NERDCommenterFirstInit = 1
|
|
|
|
|
call nerdcommenter#SwitchToAlternativeDelimiters(0)
|
|
|
|
|
endif
|
|
|
|
|
else
|
|
|
|
|
let b:NERDCommenterDelims = s:CreateDelimMapFromCms()
|
|
|
|
|
@@ -506,8 +521,8 @@ function! s:CreateDelimMapFromCms() abort
|
|
|
|
|
return delims
|
|
|
|
|
endif
|
|
|
|
|
return {
|
|
|
|
|
\ 'left': substitute(&commentstring, '\([^ \t]*\)\s*%s.*', '\1', ''),
|
|
|
|
|
\ 'right': substitute(&commentstring, '.*%s\s*\(.*\)', '\1', 'g'),
|
|
|
|
|
\ 'left': matchstr(&commentstring, '^\S*\ze\s*%s'),
|
|
|
|
|
\ 'right': matchstr(&commentstring, '%s\s*\zs.*$'),
|
|
|
|
|
\ 'nested': 0,
|
|
|
|
|
\ 'leftAlt': '',
|
|
|
|
|
\ 'rightAlt': '',
|
|
|
|
|
@@ -525,10 +540,10 @@ endfunction
|
|
|
|
|
" if this function changed the delimiters or not
|
|
|
|
|
" function nerdcommenter#SwitchToAlternativeDelimiters(printMsgs)
|
|
|
|
|
function! nerdcommenter#SwitchToAlternativeDelimiters(printMsgs) abort
|
|
|
|
|
call nerdcommenter#SetUp()
|
|
|
|
|
if exists('*NERDCommenter_before')
|
|
|
|
|
exe 'call NERDCommenter_before()'
|
|
|
|
|
endif
|
|
|
|
|
call nerdcommenter#SetUp()
|
|
|
|
|
"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'] ==# ''
|
|
|
|
|
@@ -651,7 +666,7 @@ function! s:CommentBlock(top, bottom, lSide, rSide, forceNested) abort
|
|
|
|
|
"alternative delimiters (if THEY are) as the comment will be better and more
|
|
|
|
|
"accurate with multipart delimiters
|
|
|
|
|
let switchedDelims = 0
|
|
|
|
|
if !s:Multipart() && !g:NERDAllowAnyVisualDelims && s:AltMultipart()
|
|
|
|
|
if !s:Multipart() && g:NERDAllowAnyVisualDelims && s:AltMultipart()
|
|
|
|
|
let switchedDelims = 1
|
|
|
|
|
call nerdcommenter#SwitchToAlternativeDelimiters(0)
|
|
|
|
|
endif
|
|
|
|
|
@@ -1068,7 +1083,7 @@ function! s:CommentRegion(topLine, topCol, bottomLine, bottomCol, forceNested) a
|
|
|
|
|
|
|
|
|
|
"switch delimiters (if we can) if the current set isn't multipart
|
|
|
|
|
let switchedDelims = 0
|
|
|
|
|
if !s:Multipart() && s:AltMultipart() && !g:NERDAllowAnyVisualDelims
|
|
|
|
|
if !s:Multipart() && s:AltMultipart() && g:NERDAllowAnyVisualDelims
|
|
|
|
|
let switchedDelims = 1
|
|
|
|
|
call nerdcommenter#SwitchToAlternativeDelimiters(0)
|
|
|
|
|
endif
|
|
|
|
|
@@ -1091,7 +1106,7 @@ function! s:CommentRegion(topLine, topCol, bottomLine, bottomCol, forceNested) a
|
|
|
|
|
|
|
|
|
|
"comment the bottom line
|
|
|
|
|
let bottom = getline(a:bottomLine)
|
|
|
|
|
let numLeadingSpacesTabs = strlen(substitute(bottom, '^\([ \t]*\).*$', '\1', ''))
|
|
|
|
|
let numLeadingSpacesTabs = strlen(matchstr(bottom, '^\s*'))
|
|
|
|
|
call s:CommentBlock(a:bottomLine, a:bottomLine, numLeadingSpacesTabs+1, a:bottomCol, a:forceNested)
|
|
|
|
|
|
|
|
|
|
endif
|
|
|
|
|
@@ -1151,6 +1166,7 @@ endfunction
|
|
|
|
|
" -lineNo: the line number of the line to check
|
|
|
|
|
" Return: Number, 1 if the line is a comment, 0 else
|
|
|
|
|
function! nerdcommenter#IsLineCommented(lineNo) abort
|
|
|
|
|
call nerdcommenter#SetUp()
|
|
|
|
|
let theLine = getline(a:lineNo)
|
|
|
|
|
return s:IsInSexyComment(a:lineNo) || s:IsCommentedFromStartOfLine(s:Left(), theLine) || s:IsCommentedFromStartOfLine(s:Left({'alt': 1}), theLine)
|
|
|
|
|
endfunction
|
|
|
|
|
@@ -1165,10 +1181,10 @@ endfunction
|
|
|
|
|
" 'Minimal', 'Toggle', 'AlignLeft', 'AlignBoth', 'Comment',
|
|
|
|
|
" 'Nested', 'ToEOL', 'Append', 'Insert', 'Uncomment', 'Yank'
|
|
|
|
|
function! nerdcommenter#Comment(mode, type) range abort
|
|
|
|
|
call nerdcommenter#SetUp()
|
|
|
|
|
if exists('*NERDCommenter_before')
|
|
|
|
|
exe 'call NERDCommenter_before()'
|
|
|
|
|
endif
|
|
|
|
|
call nerdcommenter#SetUp()
|
|
|
|
|
|
|
|
|
|
let isVisual = a:mode =~# '[vsx]'
|
|
|
|
|
|
|
|
|
|
@@ -1236,7 +1252,7 @@ function! nerdcommenter#Comment(mode, type) range abort
|
|
|
|
|
for i in range(firstLine, lastLine)
|
|
|
|
|
let theLine = getline(i)
|
|
|
|
|
" if have one line no comment(not include blank/whitespace-only lines), then comment all lines
|
|
|
|
|
if theLine =~# '[^ \t]\+' && !s:IsInSexyComment(firstLine) && !s:IsCommentedFromStartOfLine(s:Left(), theLine) && !s:IsCommentedFromStartOfLine(s:Left({'alt': 1}), theLine)
|
|
|
|
|
if theLine =~# '\S\+' && !s:IsInSexyComment(firstLine) && !s:IsCommentedFromStartOfLine(s:Left(), theLine) && !s:IsCommentedFromStartOfLine(s:Left({'alt': 1}), theLine)
|
|
|
|
|
let l:commentAllLines = 1
|
|
|
|
|
break
|
|
|
|
|
else
|
|
|
|
|
@@ -1259,9 +1275,9 @@ function! nerdcommenter#Comment(mode, type) range abort
|
|
|
|
|
endtry
|
|
|
|
|
|
|
|
|
|
elseif a:type ==? 'ToEOL'
|
|
|
|
|
call s:SaveScreenState()
|
|
|
|
|
let view = winsaveview()
|
|
|
|
|
call s:CommentBlock(firstLine, firstLine, col('.'), col('$')-1, 1)
|
|
|
|
|
call s:RestoreScreenState()
|
|
|
|
|
call winrestview(view)
|
|
|
|
|
|
|
|
|
|
elseif a:type ==? 'Append'
|
|
|
|
|
call s:AppendCommentToLine()
|
|
|
|
|
@@ -1298,7 +1314,7 @@ function! nerdcommenter#Comment(mode, type) range abort
|
|
|
|
|
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
" Function: NERDCommentIsCharCommented(line, col) abort
|
|
|
|
|
" Function: nerdcommenter#IsCharCommented(line, col) abort
|
|
|
|
|
" Check if the character at [line, col] is inside a comment
|
|
|
|
|
" Note the Comment delimeter it self is considered as part of the comment
|
|
|
|
|
"
|
|
|
|
|
@@ -1306,7 +1322,8 @@ endfunction
|
|
|
|
|
" -line the line number of the character
|
|
|
|
|
" -col the column number of the character
|
|
|
|
|
" Return: Number, 1 if the character is inside a comment, 0 if is not
|
|
|
|
|
function! NERDCommentIsCharCommented(line, col) abort
|
|
|
|
|
function! nerdcommenter#IsCharCommented(line, col) abort
|
|
|
|
|
call nerdcommenter#SetUp()
|
|
|
|
|
" Function: s:searchfor(str, line, col, direction, [maxline])
|
|
|
|
|
" search str in the buffer, including the character at [line, col]
|
|
|
|
|
" Args:
|
|
|
|
|
@@ -1417,46 +1434,20 @@ function! s:PlaceDelimitersAndInsBetween() abort
|
|
|
|
|
let left = s:Left({'space': 1})
|
|
|
|
|
let right = s:Right({'space': 1})
|
|
|
|
|
|
|
|
|
|
let theLine = getline('.')
|
|
|
|
|
let lineHasLeadTabs = s:HasLeadingTabs(theLine) || (theLine =~# '^ *$' && !&expandtab)
|
|
|
|
|
|
|
|
|
|
"convert tabs to spaces and adjust the cursors column to take this into
|
|
|
|
|
"account
|
|
|
|
|
let untabbedCol = s:UntabbedCol(theLine, col('.'))
|
|
|
|
|
call setline(line('.'), s:ConvertLeadingTabsToSpaces(theLine))
|
|
|
|
|
call cursor(line('.'), untabbedCol)
|
|
|
|
|
|
|
|
|
|
" get the length of the right delimiter
|
|
|
|
|
let lenRight = strlen(right)
|
|
|
|
|
|
|
|
|
|
let isDelimOnEOL = col('.') >= strlen(getline('.'))
|
|
|
|
|
|
|
|
|
|
" if the cursor is in the first col then we gotta insert rather than
|
|
|
|
|
" append the comment delimiters here
|
|
|
|
|
let insOrApp = (col('.')==1 ? 'i' : 'a')
|
|
|
|
|
|
|
|
|
|
" place the delimiters down. We do it differently depending on whether
|
|
|
|
|
" there is a left AND right delimiter
|
|
|
|
|
if lenRight > 0
|
|
|
|
|
execute ':normal! ' . insOrApp . left . right
|
|
|
|
|
execute ':normal! ' . lenRight . 'h'
|
|
|
|
|
else
|
|
|
|
|
execute ':normal! ' . insOrApp . left
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
"if needed convert spaces back to tabs and adjust the cursors col
|
|
|
|
|
"accordingly
|
|
|
|
|
if lineHasLeadTabs
|
|
|
|
|
let tabbedCol = s:TabbedCol(getline('.'), col('.'))
|
|
|
|
|
call setline(line('.'), s:ConvertLeadingSpacesToTabs(getline('.')))
|
|
|
|
|
call cursor(line('.'), tabbedCol)
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
if isDelimOnEOL && lenRight ==# 0
|
|
|
|
|
startinsert!
|
|
|
|
|
else
|
|
|
|
|
call feedkeys('a', 'ni')
|
|
|
|
|
endif
|
|
|
|
|
" 0. Entered insert normal mode using <C-\><C-O> (:h i_CTRL-\_CTRL-O) to
|
|
|
|
|
" maintain the cursor position (from <Plug>NERDCommenterInsert).
|
|
|
|
|
" 1. Enter insert mode without changing the cursor position.
|
|
|
|
|
" If the cursor is on EOL (right of the last char), use 'a'.
|
|
|
|
|
" Otherwise, use 'i'.
|
|
|
|
|
let insert = col('.') > strlen(getline('.')) ? 'a' : 'i'
|
|
|
|
|
" 2. Insert comment delimiters.
|
|
|
|
|
" 3. Move the cursor to the left of the closing delimiter, without
|
|
|
|
|
" breaking undo sequence.
|
|
|
|
|
" 4. Enter insert normal mode again without changing the cursor position.
|
|
|
|
|
" This ensures that returning to the insert mode after finishing the
|
|
|
|
|
" script execution does not move the cursor.
|
|
|
|
|
" ( 1 ) ( 2 ) ( 3 ) ( 4 )
|
|
|
|
|
execute 'normal!' insert . left . right . repeat("\<C-G>U\<Left>", strchars(right)) . "\<C-\>\<C-O>"
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
" Function: s:RemoveDelimiters(left, right, line)
|
|
|
|
|
@@ -1671,7 +1662,7 @@ function! s:UncommentLinesSexy(topline, bottomline) abort
|
|
|
|
|
let theLine = getline(a:topline)
|
|
|
|
|
|
|
|
|
|
" if the first line contains only the left delimiter then just delete it
|
|
|
|
|
if theLine =~# '^[ \t]*' . left . '[ \t]*$' && !g:NERDCompactSexyComs
|
|
|
|
|
if theLine =~# '^\s*' . left . '\s*$' && !g:NERDCompactSexyComs
|
|
|
|
|
call cursor(a:topline, 1)
|
|
|
|
|
normal! dd
|
|
|
|
|
let bottomline = bottomline - 1
|
|
|
|
|
@@ -1695,7 +1686,7 @@ function! s:UncommentLinesSexy(topline, bottomline) abort
|
|
|
|
|
let theLine = getline(bottomline)
|
|
|
|
|
|
|
|
|
|
" if the bottomline contains only the right delimiter then just delete it
|
|
|
|
|
if theLine =~# '^[ \t]*' . right . '[ \t]*$'
|
|
|
|
|
if theLine =~# '^\s*' . right . '\s*$'
|
|
|
|
|
call cursor(bottomline, 1)
|
|
|
|
|
normal! dd
|
|
|
|
|
|
|
|
|
|
@@ -1712,7 +1703,7 @@ function! s:UncommentLinesSexy(topline, bottomline) abort
|
|
|
|
|
|
|
|
|
|
" if the last line also starts with a sexy comment marker then we
|
|
|
|
|
" remove this as well
|
|
|
|
|
if theLine =~# '^[ \t]*' . sexyComMarker
|
|
|
|
|
if theLine =~# '^\s*' . sexyComMarker
|
|
|
|
|
|
|
|
|
|
" remove the sexyComMarker. If there is a space after it then
|
|
|
|
|
" remove that too
|
|
|
|
|
@@ -1782,6 +1773,8 @@ function! s:UncommentLineNormal(line) abort
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let indxLeft = s:FindDelimiterIndex(s:Left(), line)
|
|
|
|
|
let indxLeftAlt = s:FindDelimiterIndex(s:Left({'alt': 1}), line)
|
|
|
|
|
let indxLeftPlace = s:FindDelimiterIndex(g:NERDLPlace, line)
|
|
|
|
|
let indxRightPlace = s:FindDelimiterIndex(g:NERDRPlace, line)
|
|
|
|
|
|
|
|
|
|
@@ -1836,7 +1829,7 @@ endfunction
|
|
|
|
|
" Function: s:AddLeftDelim(delim, theLine)
|
|
|
|
|
" Args:
|
|
|
|
|
function! s:AddLeftDelim(delim, theLine) abort
|
|
|
|
|
return substitute(a:theLine, '^\([ \t]*\)', '\1' . a:delim, '')
|
|
|
|
|
return substitute(a:theLine, '^\(\s*\)', '\1' . a:delim, '')
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
" Function: s:AddLeftDelimAligned(delim, theLine)
|
|
|
|
|
@@ -1906,7 +1899,7 @@ function! s:CanCommentLine(forceNested, lineNum) abort
|
|
|
|
|
|
|
|
|
|
" make sure we don't comment lines that are just spaces or tabs or empty,
|
|
|
|
|
" unless configured otherwise
|
|
|
|
|
if g:NERDCommentEmptyLines ==# 0 && theLine =~# "^[ \t]*$"
|
|
|
|
|
if g:NERDCommentEmptyLines ==# 0 && theLine =~# '^\s*$'
|
|
|
|
|
return 0
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
@@ -1973,7 +1966,7 @@ function! s:CanToggleCommentLine(forceNested, lineNum) abort
|
|
|
|
|
|
|
|
|
|
" make sure we don't comment lines that are just spaces or tabs or empty,
|
|
|
|
|
" unless configured otherwise
|
|
|
|
|
if g:NERDCommentEmptyLines ==# 0 && theLine =~# "^[ \t]*$"
|
|
|
|
|
if g:NERDCommentEmptyLines ==# 0 && theLine =~# '^\s*$'
|
|
|
|
|
return 0
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
@@ -2194,16 +2187,16 @@ function! s:FindBoundingLinesOfSexyCom(lineNum) abort
|
|
|
|
|
let theLine = getline(currentLine)
|
|
|
|
|
|
|
|
|
|
"check if the current line is the top of the sexy comment
|
|
|
|
|
if currentLine <= a:lineNum && theLine =~# '^[ \t]*' . left && theLine !~# '.*' . right && currentLine < s:NumLinesInBuf()
|
|
|
|
|
if currentLine <= a:lineNum && theLine =~# '^\s*' . left && theLine !~# '.*' . right && currentLine < s:NumLinesInBuf()
|
|
|
|
|
let top = currentLine
|
|
|
|
|
let currentLine = a:lineNum
|
|
|
|
|
|
|
|
|
|
"check if the current line is the bottom of the sexy comment
|
|
|
|
|
elseif theLine =~# '^[ \t]*' . right && theLine !~# '.*' . left && currentLine > 1
|
|
|
|
|
elseif theLine =~# '^\s*' . right && theLine !~# '.*' . left && currentLine > 1
|
|
|
|
|
let bottom = currentLine
|
|
|
|
|
|
|
|
|
|
"the right delimiter is on the same line as the last sexyComMarker
|
|
|
|
|
elseif theLine =~# '^[ \t]*' . sexyComMarker . '.*' . right
|
|
|
|
|
elseif theLine =~# '^\s*' . sexyComMarker . '.*' . right
|
|
|
|
|
let bottom = currentLine
|
|
|
|
|
|
|
|
|
|
"we have not found the top or bottom line so we assume currentLine is an
|
|
|
|
|
@@ -2212,7 +2205,7 @@ function! s:FindBoundingLinesOfSexyCom(lineNum) abort
|
|
|
|
|
|
|
|
|
|
"if the line doesn't start with a sexyComMarker then it is not a sexy
|
|
|
|
|
"comment
|
|
|
|
|
if theLine !~# '^[ \t]*' . sexyComMarker
|
|
|
|
|
if theLine !~# '^\s*' . sexyComMarker
|
|
|
|
|
return []
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
@@ -2450,7 +2443,7 @@ endfunction
|
|
|
|
|
" -left: the left delimiter to check for
|
|
|
|
|
function! s:IsCommentedFromStartOfLine(left, line) abort
|
|
|
|
|
let theLine = s:ConvertLeadingTabsToSpaces(a:line)
|
|
|
|
|
let numSpaces = strlen(substitute(theLine, '^\( *\).*$', '\1', ''))
|
|
|
|
|
let numSpaces = strlen(matchstr(theLine, '^ *'))
|
|
|
|
|
let delimIndx = s:FindDelimiterIndex(a:left, theLine)
|
|
|
|
|
return delimIndx ==# numSpaces
|
|
|
|
|
endfunction
|
|
|
|
|
@@ -2544,15 +2537,15 @@ function! s:IsDelimValid(delimiter, delIndx, line) abort
|
|
|
|
|
|
|
|
|
|
"vim comments are so fucking stupid!! Why the hell do they have comment
|
|
|
|
|
"delimiters that are used elsewhere in the syntax?!?! We need to check
|
|
|
|
|
"some conditions especially for vim
|
|
|
|
|
if &filetype ==# 'vim'
|
|
|
|
|
"some conditions especially for vim.
|
|
|
|
|
"Also check &commentstring because it may be overwritten for embedded lua.
|
|
|
|
|
if &filetype ==# 'vim' && &commentstring[0] ==# '"'
|
|
|
|
|
if !s:IsNumEven(s:CountNonESCedOccurances(preComStr, '"', "\\"))
|
|
|
|
|
return 0
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
"if the delimiter is on the very first char of the line or is the
|
|
|
|
|
"first non-tab/space char on the line then it is a valid comment delimiter
|
|
|
|
|
if a:delIndx ==# 0 || a:line =~# "^[ \t]\\{" . a:delIndx . "\\}\".*$"
|
|
|
|
|
" if the delimiter is the first non-whitespace character, it is valid
|
|
|
|
|
if a:line =~# '^\s*"'
|
|
|
|
|
return 1
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
@@ -2653,7 +2646,7 @@ function! s:IsSexyComment(topline, bottomline) abort
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
"if the top line doesn't begin with a left delimiter then the comment isn't sexy
|
|
|
|
|
if getline(a:topline) !~# '^[ \t]*' . left
|
|
|
|
|
if getline(a:topline) !~# '^\s*' . left
|
|
|
|
|
return 0
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
@@ -2681,7 +2674,7 @@ function! s:IsSexyComment(topline, bottomline) abort
|
|
|
|
|
while currentLine < a:bottomline
|
|
|
|
|
let theLine = getline(currentLine)
|
|
|
|
|
|
|
|
|
|
if theLine !~# '^[ \t]*' . sexyComMarker
|
|
|
|
|
if theLine !~# '^\s*' . sexyComMarker
|
|
|
|
|
return 0
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
@@ -2780,12 +2773,12 @@ function! s:LeftMostIndx(countCommentedLines, countEmptyLines, topline, bottomli
|
|
|
|
|
" get the next line and if it is allowed to be commented, or is not
|
|
|
|
|
" commented, check it
|
|
|
|
|
let theLine = getline(currentLine)
|
|
|
|
|
if a:countEmptyLines || theLine !~# '^[ \t]*$'
|
|
|
|
|
if a:countEmptyLines || theLine !~# '^\s*$'
|
|
|
|
|
if a:countCommentedLines || (!s:IsCommented(s:Left(), s:Right(), theLine) && !s:IsCommented(s:Left({'alt': 1}), s:Right({'alt': 1}), theLine))
|
|
|
|
|
" convert spaces to tabs and get the number of leading spaces for
|
|
|
|
|
" this line and update leftMostIndx if need be
|
|
|
|
|
let theLine = s:ConvertLeadingTabsToSpaces(theLine)
|
|
|
|
|
let leadSpaceOfLine = strlen( substitute(theLine, '\(^[ \t]*\).*$','\1','') )
|
|
|
|
|
let leadSpaceOfLine = strlen(matchstr(theLine, '^\s*'))
|
|
|
|
|
if leadSpaceOfLine < leftMostIndx
|
|
|
|
|
let leftMostIndx = leadSpaceOfLine
|
|
|
|
|
endif
|
|
|
|
|
@@ -2833,7 +2826,7 @@ endfunction
|
|
|
|
|
" Function: s:NumberOfLeadingTabs(s)
|
|
|
|
|
" returns the number of leading tabs in the given string
|
|
|
|
|
function! s:NumberOfLeadingTabs(s) abort
|
|
|
|
|
return strlen(substitute(a:s, '^\(\t*\).*$', '\1', ''))
|
|
|
|
|
return strlen(matchstr(a:s, '^\t*'))
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
" Function: s:NumLinesInBuf()
|
|
|
|
|
@@ -2907,21 +2900,6 @@ function! s:ReplaceRightMostDelim(toReplace, replacor, str) abort
|
|
|
|
|
return line
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
"FUNCTION: s:RestoreScreenState()
|
|
|
|
|
"
|
|
|
|
|
"Sets the screen state back to what it was when s:SaveScreenState was last
|
|
|
|
|
"called.
|
|
|
|
|
"
|
|
|
|
|
function! s:RestoreScreenState() abort
|
|
|
|
|
if !exists('t:NERDComOldTopLine') || !exists('t:NERDComOldPos')
|
|
|
|
|
throw 'NERDCommenter exception: cannot restore screen'
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
call cursor(t:NERDComOldTopLine, 0)
|
|
|
|
|
normal! zt
|
|
|
|
|
call setpos('.', t:NERDComOldPos)
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
" Function: s:Right(...)
|
|
|
|
|
" returns right delimiter data
|
|
|
|
|
function! s:Right(...) abort
|
|
|
|
|
@@ -2963,7 +2941,7 @@ function! s:RightMostIndx(countCommentedLines, countEmptyLines, topline, bottoml
|
|
|
|
|
" get the next line and see if it is commentable, otherwise it doesn't
|
|
|
|
|
" count
|
|
|
|
|
let theLine = getline(currentLine)
|
|
|
|
|
if a:countEmptyLines || theLine !~# '^[ \t]*$'
|
|
|
|
|
if a:countEmptyLines || theLine !~# '^\s*$'
|
|
|
|
|
|
|
|
|
|
if a:countCommentedLines || (!s:IsCommented(s:Left(), s:Right(), theLine) && !s:IsCommented(s:Left({'alt': 1}), s:Right({'alt': 1}), theLine))
|
|
|
|
|
|
|
|
|
|
@@ -2983,14 +2961,6 @@ function! s:RightMostIndx(countCommentedLines, countEmptyLines, topline, bottoml
|
|
|
|
|
return rightMostIndx
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
"FUNCTION: s:SaveScreenState()
|
|
|
|
|
"Saves the current cursor position in the current buffer and the window
|
|
|
|
|
"scroll position
|
|
|
|
|
function! s:SaveScreenState() abort
|
|
|
|
|
let t:NERDComOldPos = getpos('.')
|
|
|
|
|
let t:NERDComOldTopLine = line('w0')
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
" Function: s:SwapOuterMultiPartDelimsForPlaceHolders(line)
|
|
|
|
|
" This function takes a line and swaps the outer most multi-part delimiters for
|
|
|
|
|
" place holders
|
|
|
|
|
@@ -3040,18 +3010,6 @@ function! s:SwapOuterPlaceHoldersForMultiPartDelims(line) abort
|
|
|
|
|
return line
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
" Function: s:TabbedCol(line, col)
|
|
|
|
|
" Gets the col number for given line and existing col number. The new col
|
|
|
|
|
" number is the col number when all leading spaces are converted to tabs
|
|
|
|
|
" Args:
|
|
|
|
|
" -line:the line to get the rel col for
|
|
|
|
|
" -col: the abs col
|
|
|
|
|
function! s:TabbedCol(line, col) abort
|
|
|
|
|
let lineTruncated = strpart(a:line, 0, a:col)
|
|
|
|
|
let lineSpacesToTabs = substitute(lineTruncated, s:TabSpace(), '\t', 'g')
|
|
|
|
|
return strlen(lineSpacesToTabs)
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
"FUNCTION: s:TabSpace()
|
|
|
|
|
"returns a string of spaces equal in length to &tabstop
|
|
|
|
|
function! s:TabSpace() abort
|
|
|
|
|
@@ -3072,15 +3030,3 @@ endfunction
|
|
|
|
|
function! s:UnEsc(str, escChar) abort
|
|
|
|
|
return substitute(a:str, a:escChar, '', 'g')
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
" Function: s:UntabbedCol(line, col)
|
|
|
|
|
" Takes a line and a col and returns the absolute column of col taking into
|
|
|
|
|
" account that a tab is worth 3 or 4 (or whatever) spaces.
|
|
|
|
|
" Args:
|
|
|
|
|
" -line:the line to get the abs col for
|
|
|
|
|
" -col: the col that doesn't take into account tabs
|
|
|
|
|
function! s:UntabbedCol(line, col) abort
|
|
|
|
|
let lineTruncated = strpart(a:line, 0, a:col)
|
|
|
|
|
let lineTabsToSpaces = substitute(lineTruncated, '\t', s:TabSpace(), 'g')
|
|
|
|
|
return strlen(lineTabsToSpaces)
|
|
|
|
|
endfunction
|
|
|
|
|
|