diff options
| author | Byron Torres <b@torresjrjr.com> | 2024-02-25 13:00:01 +0000 |
|---|---|---|
| committer | Byron Torres <b@torresjrjr.com> | 2024-02-25 14:28:03 +0000 |
| commit | abfb2ca834a7b7e5c5428d6e82fda2e73dcb6f54 (patch) | |
| tree | 072d2072e7f889e50cd0bbb9db090225fbe6e079 | |
| parent | neovim: use :terminal in split window (diff) | |
| download | vim-haredoc-abfb2ca834a7b7e5c5428d6e82fda2e73dcb6f54.tar.gz | |
rewrite symbol resolution; achieve neovim compat
| -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 |
