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 7BC834196F2 for ; Mon, 12 Apr 2010 03:13:38 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -1.9 X-Spam-Level: X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001] autolearn=ham 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 lJ8wu9IcUIuF for ; Mon, 12 Apr 2010 03:13:37 -0700 (PDT) Received: from mail-bw0-f210.google.com (mail-bw0-f210.google.com [209.85.218.210]) by olra.theworths.org (Postfix) with ESMTP id 21519431FC1 for ; Mon, 12 Apr 2010 03:13:36 -0700 (PDT) Received: by bwz2 with SMTP id 2so4083417bwz.30 for ; Mon, 12 Apr 2010 03:13:36 -0700 (PDT) Received: by 10.204.83.26 with SMTP id d26mr4353701bkl.157.1271067215944; Mon, 12 Apr 2010 03:13:35 -0700 (PDT) Received: from ut.hh.sledj.net (gmp-ea-fw-1b.sun.com [192.18.8.1]) by mx.google.com with ESMTPS id d5sm36761027bkd.13.2010.04.12.03.13.34 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 12 Apr 2010 03:13:35 -0700 (PDT) Received: by ut.hh.sledj.net (Postfix, from userid 1000) id 6CEE65941E1; Mon, 12 Apr 2010 11:13:30 +0100 (BST) To: notmuch Subject: [PATCH] emacs: Add notmuch-hello.el, a friendly frontend to notmuch From: David Edmondson Date: Mon, 12 Apr 2010 11:13:30 +0100 Message-ID: <87fx31j7w5.fsf@ut.hh.sledj.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 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: Mon, 12 Apr 2010 10:13:38 -0000 commit e55dc251b9e8001fe16873fadac565563e606d69 Author: David Edmondson Date: Mon Apr 12 11:12:23 2010 +0100 emacs: Add notmuch-hello.el, a friendly frontend to notmuch New emacs/notmuch-hello.el diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el new file mode 100644 index 0000000..279c424 --- /dev/null +++ b/emacs/notmuch-hello.el @@ -0,0 +1,122 @@ +;; notmuch-hello.el --- welcome to notmuch, a frontend +;; +;; Copyright =C2=A9 David Edmondson +;; +;; This file is part of Notmuch. +;; +;; Notmuch is free software: you can redistribute it and/or modify it +;; under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. +;; +;; Notmuch is distributed in the hope that it will be useful, but +;; WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;; General Public License for more details. +;; +;; You should have received a copy of the GNU General Public License +;; along with Notmuch. If not, see . +;; +;; Authors: David Edmondson + +(require 'widget) + +(require 'notmuch-lib) + +(defvar notmuch-hello-searches-to-save 10) +(defvar notmuch-hello-search-width 60) + +(defvar notmuch-hello-recent-searches nil) + +(defun notmuch-hello-save-search (search) + (if (not (memq search notmuch-hello-recent-searches)) + (push search notmuch-hello-recent-searches)) + (if (> (length notmuch-hello-recent-searches) + notmuch-hello-searches-to-save) + (setq notmuch-hello-recent-searches (butlast notmuch-hello-recent-se= arches)))) + +(defun notmuch-hello-trim (search) + "Trim whitespace." + (if (string-match "^[[:space:]]*\\(.*[^[:space:]]\\)[[:space:]]*$" searc= h) + (match-string 1 search) + search)) + +(defun notmuch-hello-search (search) + (let ((search (notmuch-hello-trim search))) + (notmuch-hello-save-search search) + (notmuch-search search))) + +(defun notmuch-hello () + (interactive) + + (switch-to-buffer "*notmuch-hello*") + (kill-all-local-variables) + (let ((inhibit-read-only t)) + (erase-buffer)) + + (let ((all (overlay-lists))) + ;; Delete all the overlays. + (mapcar 'delete-overlay (car all)) + (mapcar 'delete-overlay (cdr all))) + + (widget-insert "\nWelcome to notmuch.\n\n") + (let ((start (point))) + (widget-insert "Search: ") + (widget-create 'editable-field + :size notmuch-hello-search-width + :action (lambda (widget &rest ignore) + (let ((search (widget-value widget))) + (notmuch-hello-search search)))) + (widget-insert "\n") + (indent-rigidly start (point) 4)) + + (when notmuch-hello-recent-searches + (widget-insert "\nRecent searches:\n\n") + (let ((start (point))) + (mapcar '(lambda (search) + (widget-create 'editable-field + :size notmuch-hello-search-width + :action (lambda (widget &rest ignore) + (let ((search (widget-value widget))) + (notmuch-hello-search search))) + search) + (widget-insert "\n")) + notmuch-hello-recent-searches) + (indent-rigidly start (point) 4))) + + (widget-insert "\nFolders:\n\n") + (let ((start (point))) + (mapcar '(lambda (folder) + (let ((w (widget-create 'push-button + :notify (lambda (widget &rest ignore) + (notmuch-search (widget-get widget :notmuch-search-terms))) + "open"))) + (widget-put w :notmuch-search-terms (cdr folder))) + (widget-insert (format " %6s %s\n" (notmuch-folder-count (cdr fold= er)) (car folder)))) + notmuch-folders) + (indent-rigidly start (point) 4)) + + (widget-insert "\nAll tags:\n\n") + (let ((start (point))) + (mapcar '(lambda (tag) + (let ((w (widget-create 'push-button + :notify (lambda (widget &rest ignore) + (notmuch-search (widget-get widget :notmuch-search-terms))) + "open"))) + (widget-put w :notmuch-search-terms (concat "tag:" tag))) + (widget-insert (format " %6s %s\n" (notmuch-folder-count + (concat "tag:" tag)) + tag))) + (process-lines notmuch-command "search-tags")) + (indent-rigidly start (point) 4)) + + (use-local-map widget-keymap) + (local-set-key "=3D" 'notmuch-hello) + (local-set-key "q" '(lambda () (interactive) (kill-buffer (current-buffe= r)))) + + (widget-setup) + + ;; Always put point inside the `search' widget, which we know is + ;; first. + (goto-char (point-min)) + (widget-forward 1)) dme. --=20 David Edmondson, http://dme.org