* [PATCH] VIM: Use notmuch CLI for config
@ 2014-10-02 21:53 Ian Main
2014-10-02 23:47 ` [PATCH v2] " Ian Main
0 siblings, 1 reply; 9+ messages in thread
From: Ian Main @ 2014-10-02 21:53 UTC (permalink / raw)
To: notmuch
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
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2] VIM: Use notmuch CLI for config
2014-10-02 21:53 [PATCH] VIM: Use notmuch CLI for config Ian Main
@ 2014-10-02 23:47 ` Ian Main
2014-10-03 6:54 ` David Bremner
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: Ian Main @ 2014-10-02 23:47 UTC (permalink / raw)
To: notmuch
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
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v2] VIM: Use notmuch CLI for config
2014-10-02 23:47 ` [PATCH v2] " Ian Main
@ 2014-10-03 6:54 ` David Bremner
2014-10-03 10:50 ` Sergei Shilovsky
2014-10-03 18:41 ` Ian Main
2014-10-10 9:32 ` Franz Fellner
` (2 subsequent siblings)
3 siblings, 2 replies; 9+ messages in thread
From: David Bremner @ 2014-10-03 6:54 UTC (permalink / raw)
To: Ian Main, notmuch
Ian Main <imain@stemwinder.org> writes:
> 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
The general approach seems sane; it seems quite brittle to read the
config file directly. I notice there is not really any error handling;
OTOH, as far as I can read Ruby, there is not any in the previous
version either. Technically, this does add a dependency of the vim
client on the CLI that did not exist before. Personally I don't find
this onerous (even notmuch-vim users need "notmuch new", except in
rather unusual circumstances.).
I'd like feedback/testing from actual vim interface users before
merging.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2] VIM: Use notmuch CLI for config
2014-10-03 6:54 ` David Bremner
@ 2014-10-03 10:50 ` Sergei Shilovsky
2014-10-03 18:41 ` Ian Main
1 sibling, 0 replies; 9+ messages in thread
From: Sergei Shilovsky @ 2014-10-03 10:50 UTC (permalink / raw)
To: David Bremner; +Cc: notmuch
The patch works fine for me.
Ian, though I could not test whether result='' matters or not, cause
'notmuch get' looks to always return a string.
It also fixes id:CAHc2pO19AZabAiJhdfQR1rL5t0GufLAq5cKb_7w-Z8y+JXT5+g@mail.gmail.com
On Fri, Oct 3, 2014 at 10:54 AM, David Bremner <david@tethera.net> wrote:
> Ian Main <imain@stemwinder.org> writes:
>
>> 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
>
> The general approach seems sane; it seems quite brittle to read the
> config file directly. I notice there is not really any error handling;
> OTOH, as far as I can read Ruby, there is not any in the previous
> version either. Technically, this does add a dependency of the vim
> client on the CLI that did not exist before. Personally I don't find
> this onerous (even notmuch-vim users need "notmuch new", except in
> rather unusual circumstances.).
>
> I'd like feedback/testing from actual vim interface users before
> merging.
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch
--
С уважением,
Сергей Шиловский
Sergei Shilovsky
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2] VIM: Use notmuch CLI for config
2014-10-03 6:54 ` David Bremner
2014-10-03 10:50 ` Sergei Shilovsky
@ 2014-10-03 18:41 ` Ian Main
1 sibling, 0 replies; 9+ messages in thread
From: Ian Main @ 2014-10-03 18:41 UTC (permalink / raw)
To: David Bremner, David Bremner, notmuch
David Bremner wrote:
> Ian Main <imain@stemwinder.org> writes:
>
> > 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
>
> The general approach seems sane; it seems quite brittle to read the
> config file directly. I notice there is not really any error handling;
> OTOH, as far as I can read Ruby, there is not any in the previous
> version either. Technically, this does add a dependency of the vim
> client on the CLI that did not exist before. Personally I don't find
> this onerous (even notmuch-vim users need "notmuch new", except in
> rather unusual circumstances.).
>
> I'd like feedback/testing from actual vim interface users before
> merging.
I am actually just following suit on what was already being done.
The Vim client was already calling out to notmuch CLI for other things,
eg:
system "notmuch show --format=mbox id:#{m.message_id} > #{mbox} && #{cmd}"
Is used to save the email for display in another program. Also with no
error checking. I think basically we are relying on rubys exception handling
to display errors to the user.. not the best idea but it is functional.
I could add a check for 'notmuch' binary.. especially there because loading
the config is the first thing that is done on startup.
Ian
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2] VIM: Use notmuch CLI for config
2014-10-02 23:47 ` [PATCH v2] " Ian Main
2014-10-03 6:54 ` David Bremner
@ 2014-10-10 9:32 ` Franz Fellner
2014-10-19 18:11 ` David Bremner
2014-10-21 8:31 ` David Bremner
3 siblings, 0 replies; 9+ messages in thread
From: Franz Fellner @ 2014-10-10 9:32 UTC (permalink / raw)
To: notmuch
On Thu, 2 Oct 2014 16:47:15 -0700, Ian Main <imain@stemwinder.org> wrote:
> 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')
Just wanted to note that you read user.name twice.
> $email = "%s <%s>" % [$email_name, $email_address]
This is not related to this patch:
I don't know if it is a good idea to force $email_name on every
$email_address. Maybe use it as a fallback and introduce an optional
mailaddress-sendername map. So the user can specify which name should be
used. (Imagine a "Dr." who wants to have "Dr. P. Harmony" for his official
mails, but "Phil Harmony" for private ones. Or a writer who uses several
psudonyms.)
Maybe this can be solved by the sendmail application, but probably
that requires leaving out email_name entirely. Will setup a test env
later to evaluate.
> end
>
> --
> 1.9.3
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2] VIM: Use notmuch CLI for config
2014-10-02 23:47 ` [PATCH v2] " Ian Main
2014-10-03 6:54 ` David Bremner
2014-10-10 9:32 ` Franz Fellner
@ 2014-10-19 18:11 ` David Bremner
2014-10-20 17:47 ` Ian Main
2014-10-21 8:31 ` David Bremner
3 siblings, 1 reply; 9+ messages in thread
From: David Bremner @ 2014-10-19 18:11 UTC (permalink / raw)
To: Felipe Contreras; +Cc: notmuch
Ian Main <imain@stemwinder.org> writes:
> 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
We're starting to get a few notmuch-vim patches ready at
http://nmbug.tethera.net/status/#Maybe-Ready-vim-
Unless Felipe convinces me otherwise, I'll start merging these into
notmuch master in the next few days.
d
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2] VIM: Use notmuch CLI for config
2014-10-19 18:11 ` David Bremner
@ 2014-10-20 17:47 ` Ian Main
0 siblings, 0 replies; 9+ messages in thread
From: Ian Main @ 2014-10-20 17:47 UTC (permalink / raw)
To: David Bremner; +Cc: notmuch
David Bremner wrote:
> Ian Main <imain@stemwinder.org> writes:
>
> > 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
>
> We're starting to get a few notmuch-vim patches ready at
>
> http://nmbug.tethera.net/status/#Maybe-Ready-vim-
>
> Unless Felipe convinces me otherwise, I'll start merging these into
> notmuch master in the next few days.
>
> d
That's great! Thanks David.
I think the 'Make patch saving in vim a little better.' patch set
should go in soon too as it actually fixes a bug (patch saving causes a
backtrace right now).
Ian
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2] VIM: Use notmuch CLI for config
2014-10-02 23:47 ` [PATCH v2] " Ian Main
` (2 preceding siblings ...)
2014-10-19 18:11 ` David Bremner
@ 2014-10-21 8:31 ` David Bremner
3 siblings, 0 replies; 9+ messages in thread
From: David Bremner @ 2014-10-21 8:31 UTC (permalink / raw)
To: Ian Main, notmuch
Ian Main <imain@stemwinder.org> writes:
> 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.
pushed
d
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2014-10-21 8:31 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-02 21:53 [PATCH] VIM: Use notmuch CLI for config Ian Main
2014-10-02 23:47 ` [PATCH v2] " Ian Main
2014-10-03 6:54 ` David Bremner
2014-10-03 10:50 ` Sergei Shilovsky
2014-10-03 18:41 ` Ian Main
2014-10-10 9:32 ` Franz Fellner
2014-10-19 18:11 ` David Bremner
2014-10-20 17:47 ` Ian Main
2014-10-21 8:31 ` David Bremner
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).