mirror of
https://github.com/junegunn/vim-easy-align.git
synced 2025-11-10 10:53:49 -05:00
Implement mode_sequence expansion (#7)
This commit is contained in:
@@ -518,6 +518,14 @@ in interactive mode with the special key `CTRL-O`)
|
||||
" (**) Alternating alignments (default: lr or rl)
|
||||
" Right, left, center, right, left, center, ...
|
||||
:EasyAlign **={ 'm': 'rlc' }
|
||||
|
||||
" Right, left, center, center, center, ... repeating alignment
|
||||
" over the 3rd to the last occurrences of delimiters
|
||||
:EasyAlign 3={ 'm': 'rlc*' }
|
||||
|
||||
" Right, left, center, right, left, center, ... alternating alignment
|
||||
" over the 3rd to the last occurrences of delimiters
|
||||
:EasyAlign 3={ 'm': 'rlc**' }
|
||||
```
|
||||
|
||||
### Extending alignment rules
|
||||
|
||||
@@ -544,7 +544,7 @@ function! s:interactive(modes)
|
||||
let opts['ig'] = s:shift(vals['ignore_groups'], 1)
|
||||
elseif ch == "\<C-O>"
|
||||
let modes = tolower(s:input("Mode sequence: ", get(opts, 'm', mode)))
|
||||
if match(modes, '^[lrc]\+$') != -1
|
||||
if match(modes, '^[lrc]\+\*\{0,2}$') != -1
|
||||
let opts['m'] = modes
|
||||
let mode = modes[0]
|
||||
while mode != s:shift(a:modes, 1)
|
||||
@@ -700,10 +700,19 @@ function! easy_align#align(bang, expr) range
|
||||
|
||||
let aseq = get(dict, 'mode_sequence',
|
||||
\ recur == 2 ? (mode ==? 'r' ? ['r', 'l'] : ['l', 'r']) : [mode])
|
||||
let mode_expansion = matchstr(aseq, '\*\+$')
|
||||
if mode_expansion == '*'
|
||||
let aseq = aseq[0 : -2]
|
||||
let recur = 1
|
||||
elseif mode_expansion == '**'
|
||||
let aseq = aseq[0 : -3]
|
||||
let recur = 2
|
||||
endif
|
||||
let aseq_list = type(aseq) == 1 ? split(tolower(aseq), '\s*') : map(copy(aseq), 'tolower(v:val)')
|
||||
|
||||
try
|
||||
call s:do_align(
|
||||
\ type(aseq) == 1 ? split(tolower(aseq), '\s*') : map(copy(aseq), 'tolower(v:val)'),
|
||||
\ aseq_list,
|
||||
\ {}, {}, a:firstline, a:lastline,
|
||||
\ bvisual ? min([col("'<"), col("'>")]) : 1,
|
||||
\ bvisual ? max([col("'<"), col("'>")]) : 0,
|
||||
|
||||
@@ -1048,3 +1048,19 @@ aaaa, ,
|
||||
aaa, b,
|
||||
aa, bb,
|
||||
a, bbb,
|
||||
|
||||
1 22222 33 444 555 6666 7 888
|
||||
11 222 3333 4 55 6666 77 888
|
||||
111 22 333 444 55555 6666 7 88888
|
||||
1111 2 33 444 555 66 777 8
|
||||
|
||||
1 22222 33 444 555 6666 7 888
|
||||
11 222 3333 4 55 6666 77 888
|
||||
111 22 333 444 55555 6666 7 88888
|
||||
1111 2 33 444 555 66 777 8
|
||||
|
||||
1 22222 33 444 555 6666 7 888
|
||||
11 222 3333 4 55 6666 77 888
|
||||
111 22 333 444 55555 6666 7 88888
|
||||
1111 2 33 444 555 66 777 8
|
||||
|
||||
|
||||
@@ -265,3 +265,9 @@ aaaa,,
|
||||
aaa,b,
|
||||
aa,bb,
|
||||
a,bbb,
|
||||
|
||||
1 22222 33 444 555 6666 7 888
|
||||
11 222 3333 4 55 6666 77 888
|
||||
111 22 333 444 55555 6666 7 88888
|
||||
1111 2 33 444 555 66 777 8
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
4Gvipjyvip
|
||||
4Gvipjyvip
|
||||
|
||||
Reference in New Issue
Block a user