[PATCH v3 1/2] emacs: User-defined sections in notmuch-hello
authorDaniel Schoepe <daniel.schoepe@googlemail.com>
Tue, 5 Jul 2011 16:23:49 +0000 (18:23 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:38:58 +0000 (09:38 -0800)
d3/a7b0822ac1d4058fe877a39605a84263fddf7d [new file with mode: 0644]

diff --git a/d3/a7b0822ac1d4058fe877a39605a84263fddf7d b/d3/a7b0822ac1d4058fe877a39605a84263fddf7d
new file mode 100644 (file)
index 0000000..1d25e88
--- /dev/null
@@ -0,0 +1,778 @@
+Return-Path: <daniel.schoepe@googlemail.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 627DF429E25\r
+       for <notmuch@notmuchmail.org>; Tue,  5 Jul 2011 09:24:11 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.799\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
+       tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+       FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id 5NBFZTJswTJK for <notmuch@notmuchmail.org>;\r
+       Tue,  5 Jul 2011 09:24:06 -0700 (PDT)\r
+Received: from mail-fx0-f46.google.com (mail-fx0-f46.google.com\r
+       [209.85.161.46]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id EA934429E2B\r
+       for <notmuch@notmuchmail.org>; Tue,  5 Jul 2011 09:24:03 -0700 (PDT)\r
+Received: by mail-fx0-f46.google.com with SMTP id 19so6243003fxh.19\r
+       for <notmuch@notmuchmail.org>; Tue, 05 Jul 2011 09:24:03 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+       d=googlemail.com; s=gamma;\r
+       h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;\r
+       bh=6XJUT2UvfnSm5zRPusxdTu3uqvN8FkZC3/Ao1+q63wo=;\r
+       b=keQ0/rk1Au2FYF/gXE8lUlGN2LCCuL6LgaKT4NL2ukVd1jx7tsur8JzZ0rlWzPUNnW\r
+       j16lsY+YrEvj+g4KKqu+YtdqViZ/U8KIhke8krO4Bpk4Zv+9P7tpnmELYSegabGgMiG0\r
+       sMJT/oFXrvsgdP0QhMZtalCymg6Be84vRcs9E=\r
+Received: by 10.223.20.210 with SMTP id g18mr11769289fab.30.1309883043531;\r
+       Tue, 05 Jul 2011 09:24:03 -0700 (PDT)\r
+Received: from localhost (dslb-178-004-223-219.pools.arcor-ip.net\r
+       [178.4.223.219])\r
+       by mx.google.com with ESMTPS id k26sm5397846fak.24.2011.07.05.09.24.00\r
+       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Tue, 05 Jul 2011 09:24:01 -0700 (PDT)\r
+From: Daniel Schoepe <daniel.schoepe@googlemail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v3 1/2] emacs: User-defined sections in notmuch-hello\r
+Date: Tue,  5 Jul 2011 18:23:49 +0200\r
+Message-Id: <1309883030-28899-2-git-send-email-daniel.schoepe@googlemail.com>\r
+X-Mailer: git-send-email 1.7.5.4\r
+In-Reply-To: <1309883030-28899-1-git-send-email-daniel.schoepe@googlemail.com>\r
+References: <1309379221-5617-1-git-send-email-daniel.schoepe@googlemail.com>\r
+       <1309883030-28899-1-git-send-email-daniel.schoepe@googlemail.com>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Tue, 05 Jul 2011 16:24:11 -0000\r
+\r
+This patch makes the notmuch-hello screen fully customizable\r
+by allowing the user to add and remove arbitrary sections. It\r
+also provides some convenience functions for constructing sections,\r
+e.g. showing the unread message count for each tag.\r
+\r
+This is done by specifying a list of functions that will be run\r
+when notmuch-hello is invoked.\r
+---\r
+ emacs/notmuch-hello.el |  609 +++++++++++++++++++++++++++++++-----------------\r
+ 1 files changed, 393 insertions(+), 216 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el\r
+index 65fde75..9c18caa 100644\r
+--- a/emacs/notmuch-hello.el\r
++++ b/emacs/notmuch-hello.el\r
+@@ -55,26 +55,6 @@\r
+   :type 'boolean\r
+   :group 'notmuch)\r
\r
+-(defcustom notmuch-hello-tag-list-make-query nil\r
+-  "Function or string to generate queries for the all tags list.\r
+-\r
+-This variable controls which query results are shown for each tag\r
+-in the \"all tags\" list. If nil, it will use all messages with\r
+-that tag. If this is set to a string, it is used as a filter for\r
+-messages having that tag (equivalent to \"tag:TAG and (THIS-VARIABLE)\").\r
+-Finally this can be a function that will be called for each tag and\r
+-should return a filter for that tag, or nil to hide the tag."\r
+-  :type '(choice (const :tag "All messages" nil)\r
+-               (const :tag "Unread messages" "tag:unread")\r
+-               (const :tag "Custom filter" string)\r
+-               (const :tag "Custom filter function" function))\r
+-  :group 'notmuch)\r
+-\r
+-(defcustom notmuch-hello-hide-tags nil\r
+-  "List of tags to be hidden in the \"all tags\"-section."\r
+-  :type '(repeat string)\r
+-  :group 'notmuch)\r
+-\r
+ (defface notmuch-hello-logo-background\r
+   '((((class color)\r
+       (background dark))\r
+@@ -123,6 +103,75 @@ Typically \",\" in the US and UK and \".\" in Europe."\r
\r
+ (defvar notmuch-hello-recent-searches nil)\r
\r
++(define-widget 'notmuch-hello-tags-section 'lazy\r
++  "Customize-type for notmuch-hello tag-list sections."\r
++  :tag "Customized tag-list"\r
++  :type\r
++  (let ((opts\r
++       '((:title (string :tag "Title for this section"))\r
++         (:make-query (string :tag "Filter for each tag"))\r
++         (:make-count (string :tag "Different query to generate counts"))\r
++         (:hide-tags (repeat :tag "Tags that will be hidden" string))\r
++         (:initially-hidden (boolean :tag "Hide this on startup?"))\r
++         (:hide-empty-tags (boolean :tag "Hide tags with no matching messages"))\r
++         (:hide-if-empty (boolean :tag "Hide if empty")))))\r
++    `(list (const :tag "" notmuch-hello-insert-tags-section)\r
++         (plist :inline t :options ,opts))))\r
++\r
++(define-widget 'notmuch-hello-query-section 'lazy\r
++  "Customize-type for custom saved-search-like sections"\r
++  :tag "Customized queries section"\r
++  :type\r
++  '(list (const :tag "" notmuch-hello-insert-query-list)\r
++       (string :tag "Title for this section")\r
++       (repeat :tag "Queries"\r
++               (cons (string :tag "Name") (string :tag "Query")))\r
++       (plist :inline t\r
++              :options\r
++              ((:initially-hidden (boolean :tag "Hide this on startup?"))\r
++               (:hide-empty-tags\r
++                (boolean :tag "Hide tags with no matching messages"))\r
++               (:hide-if-empty (boolean :tag "Hide if empty"))))))\r
++\r
++(defcustom notmuch-hello-sections\r
++  (list #'notmuch-hello-insert-header\r
++      #'notmuch-hello-insert-saved-searches\r
++      #'notmuch-hello-insert-search\r
++      #'notmuch-hello-insert-recent-searches\r
++      #'notmuch-hello-insert-alltags\r
++      #'notmuch-hello-insert-footer)\r
++  "Sections for notmuch-hello.\r
++\r
++Each entry of this list should be a function of no arguments that\r
++should return if notmuch-hello-target is produced as part of its\r
++output and nil otherwise. For convenience an element can also be\r
++a list of the form (FUNC ARG1 ARG2 .. ARGN) in which case FUNC\r
++will be applied to the rest of the list.\r
++\r
++The functions will be run to construct the content of the\r
++notmuch-hello buffer in the order they appear in this list."\r
++  :group 'notmuch\r
++  :type \r
++  '(repeat\r
++    (choice (function-item notmuch-hello-insert-header)\r
++          (function-item notmuch-hello-insert-saved-searches)\r
++          (function-item notmuch-hello-insert-search)\r
++          (function-item notmuch-hello-insert-recent-searches)\r
++          (function-item notmuch-hello-insert-alltags)\r
++          (function-item notmuch-hello-insert-footer)\r
++          (function-item notmuch-hello-insert-inbox)\r
++          notmuch-hello-tags-section\r
++          notmuch-hello-query-section\r
++          (function :tag "Custom function"))))\r
++\r
++;; only defined to avoid compilation warnings about free variables\r
++(defvar notmuch-hello-target nil)\r
++\r
++(defvar notmuch-hello-hidden-sections nil\r
++  "List of query sections whose contents are hidden")\r
++\r
++(defvar notmuch-hello-first-run t)\r
++\r
+ (defun notmuch-hello-remember-search (search)\r
+   (if (not (member search notmuch-hello-recent-searches))\r
+       (push search notmuch-hello-recent-searches))\r
+@@ -173,8 +222,8 @@ Typically \",\" in the US and UK and \".\" in Europe."\r
+     (message "Saved '%s' as '%s'." search name)\r
+     (notmuch-hello-update)))\r
\r
+-(defun notmuch-hello-longest-label (tag-alist)\r
+-  (or (loop for elem in tag-alist\r
++(defun notmuch-hello-longest-label (searches-alist)\r
++  (or (loop for elem in searches-alist\r
+           maximize (length (car elem)))\r
+       0))\r
\r
+@@ -238,12 +287,71 @@ should be. Returns a cons cell `(tags-per-line width)'."\r
+                                  (* tags-per-line (+ 9 1))))\r
+                          tags-per-line))))\r
\r
+-(defun notmuch-hello-insert-tags (tag-alist widest target)\r
+-  (let* ((tags-and-width (notmuch-hello-tags-per-line widest))\r
++(defun notmuch-hello-filtered-query (query filter)\r
++  "Constructs a query to search all messages matching QUERY and FILTER.\r
++\r
++If FILTER is a string, it is directly used in the returned query.\r
++\r
++If FILTER is a function, it is called with QUERY as a parameter and\r
++the string it returns is used as the filter.\r
++\r
++Otherwise, FILTER is ignored.\r
++"\r
++  (cond\r
++   ((functionp filter)\r
++    (let ((result (funcall filter query)))\r
++      (and result (concat query " and (" result ")"))))\r
++   ((stringp filter)\r
++    (concat query " and (" filter ")"))\r
++   (t (concat query))))\r
++\r
++(defun notmuch-hello-query-counts (query-alist &rest options)\r
++  "Compute list of counts of matched messages from QUERY-ALIST.\r
++\r
++QUERY-ALIST must be a list containing elements of the form (NAME . QUERY)\r
++or (NAME QUERY COUNT-QUERY). If the latter form is used,\r
++COUNT-QUERY specifies an alternate query to be used to generate\r
++the count for the associated query.\r
++\r
++The result is the list of elements of the form (NAME QUERY COUNT).\r
++\r
++The values :hide-empty-searches, :make-query and :make-count from\r
++options will be handled as specified for\r
++`notmuch-hello-insert-searches'."\r
++  (notmuch-remove-if-not\r
++   #'identity\r
++   (mapcar\r
++    (lambda (elem)\r
++      (let* ((name (car elem))\r
++           (query-and-count (if (consp (cdr elem))\r
++                                ;; do we have a different query for the message count?\r
++                                (cons (second elem) (third elem))\r
++                              (cons (cdr elem) (cdr elem))))\r
++           (message-count\r
++            (string-to-number\r
++             (notmuch-saved-search-count\r
++              (notmuch-hello-filtered-query (cdr query-and-count)\r
++                                            (or (plist-get options :make-count)\r
++                                               (plist-get options :make-query)))))))\r
++      (and (or (not (plist-get options :hide-empty-searches)) (> message-count 0))\r
++         (list name (notmuch-hello-filtered-query\r
++                     (car query-and-count) (plist-get options :make-query))\r
++               message-count))))\r
++    query-alist)))\r
++\r
++(defun notmuch-hello-insert-buttons (searches)\r
++  "Insert buttons for SEARCHES.\r
++\r
++SEARCHES must be a list containing lists of the form (NAME QUERY COUNT), where\r
++QUERY is the query to start when the button for the corresponding entry is\r
++activated. COUNT should be the number of messages matching the query.\r
++Such a list can be computed with `notmuch-hello-query-counts'."\r
++  (let* ((widest (notmuch-hello-longest-label searches))\r
++       (tags-and-width (notmuch-hello-tags-per-line widest))\r
+        (tags-per-line (car tags-and-width))\r
+        (widest (cdr tags-and-width))\r
+        (count 0)\r
+-       (reordered-list (notmuch-hello-reflect tag-alist tags-per-line))\r
++       (reordered-list (notmuch-hello-reflect searches tags-per-line))\r
+        ;; Hack the display of the buttons used.\r
+        (widget-push-button-prefix "")\r
+        (widget-push-button-suffix "")\r
+@@ -253,13 +361,13 @@ should be. Returns a cons cell `(tags-per-line width)'."\r
+     (mapc (lambda (elem)\r
+           ;; (not elem) indicates an empty slot in the matrix.\r
+           (when elem\r
+-            (let* ((name (car elem))\r
+-                   (query (cdr elem))\r
++            (let* ((name (first elem))\r
++                   (query (second elem))\r
++                   (count (third elem))\r
+                    (formatted-name (format "%s " name)))\r
+               (widget-insert (format "%8s "\r
+-                                     (notmuch-hello-nice-number\r
+-                                      (string-to-number (notmuch-saved-search-count query)))))\r
+-              (if (string= formatted-name target)\r
++                                     (notmuch-hello-nice-number count)))\r
++              (if (string= formatted-name notmuch-hello-target)\r
+                   (setq found-target-pos (point-marker)))\r
+               (widget-create 'push-button\r
+                              :notify #'notmuch-hello-widget-search\r
+@@ -277,7 +385,7 @@ should be. Returns a cons cell `(tags-per-line width)'."\r
+           (setq count (1+ count))\r
+           (if (eq (% count tags-per-line) 0)\r
+               (widget-insert "\n")))\r
+-        reordered-list)\r
++        searches)\r
\r
+     ;; If the last line was not full (and hence did not include a\r
+     ;; carriage return), insert one now.\r
+@@ -325,59 +433,268 @@ should be. Returns a cons cell `(tags-per-line width)'."\r
+ (fset 'notmuch-hello-mode-map notmuch-hello-mode-map)\r
\r
+ (defun notmuch-hello-mode ()\r
+- "Major mode for convenient notmuch navigation. This is your entry portal into notmuch.\r
++  "Major mode for convenient notmuch navigation. This is your entry portal into notmuch.\r
\r
+ Complete list of currently available key bindings:\r
\r
+ \\{notmuch-hello-mode-map}"\r
+- (interactive)\r
+- (kill-all-local-variables)\r
+- (use-local-map notmuch-hello-mode-map)\r
+- (setq major-mode 'notmuch-hello-mode\r
+-       mode-name "notmuch-hello")\r
+- ;;(setq buffer-read-only t)\r
+-)\r
+-\r
+-(defun notmuch-hello-generate-tag-alist ()\r
++  (interactive)\r
++  (kill-all-local-variables)\r
++  (use-local-map notmuch-hello-mode-map)\r
++  (setq major-mode 'notmuch-hello-mode\r
++      mode-name "notmuch-hello")\r
++  ;;(setq buffer-read-only t)\r
++  )\r
++\r
++(defun notmuch-hello-generate-tag-alist (&optional hide-tags filter-query filter-count)\r
+   "Return an alist from tags to queries to display in the all-tags section."\r
+   (notmuch-remove-if-not\r
+-   #'cdr\r
++   #'identity\r
+    (mapcar (lambda (tag)\r
+-           (cons tag\r
+-                 (cond\r
+-                  ((functionp notmuch-hello-tag-list-make-query)\r
+-                   (concat "tag:" tag " and ("\r
+-                           (funcall notmuch-hello-tag-list-make-query tag) ")"))\r
+-                  ((stringp notmuch-hello-tag-list-make-query)\r
+-                   (concat "tag:" tag " and ("\r
+-                           notmuch-hello-tag-list-make-query ")"))\r
+-                  (t (concat "tag:" tag)))))\r
++           (let ((query (notmuch-hello-filtered-query (concat "tag:" tag)\r
++                                                      filter-query)))\r
++             (when query\r
++               (if filter-count\r
++                   (list tag (notmuch-hello-filtered-query tag filter-query)\r
++                         (notmuch-hello-filtered-query (concat "tag:" tag)\r
++                                                       filter-count))\r
++                 (cons tag (notmuch-hello-filtered-query\r
++                            (concat "tag:" tag) filter-query))))))\r
+          (notmuch-remove-if-not\r
+           (lambda (tag)\r
+-            (not (member tag notmuch-hello-hide-tags)))\r
++            (not (member tag hide-tags)))\r
+           (process-lines notmuch-command "search-tags")))))\r
\r
++(defun notmuch-hello-insert-header ()\r
++  "Insert the default notmuch-hello header."\r
++  (when notmuch-show-logo\r
++    (let ((image notmuch-hello-logo))\r
++      ;; The notmuch logo uses transparency. That can display poorly\r
++      ;; when inserting the image into an emacs buffer (black logo on\r
++      ;; a black background), so force the background colour of the\r
++      ;; image. We use a face to represent the colour so that\r
++      ;; `defface' can be used to declare the different possible\r
++      ;; colours, which depend on whether the frame has a light or\r
++      ;; dark background.\r
++      (setq image (cons 'image\r
++                      (append (cdr image)\r
++                              (list :background (face-background 'notmuch-hello-logo-background)))))\r
++      (insert-image image))\r
++    (widget-insert "  "))\r
++\r
++  (widget-insert "Welcome to ")\r
++  ;; Hack the display of the links used.\r
++  (let ((widget-link-prefix "")\r
++      (widget-link-suffix ""))\r
++    (widget-create 'link\r
++                 :notify (lambda (&rest ignore)\r
++                           (browse-url notmuch-hello-url))\r
++                 :help-echo "Visit the notmuch website."\r
++                 "notmuch")\r
++    (widget-insert ". ")\r
++    (widget-insert "You have ")\r
++    (widget-create 'link\r
++                 :notify (lambda (&rest ignore)\r
++                           (notmuch-hello-update))\r
++                 :help-echo "Refresh"\r
++                 (notmuch-hello-nice-number\r
++                  (string-to-number (car (process-lines notmuch-command "count")))))\r
++    (widget-insert " messages.")))\r
++\r
++\r
++(defun notmuch-hello-insert-saved-searches ()\r
++  "Insert the saved-searches section."\r
++  (let ((searches (notmuch-hello-query-counts\r
++                notmuch-saved-searches\r
++                :hide-empty-searches (not notmuch-show-empty-saved-searches)))\r
++      found-target-pos final-target-pos)\r
++    (when searches\r
++      (widget-insert "\nSaved searches: ")\r
++      (widget-create 'push-button\r
++                   :notify (lambda (&rest ignore)\r
++                             (customize-variable 'notmuch-saved-searches))\r
++                   "edit")\r
++      (widget-insert "\n\n")\r
++      (setq final-target-pos (point-marker))\r
++      (let ((start (point)))\r
++      (setq found-target-pos\r
++            (notmuch-hello-insert-buttons searches))\r
++      (if found-target-pos\r
++          (setq final-target-pos found-target-pos))\r
++      (indent-rigidly start (point) notmuch-hello-indent)\r
++      final-target-pos))))\r
++\r
++(defun notmuch-hello-insert-search ()\r
++  "Insert a search widget."\r
++  (widget-insert "Search: ")\r
++  (setq notmuch-hello-search-bar-marker (point-marker))\r
++  (widget-create 'editable-field\r
++               ;; Leave some space at the start and end of the\r
++               ;; search boxes.\r
++               :size (max 8 (- (window-width) notmuch-hello-indent\r
++                               (length "Search: ")))\r
++               :action (lambda (widget &rest ignore)\r
++                         (notmuch-hello-search (widget-value widget)))))\r
++\r
++(defun notmuch-hello-insert-recent-searches ()\r
++  "Insert recent searches."\r
++  (when notmuch-hello-recent-searches\r
++    (widget-insert "\nRecent searches: ")\r
++    (widget-create 'push-button\r
++                 :notify (lambda (&rest ignore)\r
++                           (setq notmuch-hello-recent-searches nil)\r
++                           (notmuch-hello-update))\r
++                 "clear")\r
++    (widget-insert "\n\n")\r
++    (let ((start (point))\r
++        (nth 0))\r
++      (mapc '(lambda (search)\r
++             (let ((widget-symbol (intern (format "notmuch-hello-search-%d" nth))))\r
++               (set widget-symbol\r
++                    (widget-create 'editable-field\r
++                                   ;; Don't let the search boxes be\r
++                                   ;; less than 8 characters wide.\r
++                                   :size (max 8\r
++                                              (- (window-width)\r
++                                                 ;; Leave some space\r
++                                                 ;; at the start and\r
++                                                 ;; end of the\r
++                                                 ;; boxes.\r
++                                                 (* 2 notmuch-hello-indent)\r
++                                                 ;; 1 for the space\r
++                                                 ;; before the\r
++                                                 ;; `[save]' button. 6\r
++                                                 ;; for the `[save]'\r
++                                                 ;; button.\r
++                                                 1 6))\r
++                                   :action (lambda (widget &rest ignore)\r
++                                             (notmuch-hello-search (widget-value widget)))\r
++                                   search))\r
++               (widget-insert " ")\r
++               (widget-create 'push-button\r
++                              :notify (lambda (widget &rest ignore)\r
++                                        (notmuch-hello-add-saved-search widget))\r
++                              :notmuch-saved-search-widget widget-symbol\r
++                              "save"))\r
++             (widget-insert "\n")\r
++             (setq nth (1+ nth)))\r
++          notmuch-hello-recent-searches)\r
++      (indent-rigidly start (point) notmuch-hello-indent))))\r
++\r
++(defun notmuch-hello-insert-searches (title query-alist &rest options)\r
++  "Insert a section with TITLE showing a list of buttons made from QUERY-ALIST.\r
++\r
++QUERY-ALIST must be a list containing elements of the form (NAME . QUERY)\r
++or (NAME QUERY COUNT-QUERY). If the latter form is used,\r
++COUNT-QUERY specifies an alternate query to be used to generate\r
++the count for the associated item.\r
++\r
++Supports the following entries in OPTIONS as a plist:\r
++:initially-hidden - if non-nil, section will be hidden on startup\r
++:hide-empty-searches - hide buttons with no matching messages\r
++:hide-if-empty - hide if no buttons would be shown\r
++   (only makes sense with :hide-empty-searches)\r
++:make-query - This can be a function that takes a tag as its argument and\r
++    returns a filter to be used for the query for that tag or nil to hide the\r
++    tag. This can also be a string that is used as a filter for messages with that tag.\r
++:make-count - Seperate query to generate the count that should be displayed for each\r
++    tag. Accepts the same values as :make-query"\r
++  (widget-insert title)\r
++  (if (and notmuch-hello-first-run (plist-get options :initially-hidden))\r
++      (add-to-list 'notmuch-hello-hidden-sections title))\r
++  (let ((is-hidden (member title notmuch-hello-hidden-sections))\r
++      (start (point)))\r
++    (if is-hidden\r
++      (widget-create 'push-button\r
++                     :notify `(lambda (widget &rest ignore)\r
++                                (setq notmuch-hello-hidden-sections\r
++                                      (delete ,title notmuch-hello-hidden-sections))\r
++                                (notmuch-hello-update))\r
++                     "show")\r
++      (widget-create 'push-button\r
++                   :notify `(lambda (widget &rest ignore)\r
++                              (add-to-list 'notmuch-hello-hidden-sections\r
++                                           ,title)\r
++                              (notmuch-hello-update))\r
++                   "hide"))\r
++    (widget-insert "\n")\r
++    (let (target-pos\r
++        (searches (apply 'notmuch-hello-query-counts query-alist options)))\r
++      (when (and (not is-hidden)\r
++             (or (not (plist-get options :hide-if-empty))\r
++                searches))\r
++      (widget-insert "\n")\r
++      (setq target-pos\r
++            (notmuch-hello-insert-buttons searches))\r
++      (indent-rigidly start (point) notmuch-hello-indent)\r
++      target-pos))))\r
++\r
++(defun notmuch-hello-insert-tags-section (&optional title &rest options)\r
++  "Insert a section displaying all tags and message counts for each.\r
++\r
++TITLE defaults to \"All tags: \".\r
++Allowed options are those accepted by `notmuch-hello-insert-searches' and the\r
++following:\r
++\r
++:hide-tags - List of tags that should be excluded."\r
++  (apply 'notmuch-hello-insert-searches\r
++       (or title "All tags: ")\r
++       (notmuch-hello-generate-tag-alist\r
++        (plist-get options :hide-tags)\r
++        (plist-get options :make-query)\r
++        (plist-get options :make-count))\r
++       options))\r
++\r
++(defun notmuch-hello-insert-inbox ()\r
++  "Show an entry for each saved search and inboxed messages for each tag"\r
++  (notmuch-hello-insert-searches "What's in your inbox: "\r
++                               (append\r
++                                (notmuch-saved-searches)\r
++                                (notmuch-hello-generate-tag-alist))\r
++                               :make-query "tag:inbox"\r
++                               :hide-empty-searches t))\r
++\r
++(defun notmuch-hello-insert-alltags ()\r
++  "Insert a section displaying all tags and associated message counts"\r
++  (notmuch-hello-insert-tags-section nil :initially-hidden\r
++                                   (not notmuch-show-all-tags-list)))\r
++\r
++(defun notmuch-hello-insert-footer ()\r
++  "Insert the notmuch-hello footer."\r
++  (let ((start (point)))\r
++    (widget-insert "Type a search query and hit RET to view matching threads.\n")\r
++    (when notmuch-hello-recent-searches\r
++      (widget-insert "Hit RET to re-submit a previous search. Edit it first if you like.\n")\r
++      (widget-insert "Save recent searches with the `save' button.\n"))\r
++    (when notmuch-saved-searches\r
++      (widget-insert "Edit saved searches with the `edit' button.\n"))\r
++    (widget-insert "Hit RET or click on a saved search or tag name to view matching threads.\n")\r
++    (widget-insert "`=' refreshes this screen. `s' jumps to the search box. `q' to quit.\n")\r
++    (let ((fill-column (- (window-width) notmuch-hello-indent)))\r
++      (center-region start (point)))))\r
++\r
++\r
+ ;;;###autoload\r
+ (defun notmuch-hello (&optional no-display)\r
+   "Run notmuch and display saved searches, known tags, etc."\r
+   (interactive)\r
\r
+-  ; Jump through a hoop to get this value from the deprecated variable\r
+-  ; name (`notmuch-folders') or from the default value.\r
++                                      ; Jump through a hoop to get this value from the deprecated variable\r
++                                      ; name (`notmuch-folders') or from the default value.\r
+   (if (not notmuch-saved-searches)\r
+-    (setq notmuch-saved-searches (notmuch-saved-searches)))\r
++      (setq notmuch-saved-searches (notmuch-saved-searches)))\r
\r
+   (if no-display\r
+       (set-buffer "*notmuch-hello*")\r
+     (switch-to-buffer "*notmuch-hello*"))\r
\r
+-  (let ((target (if (widget-at)\r
+-                 (widget-value (widget-at))\r
+-               (condition-case nil\r
+-                   (progn\r
+-                     (widget-forward 1)\r
+-                     (widget-value (widget-at)))\r
+-                 (error nil)))))\r
++  (let ((notmuch-hello-target (if (widget-at)\r
++                                (widget-value (widget-at))\r
++                              (condition-case nil\r
++                                  (progn\r
++                                    (widget-forward 1)\r
++                                    (widget-value (widget-at)))\r
++                                (error nil)))))\r
\r
+     (kill-all-local-variables)\r
+     (let ((inhibit-read-only t))\r
+@@ -391,167 +708,27 @@ Complete list of currently available key bindings:\r
+       (mapc 'delete-overlay (car all))\r
+       (mapc 'delete-overlay (cdr all)))\r
\r
+-    (when notmuch-show-logo\r
+-      (let ((image notmuch-hello-logo))\r
+-      ;; The notmuch logo uses transparency. That can display poorly\r
+-      ;; when inserting the image into an emacs buffer (black logo on\r
+-      ;; a black background), so force the background colour of the\r
+-      ;; image. We use a face to represent the colour so that\r
+-      ;; `defface' can be used to declare the different possible\r
+-      ;; colours, which depend on whether the frame has a light or\r
+-      ;; dark background.\r
+-      (setq image (cons 'image\r
+-                        (append (cdr image)\r
+-                                (list :background (face-background 'notmuch-hello-logo-background)))))\r
+-      (insert-image image))\r
+-      (widget-insert "  "))\r
+-\r
+-    (widget-insert "Welcome to ")\r
+-    ;; Hack the display of the links used.\r
+-    (let ((widget-link-prefix "")\r
+-        (widget-link-suffix ""))\r
+-      (widget-create 'link\r
+-                   :notify (lambda (&rest ignore)\r
+-                             (browse-url notmuch-hello-url))\r
+-                   :help-echo "Visit the notmuch website."\r
+-                   "notmuch")\r
+-      (widget-insert ". ")\r
+-      (widget-insert "You have ")\r
+-      (widget-create 'link\r
+-                   :notify (lambda (&rest ignore)\r
+-                             (notmuch-hello-update))\r
+-                   :help-echo "Refresh"\r
+-                   (notmuch-hello-nice-number\r
+-                    (string-to-number (car (process-lines notmuch-command "count")))))\r
+-      (widget-insert " messages.\n"))\r
+-\r
+-    (let ((found-target-pos nil)\r
+-        (final-target-pos nil))\r
+-      (let* ((saved-alist\r
+-            ;; Filter out empty saved searches if required.\r
+-            (if notmuch-show-empty-saved-searches\r
+-                notmuch-saved-searches\r
+-              (loop for elem in notmuch-saved-searches\r
+-                    if (> (string-to-number (notmuch-saved-search-count (cdr elem))) 0)\r
+-                    collect elem)))\r
+-           (saved-widest (notmuch-hello-longest-label saved-alist))\r
+-           (alltags-alist (if notmuch-show-all-tags-list (notmuch-hello-generate-tag-alist)))\r
+-           (alltags-widest (notmuch-hello-longest-label alltags-alist))\r
+-           (widest (max saved-widest alltags-widest)))\r
+-\r
+-      (when saved-alist\r
+-        (widget-insert "\nSaved searches: ")\r
+-        (widget-create 'push-button\r
+-                       :notify (lambda (&rest ignore)\r
+-                                 (customize-variable 'notmuch-saved-searches))\r
+-                       "edit")\r
+-        (widget-insert "\n\n")\r
+-        (setq final-target-pos (point-marker))\r
+-        (let ((start (point)))\r
+-          (setq found-target-pos (notmuch-hello-insert-tags saved-alist widest target))\r
+-          (if found-target-pos\r
+-              (setq final-target-pos found-target-pos))\r
+-          (indent-rigidly start (point) notmuch-hello-indent)))\r
+-\r
+-      (widget-insert "\nSearch: ")\r
+-      (setq notmuch-hello-search-bar-marker (point-marker))\r
+-      (widget-create 'editable-field\r
+-                     ;; Leave some space at the start and end of the\r
+-                     ;; search boxes.\r
+-                     :size (max 8 (- (window-width) notmuch-hello-indent\r
+-                                     (length "Search: ")))\r
+-                     :action (lambda (widget &rest ignore)\r
+-                               (notmuch-hello-search (widget-value widget))))\r
+-      (widget-insert "\n")\r
+-\r
+-      (when notmuch-hello-recent-searches\r
+-        (widget-insert "\nRecent searches: ")\r
+-        (widget-create 'push-button\r
+-                       :notify (lambda (&rest ignore)\r
+-                                 (setq notmuch-hello-recent-searches nil)\r
+-                                 (notmuch-hello-update))\r
+-                       "clear")\r
+-        (widget-insert "\n\n")\r
+-        (let ((start (point))\r
+-              (nth 0))\r
+-          (mapc '(lambda (search)\r
+-                   (let ((widget-symbol (intern (format "notmuch-hello-search-%d" nth))))\r
+-                     (set widget-symbol\r
+-                          (widget-create 'editable-field\r
+-                                     ;; Don't let the search boxes be\r
+-                                     ;; less than 8 characters wide.\r
+-                                     :size (max 8\r
+-                                                (- (window-width)\r
+-                                                   ;; Leave some space\r
+-                                                   ;; at the start and\r
+-                                                   ;; end of the\r
+-                                                   ;; boxes.\r
+-                                                   (* 2 notmuch-hello-indent)\r
+-                                                   ;; 1 for the space\r
+-                                                   ;; before the\r
+-                                                   ;; `[save]' button. 6\r
+-                                                   ;; for the `[save]'\r
+-                                                   ;; button.\r
+-                                                   1 6))\r
+-                                     :action (lambda (widget &rest ignore)\r
+-                                               (notmuch-hello-search (widget-value widget)))\r
+-                                     search))\r
+-                     (widget-insert " ")\r
+-                     (widget-create 'push-button\r
+-                                    :notify (lambda (widget &rest ignore)\r
+-                                              (notmuch-hello-add-saved-search widget))\r
+-                                    :notmuch-saved-search-widget widget-symbol\r
+-                                    "save"))\r
+-                   (widget-insert "\n")\r
+-                   (setq nth (1+ nth)))\r
+-                notmuch-hello-recent-searches)\r
+-          (indent-rigidly start (point) notmuch-hello-indent)))\r
+-\r
+-      (when alltags-alist\r
+-        (widget-insert "\nAll tags: ")\r
+-        (widget-create 'push-button\r
+-                       :notify (lambda (widget &rest ignore)\r
+-                                 (setq notmuch-show-all-tags-list nil)\r
+-                                 (notmuch-hello-update))\r
+-                       "hide")\r
+-        (widget-insert "\n\n")\r
+-        (let ((start (point)))\r
+-          (setq found-target-pos (notmuch-hello-insert-tags alltags-alist widest target))\r
+-          (if (not final-target-pos)\r
+-              (setq final-target-pos found-target-pos))\r
+-          (indent-rigidly start (point) notmuch-hello-indent)))\r
+-\r
+-      (widget-insert "\n")\r
+-\r
+-      (if (not notmuch-show-all-tags-list)\r
+-          (widget-create 'push-button\r
+-                         :notify (lambda (widget &rest ignore)\r
+-                                   (setq notmuch-show-all-tags-list t)\r
+-                                   (notmuch-hello-update))\r
+-                         "Show all tags")))\r
+-\r
+-      (let ((start (point)))\r
+-      (widget-insert "\n\n")\r
+-      (widget-insert "Type a search query and hit RET to view matching threads.\n")\r
+-      (when notmuch-hello-recent-searches\r
+-        (widget-insert "Hit RET to re-submit a previous search. Edit it first if you like.\n")\r
+-        (widget-insert "Save recent searches with the `save' button.\n"))\r
+-      (when notmuch-saved-searches\r
+-        (widget-insert "Edit saved searches with the `edit' button.\n"))\r
+-      (widget-insert "Hit RET or click on a saved search or tag name to view matching threads.\n")\r
+-      (widget-insert "`=' refreshes this screen. `s' jumps to the search box. `q' to quit.\n")\r
+-      (let ((fill-column (- (window-width) notmuch-hello-indent)))\r
+-        (center-region start (point))))\r
++    (let (final-target-pos)\r
++      (mapc\r
++       (lambda (section)\r
++       (let ((result (if (functionp section)\r
++                         (funcall section)\r
++                       (apply (car section) (cdr section)))))\r
++         (if (and (not final-target-pos) (integer-or-marker-p result))\r
++             (setq final-target-pos result))\r
++           (widget-insert "\n")))\r
++       notmuch-hello-sections)\r
\r
+       (widget-setup)\r
+-\r
++      \r
+       (when final-target-pos\r
+       (goto-char final-target-pos)\r
+       (unless (widget-at)\r
+         (widget-forward 1)))\r
+-\r
++      \r
+       (unless (widget-at)\r
+-      (notmuch-hello-goto-search)))))\r
++      (notmuch-hello-goto-search)))\r
++    (setq notmuch-hello-first-run nil)))\r
\r
+ (defun notmuch-folder ()\r
+   "Deprecated function for invoking notmuch---calling `notmuch' is preferred now."\r
+-- \r
+1.7.5.4\r
+\r