[gnus git] branch master updated: n0-17-167-g392690f =1= Add the new nnir `notmuch' backend.

Lars Magne Ingebrigtsen <[email protected]>
Newsgroups gmane.emacs.gnus.cvs
Message-ID <[email protected]>
       via  392690f0c83ff0697a48691ec4e81a4d91d7577c (commit)
      from  1df0dc47f4fb731afe03347f65cd0358fca24ef7 (commit)


- Log -----------------------------------------------------------------
commit 392690f0c83ff0697a48691ec4e81a4d91d7577c
Author: Kan-Ru Chen <[email protected]>
Date:   Tue Jul 5 22:22:13 2011 +0200

    Add the new nnir `notmuch' backend.
    
    * nnir.el (nnir-notmuch-program, nnir-notmuch-additional-switches)
    (nnir-notmuch-remove-prefix, nnir-engines, nnir-run-notmuch): New nnir
    `notmuch' backend.

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 5a093c0..1085051 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,9 @@
+2011-04-03  Kan-Ru Chen  <[email protected]>
+
+	* nnir.el (nnir-notmuch-program, nnir-notmuch-additional-switches)
+	(nnir-notmuch-remove-prefix, nnir-engines, nnir-run-notmuch): New nnir
+	`notmuch' backend.
+
 2011-07-05  Lars Magne Ingebrigtsen  <[email protected]>
 
 	* mm-decode.el (mm-text-html-renderer): Doc fix.
diff --git a/lisp/nnir.el b/lisp/nnir.el
index 71b8518..8099cc2 100644
--- a/lisp/nnir.el
+++ b/lisp/nnir.el
@@ -499,6 +499,31 @@ arrive at the correct group name, \"mail.misc\"."
   :type '(directory)
   :group 'nnir)
 
+(defcustom nnir-notmuch-program "notmuch"
+  "*Name of notmuch search executable."
+  :type '(string)
+  :group 'nnir)
+
+(defcustom nnir-notmuch-additional-switches '()
+  "*A list of strings, to be given as additional arguments to notmuch.
+
+Note that this should be a list.  Ie, do NOT use the following:
+    (setq nnir-notmuch-additional-switches \"-i -w\") ; wrong
+Instead, use this:
+    (setq nnir-notmuch-additional-switches '(\"-i\" \"-w\"))"
+  :type '(repeat (string))
+  :group 'nnir)
+
+(defcustom nnir-notmuch-remove-prefix (concat (getenv "HOME") "/Mail/")
+  "*The prefix to remove from each file name returned by notmuch
+in order to get a group name (albeit with / instead of .).  This is a
+regular expression.
+
+This variable is very similar to `nnir-namazu-remove-prefix', except
+that it is for notmuch, not Namazu."
+  :type '(regexp)
+  :group 'nnir)
+
 ;;; Developer Extension Variable:
 
 (defvar nnir-engines
@@ -519,6 +544,8 @@ arrive at the correct group name, \"mail.misc\"."
              ((group . "Swish-e Group spec: ")))
     (namazu  nnir-run-namazu
              ())
+    (notmuch nnir-run-notmuch
+             ())
     (hyrex   nnir-run-hyrex
 	     ((group . "Hyrex Group spec: ")))
     (find-grep nnir-run-find-grep
@@ -1338,6 +1365,80 @@ Tested with Namazu 2.0.6 on a GNU/Linux system."
                                (> (nnir-artitem-rsv x)
                                   (nnir-artitem-rsv y)))))))))
 
+(defun nnir-run-notmuch (query server &optional group)
+  "Run QUERY against notmuch.
+Returns a vector of (group name, file name) pairs (also vectors,
+actually)."
+
+  ;; (when group
+  ;;   (error "The notmuch backend cannot search specific groups"))
+
+  (save-excursion
+    (let ( (qstring (cdr (assq 'query query)))
+	   (groupspec (cdr (assq 'group query)))
+	   (prefix (nnir-read-server-parm 'nnir-notmuch-remove-prefix server))
+           artlist
+           (article-pattern (if (string= (gnus-group-server server) "nnmaildir")
+			       ":[0-9]+"
+			     "^[0-9]+$"))
+           artno dirnam filenam)
+
+      (when (equal "" qstring)
+        (error "notmuch: You didn't enter anything"))
+
+      (set-buffer (get-buffer-create nnir-tmp-buffer))
+      (erase-buffer)
+
+      (if groupspec
+          (message "Doing notmuch query %s on %s..." qstring groupspec)
+        (message "Doing notmuch query %s..." qstring))
+
+      (let* ((cp-list `( ,nnir-notmuch-program
+                         nil            ; input from /dev/null
+                         t              ; output
+                         nil            ; don't redisplay
+                         "search"
+                         "--format=text"
+                         "--output=files"
+                         ,@(nnir-read-server-parm 'nnir-notmuch-additional-switches server)
+                         ,qstring       ; the query, in notmuch format
+                         ))
+             (exitstatus
+              (progn
+                (message "%s args: %s" nnir-notmuch-program
+                         (mapconcat 'identity (cddddr cp-list) " ")) ;; ???
+                (apply 'call-process cp-list))))
+        (unless (or (null exitstatus)
+                    (zerop exitstatus))
+          (nnheader-report 'nnir "Couldn't run notmuch: %s" exitstatus)
+          ;; notmuch failure reason is in this buffer, show it if
+          ;; the user wants it.
+          (when (> gnus-verbose 6)
+            (display-buffer nnir-tmp-buffer))))
+
+      ;; The results are output in the format of:
+      ;; absolute-path-name
+      (goto-char (point-min))
+      (while (not (eobp))
+        (setq filenam (buffer-substring-no-properties (line-beginning-position)
+                                                      (line-end-position))
+              artno (file-name-nondirectory filenam)
+              dirnam (file-name-directory filenam))
+        (forward-line 1)
+
+        ;; don't match directories
+        (when (string-match article-pattern artno)
+          (when (not (null dirnam))
+
+	    ;; maybe limit results to matching groups.
+	    (when (or (not groupspec)
+		      (string-match groupspec dirnam))
+	      (nnir-add-result dirnam artno "" prefix server artlist)))))
+
+      (message "Massaging notmuch output...done")
+
+      artlist)))
+
 (defun nnir-run-find-grep (query server &optional grouplist)
   "Run find and grep to obtain matching articles."
   (let* ((method (gnus-server-to-method server))

-----------------------------------------------------------------------
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we listed those
revisions in full, above.

Summary of changes:
 lisp/ChangeLog |    6 +++
 lisp/nnir.el   |  101 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 107 insertions(+), 0 deletions(-)

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Gnus Project".

The branch, master has been updated


hooks/post-receive
-- 
Gnus Project
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.