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 C18BA431FBF for ; Fri, 20 Nov 2009 23:15:24 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org 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 OY06CbIGgdIX for ; Fri, 20 Nov 2009 23:15:21 -0800 (PST) Received: from keithp.com (home.keithp.com [63.227.221.253]) by olra.theworths.org (Postfix) with ESMTP id E5F46431FBC for ; Fri, 20 Nov 2009 23:15:17 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by keithp.com (Postfix) with ESMTP id 680B3760228 for ; Fri, 20 Nov 2009 23:15:17 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at keithp.com Received: from keithp.com ([127.0.0.1]) by localhost (keithp.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id C8uqZH6hDBhn; Fri, 20 Nov 2009 23:15:14 -0800 (PST) Received: by keithp.com (Postfix, from userid 1033) id B3AFE760220; Fri, 20 Nov 2009 23:15:13 -0800 (PST) Received: from koto.keithp.com (localhost [127.0.0.1]) by keithp.com (Postfix) with ESMTP id B01AE76012C; Fri, 20 Nov 2009 23:15:13 -0800 (PST) Received: by koto.keithp.com (Postfix, from userid 1488) id 487DD1982A8; Fri, 20 Nov 2009 23:15:13 -0800 (PST) From: Keith Packard To: notmuch@notmuchmail.org Date: Fri, 20 Nov 2009 23:15:08 -0800 Message-Id: <1258787708-21121-3-git-send-email-keithp@keithp.com> X-Mailer: git-send-email 1.6.5.2 In-Reply-To: <1258787708-21121-2-git-send-email-keithp@keithp.com> References: <1258787708-21121-1-git-send-email-keithp@keithp.com> <1258787708-21121-2-git-send-email-keithp@keithp.com> Subject: [notmuch] [PATCH 3/3] Add notmuch-index mode to display message counts X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.12 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: Sat, 21 Nov 2009 07:15:25 -0000 Index mode takes a (user-configurable) list of search patterns and produces a list of those patterns and the count of messages that they match. When an entry in this list is selected, a search window with the defined search is opened. The set of indexes is defined as a list, each element contains the name of the index and the query string to count. This provides a view similar to a folder list in a more traditional mail client. Signed-off-by: Keith Packard --- notmuch.el | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 81 insertions(+), 0 deletions(-) diff --git a/notmuch.el b/notmuch.el index 4f369de..454320e 100644 --- a/notmuch.el +++ b/notmuch.el @@ -1046,4 +1046,85 @@ current search results AND that are tagged with the given tag." (setq mail-user-agent 'message-user-agent) +(defvar notmuch-index-mode-map + (let ((map (make-sparse-keymap))) + (define-key map "n" 'next-line) + (define-key map "p" 'previous-line) + (define-key map "x" 'kill-this-buffer) + (define-key map "q" 'kill-this-buffer) + (define-key map "s" 'notmuch-search) + (define-key map (kbd "RET") 'notmuch-index-show-search) + (define-key map "<" 'beginning-of-buffer) + (define-key map "=" 'notmuch-index) + (define-key map "?" 'describe-mode) + (define-key map [mouse-1] 'notmuch-index-show-search) + map) + "Keymap for \"notmuch index\" buffers.") + +(fset 'notmuch-index-mode-map notmuch-index-mode-map) + +(defcustom notmuch-indexes (quote (("inbox" . "tag:inbox") ("unread" . "tag:unread"))) + "List of searches for the notmuch index view" + :type '(alist :key-type (string) :value-type (string)) + :group 'notmuch) + +(defun notmuch-index-mode () + "Major mode for showing index of notmuch tags. + +This buffer contains a list of messages counts returned by a +customizable set of searches of your email archives. Each line +in the buffer shows the search terms and the resulting message count. + +Pressing RET on any line opens a search window containing the search +results for the search terms in that line. + +\\{notmuch-index-mode-map}" + (interactive) + (kill-all-local-variables) + (use-local-map 'notmuch-index-mode-map) + (setq truncate-lines t) + (hl-line-mode 1) + (setq major-mode 'notmuch-index-mode + mode-name "notmuch-index") + (setq buffer-read-only t)) + +(defun notmuch-index-add (indexes) + (if indexes + (let ((name (car (car indexes))) + (inhibit-read-only t) + (search (cdr (car indexes)))) + (insert name) + (indent-to 16 1) + (call-process notmuch-command nil t nil "count" search) + (notmuch-index-add (cdr indexes))))) + +(defun notmuch-index-find-name () + (save-excursion + (beginning-of-line) + (let ((beg (point))) + (forward-word) + (filter-buffer-substring beg (point))))) + +(defun notmuch-index-show-search (&optional index) + "Show a search window for the search related to the specified index." + (interactive) + (if (null index) + (setq index (notmuch-index-find-name))) + (let ((search (assoc index notmuch-indexes))) + (if search + (notmuch-search (cdr search) t)))) + +(defun notmuch-index () + "Show the message index and update the displayed counts." + (interactive) + (let ((buffer (get-buffer-create "*notmuch-index*"))) + (switch-to-buffer buffer) + (let ((inhibit-read-only t) + (n (line-number-at-pos))) + (erase-buffer) + (notmuch-index-mode) + (notmuch-index-add notmuch-indexes) + (goto-char (point-min)) + (goto-line n)))) + (provide 'notmuch) -- 1.6.5.2