VIM: Use notmuch CLI for config
authorIan Main <imain@stemwinder.org>
Thu, 2 Oct 2014 23:47:15 +0000 (16:47 -0700)
committerDavid Bremner <david@tethera.net>
Tue, 21 Oct 2014 08:22:44 +0000 (10:22 +0200)
This patch switches from reading .notmuch-config directly to using
the CLI the same way that emacs does it.  It actually uses less code
and is probably less error prone.

    Ian

vim/notmuch.vim

index 331e9300842b1ef62f0cc62baacdaf64da7ffe46..b251af6ee27937898f3e9716ae3a4db7affbe82c 100644 (file)
@@ -471,28 +471,21 @@ ruby << EOF
        $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]
        end