From ecf20b005c03e0cab453ca5c4865842162075eba Mon Sep 17 00:00:00 2001 From: marty Date: Tue, 30 Nov 2010 10:20:51 +1300 Subject: [PATCH 01/12] use echom instead of echo so the user can check :messages --- plugin/NERD_commenter.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/NERD_commenter.vim b/plugin/NERD_commenter.vim index 982b140..ce39eb5 100644 --- a/plugin/NERD_commenter.vim +++ b/plugin/NERD_commenter.vim @@ -2400,10 +2400,10 @@ endfunction function s:NerdEcho(msg, typeOfMsg) if a:typeOfMsg == 0 echohl WarningMsg - echo 'NERDCommenter:' . a:msg + echom 'NERDCommenter:' . a:msg echohl None elseif a:typeOfMsg == 1 - echo 'NERDCommenter:' . a:msg + echom 'NERDCommenter:' . a:msg endif endfunction From 24c68a685262d4d7aeabf574b6f77acb74f14ddc Mon Sep 17 00:00:00 2001 From: marty Date: Tue, 30 Nov 2010 10:21:32 +1300 Subject: [PATCH 02/12] complain if the user doesnt have filetype plugins enabled --- plugin/NERD_commenter.vim | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugin/NERD_commenter.vim b/plugin/NERD_commenter.vim index ce39eb5..aa84478 100644 --- a/plugin/NERD_commenter.vim +++ b/plugin/NERD_commenter.vim @@ -1001,6 +1001,10 @@ function! NERDComment(isVisual, type) range let oldIgnoreCase = &ignorecase set noignorecase + if !exists("g:did_load_ftplugin") || g:did_load_ftplugin != 1 + call s:NerdEcho("filetype plugins should be enabled. See :help NERDComInstallation and :help :filetype-plugin-on", 0) + endif + if a:isVisual let firstLine = line("'<") let lastLine = line("'>") From 4447e9e6e898a8ccf5c31df721ff606da29489af Mon Sep 17 00:00:00 2001 From: marty Date: Tue, 30 Nov 2010 10:31:50 +1300 Subject: [PATCH 03/12] update the change log --- doc/NERD_commenter.txt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/doc/NERD_commenter.txt b/doc/NERD_commenter.txt index d7493b1..076098f 100644 --- a/doc/NERD_commenter.txt +++ b/doc/NERD_commenter.txt @@ -781,6 +781,15 @@ The latest dev versions are on github ============================================================================== 8. Changelog *NERDComChangelog* +2.2.3 + - remove all filetypes which have a &commentstring in the standard vim + runtime for vim > 7.0 unless the script stores an alternate set of + delimiters + - make the script complain if the user doesnt have filetype plugins enabled + - use instead of comma to start the default mappings + - fix a couple of bugs with sexy comments - thanks to Tim Smart + - lots of refactoring + 2.2.2 - remove the NERDShutup option and the message is suppresses, this makes the plugin silently rely on &commentstring for unknown filetypes. From 591dd3e1fde8828bab2622900c486f572dc1dcd2 Mon Sep 17 00:00:00 2001 From: marty Date: Wed, 8 Dec 2010 09:37:01 +1300 Subject: [PATCH 04/12] update version to 2.3.0 --- doc/NERD_commenter.txt | 2 +- plugin/NERD_commenter.vim | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/NERD_commenter.txt b/doc/NERD_commenter.txt index 076098f..5309f61 100644 --- a/doc/NERD_commenter.txt +++ b/doc/NERD_commenter.txt @@ -781,7 +781,7 @@ The latest dev versions are on github ============================================================================== 8. Changelog *NERDComChangelog* -2.2.3 +2.3.0 - remove all filetypes which have a &commentstring in the standard vim runtime for vim > 7.0 unless the script stores an alternate set of delimiters diff --git a/plugin/NERD_commenter.vim b/plugin/NERD_commenter.vim index aa84478..ef88dd4 100644 --- a/plugin/NERD_commenter.vim +++ b/plugin/NERD_commenter.vim @@ -1,9 +1,9 @@ " ============================================================================ " File: NERD_commenter.vim " Description: vim global plugin that provides easy code commenting -" Maintainer: Martin Grenfell -" Version: 2.2.2 -" Last Change: 09th October, 2010 +" Maintainer: Martin Grenfell +" Version: 2.3.0 +" Last Change: 08th December, 2010 " License: This program is free software. It comes without any warranty, " to the extent permitted by applicable law. You can redistribute " it and/or modify it under the terms of the Do What The Fuck You From 760df352734666753ceb66a0886e0f0a844c3a48 Mon Sep 17 00:00:00 2001 From: Anurag Priyam Date: Thu, 11 Nov 2010 16:48:55 +0800 Subject: [PATCH 05/12] corrected comment delimiter for liquid filetype --- plugin/NERD_commenter.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/NERD_commenter.vim b/plugin/NERD_commenter.vim index ef88dd4..bbfeb63 100644 --- a/plugin/NERD_commenter.vim +++ b/plugin/NERD_commenter.vim @@ -208,7 +208,7 @@ let s:delimiterMap = { \ 'ldif': { 'left': '#' }, \ 'lilo': { 'left': '#' }, \ 'lilypond': { 'left': '%' }, - \ 'liquid': { 'left': '{%', 'right': '%}' }, + \ 'liquid': { 'left': '{% comment %}', 'right': '{% endcomment %}' }, \ 'lisp': { 'left': ';', 'leftAlt': '#|', 'rightAlt': '|#' }, \ 'llvm': { 'left': ';' }, \ 'lotos': { 'left': '(*', 'right': '*)' }, From 17141e22447911f6d1d58c5ffcdd2816c8ef132e Mon Sep 17 00:00:00 2001 From: Martin Grenfell Date: Sat, 5 Feb 2011 22:40:20 +1300 Subject: [PATCH 06/12] rename the augroup to NERDCommenter --- plugin/NERD_commenter.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/NERD_commenter.vim b/plugin/NERD_commenter.vim index bbfeb63..b25f7dd 100644 --- a/plugin/NERD_commenter.vim +++ b/plugin/NERD_commenter.vim @@ -381,7 +381,7 @@ let s:delimiterMap = { " Section: Comment enabler autocommands {{{2 " ============================================================================ -augroup commentEnablers +augroup NERDCommenter "if the user enters a buffer or reads a buffer then we gotta set up "the comment delimiters for that new filetype From 1577f77ef442eb9efaf2237c91b2c7d7a8aac7eb Mon Sep 17 00:00:00 2001 From: Martin Grenfell Date: Sat, 5 Feb 2011 22:56:03 +1300 Subject: [PATCH 07/12] make the script handle compound filetypes better --- plugin/NERD_commenter.vim | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/plugin/NERD_commenter.vim b/plugin/NERD_commenter.vim index b25f7dd..4ad308c 100644 --- a/plugin/NERD_commenter.vim +++ b/plugin/NERD_commenter.vim @@ -403,10 +403,18 @@ augroup END " set for this buffer. " function s:SetUpForNewFiletype(filetype, forceReset) + let ft = a:filetype + + "for compound filetypes, if we dont know how to handle the full filetype + "then just use the first part, e.g. 'foo.bar' is treated as 'foo' + if ft =~ '\.' && !has_key(s:delimiterMap, ft) + let ft = split(a:filetype, '\.')[0] + endif + let b:NERDSexyComMarker = '' - if has_key(s:delimiterMap, a:filetype) - let b:NERDCommenterDelims = s:delimiterMap[a:filetype] + if has_key(s:delimiterMap, ft) + let b:NERDCommenterDelims = s:delimiterMap[ft] for i in ['left', 'leftAlt', 'right', 'rightAlt'] if !has_key(b:NERDCommenterDelims, i) let b:NERDCommenterDelims[i] = '' From 47d983374037b80f3e7627830c43d613fd69ee8c Mon Sep 17 00:00:00 2001 From: Martin Grenfell Date: Sat, 5 Feb 2011 22:56:27 +1300 Subject: [PATCH 08/12] remove a stray macro that somehow got in the script ... --- plugin/NERD_commenter.vim | 1 - 1 file changed, 1 deletion(-) diff --git a/plugin/NERD_commenter.vim b/plugin/NERD_commenter.vim index 4ad308c..93854cd 100644 --- a/plugin/NERD_commenter.vim +++ b/plugin/NERD_commenter.vim @@ -64,7 +64,6 @@ call s:InitVariable("g:NERDSpaceDelims", 0) call s:InitVariable("g:NERDDelimiterRequests", 1) let s:NERDFileNameEscape="[]#*$%'\" ?`!&();<>\\" -"vf ;;dA:hcs"'A {j^f(lyi(k$p0f{a A }0f{a 'left':jdd^ let s:delimiterMap = { \ 'aap': { 'left': '#' }, From 9f955640eefcf22825a4fafa9d1ec2b4fb9d04f9 Mon Sep 17 00:00:00 2001 From: Martin Grenfell Date: Sun, 6 Feb 2011 08:48:27 +1300 Subject: [PATCH 09/12] remove an unused option --- plugin/NERD_commenter.vim | 1 - 1 file changed, 1 deletion(-) diff --git a/plugin/NERD_commenter.vim b/plugin/NERD_commenter.vim index 93854cd..134101f 100644 --- a/plugin/NERD_commenter.vim +++ b/plugin/NERD_commenter.vim @@ -61,7 +61,6 @@ call s:InitVariable("g:NERDRemoveAltComs", 1) call s:InitVariable("g:NERDRemoveExtraSpaces", 1) call s:InitVariable("g:NERDRPlace", "<]") call s:InitVariable("g:NERDSpaceDelims", 0) -call s:InitVariable("g:NERDDelimiterRequests", 1) let s:NERDFileNameEscape="[]#*$%'\" ?`!&();<>\\" From 90cf828ac0e6985480344dd9faebe949aed0b627 Mon Sep 17 00:00:00 2001 From: Martin Grenfell Date: Sun, 6 Feb 2011 09:07:14 +1300 Subject: [PATCH 10/12] add NERDCustomDelimiters option this allows users to override or specify delimiters for their own filetypes outside of the script --- plugin/NERD_commenter.vim | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/plugin/NERD_commenter.vim b/plugin/NERD_commenter.vim index 134101f..37108d1 100644 --- a/plugin/NERD_commenter.vim +++ b/plugin/NERD_commenter.vim @@ -47,7 +47,7 @@ endfunction let s:spaceStr = ' ' let s:lenSpaceStr = strlen(s:spaceStr) -" Section: variable init calls {{{2 +" Section: variable initialization {{{2 call s:InitVariable("g:NERDAllowAnyVisualDelims", 1) call s:InitVariable("g:NERDBlockComIgnoreEmpty", 0) call s:InitVariable("g:NERDCommentWholeLinesInVMode", 0) @@ -62,6 +62,10 @@ call s:InitVariable("g:NERDRemoveExtraSpaces", 1) call s:InitVariable("g:NERDRPlace", "<]") call s:InitVariable("g:NERDSpaceDelims", 0) +if !exists("g:NERDCustomDelimiters") + let g:NERDCustomDelimiters = {} +endif + let s:NERDFileNameEscape="[]#*$%'\" ?`!&();<>\\" let s:delimiterMap = { @@ -374,6 +378,11 @@ let s:delimiterMap = { \ 'z8a': { 'left': ';' } \ } +"merge in the custom delimiters +for ft in keys(g:NERDCustomDelimiters) + let s:delimiterMap[ft] = g:NERDCustomDelimiters[ft] +endfor + " Section: Comment mapping functions, autocommands and commands {{{1 " ============================================================================ " Section: Comment enabler autocommands {{{2 From f8be02f10acd91d4e50e39132e90ed8c4778710c Mon Sep 17 00:00:00 2001 From: Martin Grenfell Date: Sun, 6 Feb 2011 09:22:37 +1300 Subject: [PATCH 11/12] doc the new NERDCustomDelimiters option --- doc/NERD_commenter.txt | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/doc/NERD_commenter.txt b/doc/NERD_commenter.txt index 5309f61..6765b3a 100644 --- a/doc/NERD_commenter.txt +++ b/doc/NERD_commenter.txt @@ -404,6 +404,8 @@ then the script would do a sexy comment on the last visual selection. doing visual-block comments. |'NERDCommentWholeLinesInVMode'| Changes behaviour of visual comments. |'NERDCreateDefaultMappings'| Turn the default mappings on/off. +|'NERDCustomDelimiters'| Add or override delimiters for any + filetypes. |'NERDDefaultNesting'| Tells the script to use nested comments by default. |'NERDMenuMode'| Specifies how the NERD commenter menu @@ -550,7 +552,7 @@ Note that this option does not affect the behaviour of commenting in |visual-block| mode. ------------------------------------------------------------------------------ - *'NERDCreateDefaultMappings'* + *'NERDCreateDefaultMappings'* Values: 0 or 1. Default: 1. @@ -558,6 +560,25 @@ If set to 0, none of the default mappings will be created. See also |NERDComMappings|. +------------------------------------------------------------------------------ + *'NERDCustomDelimiters'* +Values: A map (format specified below). +Default: {} + +Use this option if you have new filetypes you want the script to handle, or if +you want to override the default delimiters of a filetype. + +Example: > + let g:NERDCustomDelimiters = { + \ 'ruby': { 'left': '#', 'leftAlt': 'FOO', 'rightAlt': 'BAR' }, + \ 'grondle': { 'left': '{{', 'right': '}}' } + \ } +< + +Here we override the delimiter settings for ruby and add FOO/BAR as alternative +delimiters. We also add {{ and }} as delimiters for a new filetype called +'grondle'. + ------------------------------------------------------------------------------ *'NERDRemoveAltComs'* Values: 0 or 1. From 197ce731be849c484a9c2555fae3fb094c9b88fc Mon Sep 17 00:00:00 2001 From: Martin Grenfell Date: Sun, 6 Feb 2011 09:35:14 +1300 Subject: [PATCH 12/12] improve handling for compound filetypes now we check each part of the compound filetype until we find a part we know how to handle e.g. if the filetype is foo.bar.php.java then delimiters will get set for php --- plugin/NERD_commenter.vim | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/plugin/NERD_commenter.vim b/plugin/NERD_commenter.vim index 37108d1..e2d7ce0 100644 --- a/plugin/NERD_commenter.vim +++ b/plugin/NERD_commenter.vim @@ -413,9 +413,15 @@ function s:SetUpForNewFiletype(filetype, forceReset) let ft = a:filetype "for compound filetypes, if we dont know how to handle the full filetype - "then just use the first part, e.g. 'foo.bar' is treated as 'foo' + "then break it down and use the first part that we know how to handle if ft =~ '\.' && !has_key(s:delimiterMap, ft) - let ft = split(a:filetype, '\.')[0] + let filetypes = split(a:filetype, '\.') + for i in filetypes + if has_key(s:delimiterMap, i) + let ft = i + break + endif + endfor endif let b:NERDSexyComMarker = ''