let b:nm_timestamp = reltime()
call <SID>NM_cmd_folders_mksyntax()
- call <SID>NM_set_map(g:notmuch_folders_maps)
+ call <SID>NM_set_map('n', g:notmuch_folders_maps)
setlocal cursorline
setlocal nowrap
endfunction
let b:nm_search_words = a:words
call <SID>NM_cmd_search_mksyntax()
- call <SID>NM_set_map(g:notmuch_search_maps)
+ call <SID>NM_set_map('n', g:notmuch_search_maps)
setlocal cursorline
setlocal nowrap
endfunction
let tags = s:notmuch_initial_search_words_defaults
endif
let prev_bufnr = bufnr('%')
- if b:nm_type == 'search'
+ if b:nm_type == 'search' && exists('b:nm_prev_bufnr')
" TODO: we intend to replace the current buffer,
" ... maybe we could just clear it
let prev_bufnr = b:nm_prev_bufnr
call <SID>NM_cmd_show_mkfolds()
call <SID>NM_cmd_show_mksyntax()
- call <SID>NM_set_map(g:notmuch_show_maps)
+ call <SID>NM_set_map('n', g:notmuch_show_maps)
setlocal foldtext=NM_cmd_show_foldtext()
setlocal fillchars=
setlocal foldcolumn=6
function! s:NM_newBuffer(type, content)
enew
- setlocal buftype=nofile readonly modifiable
+ setlocal buftype=nofile readonly modifiable scrolloff=0 sidescrolloff=0
silent put=a:content
keepjumps 0d
setlocal nomodifiable
- set scrolloff=0
- set sidescrolloff=0
execute printf('set filetype=notmuch-%s', a:type)
execute printf('set syntax=notmuch-%s', a:type)
let b:nm_type = a:type
return '''' . word . ''''
endfunction
+" this function was taken from git.vim, then fixed up
+" http://github.com/motemen/git-vim
+function! s:NM_shell_split(cmd)
+ let l:split_cmd = []
+ let cmd = a:cmd
+ let iStart = 0
+ while 1
+ let t = match(cmd, '\S', iStart)
+ if t < iStart
+ break
+ endif
+ let iStart = t
+
+ let iSpace = match(cmd, '\v(\s|$)', iStart)
+ if iSpace < iStart
+ break
+ endif
+
+ let iQuote1 = match(cmd, '\(^["'']\|[^\\]\@<=["'']\)', iStart)
+ if iQuote1 > iSpace || iQuote1 < iStart
+ let iEnd = iSpace - 1
+ let l:split_cmd += [ cmd[iStart : iEnd] ]
+ else
+ let q = cmd[iQuote1]
+ let iQuote2 = match(cmd, '[^\\]\@<=[' . q . ']', iQuote1 + 1)
+ if iQuote2 < iQuote1
+ throw 'No matching ' . q . ' quote'
+ endif
+ let iEnd = iQuote2
+ let l:split_cmd += [ cmd[iStart+1 : iEnd-1 ] ]
+ endif
+
+
+ let iStart = iEnd + 1
+ endwhile
+
+ return l:split_cmd
+endfunction
+
+
function! s:NM_run(args)
let words = a:args
call map(words, 's:NM_shell_escape(v:val)')
" --- assign keymaps {{{1
-function! s:NM_set_map(maps)
+function! s:NM_set_map(type, maps)
nmapclear
for [key, code] in items(a:maps)
- exec printf('nnoremap <buffer> %s %s', key, code)
+ exec printf('%snoremap <buffer> %s %s', a:type, key, code)
endfor
" --- this is a hack for development :)
nnoremap ,nmr :source ~/.vim/plugin/notmuch.vim<CR>:call NotMuch('')<CR>
let args = 'folders'
endif
- let words = split(args)
- if words[0] == 'folders'
+ let words = <SID>NM_shell_split(args)
+ if words[0] == 'folders' || words[0] == 'f'
let words = words[1:]
call <SID>NM_cmd_folders(words)
- elseif words[0] == 'search'
+
+ elseif words[0] == 'search' || words[0] == 's'
if len(words) > 1
let words = words[1:]
elseif exists('b:nm_search_words')