1 " notmuch.vim plugin --- run notmuch within vim
3 " Copyright © Carl Worth
5 " This file is part of Notmuch.
7 " Notmuch is free software: you can redistribute it and/or modify it
8 " under the terms of the GNU General Public License as published by
9 " the Free Software Foundation, either version 3 of the License, or
10 " (at your option) any later version.
12 " Notmuch is distributed in the hope that it will be useful, but
13 " WITHOUT ANY WARRANTY; without even the implied warranty of
14 " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 " General Public License for more details.
17 " You should have received a copy of the GNU General Public License
18 " along with Notmuch. If not, see <http://www.gnu.org/licenses/>.
20 " Authors: Bart Trojanowski <bart@jukie.net>
24 if !exists('g:notmuch_cmd')
25 let g:notmuch_cmd = 'notmuch'
29 " --- implement search screen
31 function! s:NM_cmd_search(words)
32 let data = split(s:NM_run(['search'] + a:words), "\n")
34 call map(disp, 'substitute(v:val, "^thread:\\S* ", "", "")' )
36 call s:NM_newBuffer('search', join(disp, "\n"))
37 let b:nm_raw_data = data
39 nnoremap <buffer> <Enter> :call <SID>NM_search_display()<CR>
42 function! s:NM_search_display()
44 if !exists('b:nm_raw_data')
45 echo 'no b:nm_raw_data'
47 let info = b:nm_raw_data[line]
48 let what = split(info, '\W\+')[0]
49 call s:NM_cmd_show([what])
54 " --- implement show screen
56 function! s:NM_cmd_show(words)
57 let data = s:NM_run(['show'] + a:words)
59 call s:NM_newBuffer('show', data)
60 let b:nm_raw_data = data
66 function! s:NM_newBuffer(ft, content)
68 setlocal buftype=nofile readonly modifiable
69 setlocal bufhidden=delete
74 execute printf('setlocal filetype=notmuch-%s', a:ft)
77 function! s:NM_run(args)
78 let cmd = g:notmuch_cmd . ' ' . join(a:args) . '< /dev/null'
82 echo substitute(out, '\n*$', '', '')
93 function! NotMuch(args)
95 call s:NM_cmd_search(['tag:inbox'])
101 let words = split(a:args)
102 " TODO: handle commands passed as arguments
104 function! CompleteNotMuch(arg_lead, cmd_line, cursor_pos)
111 command! -nargs=* -complete=customlist,CompleteNotMuch NotMuch call NotMuch(<q-args>)
112 cabbrev notmuch <c-r>=(getcmdtype()==':' && getcmdpos()==1 ? 'NotMuch' : 'notmuch')<CR>
114 " --- hacks, only for development :)
116 nnoremap ,nmr :source ~/.vim/plugin/notmuch.vim<CR>:call NotMuch('')<CR>