From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id A653C431FBC for ; Thu, 2 Oct 2014 16:47:30 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_NONE=-0.0001] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id yMWWguEOmANw for ; Thu, 2 Oct 2014 16:47:25 -0700 (PDT) Received: from cmta18.telus.net (cmta18.telus.net [209.171.16.91]) by olra.theworths.org (Postfix) with ESMTP id 10CF6431FB6 for ; Thu, 2 Oct 2014 16:47:24 -0700 (PDT) Received: from ovo.mains.priv ([207.102.88.62]) by cmta18.telus.net with TELUS id yPnP1o0061LiWEf01PnPx4; Thu, 02 Oct 2014 17:47:24 -0600 X-Authority-Analysis: v=2.0 cv=GdvJa3rL c=1 sm=2 a=EcQDfIwDZEqJA1f7rVUV8Q==:17 a=S-IsBHyFrF4A:10 a=tsa3CZZnAAAA:8 a=lnbEfRDau6mwN6_a2jMA:9 a=uq6gwDkGiqMBWQl4:21 a=EZkrjcdb60U0uwMN:21 a=EcQDfIwDZEqJA1f7rVUV8Q==:117 X-Telus-Outbound-IP: 207.102.88.62 From: Ian Main To: notmuch@notmuchmail.org Subject: [PATCH v2] VIM: Use notmuch CLI for config Date: Thu, 2 Oct 2014 16:47:15 -0700 Message-Id: <1412293635-31273-1-git-send-email-imain@stemwinder.org> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1412286796-27479-1-git-send-email-imain@stemwinder.org> References: <1412286796-27479-1-git-send-email-imain@stemwinder.org> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Oct 2014 23:47:30 -0000 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 --- This update changes result to be '' instead of nil by default so missing config items won't cause an error. vim/notmuch.vim | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/vim/notmuch.vim b/vim/notmuch.vim index 331e930..b251af6 100644 --- a/vim/notmuch.vim +++ b/vim/notmuch.vim @@ -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 -- 1.9.3