32 Commits

Author SHA1 Message Date
Caleb Maclennan
f575c18d05 Release 2.7.0 (for those using releases, tracking upstream master is recommended) 2022-11-05 12:34:59 +03:00
Allen Guan
fd2114b46d Update outdated example code in readme (#504) 2022-10-29 12:40:51 +03:00
Brian Wo
fe74a1b890 Add support for Justfile (#503) 2022-10-11 10:03:52 +03:00
Brian Wo
60f3a2bc2b Add support for Svelte (#502) 2022-10-07 10:43:59 +03:00
Giuliano
2a0a05ff98 Add support for TLA+ modeling and specification language (#497) 2022-09-12 09:15:28 +03:00
Christian Segundo
6d30ebcd42 Add support for Zig (#492) 2022-05-20 23:15:25 +03:00
Caleb Maclennan
f8671f783b Add alternate delimiter to SILE format to ease switching to Lua 2022-02-24 23:22:41 +03:00
Chris
ec002e8f5d Add support for Starkware cairo (#487) 2022-02-12 17:08:52 +03:00
Caleb Maclennan
f9c5f0fbda Merge pull request #482 from tomtomjhj/insert 2022-01-15 21:13:53 +03:00
Jaehwang Jerry Jung
ac512fe158 Do not break undo sequence when moving cursor 2022-01-16 00:10:51 +09:00
Jaehwang Jerry Jung
867618364f Simplify and fix NERDCommenterInsert
* Simplify comment delimiter insertion.
* Remove the code that unnecessarily touches the leading spaces/tabs.
* Fix a bug in which `<Plug>NERDCommenterInsert` inserts the comment
  delimiters in a wrong position when `col('.')==1`.
  Example: `1|234` (cursor at `|`) → `/* */1234`.
* NOTE: Should avoid `feedkey(.., 'ni')` for inserting comment
  delimiters to ensure that `NERDCommenter_after` is called after
  inserting the delimiters. `feedkey` only adds the input to the queue,
  which will be processed after exiting the script context. On the other
  hand, `:normal` and `feedkey(.., 'x')` are eagerly processed.
2022-01-16 00:10:51 +09:00
Caleb Maclennan
97317fc319 Merge pull request #486 from phlip9/master 2022-01-15 15:51:20 +03:00
Philip Hayes
37298c471e Add support for ATS and Lean 2022-01-14 16:38:49 -08:00
Caleb Maclennan
9fffd4c022 Merge pull request #485 from ftfunjth/master 2021-12-28 13:31:54 +03:00
ftfunjth
2e7a775dd2 Add SetUp call in IsLineCommented function definition 2021-12-28 18:13:13 +08:00
Caleb Maclennan
eddd535bdf Release 2.6.0 (for those using releases, tracking upstream master is recommended) 2021-11-27 07:22:42 +03:00
Caleb Maclennan
13d00954a6 Merge pull request #481 from dsirov/fasm+json5-syntax 2021-11-24 20:38:07 +03:00
David Sirovsky
ab67976bea autoload/nerdcommenter.vim: json5 support 2021-11-24 12:20:12 +02:00
David Sirovsky
fa9b74ff69 autoload/nerdcommenter.vim: fasm support 2021-11-24 12:19:56 +02:00
Caleb Maclennan
a65465d321 Merge pull request #479 from jiaobuzuji/master 2021-09-02 22:33:20 +03:00
Jiaobuzuji
9d5c12e126 fix 'g:NERDAllowAnyVisualDelims' action
fix 'g:NERDAllowAnyVisualDelims' action.

                                                    *'NERDAllowAnyVisualDelims'*
Values: 0 or 1.
Default: 1.

If set to 1 then, when doing a visual or visual-block comment (but not a
visual-line comment), the script will choose the right delimiters to use for
the comment. This means either using the current delimiters if they are
multipart or using the alternative delimiters if THEY are multipart.  For
example if we are editing the following java code: >
    float foo = 1221;
    float bar = 324;
    System.out.println(foo * bar);
<
If we are using // comments and select the "foo" and "bar" in visual-block
mode, as shown left below (where '|'s are used to represent the visual-block
boundary), and comment it then the script will use the alternative delimiters
as shown on the right: >

    float |foo| = 1221;                   float /*foo*/ = 1221;
    float |bar| = 324;                    float /*bar*/ = 324;
    System.out.println(foo * bar);        System.out.println(foo * bar);
<
2021-09-02 22:27:38 +08:00
Caleb Maclennan
2c87cae76e Merge pull request #475 from tomtomjhj/refactor 2021-07-31 20:24:00 +03:00
Jaehwang Jerry Jung
f7333809b6 Prefer single quoted strings 2021-08-01 00:57:34 +09:00
Jaehwang Jerry Jung
576bd64482 {Save,Restore}ScreenState → win{save,rest}view 2021-08-01 00:45:16 +09:00
Jaehwang Jerry Jung
ed591cb2a2 substitute(.., '..\(pat\)..', '\1') → matchstr() 2021-08-01 00:33:13 +09:00
Jaehwang Jerry Jung
d398a0278c [ \t] → \s, [^ \t] → \S 2021-08-01 00:33:13 +09:00
Caleb Maclennan
85364c56c4 Merge pull request #473 from preservim/shim-functions 2021-07-29 17:41:36 +03:00
Caleb Maclennan
b1bb758f14 Fix vimscript lint warnings 2021-07-29 17:26:06 +03:00
Caleb Maclennan
eeabded555 Pass range data through, error on case we can't shim 2021-07-29 17:20:35 +03:00
Caleb Maclennan
918592cdc6 Add warning messages to deprecated function calls 2021-07-29 16:49:12 +03:00
Caleb Maclennan
8e935a6367 Restore use to IsCharCommented function after autoload refactor goof 2021-07-29 16:48:31 +03:00
Caleb Maclennan
f21b0f8fab Add shim functions to pass through to autoload namespace 2021-07-29 16:23:49 +03:00
4 changed files with 102 additions and 120 deletions

View File

@@ -1,5 +1,22 @@
# Changelog # Changelog
### 2.7.0
* Support for many more filetypes
* Sort out race condition when using utility functions directly
* Fixup undo support when commenting results in cursor moves
* Refactor comment insertion code
### 2.6.0
* Refactor code to run as autoload plugin
* Add lots of community contributed file types
* Fix several languages with idiosyncrasies
* Improve interoperability with other vim settings
* Improve handling of ranges
* Improve help documentation
* Cleanup and fix vimscript issues
### 2.5.2 ### 2.5.2
* Minor update to include new file types contributed by the community over the last few months. * Minor update to include new file types contributed by the community over the last few months.

View File

@@ -201,8 +201,8 @@ Most of the following mappings are for normal/visual mode only. The **|NERDComme
While the plugin does not directly support motions, you can leverage its support for selections to do something very similar. For example, to add motions to toggle comments on the paragraph text object you could use: While the plugin does not directly support motions, you can leverage its support for selections to do something very similar. For example, to add motions to toggle comments on the paragraph text object you could use:
```vim ```vim
nnoremap <silent> <leader>c} V}:call NERDComment('x', 'toggle')<CR> nnoremap <silent> <leader>c} V}:call nerdcommenter#Comment('x', 'toggle')<CR>
nnoremap <silent> <leader>c{ V{:call NERDComment('x', 'toggle')<CR> nnoremap <silent> <leader>c{ V{:call nerdcommenter#Comment('x', 'toggle')<CR>
``` ```
## Contributions ## Contributions

View File

@@ -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': '--' },
@@ -114,6 +116,7 @@ let s:delimiterMap = {
\ 'exports': { 'left': '#' }, \ 'exports': { 'left': '#' },
\ 'factor': { 'left': '! ', 'leftAlt': '!# ' }, \ 'factor': { 'left': '! ', 'leftAlt': '!# ' },
\ 'fancy': { 'left': '#' }, \ 'fancy': { 'left': '#' },
\ 'fasm': { 'left': ';' },
\ 'faust': { 'left': '//' }, \ 'faust': { 'left': '//' },
\ 'fgl': { 'left': '#' }, \ 'fgl': { 'left': '#' },
\ 'fluent': { 'left': '#', 'leftAlt': '##' }, \ 'fluent': { 'left': '#', 'leftAlt': '##' },
@@ -187,16 +190,19 @@ let s:delimiterMap = {
\ 'jgraph': { 'left': '(*', 'right': '*)' }, \ 'jgraph': { 'left': '(*', 'right': '*)' },
\ 'jinja': { 'left': '{#', 'right': '#}', 'leftAlt': '<!--', 'rightAlt': '-->' }, \ 'jinja': { 'left': '{#', 'right': '#}', 'leftAlt': '<!--', 'rightAlt': '-->' },
\ 'jproperties': { 'left': '#' }, \ 'jproperties': { 'left': '#' },
\ 'json5': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
\ 'jsonc': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' }, \ 'jsonc': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
\ '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': '>-- ' },
@@ -340,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': ';' },
@@ -377,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': '*/' },
@@ -391,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': '#' },
@@ -434,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
@@ -506,8 +515,8 @@ function! s:CreateDelimMapFromCms() abort
return delims return delims
endif endif
return { return {
\ 'left': substitute(&commentstring, '\([^ \t]*\)\s*%s.*', '\1', ''), \ 'left': matchstr(&commentstring, '^\S*\ze\s*%s'),
\ 'right': substitute(&commentstring, '.*%s\s*\(.*\)', '\1', 'g'), \ 'right': matchstr(&commentstring, '%s\s*\zs.*$'),
\ 'nested': 0, \ 'nested': 0,
\ 'leftAlt': '', \ 'leftAlt': '',
\ 'rightAlt': '', \ 'rightAlt': '',
@@ -651,7 +660,7 @@ function! s:CommentBlock(top, bottom, lSide, rSide, forceNested) abort
"alternative delimiters (if THEY are) as the comment will be better and more "alternative delimiters (if THEY are) as the comment will be better and more
"accurate with multipart delimiters "accurate with multipart delimiters
let switchedDelims = 0 let switchedDelims = 0
if !s:Multipart() && !g:NERDAllowAnyVisualDelims && s:AltMultipart() if !s:Multipart() && g:NERDAllowAnyVisualDelims && s:AltMultipart()
let switchedDelims = 1 let switchedDelims = 1
call nerdcommenter#SwitchToAlternativeDelimiters(0) call nerdcommenter#SwitchToAlternativeDelimiters(0)
endif endif
@@ -1068,7 +1077,7 @@ function! s:CommentRegion(topLine, topCol, bottomLine, bottomCol, forceNested) a
"switch delimiters (if we can) if the current set isn't multipart "switch delimiters (if we can) if the current set isn't multipart
let switchedDelims = 0 let switchedDelims = 0
if !s:Multipart() && s:AltMultipart() && !g:NERDAllowAnyVisualDelims if !s:Multipart() && s:AltMultipart() && g:NERDAllowAnyVisualDelims
let switchedDelims = 1 let switchedDelims = 1
call nerdcommenter#SwitchToAlternativeDelimiters(0) call nerdcommenter#SwitchToAlternativeDelimiters(0)
endif endif
@@ -1091,7 +1100,7 @@ function! s:CommentRegion(topLine, topCol, bottomLine, bottomCol, forceNested) a
"comment the bottom line "comment the bottom line
let bottom = getline(a:bottomLine) 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) call s:CommentBlock(a:bottomLine, a:bottomLine, numLeadingSpacesTabs+1, a:bottomCol, a:forceNested)
endif endif
@@ -1151,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
@@ -1236,7 +1246,7 @@ function! nerdcommenter#Comment(mode, type) range abort
for i in range(firstLine, lastLine) for i in range(firstLine, lastLine)
let theLine = getline(i) let theLine = getline(i)
" if have one line no comment(not include blank/whitespace-only lines), then comment all lines " 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 let l:commentAllLines = 1
break break
else else
@@ -1259,9 +1269,9 @@ function! nerdcommenter#Comment(mode, type) range abort
endtry endtry
elseif a:type ==? 'ToEOL' elseif a:type ==? 'ToEOL'
call s:SaveScreenState() let view = winsaveview()
call s:CommentBlock(firstLine, firstLine, col('.'), col('$')-1, 1) call s:CommentBlock(firstLine, firstLine, col('.'), col('$')-1, 1)
call s:RestoreScreenState() call winrestview(view)
elseif a:type ==? 'Append' elseif a:type ==? 'Append'
call s:AppendCommentToLine() call s:AppendCommentToLine()
@@ -1298,7 +1308,7 @@ function! nerdcommenter#Comment(mode, type) range abort
endfunction endfunction
" Function: NERDCommentIsCharCommented(line, col) abort " Function: nerdcommenter#IsCharCommented(line, col) abort
" Check if the character at [line, col] is inside a comment " Check if the character at [line, col] is inside a comment
" Note the Comment delimeter it self is considered as part of the comment " Note the Comment delimeter it self is considered as part of the comment
" "
@@ -1306,7 +1316,7 @@ endfunction
" -line the line number of the character " -line the line number of the character
" -col the column 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 " 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
" Function: s:searchfor(str, line, col, direction, [maxline]) " Function: s:searchfor(str, line, col, direction, [maxline])
" search str in the buffer, including the character at [line, col] " search str in the buffer, including the character at [line, col]
" Args: " Args:
@@ -1417,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)
@@ -1671,7 +1655,7 @@ function! s:UncommentLinesSexy(topline, bottomline) abort
let theLine = getline(a:topline) let theLine = getline(a:topline)
" if the first line contains only the left delimiter then just delete it " 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) call cursor(a:topline, 1)
normal! dd normal! dd
let bottomline = bottomline - 1 let bottomline = bottomline - 1
@@ -1695,7 +1679,7 @@ function! s:UncommentLinesSexy(topline, bottomline) abort
let theLine = getline(bottomline) let theLine = getline(bottomline)
" if the bottomline contains only the right delimiter then just delete it " 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) call cursor(bottomline, 1)
normal! dd normal! dd
@@ -1712,7 +1696,7 @@ function! s:UncommentLinesSexy(topline, bottomline) abort
" if the last line also starts with a sexy comment marker then we " if the last line also starts with a sexy comment marker then we
" remove this as well " remove this as well
if theLine =~# '^[ \t]*' . sexyComMarker if theLine =~# '^\s*' . sexyComMarker
" remove the sexyComMarker. If there is a space after it then " remove the sexyComMarker. If there is a space after it then
" remove that too " remove that too
@@ -1836,7 +1820,7 @@ endfunction
" Function: s:AddLeftDelim(delim, theLine) " Function: s:AddLeftDelim(delim, theLine)
" Args: " Args:
function! s:AddLeftDelim(delim, theLine) abort function! s:AddLeftDelim(delim, theLine) abort
return substitute(a:theLine, '^\([ \t]*\)', '\1' . a:delim, '') return substitute(a:theLine, '^\(\s*\)', '\1' . a:delim, '')
endfunction endfunction
" Function: s:AddLeftDelimAligned(delim, theLine) " Function: s:AddLeftDelimAligned(delim, theLine)
@@ -1906,7 +1890,7 @@ function! s:CanCommentLine(forceNested, lineNum) abort
" make sure we don't comment lines that are just spaces or tabs or empty, " make sure we don't comment lines that are just spaces or tabs or empty,
" unless configured otherwise " unless configured otherwise
if g:NERDCommentEmptyLines ==# 0 && theLine =~# "^[ \t]*$" if g:NERDCommentEmptyLines ==# 0 && theLine =~# '^\s*$'
return 0 return 0
endif endif
@@ -1973,7 +1957,7 @@ function! s:CanToggleCommentLine(forceNested, lineNum) abort
" make sure we don't comment lines that are just spaces or tabs or empty, " make sure we don't comment lines that are just spaces or tabs or empty,
" unless configured otherwise " unless configured otherwise
if g:NERDCommentEmptyLines ==# 0 && theLine =~# "^[ \t]*$" if g:NERDCommentEmptyLines ==# 0 && theLine =~# '^\s*$'
return 0 return 0
endif endif
@@ -2194,16 +2178,16 @@ function! s:FindBoundingLinesOfSexyCom(lineNum) abort
let theLine = getline(currentLine) let theLine = getline(currentLine)
"check if the current line is the top of the sexy comment "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 top = currentLine
let currentLine = a:lineNum let currentLine = a:lineNum
"check if the current line is the bottom of the sexy comment "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 let bottom = currentLine
"the right delimiter is on the same line as the last sexyComMarker "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 let bottom = currentLine
"we have not found the top or bottom line so we assume currentLine is an "we have not found the top or bottom line so we assume currentLine is an
@@ -2212,7 +2196,7 @@ function! s:FindBoundingLinesOfSexyCom(lineNum) abort
"if the line doesn't start with a sexyComMarker then it is not a sexy "if the line doesn't start with a sexyComMarker then it is not a sexy
"comment "comment
if theLine !~# '^[ \t]*' . sexyComMarker if theLine !~# '^\s*' . sexyComMarker
return [] return []
endif endif
@@ -2450,7 +2434,7 @@ endfunction
" -left: the left delimiter to check for " -left: the left delimiter to check for
function! s:IsCommentedFromStartOfLine(left, line) abort function! s:IsCommentedFromStartOfLine(left, line) abort
let theLine = s:ConvertLeadingTabsToSpaces(a:line) let theLine = s:ConvertLeadingTabsToSpaces(a:line)
let numSpaces = strlen(substitute(theLine, '^\( *\).*$', '\1', '')) let numSpaces = strlen(matchstr(theLine, '^ *'))
let delimIndx = s:FindDelimiterIndex(a:left, theLine) let delimIndx = s:FindDelimiterIndex(a:left, theLine)
return delimIndx ==# numSpaces return delimIndx ==# numSpaces
endfunction endfunction
@@ -2552,7 +2536,7 @@ function! s:IsDelimValid(delimiter, delIndx, line) abort
"if the delimiter is on the very first char of the line or is the "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 "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 a:delIndx ==# 0 || a:line =~# "^\s\\{" . a:delIndx . "\\}\".*$"
return 1 return 1
endif endif
@@ -2653,7 +2637,7 @@ function! s:IsSexyComment(topline, bottomline) abort
endif endif
"if the top line doesn't begin with a left delimiter then the comment isn't sexy "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 return 0
endif endif
@@ -2681,7 +2665,7 @@ function! s:IsSexyComment(topline, bottomline) abort
while currentLine < a:bottomline while currentLine < a:bottomline
let theLine = getline(currentLine) let theLine = getline(currentLine)
if theLine !~# '^[ \t]*' . sexyComMarker if theLine !~# '^\s*' . sexyComMarker
return 0 return 0
endif endif
@@ -2780,12 +2764,12 @@ function! s:LeftMostIndx(countCommentedLines, countEmptyLines, topline, bottomli
" get the next line and if it is allowed to be commented, or is not " get the next line and if it is allowed to be commented, or is not
" commented, check it " commented, check it
let theLine = getline(currentLine) 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)) 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 " convert spaces to tabs and get the number of leading spaces for
" this line and update leftMostIndx if need be " this line and update leftMostIndx if need be
let theLine = s:ConvertLeadingTabsToSpaces(theLine) let theLine = s:ConvertLeadingTabsToSpaces(theLine)
let leadSpaceOfLine = strlen( substitute(theLine, '\(^[ \t]*\).*$','\1','') ) let leadSpaceOfLine = strlen(matchstr(theLine, '^\s*'))
if leadSpaceOfLine < leftMostIndx if leadSpaceOfLine < leftMostIndx
let leftMostIndx = leadSpaceOfLine let leftMostIndx = leadSpaceOfLine
endif endif
@@ -2833,7 +2817,7 @@ endfunction
" Function: s:NumberOfLeadingTabs(s) " Function: s:NumberOfLeadingTabs(s)
" returns the number of leading tabs in the given string " returns the number of leading tabs in the given string
function! s:NumberOfLeadingTabs(s) abort function! s:NumberOfLeadingTabs(s) abort
return strlen(substitute(a:s, '^\(\t*\).*$', '\1', '')) return strlen(matchstr(a:s, '^\t*'))
endfunction endfunction
" Function: s:NumLinesInBuf() " Function: s:NumLinesInBuf()
@@ -2907,21 +2891,6 @@ function! s:ReplaceRightMostDelim(toReplace, replacor, str) abort
return line return line
endfunction 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(...) " Function: s:Right(...)
" returns right delimiter data " returns right delimiter data
function! s:Right(...) abort function! s:Right(...) abort
@@ -2963,7 +2932,7 @@ function! s:RightMostIndx(countCommentedLines, countEmptyLines, topline, bottoml
" get the next line and see if it is commentable, otherwise it doesn't " get the next line and see if it is commentable, otherwise it doesn't
" count " count
let theLine = getline(currentLine) 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)) if a:countCommentedLines || (!s:IsCommented(s:Left(), s:Right(), theLine) && !s:IsCommented(s:Left({'alt': 1}), s:Right({'alt': 1}), theLine))
@@ -2983,14 +2952,6 @@ function! s:RightMostIndx(countCommentedLines, countEmptyLines, topline, bottoml
return rightMostIndx return rightMostIndx
endfunction 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) " Function: s:SwapOuterMultiPartDelimsForPlaceHolders(line)
" This function takes a line and swaps the outer most multi-part delimiters for " This function takes a line and swaps the outer most multi-part delimiters for
" place holders " place holders
@@ -3040,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
@@ -3072,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

View File

@@ -42,6 +42,7 @@ call s:InitVariable('g:NERDDefaultAlign', 'none')
call s:InitVariable('g:NERDTrimTrailingWhitespace', 0) call s:InitVariable('g:NERDTrimTrailingWhitespace', 0)
call s:InitVariable('g:NERDToggleCheckAllLines', 0) call s:InitVariable('g:NERDToggleCheckAllLines', 0)
call s:InitVariable('g:NERDDisableTabsInBlockComm', 0) call s:InitVariable('g:NERDDisableTabsInBlockComm', 0)
call s:InitVariable('g:NERDSuppressWarnings', 0)
" Section: Comment mapping and menu item setup " Section: Comment mapping and menu item setup
" =========================================================================== " ===========================================================================
@@ -78,6 +79,7 @@ function! s:CreateMaps(modes, target, desc, combo)
endif endif
endfor endfor
endfunction endfunction
call s:CreateMaps('nx', 'Comment', 'Comment', 'cc') call s:CreateMaps('nx', 'Comment', 'Comment', 'cc')
call s:CreateMaps('nx', 'Toggle', 'Toggle', 'c<Space>') call s:CreateMaps('nx', 'Toggle', 'Toggle', 'c<Space>')
call s:CreateMaps('nx', 'Minimal', 'Minimal', 'cm') call s:CreateMaps('nx', 'Minimal', 'Minimal', 'cm')
@@ -97,7 +99,33 @@ call s:CreateMaps('i', 'Insert', 'Insert Comment Here', '')
call s:CreateMaps('', ':', '-Sep3-', '') call s:CreateMaps('', ':', '-Sep3-', '')
call s:CreateMaps('', ':help NERDCommenterContents<CR>', 'Help', '') call s:CreateMaps('', ':help NERDCommenterContents<CR>', 'Help', '')
inoremap <silent> <Plug>NERDCommenterInsert <Space><BS><Esc>:call nerdcommenter#Comment('i', "insert")<CR> " Shim functions so old code gets passed through to the autoload functions
function! NERDComment(mode, type) range
if !g:NERDSuppressWarnings
echom 'Function NERDComment() has been deprecated, please use nerdcommenter#Comment() instead'
endif
if a:firstline != a:lastline
echoerr "Sorry! We can't pass a range through this deprecation shim, please update your code."
return v:false
endif
return nerdcommenter#Comment(a:mode, a:type)
endfunction
function! NERDCommentIsLineCommented(lineNo)
if !g:NERDSuppressWarnings
echom 'Function NERDCommentIsLineCommented() has been deprecated, please use nerdcommenter#IsLineCommented() instead'
endif
return nerdcommenter#IsLineCommented(a:lineNo)
endfunction
function! NERDCommentIsCharCommented(line, col)
if !g:NERDSuppressWarnings
echom 'Function NERDCommentIsCharCommented() has been deprecated, please use nerdcommenter#IsCharCommented() instead'
endif
return nerdcommenter#IsCharCommented(a:line, a:col)
endfunction
inoremap <silent> <Plug>NERDCommenterInsert <C-\><C-O>:call nerdcommenter#Comment('i', "Insert")<CR>
" switch to/from alternative delimiters (does not use wrapper function) " switch to/from alternative delimiters (does not use wrapper function)
nnoremap <Plug>NERDCommenterAltDelims :call nerdcommenter#SwitchToAlternativeDelimiters(1)<CR> nnoremap <Plug>NERDCommenterAltDelims :call nerdcommenter#SwitchToAlternativeDelimiters(1)<CR>