From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/78324 Path: news.gmane.org!not-for-mail From: Kan-Ru Chen Newsgroups: gmane.emacs.gnus.general Subject: [PATCH 2/2] nnir.el: New `notmuch' backend. Date: Sun, 3 Apr 2011 22:48:25 +0800 Message-ID: <1301842105-18495-2-git-send-email-kanru@kanru.info> References: <1301842105-18495-1-git-send-email-kanru@kanru.info> NNTP-Posting-Host: lo.gmane.org X-Trace: dough.gmane.org 1301842356 14078 80.91.229.12 (3 Apr 2011 14:52:36 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 3 Apr 2011 14:52:36 +0000 (UTC) Cc: Andrew Cohen , Kan-Ru Chen To: ding@gnus.org Original-X-From: ding-owner+M26632@lists.math.uh.edu Sun Apr 03 16:52:31 2011 Return-path: Envelope-to: ding-account@gmane.org Original-Received: from util0.math.uh.edu ([129.7.128.18]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Q6OfG-0003yB-9J for ding-account@gmane.org; Sun, 03 Apr 2011 16:52:30 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.math.uh.edu) by util0.math.uh.edu with smtp (Exim 4.63) (envelope-from ) id 1Q6Oc1-0001f6-UJ; Sun, 03 Apr 2011 09:49:09 -0500 Original-Received: from mx1.math.uh.edu ([129.7.128.32]) by util0.math.uh.edu with esmtps (TLSv1:AES256-SHA:256) (Exim 4.63) (envelope-from ) id 1Q6Oc0-0001ew-FI for ding@lists.math.uh.edu; Sun, 03 Apr 2011 09:49:08 -0500 Original-Received: from quimby.gnus.org ([80.91.231.51]) by mx1.math.uh.edu with esmtp (Exim 4.72) (envelope-from ) id 1Q6Obv-00057E-0j for ding@lists.math.uh.edu; Sun, 03 Apr 2011 09:49:08 -0500 Original-Received: from mail-iy0-f172.google.com ([209.85.210.172]) by quimby.gnus.org with esmtp (Exim 4.72) (envelope-from ) id 1Q6Obt-0002c7-VM for ding@gnus.org; Sun, 03 Apr 2011 16:49:02 +0200 Original-Received: by iye19 with SMTP id 19so8062280iye.17 for ; Sun, 03 Apr 2011 07:48:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:sender:from:to:cc:subject:date:message-id :x-mailer:in-reply-to:references; bh=6HRZg+0drHyUfXaFFN85ZYQ8xf4PzcGWIow2tNLP+nI=; b=FXBvoWo3s90eCeM49Bs0ClWHihhfCU+e4xaw5E+ViC9Y5SYVtC0eKxR7lA9LecvdqR KbZNqpVN61aD4AkzoOvNAVYh1eXz5CM+ARyQFpivlIamjcBz2P5ePzWtcnd47uD8yfCg zZHjVE5gOsMXTackumF7h+K0LYLB6clwG+g+g= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; b=e9XL56DkWSRU89eS0aGl3zzRUD6exQN11O7SUPi/1lmB25IH/vAWcVWrrdJLbTAlDO CLAOic+Jen+ysvxCIRdubz0hvU5SWQ1CHax6tUxCZSaMZFp7negrFqBVKJ7Izq76lmZ/ 05aD76Fv9AwfdK6S22C3rsJvG3EAmVKbM5nAI= Original-Received: by 10.231.52.209 with SMTP id j17mr5976296ibg.163.1301842135631; Sun, 03 Apr 2011 07:48:55 -0700 (PDT) Original-Received: from anar.kanru.info (61-228-157-181.dynamic.hinet.net [61.228.157.181]) by mx.google.com with ESMTPS id i3sm3022682iby.23.2011.04.03.07.48.53 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 03 Apr 2011 07:48:54 -0700 (PDT) Original-Received: from kanru by anar.kanru.info with local (Exim 4.75) (envelope-from ) id 1Q6Obi-0004oz-Lp; Sun, 03 Apr 2011 22:48:50 +0800 X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1301842105-18495-1-git-send-email-kanru@kanru.info> X-Spam-Score: -2.9 (--) List-ID: Precedence: bulk Xref: news.gmane.org gmane.emacs.gnus.general:78324 Archived-At: Signed-off-by: Kan-Ru Chen --- lisp/ChangeLog | 6 +++ lisp/nnir.el | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+), 0 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 4a802c5..30fc228 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,5 +1,11 @@ 2011-04-03 Kan-Ru Chen + * nnir.el (nnir-notmuch-program, nnir-notmuch-additional-switches) + (nnir-notmuch-remove-prefix, nnir-engines, nnir-run-notmuch): New nnir + `notmuch' backend. + +2011-04-03 Kan-Ru Chen + * nnir.el (nnir-read-server-parm): Use default value. 2011-04-02 Chong Yidong diff --git a/lisp/nnir.el b/lisp/nnir.el index 6f3cd9e..a2a56a8 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 @@ -1317,6 +1344,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)) -- 1.7.4.1