Shorthand notation for ignore_groups/ignore_unmatched

e.g. ig['String']iu0
This commit is contained in:
Junegunn Choi
2013-10-04 02:29:24 +09:00
parent f944f5bf29
commit 98bd9fe6f0
3 changed files with 26 additions and 20 deletions

View File

@@ -242,18 +242,15 @@ Supported shorthand notations are listed below.
| Expression | Option |
| ---------- | ---------------- |
| `l[0-9]` | left_margin |
| `r[0-9]` | right_margin |
| `l[0-9]+` | left_margin |
| `r[0-9]+` | right_margin |
| `s[01]` | stick_to_left |
| `u[01]` | ignore_unmatched |
| `iu[01]` | ignore_unmatched |
| `ig\[.*\]` | ignore_groups |
| `d[lrc]` | delimiter_align |
| `m[lrc*]*` | mode_sequence |
| `i[ksdn]` | indentation |
Notice that some option values cannot be expressed in shorthand notation.
- `:EasyAlign*/[:;]\+/s1l0 {'ig': []}`
### Partial alignment in blockwise-visual mode
In blockwise-visual mode (`CTRL-V`), EasyAlign command aligns only the selected

View File

@@ -691,11 +691,11 @@ endfunction
function! s:parse_shortcut_opts(expr)
let opts = {}
let expr = tolower(substitute(a:expr, '\s', '', 'g'))
let expr = substitute(a:expr, '\s', '', 'g')
let regex =
\ '^\('
\ .'\(l[0-9]\+\)\|\(r[0-9]\+\)\|\(u[01]\)\|\(s[01]\)\|'
\ .'\(d[clr]\)\|\(m[lrc*]\+\)\|\(i[kdsn]\)'
\ .'\(l[0-9]\+\)\|\(r[0-9]\+\)\|\(iu[01]\)\|\(s[01]\)\|'
\ .'\(d[clr]\)\|\(m[lrc*]\+\)\|\(i[kdsn]\)\|\(ig\[.*\]\)'
\ .'\)\+$'
if empty(expr)
@@ -706,12 +706,24 @@ function! s:parse_shortcut_opts(expr)
let match = matchlist(expr, regex)
if empty(match) | break | endif
for m in filter(match[ 2 : -1 ], '!empty(v:val)')
let k = m[0]
let k = tolower(m[0])
let kk = tolower(m[0 : 1])
let rest = m[1 : -1]
if index(['l', 'r', 's'], k) >= 0
let opts[k] = str2nr(rest)
elseif k == 'u'
let opts['iu'] = str2nr(rest)
elseif kk == 'iu'
let opts['iu'] = str2nr(m[2 : -1])
elseif kk == 'ig'
try
let arr = eval(m[2 : -1])
if type(arr) == 3
let opts['ig'] = arr
else
throw 'Not an array'
endif
catch
call s:exit("Invalid ignore_groups: ". a:expr)
endtry
elseif k == 'i'
let opts['idt'] = rest
else

View File

@@ -167,18 +167,15 @@ Supported shorthand notations are listed below.
| Expression | Option |
| ---------- | -------------- |
| l[0-9] | left_margin |
| r[0-9] | right_margin |
| l[0-9]+ | left_margin |
| r[0-9]+ | right_margin |
| s[01] | stick_to_left |
| u[01] | ignore_unmatched |
| iu[01] | ignore_unmatched |
| ig\[.*\] | ignore_groups |
| d[lrc] | delimiter_align |
| m[lrc*]+ | mode_sequence |
| i[ksdn] | indentation |
Notice that some option values cannot be expressed in shorthand notation.
:EasyAlign*/[:;]\+/s1l0 {'ig': []}
Partial alignment in blockwise-visual mode
-------------------------------------------------------------------------