Flatten indent
This commit is contained in:
parent
9812233fac
commit
4eeae613bc
@ -3,19 +3,20 @@
|
||||
" Author: Kim Silkebækken <kim.silkebaekken+vim@gmail.com>
|
||||
" Source repository: https://github.com/Lokaltog/vim-easymotion
|
||||
|
||||
" Saving 'cpoptions' {{{
|
||||
" == Saving 'cpoptions' {{{
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
" }}}
|
||||
" Reset {{{
|
||||
" == Reset {{{
|
||||
function! EasyMotion#reset()
|
||||
" Reset Migemo Dictionary
|
||||
let s:migemo_dicts = {}
|
||||
return ""
|
||||
endfunction "}}}
|
||||
" Motion functions {{{
|
||||
" == Find Motion =========================
|
||||
function! EasyMotion#F(visualmode, direction) " {{{
|
||||
|
||||
" == Motion functions {{{
|
||||
" -- Find Motion -------------------------
|
||||
function! EasyMotion#F(visualmode, direction) " {{{
|
||||
let char = s:GetSearchChar(a:visualmode)
|
||||
|
||||
if empty(char)
|
||||
@ -25,8 +26,8 @@ endfunction "}}}
|
||||
let re = s:findMotion(char)
|
||||
|
||||
call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', mode(1))
|
||||
endfunction " }}}
|
||||
function! EasyMotion#S(visualmode, direction) " {{{
|
||||
endfunction " }}}
|
||||
function! EasyMotion#S(visualmode, direction) " {{{
|
||||
let char = s:GetSearchChar(a:visualmode)
|
||||
|
||||
if empty(char)
|
||||
@ -36,8 +37,8 @@ endfunction "}}}
|
||||
let re = s:findMotion(char)
|
||||
|
||||
call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', mode(1))
|
||||
endfunction " }}}
|
||||
function! EasyMotion#T(visualmode, direction) " {{{
|
||||
endfunction " }}}
|
||||
function! EasyMotion#T(visualmode, direction) " {{{
|
||||
let char = s:GetSearchChar(a:visualmode)
|
||||
|
||||
if empty(char)
|
||||
@ -55,35 +56,35 @@ endfunction "}}}
|
||||
endif
|
||||
|
||||
call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', mode(1))
|
||||
endfunction " }}}
|
||||
" == Word Motion =========================
|
||||
function! EasyMotion#WB(visualmode, direction) " {{{
|
||||
endfunction " }}}
|
||||
" -- Word Motion -------------------------
|
||||
function! EasyMotion#WB(visualmode, direction) " {{{
|
||||
call s:EasyMotion('\(\<.\|^$\)', a:direction, a:visualmode ? visualmode() : '', '')
|
||||
endfunction " }}}
|
||||
function! EasyMotion#WBW(visualmode, direction) " {{{
|
||||
endfunction " }}}
|
||||
function! EasyMotion#WBW(visualmode, direction) " {{{
|
||||
call s:EasyMotion('\(\(^\|\s\)\@<=\S\|^$\)', a:direction, a:visualmode ? visualmode() : '', '')
|
||||
endfunction " }}}
|
||||
function! EasyMotion#E(visualmode, direction) " {{{
|
||||
endfunction " }}}
|
||||
function! EasyMotion#E(visualmode, direction) " {{{
|
||||
call s:EasyMotion('\(.\>\|^$\)', a:direction, a:visualmode ? visualmode() : '', mode(1))
|
||||
endfunction " }}}
|
||||
function! EasyMotion#EW(visualmode, direction) " {{{
|
||||
endfunction " }}}
|
||||
function! EasyMotion#EW(visualmode, direction) " {{{
|
||||
call s:EasyMotion('\(\S\(\s\|$\)\|^$\)', a:direction, a:visualmode ? visualmode() : '', mode(1))
|
||||
endfunction " }}}
|
||||
" == JK Motion ===========================
|
||||
function! EasyMotion#JK(visualmode, direction) " {{{
|
||||
endfunction " }}}
|
||||
" -- JK Motion ---------------------------
|
||||
function! EasyMotion#JK(visualmode, direction) " {{{
|
||||
if g:EasyMotion_startofline
|
||||
call s:EasyMotion('^\(\w\|\s*\zs\|$\)', a:direction, a:visualmode ? visualmode() : '', '')
|
||||
else
|
||||
let prev_column = getpos('.')[2] - 1
|
||||
call s:EasyMotion('^.\{,' . prev_column . '}\zs\(.\|$\)', a:direction, a:visualmode ? visualmode() : '', '')
|
||||
endif
|
||||
endfunction " }}}
|
||||
" == Search Motion =======================
|
||||
function! EasyMotion#Search(visualmode, direction) " {{{
|
||||
endfunction " }}}
|
||||
" -- Search Motion -----------------------
|
||||
function! EasyMotion#Search(visualmode, direction) " {{{
|
||||
call s:EasyMotion(@/, a:direction, a:visualmode ? visualmode() : '', '')
|
||||
endfunction " }}}
|
||||
" == JumpToAnywhere Motion ===============
|
||||
function! EasyMotion#JumpToAnywhere(visualmode, direction) " {{{
|
||||
endfunction " }}}
|
||||
" -- JumpToAnywhere Motion ---------------
|
||||
function! EasyMotion#JumpToAnywhere(visualmode, direction) " {{{
|
||||
if !exists('g:EasyMotion_re_anywhere')
|
||||
" Anywhere regular expression: {{{
|
||||
let re = '\v' .
|
||||
@ -102,9 +103,9 @@ endfunction "}}}
|
||||
endif
|
||||
"
|
||||
call s:EasyMotion( g:EasyMotion_re_anywhere, a:direction, a:visualmode ? visualmode() : '', '')
|
||||
endfunction " }}}
|
||||
" == Line Motion =========================
|
||||
function! EasyMotion#SL(visualmode, direction) " {{{
|
||||
endfunction " }}}
|
||||
" -- Line Motion -------------------------
|
||||
function! EasyMotion#SL(visualmode, direction) " {{{
|
||||
let char = s:GetSearchChar(a:visualmode)
|
||||
|
||||
if empty(char)
|
||||
@ -115,14 +116,14 @@ endfunction "}}}
|
||||
let re = '\%' . line('.') . 'l' . re
|
||||
|
||||
call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', mode(1))
|
||||
endfunction " }}}
|
||||
function! EasyMotion#WBL(visualmode, direction) " {{{
|
||||
endfunction " }}}
|
||||
function! EasyMotion#WBL(visualmode, direction) " {{{
|
||||
call s:EasyMotion('\%'.line('.').'l'.'\(\<.\|^$\)', a:direction, a:visualmode ? visualmode() : '', '')
|
||||
endfunction " }}}
|
||||
function! EasyMotion#EL(visualmode, direction) " {{{
|
||||
endfunction " }}}
|
||||
function! EasyMotion#EL(visualmode, direction) " {{{
|
||||
call s:EasyMotion('\%'.line('.').'l'.'\(.\>\|^$\)', a:direction, a:visualmode ? visualmode() : '', mode(1))
|
||||
endfunction " }}}
|
||||
function! EasyMotion#LineAnywhere(visualmode, direction) " {{{
|
||||
endfunction " }}}
|
||||
function! EasyMotion#LineAnywhere(visualmode, direction) " {{{
|
||||
|
||||
if ! exists('s:re_line_flag') "{{{
|
||||
" Load once!
|
||||
@ -149,9 +150,9 @@ endfunction "}}}
|
||||
endif "}}}
|
||||
let re = s:re_line_flag . line('.') . s:re_line_after
|
||||
call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', '')
|
||||
endfunction " }}}
|
||||
" == Special Motion ======================
|
||||
function! EasyMotion#SelectLines() "{{{
|
||||
endfunction " }}}
|
||||
" -- Special Motion ----------------------
|
||||
function! EasyMotion#SelectLines() "{{{
|
||||
let orig_pos = [line('.'), col('.')]
|
||||
|
||||
call s:EasyMotion('^\(\w\|\s*\zs\|$\)', 2, '', '', 0, 0, 1)
|
||||
@ -172,14 +173,14 @@ endfunction "}}}
|
||||
return 1
|
||||
endif
|
||||
endif
|
||||
endfunction "}}}
|
||||
function! EasyMotion#SelectLinesYank() "{{{
|
||||
endfunction "}}}
|
||||
function! EasyMotion#SelectLinesYank() "{{{
|
||||
let orig_pos = [line('.'), col('.')]
|
||||
call EasyMotion#SelectLines()
|
||||
normal! y
|
||||
keepjumps call cursor(orig_pos[0], orig_pos[1])
|
||||
endfunction "}}}
|
||||
function! EasyMotion#SelectLinesDelete() "{{{
|
||||
endfunction "}}}
|
||||
function! EasyMotion#SelectLinesDelete() "{{{
|
||||
let orig_pos = [line('.'), col('.')]
|
||||
" if cancelled?
|
||||
if EasyMotion#SelectLines()
|
||||
@ -198,9 +199,9 @@ endfunction "}}}
|
||||
else
|
||||
keepjumps call cursor(orig_pos[0], orig_pos[1])
|
||||
endif
|
||||
endfunction "}}}
|
||||
endfunction "}}}
|
||||
|
||||
function! EasyMotion#SelectPhrase() "{{{
|
||||
function! EasyMotion#SelectPhrase() "{{{
|
||||
let chars = s:GetSearchChar2(0)
|
||||
if empty(chars)
|
||||
return
|
||||
@ -233,15 +234,15 @@ endfunction "}}}
|
||||
return 1
|
||||
endif
|
||||
endif
|
||||
endfunction "}}}
|
||||
function! EasyMotion#SelectPhraseYank() "{{{
|
||||
endfunction "}}}
|
||||
function! EasyMotion#SelectPhraseYank() "{{{
|
||||
let orig_pos = [line('.'), col('.')]
|
||||
|
||||
call EasyMotion#SelectPhrase()
|
||||
normal! y
|
||||
keepjumps call cursor(orig_pos[0], orig_pos[1])
|
||||
endfunction "}}}
|
||||
function! EasyMotion#SelectPhraseDelete() "{{{
|
||||
endfunction "}}}
|
||||
function! EasyMotion#SelectPhraseDelete() "{{{
|
||||
let orig_pos = [line('.'), col('.')]
|
||||
|
||||
" If cancelled?
|
||||
@ -261,33 +262,31 @@ endfunction "}}}
|
||||
else
|
||||
keepjumps call cursor(orig_pos[0], orig_pos[1])
|
||||
endif
|
||||
endfunction "}}}
|
||||
" == User Motion =========================
|
||||
function! EasyMotion#User(pattern, visualmode, direction) " {{{
|
||||
endfunction "}}}
|
||||
" -- User Motion -------------------------
|
||||
function! EasyMotion#User(pattern, visualmode, direction) " {{{
|
||||
let re = escape(a:pattern, '|')
|
||||
call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', mode(1))
|
||||
endfunction " }}}
|
||||
function! EasyMotion#UserMapping(re, mapping, direction) " {{{
|
||||
endfunction " }}}
|
||||
function! EasyMotion#UserMapping(re, mapping, direction) " {{{
|
||||
silent exec "nnoremap ".a:mapping." :call EasyMotion#User('".a:re."', 0, ".a:direction.")<CR>"
|
||||
silent exec "onoremap ".a:mapping." :call EasyMotion#User('".a:re."', 0, ".a:direction.")<CR>"
|
||||
silent exec "vnoremap ".a:mapping." :<C-u>call EasyMotion#User('".a:re."', 0,".a:direction.")<CR>"
|
||||
endfunction " }}}
|
||||
endfunction " }}}
|
||||
|
||||
" }}}
|
||||
" Helper functions {{{
|
||||
" Message {{{
|
||||
function! s:Message(message) " {{{
|
||||
" == Helper functions {{{
|
||||
" -- Message -----------------------------
|
||||
function! s:Message(message) " {{{
|
||||
echo 'EasyMotion: ' . a:message
|
||||
endfunction " }}}
|
||||
function! s:Prompt(message) " {{{
|
||||
endfunction " }}}
|
||||
function! s:Prompt(message) " {{{
|
||||
echohl Question
|
||||
echo a:message . ': '
|
||||
echohl None
|
||||
endfunction " }}}
|
||||
"}}}
|
||||
|
||||
" Save & Restore values {{{
|
||||
function! s:VarReset(var, ...) " {{{
|
||||
endfunction " }}}
|
||||
" -- Save & Restore values ---------------
|
||||
function! s:VarReset(var, ...) " {{{
|
||||
if ! exists('s:var_reset')
|
||||
let s:var_reset = {}
|
||||
endif
|
||||
@ -307,8 +306,8 @@ endfunction "}}}
|
||||
" Set new var value
|
||||
call setbufvar("", a:var, new_value)
|
||||
endif
|
||||
endfunction " }}}
|
||||
function! s:SaveValue() "{{{
|
||||
endfunction " }}}
|
||||
function! s:SaveValue() "{{{
|
||||
call s:VarReset('&scrolloff', 0)
|
||||
call s:VarReset('&modified', 0)
|
||||
call s:VarReset('&modifiable', 1)
|
||||
@ -316,8 +315,8 @@ endfunction "}}}
|
||||
call s:VarReset('&spell', 0)
|
||||
call s:VarReset('&virtualedit', '')
|
||||
call s:VarReset('&foldmethod', 'manual')
|
||||
endfunction "}}}
|
||||
function! s:RestoreValue() "{{{
|
||||
endfunction "}}}
|
||||
function! s:RestoreValue() "{{{
|
||||
call s:VarReset('&scrolloff')
|
||||
call s:VarReset('&modified')
|
||||
call s:VarReset('&modifiable')
|
||||
@ -325,11 +324,9 @@ endfunction "}}}
|
||||
call s:VarReset('&spell')
|
||||
call s:VarReset('&virtualedit')
|
||||
call s:VarReset('&foldmethod')
|
||||
endfunction "}}}
|
||||
"}}}
|
||||
|
||||
" Draw {{{
|
||||
function! s:SetLines(lines, key) " {{{
|
||||
endfunction "}}}
|
||||
" -- Draw --------------------------------
|
||||
function! s:SetLines(lines, key) " {{{
|
||||
if ! filereadable(s:undo_file)
|
||||
" Try to join changes with previous undo block once
|
||||
undojoin
|
||||
@ -337,11 +334,9 @@ endfunction "}}}
|
||||
for [line_num, line] in a:lines
|
||||
call setline(line_num, line[a:key])
|
||||
endfor
|
||||
endfunction " }}}
|
||||
"}}}
|
||||
|
||||
" Get characters from user input {{{
|
||||
function! s:GetChar() " {{{
|
||||
endfunction " }}}
|
||||
" -- Get characters from user input ------
|
||||
function! s:GetChar() " {{{
|
||||
let char = getchar()
|
||||
|
||||
if char == 27
|
||||
@ -354,8 +349,8 @@ endfunction "}}}
|
||||
endif
|
||||
|
||||
return nr2char(char)
|
||||
endfunction " }}}
|
||||
function! s:GetSearchChar2(visualmode) " {{{
|
||||
endfunction " }}}
|
||||
function! s:GetSearchChar2(visualmode) " {{{
|
||||
|
||||
let chars = []
|
||||
for i in [1, 2]
|
||||
@ -377,8 +372,8 @@ endfunction "}}}
|
||||
endfor
|
||||
|
||||
return chars
|
||||
endfunction " }}}
|
||||
function! s:GetSearchChar(visualmode) " {{{
|
||||
endfunction " }}}
|
||||
function! s:GetSearchChar(visualmode) " {{{
|
||||
call s:Prompt('Search for character')
|
||||
|
||||
let char = s:GetChar()
|
||||
@ -394,11 +389,9 @@ endfunction "}}}
|
||||
endif
|
||||
|
||||
return char
|
||||
endfunction " }}}
|
||||
"}}}
|
||||
|
||||
"Find Motion Helper {{{
|
||||
function! s:findMotion(char) "{{{
|
||||
endfunction " }}}
|
||||
" -- Find Motion Helper ------------------
|
||||
function! s:findMotion(char) "{{{
|
||||
" Find Motion: S,F,T
|
||||
let re = escape(a:char, '.$^~\')
|
||||
|
||||
@ -411,8 +404,8 @@ endfunction "}}}
|
||||
endif
|
||||
|
||||
return re
|
||||
endfunction "}}}
|
||||
function! s:convertMigemo(re) "{{{
|
||||
endfunction "}}}
|
||||
function! s:convertMigemo(re) "{{{
|
||||
let re = a:re
|
||||
if ! has_key(s:migemo_dicts, &l:encoding)
|
||||
let s:migemo_dicts[&l:encoding] = s:load_migemo_dict()
|
||||
@ -421,8 +414,8 @@ endfunction "}}}
|
||||
let re = s:migemo_dicts[&l:encoding][re]
|
||||
endif
|
||||
return re
|
||||
endfunction "}}}
|
||||
function! s:convertSmartcase(re, char) "{{{
|
||||
endfunction "}}}
|
||||
function! s:convertSmartcase(re, char) "{{{
|
||||
let re = a:re
|
||||
if a:char =~# '\U' "nonuppercase
|
||||
if s:useSmartsign()
|
||||
@ -433,8 +426,8 @@ endfunction "}}}
|
||||
else "uppercase
|
||||
return '\C' . re
|
||||
endif
|
||||
endfunction "}}}
|
||||
function! s:convertSmartsign(re, char) "{{{
|
||||
endfunction "}}}
|
||||
function! s:convertSmartsign(re, char) "{{{
|
||||
let smart_dict = s:load_smart_dict()
|
||||
let upper_sign = escape(get(smart_dict, a:char, ''), '.$^~')
|
||||
if upper_sign ==# ''
|
||||
@ -443,16 +436,16 @@ endfunction "}}}
|
||||
let re = a:re . '\|' . upper_sign
|
||||
return re
|
||||
endif
|
||||
endfunction "}}}
|
||||
function! s:useSmartsign() "{{{
|
||||
endfunction "}}}
|
||||
function! s:useSmartsign() "{{{
|
||||
if exists('g:EasyMotion_use_smartsign_us') ||
|
||||
\ exists('g:EasyMotion_use_smartsign_jp')
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
endif
|
||||
endfunction "}}}
|
||||
function! s:load_smart_dict() "{{{
|
||||
endfunction "}}}
|
||||
function! s:load_smart_dict() "{{{
|
||||
if exists('g:EasyMotion_use_smartsign_us')
|
||||
return g:EasyMotion#sticky_table#us
|
||||
elseif exists('g:EasyMotion_use_smartsign_jp')
|
||||
@ -460,8 +453,8 @@ endfunction "}}}
|
||||
else
|
||||
return ''
|
||||
endif
|
||||
endfunction "}}}
|
||||
function! s:load_migemo_dict() "{{{
|
||||
endfunction "}}}
|
||||
function! s:load_migemo_dict() "{{{
|
||||
let enc = &l:encoding
|
||||
if enc ==# 'utf-8'
|
||||
return EasyMotion#migemo#utf8#load_dict()
|
||||
@ -473,11 +466,10 @@ endfunction "}}}
|
||||
let g:EasyMotion_use_migemo = 0
|
||||
throw "Error: ".enc." is not supported. Migemo is made disabled."
|
||||
endif
|
||||
endfunction "}}}
|
||||
"}}}
|
||||
|
||||
endfunction "}}}
|
||||
" -- Others ------------------------------
|
||||
" Handle Visual Mode {{{
|
||||
function! s:GetVisualStartPosition(c_pos, v_start, v_end, direction) "{{{
|
||||
function! s:GetVisualStartPosition(c_pos, v_start, v_end, direction) "{{{
|
||||
let vmode = mode(1)
|
||||
if match('Vv',vmode) < 0
|
||||
throw 'Unkown visual mode:'.vmode
|
||||
@ -513,28 +505,24 @@ endfunction "}}}
|
||||
endif
|
||||
"}}}
|
||||
return v_pos
|
||||
endfunction "}}}
|
||||
|
||||
function! s:is_folded(line) "{{{
|
||||
endfunction "}}}
|
||||
function! s:is_folded(line) "{{{
|
||||
" Return false if g:EasyMotion_skipfoldedline == 1
|
||||
" and line is start of folded lines
|
||||
return foldclosed(a:line) != -1 &&
|
||||
\ (g:EasyMotion_skipfoldedline == 1 ||
|
||||
\ a:line != foldclosed(a:line))
|
||||
endfunction "}}}
|
||||
|
||||
endfunction "}}}
|
||||
" }}}
|
||||
|
||||
" }}}
|
||||
" Grouping algorithms {{{
|
||||
let s:grouping_algorithms = {
|
||||
\ 1: 'SCTree'
|
||||
\ , 2: 'Original'
|
||||
\ }
|
||||
" Single-key/closest target priority tree {{{
|
||||
" This algorithm tries to assign one-key jumps to all the targets closest to the cursor.
|
||||
" It works recursively and will work correctly with as few keys as two.
|
||||
function! s:GroupingAlgorithmSCTree(targets, keys)
|
||||
" == Grouping algorithms {{{
|
||||
let s:grouping_algorithms = {
|
||||
\ 1: 'SCTree'
|
||||
\ , 2: 'Original'
|
||||
\ }
|
||||
" -- Single-key/closest target priority tree {{{
|
||||
" This algorithm tries to assign one-key jumps to all the targets closest to the cursor.
|
||||
" It works recursively and will work correctly with as few keys as two.
|
||||
function! s:GroupingAlgorithmSCTree(targets, keys) "{{{
|
||||
" Prepare variables for working
|
||||
let targets_len = len(a:targets)
|
||||
let keys_len = len(a:keys)
|
||||
@ -620,10 +608,10 @@ endfunction "}}}
|
||||
|
||||
" Finally!
|
||||
return groups
|
||||
endfunction
|
||||
" }}}
|
||||
" Original {{{
|
||||
function! s:GroupingAlgorithmOriginal(targets, keys)
|
||||
endfunction "}}}
|
||||
" }}}
|
||||
" -- Original ---------------------------- {{{
|
||||
function! s:GroupingAlgorithmOriginal(targets, keys)
|
||||
" Split targets into groups (1 level)
|
||||
let targets_len = len(a:targets)
|
||||
let keys_len = len(a:keys)
|
||||
@ -652,10 +640,11 @@ endfunction "}}}
|
||||
endif
|
||||
|
||||
return groups
|
||||
endfunction
|
||||
" }}}
|
||||
" Coord/key dictionary creation {{{
|
||||
function! s:CreateCoordKeyDict(groups, ...)
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
" -- Coord/key dictionary creation ------- {{{
|
||||
function! s:CreateCoordKeyDict(groups, ...)
|
||||
" Dict structure:
|
||||
" 1,2 : a
|
||||
" 2,3 : b
|
||||
@ -692,13 +681,12 @@ endfunction "}}}
|
||||
endfor
|
||||
|
||||
return [sort_list, coord_keys]
|
||||
endfunction
|
||||
" }}}
|
||||
endfunction
|
||||
" }}}
|
||||
" Core functions {{{
|
||||
function! s:PromptUser(groups, allows_repeat, fixed_column) "{{{
|
||||
|
||||
" If only one possible match, jump directly to it {{{
|
||||
" }}}
|
||||
" == Core functions {{{
|
||||
function! s:PromptUser(groups, allows_repeat, fixed_column) "{{{
|
||||
" -- If only one possible match, jump directly to it {{{
|
||||
let group_values = values(a:groups)
|
||||
|
||||
if len(group_values) == 1
|
||||
@ -707,7 +695,7 @@ endfunction "}}}
|
||||
return group_values[0]
|
||||
endif
|
||||
" }}}
|
||||
" Prepare marker lines {{{
|
||||
" -- Prepare marker lines ---------------- {{{
|
||||
let lines = {}
|
||||
let hl_coords = []
|
||||
let hl2_first_coords = [] " Highlight for two characters
|
||||
@ -776,7 +764,6 @@ endfunction "}}}
|
||||
else
|
||||
if strlen(lines[line_num]['marker']) > 0
|
||||
" Substitute marker character if line length > 0
|
||||
|
||||
let c = 0
|
||||
while c < target_key_len && c < 2
|
||||
if strlen(lines[line_num]['marker']) >= col_num + c
|
||||
@ -823,7 +810,7 @@ endfunction "}}}
|
||||
|
||||
let lines_items = items(lines)
|
||||
" }}}
|
||||
" Highlight targets {{{
|
||||
" -- Highlight targets ------------------- {{{
|
||||
if len(hl_coords) > 0
|
||||
let target_hl_id = matchadd(g:EasyMotion_hl_group_target, join(hl_coords, '\|'), 1)
|
||||
endif
|
||||
@ -833,20 +820,17 @@ endfunction "}}}
|
||||
if len(hl2_first_coords) > 0
|
||||
let target_hl2_first_id = matchadd(g:EasyMotion_hl2_first_group_target, join(hl2_first_coords, '\|'), 1)
|
||||
endif
|
||||
|
||||
" }}}
|
||||
|
||||
" -- Put labels on targets & Get User Input & Restore all {{{
|
||||
" Save undo tree {{{
|
||||
let s:undo_file = tempname()
|
||||
execute "wundo" s:undo_file
|
||||
"}}}
|
||||
try
|
||||
|
||||
" Set lines with markers
|
||||
call s:SetLines(lines_items, 'marker')
|
||||
|
||||
redraw
|
||||
|
||||
" Get target character {{{
|
||||
call s:Prompt('Target key')
|
||||
|
||||
@ -881,17 +865,18 @@ endfunction "}}}
|
||||
endif "}}}
|
||||
|
||||
redraw
|
||||
endtry
|
||||
endtry "}}}
|
||||
|
||||
" Check if we have an input char {{{
|
||||
" -- Check if we have an input char ------ {{{
|
||||
if empty(char)
|
||||
throw 'Cancelled'
|
||||
endif
|
||||
" }}}
|
||||
" Check if the input char is valid {{{
|
||||
" -- Repeat EasyMotion ------------------- {{{
|
||||
if a:allows_repeat && char == '.'
|
||||
return g:EasyMotion_old_target
|
||||
else
|
||||
endif "}}}
|
||||
" -- Check if the input char is valid ---- {{{
|
||||
if ! has_key(a:groups, char)
|
||||
throw 'Invalid target'
|
||||
endif
|
||||
@ -906,10 +891,8 @@ endfunction "}}}
|
||||
" Prompt for new target character
|
||||
return s:PromptUser(target, a:allows_repeat, a:fixed_column)
|
||||
endif
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
function! s:EasyMotion(regexp, direction, visualmode, mode, ...) " {{{
|
||||
endfunction "}}}
|
||||
function! s:EasyMotion(regexp, direction, visualmode, mode, ...) " {{{
|
||||
" For SelectLines(), to highlight previous selected line
|
||||
let hlcurrent = a:0 >= 1 ? a:1 : 0
|
||||
" For SelectLines(), to allows '.' to repeat the previously pressed
|
||||
@ -925,11 +908,11 @@ endfunction "}}}
|
||||
let targets = []
|
||||
|
||||
try
|
||||
" Reset properties {{{
|
||||
" -- Reset properties -------------------- {{{
|
||||
" Save original value and set new value
|
||||
call s:SaveValue()
|
||||
" }}}
|
||||
" Find motion targets {{{
|
||||
" -- Find motion targets ----------------- {{{
|
||||
" Setup searchpos args {{{
|
||||
let search_direction = (a:direction >= 1 ? 'b' : '')
|
||||
let search_stopline = line(a:direction >= 1 ? 'w0' : 'w$')
|
||||
@ -945,6 +928,7 @@ endfunction "}}}
|
||||
let v_end = [line("'>"),col("'>")] " visual_end_position
|
||||
|
||||
let v_original_pos = s:GetVisualStartPosition(c_pos, v_start, v_end, a:direction)
|
||||
"}}}
|
||||
|
||||
" Reselect visual text {{{
|
||||
keepjumps call cursor(v_original_pos)
|
||||
@ -979,7 +963,7 @@ endfunction "}}}
|
||||
endwhile
|
||||
"}}}
|
||||
|
||||
" Handle direction == 2"{{{
|
||||
" Handle bidirection "{{{
|
||||
" Reconstruct match dict
|
||||
if a:direction == 2
|
||||
if ! empty(a:visualmode)
|
||||
@ -1033,7 +1017,7 @@ endfunction "}}}
|
||||
let GroupingFn = function('s:GroupingAlgorithm' . s:grouping_algorithms[g:EasyMotion_grouping])
|
||||
let groups = GroupingFn(targets, split(g:EasyMotion_keys, '\zs'))
|
||||
|
||||
" Shade inactive source {{{
|
||||
" -- Shade inactive source --------------- {{{
|
||||
if g:EasyMotion_do_shade
|
||||
let shade_hl_pos = '\%' . orig_pos[0] . 'l\%'. orig_pos[1] .'c'
|
||||
|
||||
@ -1059,19 +1043,19 @@ endfunction "}}}
|
||||
endif
|
||||
" }}}
|
||||
|
||||
" Prompt user for target group/character"{{{
|
||||
" -- Prompt user for target group/character {{{
|
||||
let coords = s:PromptUser(groups, allows_repeat, fixed_column)
|
||||
let g:EasyMotion_old_target = coords
|
||||
"}}}
|
||||
|
||||
" Update selection {{{
|
||||
" -- Update selection -------------------- {{{
|
||||
if ! empty(a:visualmode)
|
||||
keepjumps call cursor(orig_pos[0], orig_pos[1])
|
||||
|
||||
exec 'normal! ' . a:visualmode
|
||||
endif
|
||||
" }}}
|
||||
" Handle operator-pending mode {{{
|
||||
" -- Handle operator-pending mode -------- {{{
|
||||
if a:mode == 'no'
|
||||
" This mode requires that we eat one more
|
||||
" character to the right if we're using
|
||||
@ -1083,7 +1067,7 @@ endfunction "}}}
|
||||
endif
|
||||
" }}}
|
||||
|
||||
" Update cursor position"{{{
|
||||
" -- Update cursor position -------------- {{{
|
||||
call cursor(orig_pos[0], orig_pos[1])
|
||||
let mark_save = getpos("'e")
|
||||
call setpos("'e", [bufnr('%'), coords[0], coords[1], 0])
|
||||
@ -1099,7 +1083,7 @@ endfunction "}}}
|
||||
" Show exception message
|
||||
call s:Message(v:exception)
|
||||
|
||||
" Restore original cursor position/selection {{{
|
||||
" -- Restore original cursor position/selection {{{
|
||||
if ! empty(a:visualmode)
|
||||
silent exec 'normal! gv'
|
||||
keepjumps call cursor(c_pos[0], c_pos[1])
|
||||
@ -1109,10 +1093,10 @@ endfunction "}}}
|
||||
" }}}
|
||||
let s:EasyMotion_cancelled = 1
|
||||
finally
|
||||
" Restore properties {{{
|
||||
" -- Restore properties ------------------ {{{
|
||||
call s:RestoreValue()
|
||||
" }}}
|
||||
" Remove shading {{{
|
||||
" -- Remove shading ---------------------- {{{
|
||||
if g:EasyMotion_do_shade && exists('shade_hl_id') && (!fixed_column)
|
||||
call matchdelete(shade_hl_id)
|
||||
endif
|
||||
@ -1121,12 +1105,13 @@ endfunction "}}}
|
||||
endif
|
||||
" }}}
|
||||
endtry
|
||||
endfunction " }}}
|
||||
" }}}
|
||||
" Call Reset {{{
|
||||
endfunction " }}}
|
||||
"}}}
|
||||
|
||||
" == Call Reset {{{
|
||||
call EasyMotion#reset()
|
||||
"}}}
|
||||
" Restore 'cpoptions' {{{
|
||||
" == Restore 'cpoptions' {{{
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
||||
" }}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user