patches to mutt-notmuch

Scott Barker scott at mostlylinux.ca
Fri Feb 10 13:58:35 PST 2012


I have recently switched from using mutt + maildir-utils (mu) for searching
my email to using mutt + notmuch. I made use of the mutt-notmuch perl script
by Stefano Zacchiroli to integrate mutt and notmuch. You can find it at:
http://upsilon.cc/~zack/blog/posts/2011/01/how_to_use_Notmuch_with_Mutt

I have written a few patches (attached to this email) to extend the
functionality of Stefano's script, as follows:

  mutt-notmuch-readline.diffs
    This patch makes mutt-notmuch use Term::ReadLine::GNU instead of reading
    directly from STDIN.

  mutt-notmuch-prompt-and-commandline-search-params.diffs
    This patch uses the readline PREPUT functionality to pre-populate the
    readline string with any search terms from the command line.

  mutt-notmuch-mutt-folder-cleanup.diffs
    This patch just removes the "=" from folder names as used in mutt, so
    that the following can be made to work:

      folder-hook . 'set my_oldrecord=$record; set record=^; set my_folder=$record; set record=$my_oldrecord; macro index <F7> "<enter-command>unset wait_key<enter><shell-escape>~/bin/mutt-notmuch --prompt search folder:$my_folder<enter><change-folder-readonly>~/.cache/mutt_results<enter>" "search $my_folder (using notmuch)"'

Hopefully other people will find these patches of use as well.

PS - any word on whether mutt-notmuch will be included with notmuch, as
mentioned in Debian bug # 628018?
(see http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=628018)

-- 
Scott Barker
Linux Consultant
scott at mostlylinux.ca
http://www.mostlylinux.ca
-------------- next part --------------
--- mutt-notmuch.old	2012-02-10 13:45:42.519241832 -0700
+++ mutt-notmuch	2012-02-10 14:21:06.835802055 -0700
@@ -16,6 +16,7 @@
 use Mail::Internet;
 use Mail::Box::Maildir;
 use Pod::Usage;
+use Term::ReadLine;
 
 
 # create an empty maildir (if missing) or empty an existing maildir"
@@ -41,12 +42,24 @@
 sub prompt($) {
     my ($text) = @_;
     my $query = "";
+    my $term = Term::ReadLine->new( "mutt-notmuch" );
+    $term->ornaments( 0 );
+    $term->unbind_key( ord( "\t" ) );
+    $term->MinLine( 3 );
+    if ($ENV{MUTT_NOTMUCH_HISTFILE} && -r "$ENV{MUTT_NOTMUCH_HISTFILE}") {
+      $term->ReadHistory("$ENV{MUTT_NOTMUCH_HISTFILE}");
+    } elsif (-r "$ENV{HOME}/.mutt-notmuch.history") {
+      $term->ReadHistory("$ENV{HOME}/.mutt-notmuch.history");
+    }
     while (1) {
-	print $text;
-	chomp($query = <STDIN>);
+	chomp($query = $term->readline($text));
 	if ($query eq "?") {
 	    system("man notmuch");
 	} else {
+       if (!$ENV{MUTT_NOTMUCH_HISTFILE} ||
+           !$term->WriteHistory("$ENV{MUTT_NOTMUCH_HISTFILE}")) {
+         $term->WriteHistory("$ENV{HOME}/.mutt-notmuch.history");
+       }
 	    return $query;
 	}
     }
-------------- next part --------------
--- mutt-notmuch	2012-02-10 14:21:06.835802055 -0700
+++ mutt-notmuch.new	2012-02-10 14:20:49.732441826 -0700
@@ -39,8 +39,8 @@
 	   . " | xargs --no-run-if-empty ln -s -t $maildir/cur/");
 }
 
-sub prompt($) {
-    my ($text) = @_;
+sub prompt($$) {
+    my ($text, $default) = @_;
     my $query = "";
     my $term = Term::ReadLine->new( "mutt-notmuch" );
     $term->ornaments( 0 );
@@ -52,7 +52,7 @@
       $term->ReadHistory("$ENV{HOME}/.mutt-notmuch.history");
     }
     while (1) {
-	chomp($query = $term->readline($text));
+	chomp($query = $term->readline($text, $default));
 	if ($query eq "?") {
 	    system("man notmuch");
 	} else {
@@ -77,7 +77,7 @@
     if (! $interactive) {
 	search($results_dir, join(' ', @params));
     } else {
-	my $query = prompt("search ('?' for man): ");
+	my $query = prompt("search ('?' for man): ", join(' ', @params));
 	if ($query ne "") {
 	    search($results_dir,$query);
 	}
-------------- next part --------------
--- mutt-notmuch	2012-02-10 14:21:06.835802055 -0700
+++ mutt-notmuch.new	2012-02-10 14:20:49.732441826 -0700
@@ -117,6 +117,10 @@
     if (! $getopt || $#ARGV < 0) { die_usage() };
     my ($action, @params) = ($ARGV[0], @ARGV[1..$#ARGV]);
 
+    foreach my $param (@params) {
+      $param =~ s/folder:=/folder:/g;
+    }
+
     if ($help_needed) {
 	die_usage();
     } elsif ($action eq "search" && $#ARGV == 0 && ! $interactive) {


More information about the notmuch mailing list