Allow negation operator in ignore_groups option

e.g. ig['!String']
This commit is contained in:
Junegunn Choi
2014-06-24 00:07:48 +09:00
parent a98c1ccc99
commit fc9555cd65
3 changed files with 13 additions and 8 deletions

View File

@@ -219,7 +219,7 @@ Aligning in-line comments
-------------------------
*Note: Since the current version provides '#'-rule as one of the default rules,
you can ignore this section*
you can ignore this section.*
```ruby
apple = 1 # comment not aligned

View File

@@ -90,7 +90,7 @@ shortcuts for the most common use cases with the concept of "_alignment rule_".
An *alignment rule* is a predefined set of options for common alignment tasks,
which is identified by a single character, *DELIMITER KEY*, such as `<Space>`,
`=`, `:`, `.`, `|`, `&`, and `,`.
`=`, `:`, `.`, `|`, `&`, `#`, and `,`.
Think of it as a shortcut. Instead of writing regular expression and setting
several options, you can just type in a single character.
@@ -149,7 +149,7 @@ With these mappings, you can align text with only a few keystrokes.
- `-` Around the last occurrences of delimiters (`-1`)
- `-2` Around the second to last occurrences of delimiters
- ...
1. Delimiter key (a single keystroke; `<Space>`, `=`, `:`, `.`, `|`, `&`, `,`)
1. Delimiter key (a single keystroke; `<Space>`, `=`, `:`, `.`, `|`, `&`, `#`, `,`)
#### Predefined alignment rules
@@ -452,7 +452,9 @@ For example if you set `ignore_groups` option to be an empty list, you get
}
```
Satisfied? :satisfied:
If a pattern in `ignore_groups` is prepended by a `!`, it will have the opposite
meaning. For instance, if `ignore_groups` is given as `['!Comment']`, delimiters
that are *not* highlighted as Comment will be ignored during the alignment.
### Ignoring unmatched lines
@@ -674,7 +676,7 @@ let g:easy_align_delimiters = {
\ '/': {
\ 'pattern': '//\+\|/\*\|\*/',
\ 'delimiter_align': 'l',
\ 'ignore_groups': ['^\(.\(Comment\)\@!\)*$'] },
\ 'ignore_groups': ['!Comment'] },
\ ']': {
\ 'pattern': '[[\]]',
\ 'left_margin': 0,

View File

@@ -37,8 +37,7 @@ let s:easy_align_delimiters_default = {
\ ',': { 'pattern': ',', 'left_margin': 0, 'right_margin': 1, 'stick_to_left': 1 },
\ '|': { 'pattern': '|', 'left_margin': 1, 'right_margin': 1, 'stick_to_left': 0 },
\ '.': { 'pattern': '\.', 'left_margin': 0, 'right_margin': 0, 'stick_to_left': 0 },
\ '#': { 'pattern': '#\+',
\ 'delimiter_align': 'l', 'ignore_groups': ['^\(.\(Comment\)\@!\)*$'] },
\ '#': { 'pattern': '#\+', 'delimiter_align': 'l', 'ignore_groups': ['!Comment'] },
\ '&': { 'pattern': '\\\@<!&\|\\\\',
\ 'left_margin': 1, 'right_margin': 1, 'stick_to_left': 0 },
\ '{': { 'pattern': '(\@<!{',
@@ -91,7 +90,11 @@ function! s:highlighted_as(line, col, groups)
if empty(a:groups) | return 0 | endif
let hl = synIDattr(synID(a:line, a:col, 0), 'name')
for grp in a:groups
if hl =~# grp
if grp[0] == '!'
if hl !~# grp[1:-1]
return 1
endif
elseif hl =~# grp
return 1
endif
endfor