unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: David Edmondson <dme@dme.org>
To: notmuch <notmuch@notmuchmail.org>
Subject: [PATCH] emacs: Add notmuch-hello.el, a friendly frontend to notmuch
Date: Mon, 12 Apr 2010 11:13:30 +0100	[thread overview]
Message-ID: <87fx31j7w5.fsf@ut.hh.sledj.net> (raw)

commit e55dc251b9e8001fe16873fadac565563e606d69
Author: David Edmondson <dme@dme.org>
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 © 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 <http://www.gnu.org/licenses/>.
+;;
+;; Authors: David Edmondson <dme@dme.org>
+
+(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-searches))))
+
+(defun notmuch-hello-trim (search)
+  "Trim whitespace."
+  (if (string-match "^[[:space:]]*\\(.*[^[:space:]]\\)[[:space:]]*$" search)
+      (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 folder)) (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 "=" 'notmuch-hello)
+  (local-set-key "q" '(lambda () (interactive) (kill-buffer (current-buffer))))
+
+  (widget-setup)
+
+  ;; Always put point inside the `search' widget, which we know is
+  ;; first.
+  (goto-char (point-min))
+  (widget-forward 1))


dme.
-- 
David Edmondson, http://dme.org

             reply	other threads:[~2010-04-12 10:13 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-12 10:13 David Edmondson [this message]
2010-04-13  4:58 ` [PATCH] emacs: Add notmuch-hello.el, a friendly frontend to notmuch Xavier Maillard
2010-04-13  6:54   ` David Edmondson
2010-04-13 10:25 ` Michal Sojka
2010-04-13 10:33   ` David Edmondson
  -- strict thread matches above, loose matches on Subject: below --
2010-04-22  1:11 Update on 0.3 progress Carl Worth
2010-04-22  8:27 ` [PATCH] emacs: Add notmuch-hello.el, a friendly frontend to notmuch David Edmondson
2010-04-23 20:13   ` Carl Worth
2010-04-23 22:49     ` Carl Worth
2010-04-26  9:36     ` David Edmondson
2010-04-26 14:59       ` Carl Worth
2010-04-26 17:16         ` Carl Worth
2010-04-26 17:38           ` Jameson Rollins
2010-04-26 18:03             ` David Edmondson
2010-04-26 18:38               ` Carl Worth
2010-04-26 15:07     ` David Edmondson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87fx31j7w5.fsf@ut.hh.sledj.net \
    --to=dme@dme.org \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).