mirror of
https://github.com/junegunn/vim-easy-align.git
synced 2025-11-10 10:53:49 -05:00
Allow shorthand option notation when using delimiter key
e.g. :EasyAlign=l2r2dlmlr**
This commit is contained in:
@@ -701,14 +701,16 @@ function! s:test_regexp(regexp)
|
|||||||
return a:regexp
|
return a:regexp
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:parse_shortcut_opts(expr)
|
let s:shorthand_regex =
|
||||||
|
\ '\s*\('
|
||||||
|
\ .'\(lm\?[0-9]\+\)\|\(rm\?[0-9]\+\)\|\(iu[01]\)\|\(s\%(tl\)\?[01]\)\|'
|
||||||
|
\ .'\(da\?[clr]\)\|\(ms\?[lrc*]\+\)\|\(i\%(dt\)\?[kdsn]\)\|\(ig\[.*\]\)'
|
||||||
|
\ .'\)\+\s*$'
|
||||||
|
|
||||||
|
function! s:parse_shorthand_opts(expr)
|
||||||
let opts = {}
|
let opts = {}
|
||||||
let expr = substitute(a:expr, '\s', '', 'g')
|
let expr = substitute(a:expr, '\s', '', 'g')
|
||||||
let regex =
|
let regex = '^'. s:shorthand_regex
|
||||||
\ '^\('
|
|
||||||
\ .'\(l[0-9]\+\)\|\(r[0-9]\+\)\|\(iu[01]\)\|\(s[01]\)\|'
|
|
||||||
\ .'\(d[clr]\)\|\(m[lrc*]\+\)\|\(i[kdsn]\)\|\(ig\[.*\]\)'
|
|
||||||
\ .'\)\+$'
|
|
||||||
|
|
||||||
if empty(expr)
|
if empty(expr)
|
||||||
return opts
|
return opts
|
||||||
@@ -718,29 +720,30 @@ function! s:parse_shortcut_opts(expr)
|
|||||||
let match = matchlist(expr, regex)
|
let match = matchlist(expr, regex)
|
||||||
if empty(match) | break | endif
|
if empty(match) | break | endif
|
||||||
for m in filter(match[ 2 : -1 ], '!empty(v:val)')
|
for m in filter(match[ 2 : -1 ], '!empty(v:val)')
|
||||||
let k = tolower(m[0])
|
for key in ['lm', 'rm', 'l', 'r', 'stl', 's', 'iu', 'da', 'd', 'ms', 'm', 'ig', 'i']
|
||||||
let kk = tolower(m[0 : 1])
|
if stridx(tolower(m), key) == 0
|
||||||
let rest = m[1 : -1]
|
let rest = strpart(m, len(key))
|
||||||
if index(['l', 'r', 's'], k) >= 0
|
if key == 'i' | let key = 'idt' | endif
|
||||||
let opts[k] = str2nr(rest)
|
|
||||||
elseif kk == 'iu'
|
if key == 'idt' || index(['d', 'm'], key[0]) >= 0
|
||||||
let opts['iu'] = str2nr(m[2 : -1])
|
let opts[key] = rest
|
||||||
elseif kk == 'ig'
|
elseif key == 'ig'
|
||||||
try
|
try
|
||||||
let arr = eval(m[2 : -1])
|
let arr = eval(rest)
|
||||||
if type(arr) == 3
|
if type(arr) == 3
|
||||||
let opts['ig'] = arr
|
let opts[key] = arr
|
||||||
else
|
else
|
||||||
throw 'Not an array'
|
throw 'Not an array'
|
||||||
endif
|
endif
|
||||||
catch
|
catch
|
||||||
call s:exit("Invalid ignore_groups: ". a:expr)
|
call s:exit("Invalid ignore_groups: ". a:expr)
|
||||||
endtry
|
endtry
|
||||||
elseif k == 'i'
|
|
||||||
let opts['idt'] = rest
|
|
||||||
else
|
else
|
||||||
let opts[k] = rest
|
let opts[key] = str2nr(rest)
|
||||||
endif
|
endif
|
||||||
|
break
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
endfor
|
endfor
|
||||||
endif
|
endif
|
||||||
return s:normalize_options(opts)
|
return s:normalize_options(opts)
|
||||||
@@ -785,14 +788,18 @@ function! s:parse_args(args)
|
|||||||
let opts = s:normalize_options(opts)
|
let opts = s:normalize_options(opts)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
" Shorthand option notation
|
||||||
|
let sopts = matchstr(args, s:shorthand_regex)
|
||||||
|
if !empty(sopts)
|
||||||
|
let args = strpart(args, 0, len(args) - len(sopts))
|
||||||
|
let opts = extend(s:parse_shorthand_opts(sopts), opts)
|
||||||
|
endif
|
||||||
|
|
||||||
" Has /Regexp/?
|
" Has /Regexp/?
|
||||||
let matches = matchlist(args, '^\(.\{-}\)\s*/\(.*\)/\(.\{-}\)$')
|
let matches = matchlist(args, '^\(.\{-}\)\s*/\(.*\)/\s*$')
|
||||||
|
|
||||||
" Found regexp
|
" Found regexp
|
||||||
if !empty(matches)
|
if !empty(matches)
|
||||||
if !empty(matches[3])
|
|
||||||
let opts = extend(s:parse_shortcut_opts(matches[3]), opts)
|
|
||||||
endif
|
|
||||||
return [matches[1], s:test_regexp(matches[2]), opts, 1]
|
return [matches[1], s:test_regexp(matches[2]), opts, 1]
|
||||||
else
|
else
|
||||||
let tokens = matchlist(args, '^\([1-9][0-9]*\|-[0-9]*\|\*\*\?\)\?\s*\(.\{-}\)\?$')
|
let tokens = matchlist(args, '^\([1-9][0-9]*\|-[0-9]*\|\*\*\?\)\?\s*\(.\{-}\)\?$')
|
||||||
|
|||||||
@@ -106,3 +106,23 @@ data ;;exchange:;format
|
|||||||
apple ;: banana :: cake
|
apple ;: banana :: cake
|
||||||
data ;; exchange :; format
|
data ;; exchange :; format
|
||||||
|
|
||||||
|
a+= 1
|
||||||
|
bb==# 2
|
||||||
|
ccc= 3
|
||||||
|
dddd=> 4
|
||||||
|
|
||||||
|
apple;: banana:: cake
|
||||||
|
data;; exchange:; format
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
apple = 1 # comment not aligned
|
||||||
|
apricot = 'DAD' + 'F#AD'
|
||||||
|
banana = 'Gros Michel' # comment 2
|
||||||
|
```
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
apple = 1 # comment not aligned
|
||||||
|
apricot = 'DAD' + 'F#AD'
|
||||||
|
banana = 'Gros Michel' # comment 2
|
||||||
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
4Gvipjyvip:EasyAlign:
|
4Gvipjyvip:EasyAlign:
|
||||||
|
|||||||
Reference in New Issue
Block a user