mirror of
https://github.com/junegunn/vim-easy-align.git
synced 2025-11-09 18:33:49 -05:00
Heuristically determine if the user was in visual mode
This commit is contained in:
@@ -480,8 +480,8 @@ function! s:do_align(modes, all_tokens, all_delims, fl, ll, fc, lc, pattern, nth
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:input(str, default, sl)
|
function! s:input(str, default, vis)
|
||||||
if !a:sl
|
if a:vis
|
||||||
normal! gv
|
normal! gv
|
||||||
redraw
|
redraw
|
||||||
execute "normal! \<esc>"
|
execute "normal! \<esc>"
|
||||||
@@ -499,7 +499,7 @@ function! s:input(str, default, sl)
|
|||||||
endtry
|
endtry
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:interactive(modes, sl)
|
function! s:interactive(modes, vis)
|
||||||
let mode = s:shift(a:modes, 1)
|
let mode = s:shift(a:modes, 1)
|
||||||
let n = ''
|
let n = ''
|
||||||
let ch = ''
|
let ch = ''
|
||||||
@@ -543,9 +543,9 @@ function! s:interactive(modes, sl)
|
|||||||
elseif ch == "\<C-I>"
|
elseif ch == "\<C-I>"
|
||||||
let opts['idt'] = s:shift(vals['indentation'], 1)
|
let opts['idt'] = s:shift(vals['indentation'], 1)
|
||||||
elseif ch == "\<C-L>"
|
elseif ch == "\<C-L>"
|
||||||
let opts['lm'] = s:input("Left margin: ", get(opts, 'lm', ''), a:sl)
|
let opts['lm'] = s:input("Left margin: ", get(opts, 'lm', ''), a:vis)
|
||||||
elseif ch == "\<C-R>"
|
elseif ch == "\<C-R>"
|
||||||
let opts['rm'] = s:input("Right margin: ", get(opts, 'rm', ''), a:sl)
|
let opts['rm'] = s:input("Right margin: ", get(opts, 'rm', ''), a:vis)
|
||||||
elseif ch == "\<C-U>"
|
elseif ch == "\<C-U>"
|
||||||
let opts['iu'] = s:shift(vals['ignore_unmatched'], 1)
|
let opts['iu'] = s:shift(vals['ignore_unmatched'], 1)
|
||||||
elseif ch == "\<C-G>"
|
elseif ch == "\<C-G>"
|
||||||
@@ -560,7 +560,7 @@ function! s:interactive(modes, sl)
|
|||||||
silent! call remove(opts, 'stl')
|
silent! call remove(opts, 'stl')
|
||||||
silent! call remove(opts, 'lm')
|
silent! call remove(opts, 'lm')
|
||||||
elseif ch == "\<C-O>"
|
elseif ch == "\<C-O>"
|
||||||
let modes = tolower(s:input("Mode sequence: ", get(opts, 'm', mode), a:sl))
|
let modes = tolower(s:input("Mode sequence: ", get(opts, 'm', mode), a:vis))
|
||||||
if match(modes, '^[lrc]\+\*\{0,2}$') != -1
|
if match(modes, '^[lrc]\+\*\{0,2}$') != -1
|
||||||
let opts['m'] = modes
|
let opts['m'] = modes
|
||||||
let mode = modes[0]
|
let mode = modes[0]
|
||||||
@@ -570,7 +570,7 @@ function! s:interactive(modes, sl)
|
|||||||
silent! call remove(opts, 'm')
|
silent! call remove(opts, 'm')
|
||||||
endif
|
endif
|
||||||
elseif ch == "\<C-_>" || ch == "\<C-X>"
|
elseif ch == "\<C-_>" || ch == "\<C-X>"
|
||||||
let ch = s:input('Regular expression: ', '', a:sl)
|
let ch = s:input('Regular expression: ', '', a:vis)
|
||||||
if !empty(ch)
|
if !empty(ch)
|
||||||
let regx = 1
|
let regx = 1
|
||||||
break
|
break
|
||||||
@@ -583,10 +583,10 @@ function! s:interactive(modes, sl)
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:parse_args(args)
|
function! s:parse_args(args)
|
||||||
let n = ''
|
let n = ''
|
||||||
let ch = ''
|
let ch = ''
|
||||||
let args = a:args
|
let args = a:args
|
||||||
let cand = ''
|
let cand = ''
|
||||||
let opts = {}
|
let opts = {}
|
||||||
|
|
||||||
" Poor man's option parser
|
" Poor man's option parser
|
||||||
@@ -650,15 +650,16 @@ function! easy_align#align(bang, expr) range
|
|||||||
let ioptsr = {}
|
let ioptsr = {}
|
||||||
let iopts = {}
|
let iopts = {}
|
||||||
let regexp = 0
|
let regexp = 0
|
||||||
let sl = a:firstline == a:lastline " Possibley w/o selection
|
" Heuristically determine if the user was in visual mode
|
||||||
|
let vis = a:firstline == line("'<") && a:lastline == line("'>")
|
||||||
|
|
||||||
try
|
try
|
||||||
if empty(a:expr)
|
if empty(a:expr)
|
||||||
let [mode, n, ch, ioptsr, iopts, regexp] = s:interactive(copy(modes), sl)
|
let [mode, n, ch, ioptsr, iopts, regexp] = s:interactive(copy(modes), vis)
|
||||||
else
|
else
|
||||||
let [n, ch, opts, regexp] = s:parse_args(a:expr)
|
let [n, ch, opts, regexp] = s:parse_args(a:expr)
|
||||||
if empty(n) && empty(ch)
|
if empty(n) && empty(ch)
|
||||||
let [mode, n, ch, ioptsr, iopts, regexp] = s:interactive(copy(modes), sl)
|
let [mode, n, ch, ioptsr, iopts, regexp] = s:interactive(copy(modes), vis)
|
||||||
elseif empty(ch)
|
elseif empty(ch)
|
||||||
" Try swapping n and ch
|
" Try swapping n and ch
|
||||||
let [n, ch] = ['', n]
|
let [n, ch] = ['', n]
|
||||||
@@ -715,7 +716,7 @@ function! easy_align#align(bang, expr) range
|
|||||||
if type(ml) == 0 | let ml = repeat(' ', ml) | endif
|
if type(ml) == 0 | let ml = repeat(' ', ml) | endif
|
||||||
if type(mr) == 0 | let mr = repeat(' ', mr) | endif
|
if type(mr) == 0 | let mr = repeat(' ', mr) | endif
|
||||||
|
|
||||||
let bvisual = char2nr(visualmode()) == 22 " ^V
|
let bvisual = vis && char2nr(visualmode()) == 22 " ^V
|
||||||
|
|
||||||
if recur && bvisual
|
if recur && bvisual
|
||||||
echon "\rRecursive alignment is currently not supported in blockwise-visual mode"
|
echon "\rRecursive alignment is currently not supported in blockwise-visual mode"
|
||||||
|
|||||||
Reference in New Issue
Block a user