|
|
|
@@ -33,6 +33,7 @@ let s:delimiterMap = {
|
|
|
|
\ 'asterisk': { 'left': ';' },
|
|
|
|
\ 'asterisk': { 'left': ';' },
|
|
|
|
\ 'asy': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
|
|
|
\ 'asy': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
|
|
|
\ 'atlas': { 'left': 'C', 'right': '$' },
|
|
|
|
\ 'atlas': { 'left': 'C', 'right': '$' },
|
|
|
|
|
|
|
|
\ 'ats': { 'left': '//', 'leftAlt': '(*', 'rightAlt': '*)' },
|
|
|
|
\ 'augeas': { 'left': '(*', 'right': '*)' },
|
|
|
|
\ 'augeas': { 'left': '(*', 'right': '*)' },
|
|
|
|
\ 'autohotkey': { 'left': ';', 'leftAlt': '/*', 'rightAlt': '*/' },
|
|
|
|
\ 'autohotkey': { 'left': ';', 'leftAlt': '/*', 'rightAlt': '*/' },
|
|
|
|
\ 'autoit': { 'left': ';' },
|
|
|
|
\ 'autoit': { 'left': ';' },
|
|
|
|
@@ -49,6 +50,7 @@ let s:delimiterMap = {
|
|
|
|
\ 'btm': { 'left': '::' },
|
|
|
|
\ 'btm': { 'left': '::' },
|
|
|
|
\ 'c': { 'left': '/*', 'right': '*/', 'leftAlt': '//' },
|
|
|
|
\ 'c': { 'left': '/*', 'right': '*/', 'leftAlt': '//' },
|
|
|
|
\ 'cabal': { 'left': '--' },
|
|
|
|
\ 'cabal': { 'left': '--' },
|
|
|
|
|
|
|
|
\ 'cairo': { 'left': '#' },
|
|
|
|
\ 'calibre': { 'left': '//' },
|
|
|
|
\ 'calibre': { 'left': '//' },
|
|
|
|
\ 'caos': { 'left': '*' },
|
|
|
|
\ 'caos': { 'left': '*' },
|
|
|
|
\ 'catalog': { 'left': '--', 'right': '--' },
|
|
|
|
\ 'catalog': { 'left': '--', 'right': '--' },
|
|
|
|
@@ -193,12 +195,14 @@ let s:delimiterMap = {
|
|
|
|
\ 'jsonnet': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
|
|
|
\ 'jsonnet': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
|
|
|
\ 'jsp': { 'left': '<%--', 'right': '--%>' },
|
|
|
|
\ 'jsp': { 'left': '<%--', 'right': '--%>' },
|
|
|
|
\ 'julia': { 'left': '# ', 'leftAlt': '#=', 'rightAlt': '=#' },
|
|
|
|
\ 'julia': { 'left': '# ', 'leftAlt': '#=', 'rightAlt': '=#' },
|
|
|
|
|
|
|
|
\ 'just' : { 'left': '#' },
|
|
|
|
\ 'kivy': { 'left': '#' },
|
|
|
|
\ 'kivy': { 'left': '#' },
|
|
|
|
\ 'kix': { 'left': ';' },
|
|
|
|
\ 'kix': { 'left': ';' },
|
|
|
|
\ 'kscript': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
|
|
|
\ 'kscript': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
|
|
|
\ 'lace': { 'left': '--' },
|
|
|
|
\ 'lace': { 'left': '--' },
|
|
|
|
\ 'laravel': { 'left': '{{--', 'right': '--}}' },
|
|
|
|
\ 'laravel': { 'left': '{{--', 'right': '--}}' },
|
|
|
|
\ 'ldif': { 'left': '#' },
|
|
|
|
\ 'ldif': { 'left': '#' },
|
|
|
|
|
|
|
|
\ 'lean': { 'left': '--', 'leftAlt': '/-', 'rightAlt': '-/' },
|
|
|
|
\ 'ledger': { 'left': '#', 'leftAlt': ';' },
|
|
|
|
\ 'ledger': { 'left': '#', 'leftAlt': ';' },
|
|
|
|
\ 'less': { 'left': '/*', 'right': '*/' },
|
|
|
|
\ 'less': { 'left': '/*', 'right': '*/' },
|
|
|
|
\ 'lhaskell': { 'left': '>{-', 'right': '-}', 'leftAlt': '>-- ' },
|
|
|
|
\ 'lhaskell': { 'left': '>{-', 'right': '-}', 'leftAlt': '>-- ' },
|
|
|
|
@@ -342,7 +346,7 @@ let s:delimiterMap = {
|
|
|
|
\ 'sh': { 'left': '#' },
|
|
|
|
\ 'sh': { 'left': '#' },
|
|
|
|
\ 'shader_test': { 'left': '#' },
|
|
|
|
\ 'shader_test': { 'left': '#' },
|
|
|
|
\ 'sicad': { 'left': '*' },
|
|
|
|
\ 'sicad': { 'left': '*' },
|
|
|
|
\ 'sile': { 'left': '%' },
|
|
|
|
\ 'sile': { 'left': '%', 'leftAlt': '--' },
|
|
|
|
\ 'simula': { 'left': '%', 'leftAlt': '--' },
|
|
|
|
\ 'simula': { 'left': '%', 'leftAlt': '--' },
|
|
|
|
\ 'sinda': { 'left': '$' },
|
|
|
|
\ 'sinda': { 'left': '$' },
|
|
|
|
\ 'skill': { 'left': ';' },
|
|
|
|
\ 'skill': { 'left': ';' },
|
|
|
|
@@ -379,6 +383,7 @@ let s:delimiterMap = {
|
|
|
|
\ 'stan': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
|
|
|
\ 'stan': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
|
|
|
\ 'stp': { 'left': '/*', 'right': '*/', 'leftAlt': '//' },
|
|
|
|
\ 'stp': { 'left': '/*', 'right': '*/', 'leftAlt': '//' },
|
|
|
|
\ 'supercollider': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
|
|
|
\ 'supercollider': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
|
|
|
|
|
|
|
\ 'svelte': { 'left': '<!--', 'right': '-->' },
|
|
|
|
\ 'swift': { 'left': '/*', 'right': '*/', 'leftAlt': '//' },
|
|
|
|
\ 'swift': { 'left': '/*', 'right': '*/', 'leftAlt': '//' },
|
|
|
|
\ 'systemverilog': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
|
|
|
\ 'systemverilog': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
|
|
|
\ 'tads': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
|
|
|
\ 'tads': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
|
|
|
@@ -393,6 +398,7 @@ let s:delimiterMap = {
|
|
|
|
\ 'texmf': { 'left': '%' },
|
|
|
|
\ 'texmf': { 'left': '%' },
|
|
|
|
\ 'tf': { 'left': '#' },
|
|
|
|
\ 'tf': { 'left': '#' },
|
|
|
|
\ 'tidy': { 'left': '#' },
|
|
|
|
\ 'tidy': { 'left': '#' },
|
|
|
|
|
|
|
|
\ 'tla': { 'left': '\\*', 'leftAlt': '(*', 'rightAlt': '*)' },
|
|
|
|
\ 'tli': { 'left': '#' },
|
|
|
|
\ 'tli': { 'left': '#' },
|
|
|
|
\ 'tmux': { 'left': '#' },
|
|
|
|
\ 'tmux': { 'left': '#' },
|
|
|
|
\ 'toml': { 'left': '#' },
|
|
|
|
\ 'toml': { 'left': '#' },
|
|
|
|
@@ -436,7 +442,8 @@ let s:delimiterMap = {
|
|
|
|
\ 'xpm2': { 'left': '!' },
|
|
|
|
\ 'xpm2': { 'left': '!' },
|
|
|
|
\ 'xquery': { 'left': '(:', 'right': ':)' },
|
|
|
|
\ 'xquery': { 'left': '(:', 'right': ':)' },
|
|
|
|
\ 'yaml': { 'left': '#' },
|
|
|
|
\ 'yaml': { 'left': '#' },
|
|
|
|
\ 'z8a': { 'left': ';' }
|
|
|
|
\ 'z8a': { 'left': ';' },
|
|
|
|
|
|
|
|
\ 'zig': { 'left': '//' }
|
|
|
|
\ }
|
|
|
|
\ }
|
|
|
|
|
|
|
|
|
|
|
|
let g:NERDDelimiterMap = s:delimiterMap
|
|
|
|
let g:NERDDelimiterMap = s:delimiterMap
|
|
|
|
@@ -1153,6 +1160,7 @@ endfunction
|
|
|
|
" -lineNo: the line number of the line to check
|
|
|
|
" -lineNo: the line number of the line to check
|
|
|
|
" Return: Number, 1 if the line is a comment, 0 else
|
|
|
|
" Return: Number, 1 if the line is a comment, 0 else
|
|
|
|
function! nerdcommenter#IsLineCommented(lineNo) abort
|
|
|
|
function! nerdcommenter#IsLineCommented(lineNo) abort
|
|
|
|
|
|
|
|
call nerdcommenter#SetUp()
|
|
|
|
let theLine = getline(a:lineNo)
|
|
|
|
let theLine = getline(a:lineNo)
|
|
|
|
return s:IsInSexyComment(a:lineNo) || s:IsCommentedFromStartOfLine(s:Left(), theLine) || s:IsCommentedFromStartOfLine(s:Left({'alt': 1}), theLine)
|
|
|
|
return s:IsInSexyComment(a:lineNo) || s:IsCommentedFromStartOfLine(s:Left(), theLine) || s:IsCommentedFromStartOfLine(s:Left({'alt': 1}), theLine)
|
|
|
|
endfunction
|
|
|
|
endfunction
|
|
|
|
@@ -1419,46 +1427,20 @@ function! s:PlaceDelimitersAndInsBetween() abort
|
|
|
|
let left = s:Left({'space': 1})
|
|
|
|
let left = s:Left({'space': 1})
|
|
|
|
let right = s:Right({'space': 1})
|
|
|
|
let right = s:Right({'space': 1})
|
|
|
|
|
|
|
|
|
|
|
|
let theLine = getline('.')
|
|
|
|
" 0. Entered insert normal mode using <C-\><C-O> (:h i_CTRL-\_CTRL-O) to
|
|
|
|
let lineHasLeadTabs = s:HasLeadingTabs(theLine) || (theLine =~# '^ *$' && !&expandtab)
|
|
|
|
" maintain the cursor position (from <Plug>NERDCommenterInsert).
|
|
|
|
|
|
|
|
" 1. Enter insert mode without changing the cursor position.
|
|
|
|
"convert tabs to spaces and adjust the cursors column to take this into
|
|
|
|
" If the cursor is on EOL (right of the last char), use 'a'.
|
|
|
|
"account
|
|
|
|
" Otherwise, use 'i'.
|
|
|
|
let untabbedCol = s:UntabbedCol(theLine, col('.'))
|
|
|
|
let insert = col('.') > strlen(getline('.')) ? 'a' : 'i'
|
|
|
|
call setline(line('.'), s:ConvertLeadingTabsToSpaces(theLine))
|
|
|
|
" 2. Insert comment delimiters.
|
|
|
|
call cursor(line('.'), untabbedCol)
|
|
|
|
" 3. Move the cursor to the left of the closing delimiter, without
|
|
|
|
|
|
|
|
" breaking undo sequence.
|
|
|
|
" get the length of the right delimiter
|
|
|
|
" 4. Enter insert normal mode again without changing the cursor position.
|
|
|
|
let lenRight = strlen(right)
|
|
|
|
" This ensures that returning to the insert mode after finishing the
|
|
|
|
|
|
|
|
" script execution does not move the cursor.
|
|
|
|
let isDelimOnEOL = col('.') >= strlen(getline('.'))
|
|
|
|
" ( 1 ) ( 2 ) ( 3 ) ( 4 )
|
|
|
|
|
|
|
|
execute 'normal!' insert . left . right . repeat("\<C-G>U\<Left>", strchars(right)) . "\<C-\>\<C-O>"
|
|
|
|
" 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
|
|
|
|
|
|
|
|
endfunction
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
|
|
" Function: s:RemoveDelimiters(left, right, line)
|
|
|
|
" Function: s:RemoveDelimiters(left, right, line)
|
|
|
|
@@ -3019,18 +3001,6 @@ function! s:SwapOuterPlaceHoldersForMultiPartDelims(line) abort
|
|
|
|
return line
|
|
|
|
return line
|
|
|
|
endfunction
|
|
|
|
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()
|
|
|
|
"FUNCTION: s:TabSpace()
|
|
|
|
"returns a string of spaces equal in length to &tabstop
|
|
|
|
"returns a string of spaces equal in length to &tabstop
|
|
|
|
function! s:TabSpace() abort
|
|
|
|
function! s:TabSpace() abort
|
|
|
|
@@ -3051,15 +3021,3 @@ endfunction
|
|
|
|
function! s:UnEsc(str, escChar) abort
|
|
|
|
function! s:UnEsc(str, escChar) abort
|
|
|
|
return substitute(a:str, a:escChar, '', 'g')
|
|
|
|
return substitute(a:str, a:escChar, '', 'g')
|
|
|
|
endfunction
|
|
|
|
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
|
|
|
|
|
|
|
|
|