From 98bd9fe6f0dfcaef219c0c30d8e5901ac974d19c Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Fri, 4 Oct 2013 02:29:24 +0900 Subject: [PATCH] Shorthand notation for ignore_groups/ignore_unmatched e.g. ig['String']iu0 --- README.md | 11 ++++------- autoload/easy_align.vim | 24 ++++++++++++++++++------ doc/easy_align.txt | 11 ++++------- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index b516288..0beb92d 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/autoload/easy_align.vim b/autoload/easy_align.vim index 76ab29e..cc45475 100644 --- a/autoload/easy_align.vim +++ b/autoload/easy_align.vim @@ -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 diff --git a/doc/easy_align.txt b/doc/easy_align.txt index cb9476c..7770350 100644 --- a/doc/easy_align.txt +++ b/doc/easy_align.txt @@ -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 -------------------------------------------------------------------------