15 Commits
2.6.0 ... 2.7.0

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
4 changed files with 34 additions and 69 deletions

View File

@@ -1,5 +1,12 @@
# 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

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:
```vim
nnoremap <silent> <leader>c} V}:call NERDComment('x', 'toggle')<CR>
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 nerdcommenter#Comment('x', 'toggle')<CR>
```
## Contributions

View File

@@ -33,6 +33,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,6 +50,7 @@ let s:delimiterMap = {
\ 'btm': { 'left': '::' },
\ 'c': { 'left': '/*', 'right': '*/', 'leftAlt': '//' },
\ 'cabal': { 'left': '--' },
\ 'cairo': { 'left': '#' },
\ 'calibre': { 'left': '//' },
\ 'caos': { 'left': '*' },
\ 'catalog': { 'left': '--', 'right': '--' },
@@ -193,12 +195,14 @@ let s:delimiterMap = {
\ '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': '>-- ' },
@@ -342,7 +346,7 @@ let s:delimiterMap = {
\ 'sh': { 'left': '#' },
\ 'shader_test': { 'left': '#' },
\ 'sicad': { 'left': '*' },
\ 'sile': { 'left': '%' },
\ 'sile': { 'left': '%', 'leftAlt': '--' },
\ 'simula': { 'left': '%', 'leftAlt': '--' },
\ 'sinda': { 'left': '$' },
\ 'skill': { 'left': ';' },
@@ -379,6 +383,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': '*/' },
@@ -393,6 +398,7 @@ let s:delimiterMap = {
\ 'texmf': { 'left': '%' },
\ 'tf': { 'left': '#' },
\ 'tidy': { 'left': '#' },
\ 'tla': { 'left': '\\*', 'leftAlt': '(*', 'rightAlt': '*)' },
\ 'tli': { 'left': '#' },
\ 'tmux': { 'left': '#' },
\ 'toml': { 'left': '#' },
@@ -436,7 +442,8 @@ let s:delimiterMap = {
\ 'xpm2': { 'left': '!' },
\ 'xquery': { 'left': '(:', 'right': ':)' },
\ 'yaml': { 'left': '#' },
\ 'z8a': { 'left': ';' }
\ 'z8a': { 'left': ';' },
\ 'zig': { 'left': '//' }
\ }
let g:NERDDelimiterMap = s:delimiterMap
@@ -1153,6 +1160,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
@@ -1419,46 +1427,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)
@@ -3019,18 +3001,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
@@ -3051,15 +3021,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

View File

@@ -125,7 +125,7 @@ function! NERDCommentIsCharCommented(line, col)
return nerdcommenter#IsCharCommented(a:line, a:col)
endfunction
inoremap <silent> <Plug>NERDCommenterInsert <Space><BS><Esc>:call nerdcommenter#Comment('i', "insert")<CR>
inoremap <silent> <Plug>NERDCommenterInsert <C-\><C-O>:call nerdcommenter#Comment('i', "Insert")<CR>
" switch to/from alternative delimiters (does not use wrapper function)
nnoremap <Plug>NERDCommenterAltDelims :call nerdcommenter#SwitchToAlternativeDelimiters(1)<CR>