diff --git a/EXAMPLES.md b/EXAMPLES.md index ed233ce..28f6c01 100644 --- a/EXAMPLES.md +++ b/EXAMPLES.md @@ -242,7 +242,7 @@ So, let's define a custom mapping for `#`. if !exists('g:easy_align_delimiters') let g:easy_align_delimiters = {} endif -let g:easy_align_delimiters['#'] = { 'pattern': '#\+', 'ignores': ['String'] } } +let g:easy_align_delimiters['#'] = { 'pattern': '#', 'ignores': ['String'] } } ``` Notice that the rule overrides `ignores` attribute in order *not to ignore* @@ -252,7 +252,37 @@ Then on `#`, we get ```ruby apple = 1 # comment not aligned -apricot = 'A#B' +apricot = 'DAD' + 'F#AD' banana = 'string' # comment 2 ``` +If you don't want to define a rule, you can do the same with the following +command: + +```vim +" Using regular expression /#/ +" - "is" is fuzzy-matched to "*i*gnore*s*" +:EasyAlign/#/{'is':['String']} +``` + +In this case, the second line is ignored as it doesn't contain `#`. (The one +highlighted as String is ignored.) If you don't want the second line to be +ignored, set `g:easy_align_ignore_unmatched` to 0, or use the following +commands: + +```vim +" Using predefined rule with delimiter key # +:EasyAlign#{'iu':0}` + +" Using regular expression /#/ +:EasyAlign/#/{'is':['String'],'iu':0}` +``` + +Then we get, + +```ruby +apple = 1 # comment not aligned +apricot = 'DAD' + 'F#AD' +banana = 'string' # comment 2 +``` + diff --git a/autoload/easy_align.vim b/autoload/easy_align.vim index 8b88796..58944ca 100644 --- a/autoload/easy_align.vim +++ b/autoload/easy_align.vim @@ -116,21 +116,25 @@ endfunction function! s:normalize_options(opts) let ret = {} - for [k, v] in items(a:opts) + for k in keys(a:opts) + let v = a:opts[k] let k = s:fuzzy_lu(k) " Backward-compatibility if k == 'margin_left' | let k = 'left_margin' | endif if k == 'margin_right' | let k = 'right_margin' | endif let ret[k] = v + unlet v endfor return s:validate_options(ret) endfunction function! s:validate_options(opts) - for [k, v] in items(a:opts) + for k in keys(a:opts) + let v = a:opts[k] if index(s:known_options[k], type(v)) == -1 call s:exit("Invalid type for option: ". k) endif + unlet v endfor return a:opts endfunction @@ -175,7 +179,7 @@ function! s:do_align(just, all_tokens, fl, ll, fc, lc, pattern, nth, ml, mr, sti endif " Skip comment line - if concat && len(tokens) == 1 + if concat && len(tokens) == 1 && a:ignore_unmatched let tokens = [] endif diff --git a/test/regexp.expected b/test/regexp.expected index 46763af..de25c1d 100644 --- a/test/regexp.expected +++ b/test/regexp.expected @@ -85,3 +85,9 @@ data;;exchange: ;format apple;: banana::cake data;;exchange: ;format +```ruby +apple = 1 # comment not aligned +apricot = 'DAD' + 'F#AD' +banana = 'Gros Michel' # comment 2 +``` + diff --git a/test/regexp.md b/test/regexp.md index 483fec7..3a31b5a 100644 --- a/test/regexp.md +++ b/test/regexp.md @@ -4,3 +4,9 @@ apple;:banana::cake data;;exchange:;format +```ruby +apple = 1 # comment not aligned +apricot = 'DAD' + 'F#AD' +banana = 'Gros Michel' # comment 2 +``` + diff --git a/test/regexp.script b/test/regexp.script index 9e9d273..760c3ea 100644 --- a/test/regexp.script +++ b/test/regexp.script @@ -1 +1 @@ -4Gvipjyvip:EasyAlign: Pvip:EasyAlign*: Pvip:EasyAlign-: Pvip:EasyAlign * : Pvip:EasyAlign -2 : Pvip:EasyAlign -2: Pvip:easyA€kb€kb€kb€kb€kbEasAli€kb€kb€kbyAlign *: Pvip:EasyAlign; Pvip:EasyAlign /;/ Pvip:EasyAlign/;/ Pvip:EasyAlign*/;/ Pvip:e€kbEasyAlign/[:;]\+/ Pvip:EasyAlign*/[:;]\+/ Pvip:EasyAlign* /[:;]\+/ Pvip:EasyAlign */[:;]\+/ Pvip:EasyAlign * [:€kb€kb/[:;]\+/ Pvip:EasyAlign*[:;]\+€kb€kb€kb€kb€kb€kb€kb=/[€kb€kb€kb-/[:;]\+/ Pvip:EasyAlign-2/[:;\€kb\€kb]\+/ Pvip:EasyAlign/[:;]\+/{ 'l': '<<<', 'r': '>>>'} Pvip:EasyAlign/[:;]\+/{'l':''m€kb, 's': 1} Pvip:EasyAlign * /€kb /[:;]€kb\€kb]\+/ {'stick_to': 1, 'le': '???', 'marr': '~~~'} Pvip:EasyAlign /../ Pvip:EasyAlign*/../ Pvip:EasyAlign ** €kb/[:;]/€kb€kb\+]/ Pvip:EasyAlign/[:;\€kb\€kb]\+/'€kb{'rm':'____'} Pvip:EasyAlign**[€kb/[:;]\+/ Pvip:EasyAlign!**/[:;]\+/ Pfbjfm:EasyAlign/[:;]\+/ +4Gvipjyvip:EasyAlign: Pvip:EasyAlign*: Pvip:EasyAlign-: Pvip:EasyAlign * : Pvip:EasyAlign -2 : Pvip:EasyAlign -2: Pvip:easyA€kb€kb€kb€kb€kbEasAli€kb€kb€kbyAlign *: Pvip:EasyAlign; Pvip:EasyAlign /;/ Pvip:EasyAlign/;/ Pvip:EasyAlign*/;/ Pvip:e€kbEasyAlign/[:;]\+/ Pvip:EasyAlign*/[:;]\+/ Pvip:EasyAlign* /[:;]\+/ Pvip:EasyAlign */[:;]\+/ Pvip:EasyAlign * [:€kb€kb/[:;]\+/ Pvip:EasyAlign*[:;]\+€kb€kb€kb€kb€kb€kb€kb=/[€kb€kb€kb-/[:;]\+/ Pvip:EasyAlign-2/[:;\€kb\€kb]\+/ Pvip:EasyAlign/[:;]\+/{ 'l': '<<<', 'r': '>>>'} Pvip:EasyAlign/[:;]\+/{'l':''m€kb, 's': 1} Pvip:EasyAlign * /€kb /[:;]€kb\€kb]\+/ {'stick_to': 1, 'le': '???', 'marr': '~~~'} Pvip:EasyAlign /../ Pvip:EasyAlign*/../ Pvip:EasyAlign ** €kb/[:;]/€kb€kb\+]/ Pvip:EasyAlign/[:;\€kb\€kb]\+/'€kb{'rm':'____'} Pvip:EasyAlign**[€kb/[:;]\+/ Pvip:EasyAlign!**/[:;]\+/ Pfbjfm:EasyAlign/[:;]\+/ 90Gvip:EasyAlign/#/{'is':['String'],'iu':0}