+" --- --- search screen action functions {{{2
+
+function! s:NM_search_show_thread()
+ let id = <SID>NM_search_find_thread_id()
+ if id != ''
+ call <SID>NM_cmd_show([id])
+ endif
+endfunction
+
+function! s:NM_search_prompt()
+ " TODO: input() can support completion
+ let text = input('NotMuch Search: ')
+ if strlen(text)
+ let tags = split(text)
+ else
+ let tags = s:notmuch_initial_search_words_defaults
+ endif
+ setlocal bufhidden=delete
+ call <SID>NM_cmd_search(tags)
+endfunction
+
+function! s:NM_search_edit()
+ " TODO: input() can support completion
+ let text = input('NotMuch Search: ', join(b:nm_search_words, ' '))
+ if strlen(text)
+ call <SID>NM_cmd_search(split(text))
+ endif
+endfunction
+
+function! s:NM_search_archive_thread()
+ call <SID>NM_add_remove_tags('-', ['inbox'])
+ " TODO: this could be made better and more generic
+ setlocal modifiable
+ s/(\([^)]*\)\<inbox\>\([^)]*\))$/(\1\2)/
+ setlocal nomodifiable
+ norm j
+endfunction
+
+function! s:NM_search_filter()
+ call <SID>NM_search_filter_helper('Filter: ', '')
+endfunction
+
+function! s:NM_search_filter_by_tag()
+ call <SID>NM_search_filter_helper('Filter Tag(s): ', 'tag:')
+endfunction
+
+function! s:NM_search_filter_helper(prompt, prefix)
+ " TODO: input() can support completion
+ let text = input(a:prompt)
+ if !strlen(text)
+ return
+ endif
+
+ let tags = split(text)
+ map(tags, 'a:prefix . v:val')
+ let tags = b:nm_search_words + tags
+ echo tags
+
+ let prev_bufnr = bufnr('%')
+ setlocal bufhidden=hide
+ call <SID>NM_cmd_search(tags)
+ setlocal bufhidden=delete
+ let b:nm_prev_bufnr = prev_bufnr
+endfunction
+
+function! s:NM_new_mail()
+ echoe 'Not implemented'
+endfunction
+
+function! s:NM_search_toggle_order()
+ let g:notmuch_search_newest_first = !g:notmuch_search_newest_first
+ " FIXME: maybe this would be better done w/o reading re-reading the lines
+ " reversing the b:nm_raw_lines and the buffer lines would be better
+ call <SID>NM_search_refresh_view()
+endfunction
+
+function! s:NM_search_reply_to_thread()
+ echoe 'Not implemented'
+endfunction
+
+function! s:NM_search_add_tags(tags)
+ call <SID>NM_search_add_remove_tags('Add Tag(s): ', '+', a:tags)
+endfunction
+
+function! s:NM_search_remove_tags(tags)
+ call <SID>NM_search_add_remove_tags('Remove Tag(s): ', '-', a:tags)
+endfunction
+
+function! s:NM_search_refresh_view()
+ let lno = line('.')
+ setlocal bufhidden=delete
+ call <SID>NM_cmd_search(b:nm_search_words)
+ " FIXME: should find the line of the thread we were on if possible
+ exec printf('norm %dG', lno)
+endfunction
+
+" --- --- search screen helper functions {{{2
+
+function! s:NM_search_find_thread_id()