" --- --- bindings for folders mode {{{2
let g:notmuch_folders_maps = {
+ \ 'm': ':call <SID>NM_new_mail()<CR>',
\ 's': ':call <SID>NM_search_prompt()<CR>',
\ 'q': ':call <SID>NM_kill_this_buffer()<CR>',
\ '=': ':call <SID>NM_folders_refresh_view()<CR>',
" --- --- bindings for search screen {{{2
let g:notmuch_search_maps = {
- \ '<Enter>': ':call <SID>NM_search_show_thread()<CR>',
+ \ '<Space>': ':call <SID>NM_search_show_thread(0)<CR>',
+ \ '<Enter>': ':call <SID>NM_search_show_thread(1)<CR>',
\ '<C-]>': ':call <SID>NM_search_expand(''<cword>'')<CR>',
\ 'a': ':call <SID>NM_search_archive_thread()<CR>',
\ 'f': ':call <SID>NM_search_filter()<CR>',
\ '<C-N>': ':call <SID>NM_show_next(1, 0)<CR>',
\ '<C-]>': ':call <SID>NM_search_expand(''<cword>'')<CR>',
\ 'q': ':call <SID>NM_kill_this_buffer()<CR>',
+ \ 's': ':call <SID>NM_search_prompt()<CR>',
\
\ 'b': ':call <SID>NM_show_fold_toggle(''b'', ''bdy'', !g:notmuch_show_fold_bodies)<CR>',
\ 'c': ':call <SID>NM_show_fold_toggle(''c'', ''cit'', !g:notmuch_show_fold_citations)<CR>',
\ 'h': ':call <SID>NM_show_fold_toggle(''h'', ''hdr'', !g:notmuch_show_fold_headers)<CR>',
- \ 's': ':call <SID>NM_show_fold_toggle(''s'', ''sig'', !g:notmuch_show_fold_signatures)<CR>',
+ \ 'i': ':call <SID>NM_show_fold_toggle(''s'', ''sig'', !g:notmuch_show_fold_signatures)<CR>',
\
\ 'a': ':call <SID>NM_show_archive_thread()<CR>',
\ 'A': ':call <SID>NM_show_mark_read_then_archive_thread()<CR>',
" --- --- search screen action functions {{{2
-function! s:NM_search_show_thread()
- let id = <SID>NM_search_thread_id()
- if id != ''
- let words = [id]
- if exists('b:nm_search_words')
- let words = ['('] + b:nm_search_words + [')', 'AND', id]
- endif
- if len(words)
- call <SID>NM_cmd_show(words)
- endif
+function! s:NM_search_show_thread(everything)
+ let words = [ <SID>NM_search_thread_id() ]
+ if !a:everything && exists('b:nm_search_words')
+ call extend(words, ['AND', '('])
+ call extend(words, b:nm_search_words)
+ call add(words, ')')
endif
+ call <SID>NM_cmd_show(words)
+ let b:nm_show_everything = a:everything
endfunction
function! s:NM_search_prompt()
endfunction
function! s:NM_search_reply_to_thread()
- echo 'not implemented'
+ let cmd = ['reply']
+ call add(cmd, <SID>NM_search_thread_id())
+ call add(cmd, 'AND')
+ call extend(cmd, <SID>NM_get_search_words())
+
+ let data = <SID>NM_run(cmd)
+ let lines = split(data, "\n")
+ call <SID>NM_newComposeBuffer(lines, 0)
endfunction
function! s:NM_search_add_tags(tags)
function! s:NM_cmd_show(words)
let prev_bufnr = bufnr('%')
- let data = s:NM_run(['show'] + a:words)
+ let data = s:NM_run(['show', '--entire-thread'] + a:words)
let lines = split(data, "\n")
let info = s:NM_cmd_show_parse(lines)
endfunction
function! s:NM_show_previous(can_change_thread, find_matching)
+ let everything = exists('b:nm_show_everything') ? b:nm_show_everything : 0
let info = b:nm_raw_info
let lnum = line('.')
for msg in reverse(copy(info['msgs']))
call <SID>NM_kill_this_buffer()
if line('.') > 1
norm k
- call <SID>NM_search_show_thread()
+ call <SID>NM_search_show_thread(everything)
norm G
call <SID>NM_show_previous(0, a:find_matching)
else
endfunction
function! s:NM_show_next_thread()
+ let everything = exists('b:nm_show_everything') ? b:nm_show_everything : 0
call <SID>NM_kill_this_buffer()
if line('.') != line('$')
norm j
- call <SID>NM_search_show_thread()
+ call <SID>NM_search_show_thread(everything)
else
echo 'No more messages.'
endif
endfunction
function! s:NM_show_reply()
- echo 'not implemented'
+ let cmd = ['reply']
+ call add(cmd, <SID>NM_show_message_id())
+ call add(cmd, 'AND')
+ call extend(cmd, <SID>NM_get_search_words())
+
+ let data = <SID>NM_run(cmd)
+ let lines = split(data, "\n")
+ call <SID>NM_newComposeBuffer(lines, 0)
endfunction
function! s:NM_show_view_all_mime_parts()
let act = 'close'
endif
for fld in info['folds']
- if fld[0] == a:type
- exec printf('%dfold%s', fld[1], act)
+ if fld[0] != a:type
+ continue
endif
+ "let idx = fld[3]
+ "let msg = info['msgs'][idx]
+ "if has_key(msg,'match') && msg['match'] == '0'
+ " continue
+ "endif
+ let cls = foldclosed(fld[1])
+ if cls != -1 && cls != fld[1]
+ continue
+ endif
+ exec printf('%dfold%s', fld[1], act)
endfor
exec printf('nnoremap <buffer> %s :call <SID>NM_show_fold_toggle(''%s'', ''%s'', %d)<CR>', a:key, a:key, a:type, !a:fold)
endfunction
" --- implement compose screen {{{1
function! s:NM_cmd_compose(words, body_lines)
- let lines = !g:notmuch_compose_header_help ? [] : [
- \ 'Notmuch-Help: Type in your message here; to help you use these bindings:',
- \ 'Notmuch-Help: ,a - attach a file',
- \ 'Notmuch-Help: ,s - send the message (Notmuch-Help lines will be removed)',
- \ 'Notmuch-Help: ,q - abort the message',
- \ 'Notmuch-Help: <Tab> - skip through header lines',
- \ ]
+ let lines = []
let start_on_line = 0
let hdrs = { }
endif
endfor
- call extend(lines, [ '', '' ])
+ call add(lines, '')
if !start_on_line
let start_on_line = len(lines) + 1
endif
if len(a:body_lines)
call extend(lines, a:body_lines)
else
- call add(lines, '')
+ call extend(lines, [ '', '' ])
endif
- call extend(lines, g:notmuch_signature)
-
- let prev_bufnr = bufnr('%')
- setlocal bufhidden=hide
- call <SID>NM_newFileBuffer(g:notmuch_compose_temp_file_dir, '%s.mail',
- \ 'compose', lines)
- setlocal bufhidden=hide
- let b:nm_prev_bufnr = prev_bufnr
- call <SID>NM_set_map('n', g:notmuch_compose_nmaps)
- call <SID>NM_set_map('i', g:notmuch_compose_imaps)
-
- call cursor(start_on_line, strlen(start_on_line) + 1)
- if g:notmuch_compose_insert_mode_start
- startinsert!
- endif
- echo 'Type your message, use <TAB> to jump to next header and then body.'
+ call <SID>NM_newComposeBuffer(lines, start_on_line)
endfunction
function! s:NM_compose_send()
let lnum = lnum + 1
let line = getline(lnum)
endwhile
- let body_starts = lnum + 1
- exec printf('0,%dd', body_starts)
- write
+ let body_starts = lnum
"[-a header] [-b bcc-addr] [-c cc-addr] [-s subject] to-addr
let cmd = ['mail']
endfor
call extend(cmd, tos)
+ " TODO: make sure we have at least one target
+ " TODO: ask about empty jubject, etc
+
+ exec printf('0,%dd', body_starts)
+ write
+
call map(cmd, 's:NM_shell_escape(v:val)')
let cmdtxt = join(cmd) . '< ' . fname
let out = system(cmdtxt)
let b:nm_type = a:type
endfunction
+function! s:NM_newComposeBuffer(lines, start_on_line)
+ let lines = a:lines
+ let start_on_line = a:start_on_line
+ let real_hdr_start = 1
+ if g:notmuch_compose_header_help
+ let help_lines = [
+ \ 'Notmuch-Help: Type in your message here; to help you use these bindings:',
+ \ 'Notmuch-Help: ,a - attach a file',
+ \ 'Notmuch-Help: ,s - send the message (Notmuch-Help lines will be removed)',
+ \ 'Notmuch-Help: ,q - abort the message',
+ \ 'Notmuch-Help: <Tab> - skip through header lines',
+ \ ]
+ call extend(lines, help_lines, 0)
+ let real_hdr_start = len(help_lines)
+ if start_on_line > 0
+ let start_on_line = start_on_line + len(help_lines)
+ endif
+ endif
+ call extend(lines, g:notmuch_signature)
+
+
+ let prev_bufnr = bufnr('%')
+ setlocal bufhidden=hide
+ call <SID>NM_newFileBuffer(g:notmuch_compose_temp_file_dir, '%s.mail',
+ \ 'compose', lines)
+ setlocal bufhidden=hide
+ let b:nm_prev_bufnr = prev_bufnr
+
+ call <SID>NM_set_map('n', g:notmuch_compose_nmaps)
+ call <SID>NM_set_map('i', g:notmuch_compose_imaps)
+
+ if start_on_line > 0 && start_on_line <= len(lines)
+ call cursor(start_on_line, strlen(getline(start_on_line)) + 1)
+ else
+ call cursor(real_hdr_start, strlen(getline(real_hdr_start)) + 1)
+ call <SID>NM_compose_next_entry_area()
+ endif
+
+ if g:notmuch_compose_insert_mode_start
+ startinsert!
+ endif
+ echo 'Type your message, use <TAB> to jump to next header and then body.'
+endfunction
+
function! s:NM_assert_buffer_type(type)
if !exists('b:nm_type') || b:nm_type != a:type
throw printf('Eeek! expected type %s, but got %s.', a:type,
" --- external mail handling helpers {{{1
function! s:NM_new_mail()
- echo 'not implemented'
+ call <SID>NM_cmd_compose([], [])
endfunction
" --- tag manipulation helpers {{{1