]> git.notmuchmail.org Git - notmuch/blobdiff - vim/notmuch.vim
emacs: Add new option notmuch-search-hide-excluded
[notmuch] / vim / notmuch.vim
index 331e9300842b1ef62f0cc62baacdaf64da7ffe46..c1c2f63d20178dab69f92c9ff9aab4631dda6ee5 100644 (file)
@@ -59,6 +59,7 @@ let s:notmuch_datetime_format_default = '%d.%m.%y %H:%M:%S'
 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
 
 function! s:new_file_buffer(type, fname)
        exec printf('edit %s', a:fname)
@@ -132,7 +133,9 @@ function! s:show_reply()
        let b:compose_done = 0
        call s:set_map(g:notmuch_compose_maps)
        autocmd BufDelete <buffer> call s:on_compose_delete()
-       startinsert!
+       if g:notmuch_compose_start_insert
+               startinsert!
+       end
 endfunction
 
 function! s:compose()
@@ -140,7 +143,9 @@ function! s:compose()
        let b:compose_done = 0
        call s:set_map(g:notmuch_compose_maps)
        autocmd BufDelete <buffer> call s:on_compose_delete()
-       startinsert!
+       if g:notmuch_compose_start_insert
+               startinsert!
+       end
 endfunction
 
 function! s:show_info()
@@ -312,6 +317,9 @@ ruby << EOF
        $curbuf.render do |b|
                q = $curbuf.query(get_cur_view)
                q.sort = Notmuch::SORT_OLDEST_FIRST
+               $exclude_tags.each { |t|
+                       q.add_tag_exclude(t)
+               }
                msgs = q.search_messages
                msgs.each do |msg|
                        m = Mail.read(msg.filename)
@@ -428,6 +436,10 @@ function! s:set_defaults()
                endif
        endif
 
+       if !exists('g:notmuch_compose_start_insert')
+               let g:notmuch_compose_start_insert = s:notmuch_compose_start_insert_default
+       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
@@ -468,32 +480,28 @@ ruby << EOF
 
        $db_name = nil
        $email = $email_name = $email_address = nil
+       $exclude_tags = []
        $searches = []
        $threads = []
        $messages = []
-       $config = {}
        $mail_installed = defined?(Mail)
 
-       def get_config
-               group = nil
-               config = ENV['NOTMUCH_CONFIG'] || '~/.notmuch-config'
-               File.open(File.expand_path(config)).each do |l|
-                       l.chomp!
-                       case l
-                       when /^\[(.*)\]$/
-                               group = $1
-                       when ''
-                       when /^(.*)=(.*)$/
-                               key = "%s.%s" % [group, $1]
-                               value = $2
-                               $config[key] = value
-                       end
-               end
+       def get_config_item(item)
+               result = ''
+               IO.popen(['notmuch', 'config', 'get', item]) { |out|
+                       result = out.read
+               }
+               return result.rstrip
+       end
 
-               $db_name = $config['database.path']
-               $email_name = $config['user.name']
-               $email_address = $config['user.primary_email']
+       def get_config
+               $db_name = get_config_item('database.path')
+               $email_name = get_config_item('user.name')
+               $email_address = get_config_item('user.primary_email')
+               $email_name = get_config_item('user.name')
                $email = "%s <%s>" % [$email_name, $email_address]
+               ignore_tags = get_config_item('search.exclude_tags')
+               $exclude_tags = ignore_tags.split("\n")
        end
 
        def vim_puts(s)
@@ -635,8 +643,11 @@ ruby << EOF
                        $searches.clear
                        folders.each do |name, search|
                                q = $curbuf.query(search)
+                               $exclude_tags.each { |t|
+                                       q.add_tag_exclude(t)
+                               }
                                $searches << search
-                               count = count_threads ? q.search_threads.count : q.search_messages.count
+                               count = count_threads ? q.count_threads : q.count_messages
                                b << "%9d %-20s (%s)" % [count, name, search]
                        end
                end
@@ -646,6 +657,9 @@ ruby << EOF
                date_fmt = VIM::evaluate('g:notmuch_date_format')
                q = $curbuf.query(search)
                q.sort = Notmuch::SORT_NEWEST_FIRST
+               $exclude_tags.each { |t|
+                       q.add_tag_exclude(t)
+               }
                $threads.clear
                t = q.search_threads
 
@@ -655,7 +669,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