[vim] Plugin crashes on certain multi-mime emails

2019-03-22 Thread Nicolas Lesser
For some emails, notmuch-vim crashes. I can't figure out the reason for
this. The stack trace is:

Error detected while processing function
13_search_show_thread[10]..13_show:
line   39:
NoMethodError: undefined method `mime_type' for nil:NilClass
eval:22:in `block (2 levels) in '
eval:8:in `each'
eval:8:in `block in '
eval:323:in `render'
eval:4:in `'
eval:8:in `command'
eval:8:in `'

The error seems to only come up for multi-mime emails, but then also not
all of them. It seems like the error is that find_first_text returns nil,
but that can only happen if the message doesn't have any content-type
"text/plain" or "text/html" AFAICT, but I checked: It does both. GMail
doesn't have any problems reading that same email.

Any ideas? Thanks.

- Nicolas
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


[PATCH] vim: Add shift-tab key binding to go to the previous message.

2019-03-22 Thread Nicolas Lesser
---
 vim/notmuch.txt |  1 +
 vim/notmuch.vim | 15 +++
 2 files changed, 16 insertions(+)

diff --git a/vim/notmuch.txt b/vim/notmuch.txt
index 43741022..5c5d758e 100644
--- a/vim/notmuch.txt
+++ b/vim/notmuch.txt
@@ -77,6 +77,7 @@ p Save patches
 r  Reply
 ?  Show thread information
   Show next message
+ Show previous message
 c  Compose a new mail
 
 --
diff --git a/vim/notmuch.vim b/vim/notmuch.vim
index ad8b7c80..ef40b9ad 100644
--- a/vim/notmuch.vim
+++ b/vim/notmuch.vim
@@ -40,6 +40,7 @@ let g:notmuch_show_maps = {
\ 'r':  'show_reply()',
\ '?':  'show_info()',
\ '':  'show_next_msg()',
+   \ '':'show_prev_msg()',
\ 'c':  'compose()',
\ }
 
@@ -128,6 +129,20 @@ ruby << EOF
 EOF
 endfunction
 
+function! s:show_prev_msg()
+ruby << EOF
+   r, c = $curwin.cursor
+   n = $curbuf.line_number
+   i = $messages.index { |m| n >= m.start && n <= m.end }
+   m = $messages[i - 1]
+   if m
+   r = m.body_start + 1
+   VIM::command("normal #{m.start}zt")
+   $curwin.cursor = r, c
+   end
+EOF
+endfunction
+
 function! s:show_reply()
ruby open_reply get_message.mail
let b:compose_done = 0
-- 
2.21.0

___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


[PATCH] Add an option to hide the saved search query, disabled by default.

2019-03-22 Thread Nicolas Lesser
---
 vim/notmuch.vim | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/vim/notmuch.vim b/vim/notmuch.vim
index ad8b7c80..2c6b471f 100644
--- a/vim/notmuch.vim
+++ b/vim/notmuch.vim
@@ -60,6 +60,7 @@ let s:notmuch_reader_default = 'mutt -f %s'
 let s:notmuch_sendmail_default = 'sendmail'
 let s:notmuch_folders_count_threads_default = 0
 let s:notmuch_compose_start_insert_default = 1
+let s:notmuch_hide_saved_search_query = 0
 
 function! s:new_file_buffer(type, fname)
exec printf('edit %s', a:fname)
@@ -437,6 +438,10 @@ function! s:set_defaults()
let g:notmuch_compose_start_insert = 
s:notmuch_compose_start_insert_default
endif
 
+   if !exists('g:notmuch_hide_saved_search_query')
+   let g:notmuch_hide_saved_search_query = 
s:notmuch_hide_saved_search_query
+   endif
+
if !exists('g:notmuch_custom_search_maps') && 
exists('g:notmuch_rb_custom_search_maps')
let g:notmuch_custom_search_maps = 
g:notmuch_rb_custom_search_maps
endif
@@ -645,7 +650,11 @@ ruby << EOF
}
$searches << search
count = count_threads ? q.count_threads : 
q.count_messages
-   b << "%9d %-20s (%s)" % [count, name, search]
+   if 
VIM::evaluate('g:notmuch_hide_saved_search_query') == 1
+   b << "%9d %-20s" % [count, name]
+   else
+   b << "%9d %-20s (%s)" % [count, name, 
search]
+   end
end
end
end
-- 
2.21.0

___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


[PATCH] vim: Ignore instead of erroring out when trying to perform an action on a non-existent thread.

2019-03-22 Thread Nicolas Lesser
---
 vim/notmuch.vim | 20 +---
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/vim/notmuch.vim b/vim/notmuch.vim
index ad8b7c80..299405f4 100644
--- a/vim/notmuch.vim
+++ b/vim/notmuch.vim
@@ -237,7 +237,11 @@ function! s:search_tag(intags)
else
let tags = a:intags
endif
-   ruby do_tag(get_thread_id, VIM::evaluate('l:tags'))
+ruby << EOF
+   if (id = get_thread_id)
+ do_tag(id, VIM::evaluate('l:tags'))
+   end
+EOF
norm j
 endfunction
 
@@ -354,13 +358,14 @@ endfunction
 function! s:search_show_thread(mode)
 ruby << EOF
mode = VIM::evaluate('a:mode')
-   id = get_thread_id
-   case mode
-   when 0;
-   when 1; $cur_filter = nil
-   when 2; $cur_filter = $cur_search
+   if (id = get_thread_id)
+   case mode
+   when 0;
+   when 1; $cur_filter = nil
+   when 2; $cur_filter = $cur_search
+   end
+   VIM::command("call s:show('#{id}')")
end
-   VIM::command("call s:show('#{id}')")
 EOF
 endfunction
 
@@ -519,6 +524,7 @@ ruby << EOF
end
 
def get_thread_id
+   return nil if $threads.empty?
n = $curbuf.line_number - 1
return "thread:%s" % $threads[n]
end
-- 
2.21.0

___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


[PATCH] vim: Use non-deprecated method parse instead of new.

2019-03-21 Thread Nicolas Lesser
---
 vim/notmuch.vim | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/vim/notmuch.vim b/vim/notmuch.vim
index ad8b7c80..541698cd 100644
--- a/vim/notmuch.vim
+++ b/vim/notmuch.vim
@@ -666,7 +666,7 @@ ruby << EOF
date = Time.at(e.newest_date).strftime(date_fmt)
subject = e.messages.first['subject']
if $mail_installed
-   subject = Mail::Field.new("Subject: " + 
subject).to_s
+   subject = Mail::Field.parse("Subject: " 
+ subject).to_s
else
subject = 
subject.force_encoding('utf-8')
end
-- 
2.21.0

___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch