29 Commits

Author SHA1 Message Date
Cristiano De Michele
b4a57a0b4f Merge c7c99edfb7 into 3f860f2d98 2024-08-08 12:33:56 +03:00
Caleb Maclennan
3f860f2d98 Merge pull request #531 from svalaskevicius/master 2024-08-08 12:33:49 +03:00
Igor Prusov
c9b1078807 Add delimeters fof Device Tree Source (DTS) files (#535) 2024-08-08 12:33:00 +03:00
Mark Huang
7bb1f72e80 Add comment delimiters to support aptconf (#533) 2024-05-13 13:37:01 +03:00
Sarunas Valaskevicius
fea637c3c2 Fix alternative delimiter usage in alternate buffers
Copy the configuration for a file rather than capture by reference.

Due to the logic in the alternative delimiter configurator, which swaps the
delimiters when called, every second buffer the script is used swaps the
delimiter order in the original config. This leads to incorrect
delimiters being used in every second buffer.

This change makes a copy for each buffer so swapping the order will not
affect the next loaded buffer.
2024-01-14 15:27:11 +00:00
Mark Huang
e361a44230 Add delimiter for pamenv (#530) 2023-12-18 22:49:10 +03:00
zhaoyunfeng
da948e160d fix: Ensure #Setup is run in #IsCharCommented (#527) 2023-11-02 14:24:05 +03:00
jwellhofer
c52b6e731c Add delimiters for Alloy files (#526)
Co-authored-by: Johannes Wellhöfer <johannes.wellhofer@gmail.com>
2023-10-23 11:47:28 +03:00
Christian Segundo
d2e21d417f feat: Add delimiter for HCL files (#525) 2023-08-13 01:12:53 +03:00
qizidog
ab2ae4d502 docs: Fix title numbering error in chapter-4 (#524) 2023-06-26 11:21:32 +03:00
Rich Churcher
844b211a4c Add Dart to supported languages (#523) 2023-06-26 11:19:48 +03:00
Krzysztof Leśniak
b0b09ea46c Fix use on VIM 8 with proper arguments to bufnr() (#521) 2023-06-05 11:34:33 +03:00
Christian Segundo
2045211689 Add support for jq filter files (#520) 2023-05-17 20:39:52 +03:00
Yuxin Wu
277bdfc679 fix: Reference current buffer not '1' re b:NERDCommenterFirstInit (#519) 2023-05-08 14:58:24 +03:00
YuyaKoda
1fe9e1cfea style: Remove stray whitespaces & normalize format (#517) 2023-04-26 18:20:01 +03:00
YuyaKoda
e23f55e735 feat: Add vcl (Varnish Configuration Language) (#516) 2023-04-26 16:46:33 +03:00
Yuxin Wu
91499c76a7 Prevent caching of buffer commentstring (#515)
Co-authored-by: Yuxin Wu <ppwwyyxx@users.noreply.github.com>
2023-04-21 09:44:44 +03:00
Caleb Maclennan
bd1a29536d Revert "Prevent caching of buffer commentstring (#514)"
This reverts commit 457b383767.
2023-04-20 19:50:28 +03:00
林千里
c6766698d8 Recompute indxLeft after line has changed (#507) 2023-04-20 19:44:06 +03:00
Hazael Sanchez
c5b0f78820 Add support for CEL (#512) 2023-04-20 19:42:45 +03:00
Yuxin Wu
78029a0e90 Fix support for embedded lua in vimscript (#513)
Co-authored-by: Yuxin Wu <ppwwyyxx@users.noreply.github.com>
2023-04-20 19:42:14 +03:00
Yuxin Wu
457b383767 Prevent caching of buffer commentstring (#514) 2023-04-20 19:38:56 +03:00
Chris
d069f7fb56 Update starkware cairo comments to latest syntax (#511) 2023-02-05 23:14:12 +03:00
Dmitrii Mishutin
06f6166e5d feat(dosbatch): change delimiters (#508) 2023-01-27 21:30:52 +03:00
Caleb Maclennan
c406bba57d Fix comment syntax blooper from #510 2023-01-27 17:00:07 +03:00
Konstantin-Glukhov
ea6a4f76fa Fix bug for unable to uncomment indented comments in vim files (#510)
Closes https://github.com/preservim/nerdcommenter/issues/491
2023-01-27 13:01:58 +03:00
Sankhesh Jhaveri
1caf560df1 Allow hooks to change filetype and comment deilmiters (#509)
Fixes https://github.com/preservim/nerdcommenter/pull/479
2023-01-26 20:57:08 +03:00
Caleb Maclennan
98cc4a2d64 Fixup manual install instructions to be complete
Closes #506

Co-authored-by: Yuri Schaeffer <yuri@schaeffer.tk>
2022-11-09 12:45:12 +03:00
Cristiano De Michele
c7c99edfb7 fix for C/C++ alternative comments 2021-11-10 18:19:33 +01:00
3 changed files with 58 additions and 48 deletions

View File

@@ -68,10 +68,12 @@ git clone https://github.com/preservim/nerdcommenter.git
(For Neovim, change `~/.vim/` to `~/.config/nvim/`.)
```sh
curl -fLo ~/.vim/plugin/NERD_Commenter.vim --create-dirs \
curl -fLo ~/.vim/plugin/nerdcommenter.vim --create-dirs \
https://raw.githubusercontent.com/preservim/nerdcommenter/master/plugin/nerdcommenter.vim
curl -fLo ~/.vim/doc/NERD_Commenter.txt --create-dirs \
curl -fLo ~/.vim/doc/nerdcommenter.txt --create-dirs \
https://raw.githubusercontent.com/preservim/nerdcommenter/master/doc/nerdcommenter.txt
curl -fLo ~/.vim/autoload/nerdcommenter.vim --create-dirs \
https://raw.githubusercontent.com/preservim/nerdcommenter/master/autoload/nerdcommenter.vim
```
</details>

View File

@@ -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': '#' },
@@ -50,10 +52,11 @@ let s:delimiterMap = {
\ 'btm': { 'left': '::' },
\ 'c': { 'left': '/*', 'right': '*/', 'leftAlt': '//' },
\ 'cabal': { 'left': '--' },
\ 'cairo': { 'left': '#' },
\ 'cairo': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
\ 'calibre': { 'left': '//' },
\ 'caos': { 'left': '*' },
\ 'catalog': { 'left': '--', 'right': '--' },
\ 'cel': { 'left': '//' },
\ 'cf': { 'left': '<!---', 'right': '--->' },
\ 'cfg': { 'left': '#' },
\ 'cg': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
@@ -80,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': '#' },
@@ -87,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': ';' },
@@ -159,6 +164,7 @@ let s:delimiterMap = {
\ 'haxe': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
\ 'hb': { 'left': '#' },
\ 'hbs': { 'left': '{{!-- ', 'right': ' --}}' },
\ 'hcl': { 'left': '#', 'leftAlt': '/*', 'rightAlt': '*/' },
\ 'hercules': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
\ 'hive': { 'left': '-- ' },
\ 'hocon': { 'left': '//', 'leftAlt': '#' },
@@ -190,6 +196,7 @@ 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': '*/' },
@@ -275,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': '#' },
@@ -420,6 +428,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': '*/' },
@@ -460,10 +469,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
@@ -481,7 +486,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] = ''
@@ -493,10 +498,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()
@@ -534,10 +539,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'] ==# ''
@@ -660,7 +665,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
@@ -1077,7 +1082,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
@@ -1175,10 +1180,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]'
@@ -1317,6 +1322,7 @@ endfunction
" -col the column number of the character
" Return: Number, 1 if the character is inside a comment, 0 if is not
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:
@@ -1766,6 +1772,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)
@@ -2528,15 +2536,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 =~# "^\s\\{" . a:delIndx . "\\}\".*$"
" if the delimiter is the first non-whitespace character, it is valid
if a:line =~# '^\s*"'
return 1
endif

View File

@@ -510,7 +510,7 @@ change the filetype back: >
all selected lines is commented or not.
------------------------------------------------------------------------------
4.3 Options details *NERDCommenterOptionsDetails*
4.2 Options details *NERDCommenterOptionsDetails*
To enable any of the below options you should put the given line in your
~/.vimrc
@@ -855,7 +855,7 @@ file by the following line >
<
------------------------------------------------------------------------------
3.3 Default delimiter customisation *NERDCommenterDefaultDelims*
4.3 Default delimiter customisation *NERDCommenterDefaultDelims*
If you want the NERD commenter to use the alternative delimiters for a
specific filetype by default then put a line of this form into your vimrc: >