summaryrefslogtreecommitdiffstats
path: root/.config/nvim
diff options
context:
space:
mode:
authorYigit Sever2021-10-27 15:26:56 +0300
committerYigit Sever2021-10-27 15:26:56 +0300
commitadb93f97e43702251d48f30972acdd804b0fdef4 (patch)
tree8c16e37267f2198b1b32d618e7f2ea00dc44f501 /.config/nvim
parentb749a0b1e096d9271707a88e769a8089c38f5731 (diff)
downloaddotfiles-adb93f97e43702251d48f30972acdd804b0fdef4.tar.gz
dotfiles-adb93f97e43702251d48f30972acdd804b0fdef4.tar.bz2
dotfiles-adb93f97e43702251d48f30972acdd804b0fdef4.zip
nvim: buku omnifunc
Diffstat (limited to '.config/nvim')
-rw-r--r--.config/nvim/after/ftplugin/buku.vim1
-rw-r--r--.config/nvim/after/ftplugin/mail.vim45
-rw-r--r--.config/nvim/after/plugin/autocmds.vim4
-rw-r--r--.config/nvim/autoload/bukutagcomplete.vim18
4 files changed, 23 insertions, 45 deletions
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 @@
1setl spell 1setl spell
2setl omnifunc=mailcomplete#Complete 2setl omnifunc=mailcomplete#Complete
3 3
4function! s:OnExit(job_id, code, event) dict
5 if a:code == 0
6 " NeoMutt successfully sent the mail. Get rid of the terminal buffer and window.
7 " We can't use plain `bd!` because the terminal window may no longer have focus.
8 execute 'bd!' s:bufnr
9 " Quit if we succeeded in sending the email and there's only one buffer left.
10 if len(getbufinfo({'buflisted': 1})) == 1
11 quit
12 endif
13 else
14 " We didn't send the mail. Go back to the buffer with the message. FIXME: we
15 " probably shouldn't rely on a [plugin][1].
16 execute 'Bd!' s:bufnr
17 endif
18endfunction
19" [1]: https://github.com/moll/vim-bbye
20" [2]: https://github.com/neovim/neovim/issues/4291
21" [3]: https://vi.stackexchange.com/q/10292
22" [4]: https://redd.it/46g5wy
23" [5]: https://github.com/neovim/neovim/issues/5176
24
25function! s:SendMail()
26 let l:message_file = expand('%')
27 if l:message_file != ''
28 update
29 else
30 " Cope with the buffer not having an associated file. TODO: delete this file if we
31 " succeed in sending the mail?
32 let l:message_file = system('mktemp')
33 execute 'w!' l:message_file
34 endif
35 enew
36 " Tell NeoMutt to use `true` as the editor. This makes it show the compose menu
37 " directly instead of starting Vim inside of Vim. Also don't use the curses pinentry
38 " program. There seem to be some issues when using it from NeoMutt inside Vim inside
39 " screen(1).
40 call termopen('VISUAL=true PINENTRY_USER_DATA=gtk neomutt ' .
41 \ "-e 'set postpone=no sidebar_visible=no assumed_charset=utf-8' " .
42 \ "-H " . l:message_file, {'on_exit': function('s:OnExit')})
43 let s:bufnr = bufnr('%')
44 startinsert
45endfunction
46
47nnoremap <buffer> <silent> <C-H> :<C-U>call <SID>SendMail()<CR>
48
49nnoremap <buffer> <silent> <localleader>f gg/From:<CR>:nohlsearch<CR>4lC: 4nnoremap <buffer> <silent> <localleader>f gg/From:<CR>:nohlsearch<CR>4lC:
50nnoremap <buffer> <silent> <localleader>t gg/To:<CR>:nohlsearch<CR>2lC: 5nnoremap <buffer> <silent> <localleader>t gg/To:<CR>:nohlsearch<CR>2lC:
51nnoremap <buffer> <silent> <localleader>c gg/Cc:<CR>:nohlsearch<CR>2lC: 6nnoremap <buffer> <silent> <localleader>c gg/Cc:<CR>:nohlsearch<CR>2lC:
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 @@
2autocmd BufRead,BufWrite * if ! &bin | silent! %s/\s\+$//ge | endif 2autocmd BufRead,BufWrite * if ! &bin | silent! %s/\s\+$//ge | endif
3 3
4autocmd BufNewFile,BufRead /tmp/neomutt* set noautoindent filetype=mail wm=0 tw=80 4autocmd BufNewFile,BufRead /tmp/neomutt* set noautoindent filetype=mail wm=0 tw=80
5
6augroup bukugroup
7 au! BufRead,BufNewFile,BufEnter buku-edit-* set filetype=buku
8augroup 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 @@
1function! bukutagcomplete#Complete(findstart, base)
2 if a:findstart == 1
3 let line = getline('.')
4 let idx = col('.')
5 while idx > 0
6 let idx -= 1
7 let c = line[idx]
8 if c == ':' || c == '>'
9 return idx + 2
10 else
11 continue
12 endif
13 endwhile
14 return idx
15 else
16 return split(system('buku --stag --np | pcregrep -o1 " ([a-zA-Z ]+) (?=\()" | grep ' . a:base), '\n')
17 endif
18endfunction