Added support for proclike textobjects

Closes #10
This commit is contained in:
baabelfish 2016-02-07 16:28:33 +02:00
commit 76e54f8ad5
4 changed files with 52 additions and 3 deletions

View file

@ -60,7 +60,7 @@ function! modules#GetImports()
let [begin, end] = modules#ImportLineRange()
let lines = getline(begin, end)
return filter(split(substitute(join(lines, ""), ",", "", "g"), " "), 'v:val !~ "^ *$"')[1:-1]
return sort(filter(split(substitute(join(lines, ""), ",", "", "g"), " "), 'v:val !~ "^ *$"')[1:-1])
endfunction
function! modules#ImportMap(imports)

View file

@ -219,3 +219,46 @@ endfunction
function! util#open_module_doc(module, symbol)
call system("$BROWSER " . "http://nim-lang.org/docs/" . a:module . ".html#" . a:symbol)
endfunction
function! util#SelectNimProc(inner)
let curline = nextnonblank(line("."))
let lastline = line("$")
let sl = curline
function! s:IsProcStart(l)
return getline(a:l) =~ "\s*\\(proc\\|template\\|macro\\|func\\|method\\)\\s\\+\\w\\+("
endfunction
while sl > 0
if s:IsProcStart(sl) && (curline == sl || indent(sl) < indent(curline))
break
endif
let sl -= 1
endwhile
if !s:IsProcStart(sl)
normal <Esc>
return
endif
call cursor(sl, 0)
normal! 0V
let el = sl + 1
while getline(el) =~ "^\\s*$" || indent(el) > indent(sl)
let el += 1
endwhile
let el -= 1
if a:inner
while getline(el) =~ "^\\s*$"
let el -= 1
endwhile
endif
call cursor(el, 0)
normal! $
if a:inner
normal! h
endif
endfunction

View file

@ -41,6 +41,11 @@ nnoremap <buffer> gd :NimDefinition<cr>
nnoremap <buffer> gt :NimInfo<cr>
nnoremap <buffer> gT :NimWeb<cr>
onoremap <silent>af :<C-U>call util#SelectNimProc(0)<CR>
onoremap <silent>if :<C-U>call util#SelectNimProc(1)<CR>
vnoremap <silent>af :<C-U>call util#SelectNimProc(0)<CR><Esc>gv
vnoremap <silent>if :<C-U>call util#SelectNimProc(1)<CR><Esc>gv
autocmd! BufReadPost,BufWritePost,CursorHold,InsertLeave,TextChanged,InsertEnter *.nim call highlighter#guard()
autocmd! BufWinEnter,BufWritePost,FileWritePost *.nim call features#outline#run(1)
autocmd! VimResized,WinEnter * call features#outline#render()

View file

@ -24,6 +24,9 @@ function! FindNimModulesPath()
return "/usr/lib/nim/"
endfunction
if exists("g:ycm_semantic_triggers")
let g:ycm_semantic_triggers["nim"] = ['.', '(']
endif
let g:nvim_nim_exec_nim = CheckDependency("nim")
let g:nvim_nim_exec_nimble = CheckDependency("nimble")
@ -32,8 +35,6 @@ let g:nvim_nim_exec_bash = CheckDependency("bash")
let g:nvim_nim_deps_nim = FindNimModulesPath()
let g:nvim_nim_deps_nimble = FindNimbleModulesPath()
let g:nvim_nim_highlighter_enable = 1
let g:nvim_nim_highlighter_enable = 1
let g:nvim_nim_highlighter_semantic = 1
let g:nvim_nim_enable_async = 1