diff options
| -rw-r--r-- | plugin/haredoc.vim | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/plugin/haredoc.vim b/plugin/haredoc.vim index ae8b4f7..f6ddc6d 100644 --- a/plugin/haredoc.vim +++ b/plugin/haredoc.vim @@ -15,21 +15,20 @@ function Haredoc(symbol) let symbol = expand('<cword>') let &iskeyword = oldiskeyword - " resolve possibly partial symbols (chrono::moment) + " resolve possibly non-complete symbols (chrono::moment) if match(symbol, "::") != -1 && &buftype == '' - let [parent, base] = split(symbol, "::")[-2:-1] + let [submodule, ident] = split(symbol, "::")[-2:-1] " try joining symbol with a use statement. " example: 'use time::chrono' -> 'time::chrono::moment' - let resolvecmd =<< trim eval CMD - awk '/use [a-zA-Z:]*{parent};/ {{ - gsub("(use *|;.*)", ""); - print $1 "::" "{base}" - }}' {expand("%")} 2>&- - CMD - let joined_symbol = system(join(resolvecmd))[:-2] - if len(joined_symbol) != 0 - let symbol = joined_symbol + let use = getline(search('^use *.*::'..submodule, 'bnw')) + if use != '' + let symbol = substitute( + \ use, + \ '\(use *\|;\)', + \ '', + \ 'g' + \ )..'::'..ident endif endif endif @@ -79,6 +78,11 @@ function Haredoc(symbol) elseif has('nvim') split execute 'terminal haredoc '..symbol + tnoremap <buffer> q <C-\><C-N> + nnoremap <buffer> q :close<CR> + nnoremap <buffer> <nowait> u <C-U> + nnoremap <buffer> <nowait> d <C-D> + startinsert else execute '!haredoc '..symbol endif |
