From f21b0f8faba535e051f64112b3bfd64034ded59b Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Thu, 29 Jul 2021 16:23:49 +0300 Subject: [PATCH 1/5] Add shim functions to pass through to autoload namespace --- plugin/nerdcommenter.vim | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plugin/nerdcommenter.vim b/plugin/nerdcommenter.vim index 33eba31..c4c4497 100644 --- a/plugin/nerdcommenter.vim +++ b/plugin/nerdcommenter.vim @@ -78,6 +78,7 @@ function! s:CreateMaps(modes, target, desc, combo) endif endfor endfunction + call s:CreateMaps('nx', 'Comment', 'Comment', 'cc') call s:CreateMaps('nx', 'Toggle', 'Toggle', 'c') call s:CreateMaps('nx', 'Minimal', 'Minimal', 'cm') @@ -97,6 +98,15 @@ call s:CreateMaps('i', 'Insert', 'Insert Comment Here', '') call s:CreateMaps('', ':', '-Sep3-', '') call s:CreateMaps('', ':help NERDCommenterContents', 'Help', '') +" Shim functions so old code gets passed through to the autoload functions +function! NERDComment(mode, type) + return nerdcommenter#Comment(a:mode, a:type) +endfunction + +function! NERDCommentIsLineCommented(lineNo) + return nerdcommenter#IsLineCommented(a:lineNo) +endfunction + inoremap NERDCommenterInsert :call nerdcommenter#Comment('i', "insert") " switch to/from alternative delimiters (does not use wrapper function) From 8e935a6367712a298150a2fd46f20450dbda812a Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Thu, 29 Jul 2021 16:29:04 +0300 Subject: [PATCH 2/5] Restore use to IsCharCommented function after autoload refactor goof --- autoload/nerdcommenter.vim | 4 ++-- plugin/nerdcommenter.vim | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/autoload/nerdcommenter.vim b/autoload/nerdcommenter.vim index 6c81827..721923d 100644 --- a/autoload/nerdcommenter.vim +++ b/autoload/nerdcommenter.vim @@ -1298,7 +1298,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 +1306,7 @@ 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 " Function: s:searchfor(str, line, col, direction, [maxline]) " search str in the buffer, including the character at [line, col] " Args: diff --git a/plugin/nerdcommenter.vim b/plugin/nerdcommenter.vim index c4c4497..13db9cc 100644 --- a/plugin/nerdcommenter.vim +++ b/plugin/nerdcommenter.vim @@ -107,6 +107,10 @@ function! NERDCommentIsLineCommented(lineNo) return nerdcommenter#IsLineCommented(a:lineNo) endfunction +function! NERDCommentIsCharCommented(line, col) + return nerdcommenter#IsCharCommented(a:line, a:col) +endfunction + inoremap NERDCommenterInsert :call nerdcommenter#Comment('i', "insert") " switch to/from alternative delimiters (does not use wrapper function) From 918592cdc63bab9f3a0f9e77638ea414eac326a4 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Thu, 29 Jul 2021 16:49:12 +0300 Subject: [PATCH 3/5] Add warning messages to deprecated function calls --- plugin/nerdcommenter.vim | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plugin/nerdcommenter.vim b/plugin/nerdcommenter.vim index 13db9cc..0bc51eb 100644 --- a/plugin/nerdcommenter.vim +++ b/plugin/nerdcommenter.vim @@ -42,6 +42,7 @@ call s:InitVariable('g:NERDDefaultAlign', 'none') call s:InitVariable('g:NERDTrimTrailingWhitespace', 0) call s:InitVariable('g:NERDToggleCheckAllLines', 0) call s:InitVariable('g:NERDDisableTabsInBlockComm', 0) +call s:InitVariable('g:NERDSuppressWarnings', 0) " Section: Comment mapping and menu item setup " =========================================================================== @@ -100,14 +101,23 @@ call s:CreateMaps('', ':help NERDCommenterContents', 'Help', '') " Shim functions so old code gets passed through to the autoload functions function! NERDComment(mode, type) + if !g:NERDSuppressWarnings + echom "Function NERDComment() has been deprecated, please use nerdcommenter#Comment() instead" + 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 From eeabded55542f6ea43a0aad0971b58827817b25c Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Thu, 29 Jul 2021 16:57:29 +0300 Subject: [PATCH 4/5] Pass range data through, error on case we can't shim --- plugin/nerdcommenter.vim | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugin/nerdcommenter.vim b/plugin/nerdcommenter.vim index 0bc51eb..471d988 100644 --- a/plugin/nerdcommenter.vim +++ b/plugin/nerdcommenter.vim @@ -100,10 +100,14 @@ call s:CreateMaps('', ':', '-Sep3-', '') call s:CreateMaps('', ':help NERDCommenterContents', 'Help', '') " Shim functions so old code gets passed through to the autoload functions -function! NERDComment(mode, type) +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 From b1bb758f14e11e87b57ce1d1f2720b8ac0e8a873 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Thu, 29 Jul 2021 17:25:41 +0300 Subject: [PATCH 5/5] Fix vimscript lint warnings --- plugin/nerdcommenter.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugin/nerdcommenter.vim b/plugin/nerdcommenter.vim index 471d988..276a0ae 100644 --- a/plugin/nerdcommenter.vim +++ b/plugin/nerdcommenter.vim @@ -102,7 +102,7 @@ call s:CreateMaps('', ':help NERDCommenterContents', 'Help', '') " 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" + 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." @@ -113,14 +113,14 @@ endfunction function! NERDCommentIsLineCommented(lineNo) if !g:NERDSuppressWarnings - echom "Function NERDCommentIsLineCommented() has been deprecated, please use nerdcommenter#IsLineCommented() instead" + 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" + echom 'Function NERDCommentIsCharCommented() has been deprecated, please use nerdcommenter#IsCharCommented() instead' endif return nerdcommenter#IsCharCommented(a:line, a:col) endfunction