From adb93f97e43702251d48f30972acdd804b0fdef4 Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Wed, 27 Oct 2021 15:26:56 +0300 Subject: nvim: buku omnifunc --- .config/nvim/after/ftplugin/buku.vim | 1 + .config/nvim/after/ftplugin/mail.vim | 45 ------------------------------- .config/nvim/after/plugin/autocmds.vim | 4 +++ .config/nvim/autoload/bukutagcomplete.vim | 18 +++++++++++++ 4 files changed, 23 insertions(+), 45 deletions(-) create mode 100644 .config/nvim/after/ftplugin/buku.vim create mode 100644 .config/nvim/autoload/bukutagcomplete.vim (limited to '.config/nvim') diff --git a/.config/nvim/after/ftplugin/buku.vim b/.config/nvim/after/ftplugin/buku.vim new file mode 100644 index 0000000..5189b34 --- /dev/null +++ b/.config/nvim/after/ftplugin/buku.vim @@ -0,0 +1 @@ +setl omnifunc=bukutagcomplete#Complete diff --git a/.config/nvim/after/ftplugin/mail.vim b/.config/nvim/after/ftplugin/mail.vim index b48389a..a1fb43a 100644 --- a/.config/nvim/after/ftplugin/mail.vim +++ b/.config/nvim/after/ftplugin/mail.vim @@ -1,51 +1,6 @@ setl spell setl omnifunc=mailcomplete#Complete -function! s:OnExit(job_id, code, event) dict - if a:code == 0 - " NeoMutt successfully sent the mail. Get rid of the terminal buffer and window. - " We can't use plain `bd!` because the terminal window may no longer have focus. - execute 'bd!' s:bufnr - " Quit if we succeeded in sending the email and there's only one buffer left. - if len(getbufinfo({'buflisted': 1})) == 1 - quit - endif - else - " We didn't send the mail. Go back to the buffer with the message. FIXME: we - " probably shouldn't rely on a [plugin][1]. - execute 'Bd!' s:bufnr - endif -endfunction -" [1]: https://github.com/moll/vim-bbye -" [2]: https://github.com/neovim/neovim/issues/4291 -" [3]: https://vi.stackexchange.com/q/10292 -" [4]: https://redd.it/46g5wy -" [5]: https://github.com/neovim/neovim/issues/5176 - -function! s:SendMail() - let l:message_file = expand('%') - if l:message_file != '' - update - else - " Cope with the buffer not having an associated file. TODO: delete this file if we - " succeed in sending the mail? - let l:message_file = system('mktemp') - execute 'w!' l:message_file - endif - enew - " Tell NeoMutt to use `true` as the editor. This makes it show the compose menu - " directly instead of starting Vim inside of Vim. Also don't use the curses pinentry - " program. There seem to be some issues when using it from NeoMutt inside Vim inside - " screen(1). - call termopen('VISUAL=true PINENTRY_USER_DATA=gtk neomutt ' . - \ "-e 'set postpone=no sidebar_visible=no assumed_charset=utf-8' " . - \ "-H " . l:message_file, {'on_exit': function('s:OnExit')}) - let s:bufnr = bufnr('%') - startinsert -endfunction - -nnoremap :call SendMail() - nnoremap f gg/From::nohlsearch4lC: nnoremap t gg/To::nohlsearch2lC: nnoremap c gg/Cc::nohlsearch2lC: diff --git a/.config/nvim/after/plugin/autocmds.vim b/.config/nvim/after/plugin/autocmds.vim index 6b95ad4..b361f7c 100644 --- a/.config/nvim/after/plugin/autocmds.vim +++ b/.config/nvim/after/plugin/autocmds.vim @@ -2,3 +2,7 @@ autocmd BufRead,BufWrite * if ! &bin | silent! %s/\s\+$//ge | endif autocmd BufNewFile,BufRead /tmp/neomutt* set noautoindent filetype=mail wm=0 tw=80 + +augroup bukugroup + au! BufRead,BufNewFile,BufEnter buku-edit-* set filetype=buku +augroup END diff --git a/.config/nvim/autoload/bukutagcomplete.vim b/.config/nvim/autoload/bukutagcomplete.vim new file mode 100644 index 0000000..3049905 --- /dev/null +++ b/.config/nvim/autoload/bukutagcomplete.vim @@ -0,0 +1,18 @@ +function! bukutagcomplete#Complete(findstart, base) + if a:findstart == 1 + let line = getline('.') + let idx = col('.') + while idx > 0 + let idx -= 1 + let c = line[idx] + if c == ':' || c == '>' + return idx + 2 + else + continue + endif + endwhile + return idx + else + return split(system('buku --stag --np | pcregrep -o1 " ([a-zA-Z ]+) (?=\()" | grep ' . a:base), '\n') + endif +endfunction -- cgit v1.2.3-70-g09d2