Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 46496431FBC for ; Thu, 2 Oct 2014 14:53:25 -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 6Ua3J8oc4B9E for ; Thu, 2 Oct 2014 14:53:19 -0700 (PDT) Received: from cmta3.telus.net (cmta3.telus.net [209.171.16.76]) by olra.theworths.org (Postfix) with ESMTP id 8A207431FB6 for ; Thu, 2 Oct 2014 14:53:19 -0700 (PDT) Received: from ovo.mains.priv ([207.102.88.62]) by cmta3.telus.net with TELUS id yMtJ1o00Y1LiWEf01MtJqG; Thu, 02 Oct 2014 15:53:19 -0600 X-Authority-Analysis: v=2.0 cv=GePJa3rL c=1 sm=2 a=EcQDfIwDZEqJA1f7rVUV8Q==:17 a=S-IsBHyFrF4A:10 a=tsa3CZZnAAAA:8 a=lnbEfRDau6mwN6_a2jMA:9 a=982h0VeBkKRggbAd:21 a=CmYvmRXf5uR-RLfk:21 a=EcQDfIwDZEqJA1f7rVUV8Q==:117 X-Telus-Outbound-IP: 207.102.88.62 From: Ian Main To: notmuch@notmuchmail.org Subject: [PATCH] VIM: Use notmuch CLI for config Date: Thu, 2 Oct 2014 14:53:16 -0700 Message-Id: <1412286796-27479-1-git-send-email-imain@stemwinder.org> X-Mailer: git-send-email 1.9.3 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 21:53:25 -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 --- vim/notmuch.vim | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/vim/notmuch.vim b/vim/notmuch.vim index 331e930..faee3d2 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 = nil + 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