--- /dev/null
+Return-Path: <dmitry.kurochkin@gmail.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 08F66429E55\r
+ for <notmuch@notmuchmail.org>; Thu, 16 Feb 2012 23:49:40 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 1.061\r
+X-Spam-Level: *\r
+X-Spam-Status: No, score=1.061 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_BL_SPAMCOP_NET=1.246,\r
+ RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_SORBS_WEB=0.614] 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 MVpayFbz5TXH for <notmuch@notmuchmail.org>;\r
+ Thu, 16 Feb 2012 23:49:33 -0800 (PST)\r
+Received: from mail-bk0-f53.google.com (mail-bk0-f53.google.com\r
+ [209.85.214.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 244B8429E42\r
+ for <notmuch@notmuchmail.org>; Thu, 16 Feb 2012 23:49:33 -0800 (PST)\r
+Received: by mail-bk0-f53.google.com with SMTP id it16so3104161bkc.26\r
+ for <notmuch@notmuchmail.org>; Thu, 16 Feb 2012 23:49:32 -0800 (PST)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;\r
+ h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;\r
+ bh=eRvB1Ye+iV0nwD87OiNW2PlYEyvsv55+Gc3/r8AYGCU=;\r
+ b=tFIAJIF7S6VxvwbtBEXZXUTcJy4Mq0MtKRSA8IaUFcKhVI7G3dTnPb9hXK/nv5h9Qn\r
+ FDsndmq0JoBwuYf4pJcWFAWjkoMwpmSXPcuPlRbI5dhDiF99J1c2iib+AU1iEHdkr8Rb\r
+ pf2LOO5a9LXAUvrz5TaRiq8IyC4Ic4Mu7ft6I=\r
+Received: by 10.204.129.7 with SMTP id m7mr3682642bks.13.1329464972742;\r
+ Thu, 16 Feb 2012 23:49:32 -0800 (PST)\r
+Received: from localhost ([217.26.0.107])\r
+ by mx.google.com with ESMTPS id e13sm21132048bku.12.2012.02.16.23.49.31\r
+ (version=TLSv1/SSLv3 cipher=OTHER);\r
+ Thu, 16 Feb 2012 23:49:32 -0800 (PST)\r
+From: Dmitry Kurochkin <dmitry.kurochkin@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v9 1/2] emacs: User-defined sections in notmuch-hello\r
+Date: Fri, 17 Feb 2012 11:48:02 +0400\r
+Message-Id: <1329464884-1653-2-git-send-email-dmitry.kurochkin@gmail.com>\r
+X-Mailer: git-send-email 1.7.9\r
+In-Reply-To: <1329464884-1653-1-git-send-email-dmitry.kurochkin@gmail.com>\r
+References: <1310079227-19120-1-git-send-email-daniel.schoepe@googlemail.com>\r
+ <1329464884-1653-1-git-send-email-dmitry.kurochkin@gmail.com>\r
+Cc: Daniel Schoepe <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: Fri, 17 Feb 2012 07:49:40 -0000\r
+\r
+From: Daniel Schoepe <daniel.schoepe@googlemail.com>\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 | 624 ++++++++++++++++++++++++++++++++----------------\r
+ 1 files changed, 424 insertions(+), 200 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el\r
+index d17a30f..89c5637 100644\r
+--- a/emacs/notmuch-hello.el\r
++++ b/emacs/notmuch-hello.el\r
+@@ -154,6 +154,108 @@ International Bureau of Weights and Measures."\r
+ (defvar notmuch-hello-url "http://notmuchmail.org"\r
+ "The `notmuch' web site.")\r
+ \r
++(defvar notmuch-hello-search-pos nil\r
++ "Position of search widget, if any.\r
++\r
++This should only be set by `notmuch-hello-insert-search'.")\r
++\r
++(defvar notmuch-hello-custom-section-options\r
++ '((:filter (string :tag "Filter for each tag"))\r
++ (:filter-count (string :tag "Different filter to generate message counts"))\r
++ (:initially-hidden (const :tag "Hide this section on startup" t))\r
++ (:show-empty-searches (const :tag "Show queries with no matching messages" t))\r
++ (:hide-if-empty (const :tag "Hide this section if all queries are empty\r
++\(and not shown by show-empty-searches)" t)))\r
++ "Various customization-options for notmuch-hello-tags/query-section.")\r
++\r
++(define-widget 'notmuch-hello-tags-section 'lazy\r
++ "Customize-type for notmuch-hello tag-list sections."\r
++ :tag "Customized tag-list section (see docstring for details)"\r
++ :type\r
++ `(list :tag ""\r
++ (const :tag "" notmuch-hello-insert-tags-section)\r
++ (string :tag "Title for this section")\r
++ (plist\r
++ :inline t\r
++ :options\r
++ ,(append notmuch-hello-custom-section-options\r
++ '((:hide-tags (repeat :tag "Tags that will be hidden"\r
++ string)))))))\r
++\r
++(define-widget 'notmuch-hello-query-section 'lazy\r
++ "Customize-type for custom saved-search-like sections"\r
++ :tag "Customized queries section (see docstring for details)"\r
++ :type\r
++ `(list :tag ""\r
++ (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 :options ,notmuch-hello-custom-section-options)))\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
++The list contains functions which are used to construct sections in\r
++notmuch-hello buffer. When notmuch-hello buffer is constructed,\r
++these functions are run in the order they appear in this list. Each\r
++function produces a section simply by adding content to the current\r
++buffer. A section should not end with an empty line, because a\r
++newline will be inserted after each section by `notmuch-hello'.\r
++\r
++Each function should take no arguments. If the produced section\r
++includes `notmuch-hello-target' (i.e. cursor should be positioned\r
++inside this section), the function should return this element's\r
++position.\r
++Otherwise, it should return nil.\r
++\r
++For convenience an element can also be a list of the form (FUNC ARG1\r
++ARG2 .. ARGN) in which case FUNC will be applied to the rest of the\r
++list.\r
++\r
++A \"Customized tag-list section\" item in the customize-interface\r
++displays a list of all tags, optionally hiding some of them. It\r
++is also possible to filter the list of messages matching each tag\r
++by an additional filter query. Similarly, the count of messages\r
++displayed next to the buttons can be generated by applying a\r
++different filter to the tag query. These filters are also\r
++supported for \"Customized queries section\" items."\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 section"))))\r
++\r
++(defvar notmuch-hello-target nil\r
++ "Button text at position of point before rebuilding the notmuch-buffer.\r
++\r
++This variable contains the text of the button, if any, the\r
++point was positioned at before the notmuch-hello buffer was\r
++rebuilt. This should never actually be global and is defined as a\r
++defvar only for documentation purposes and to avoid a compiler\r
++warning about it occurring as a free variable.")\r
++\r
++(defvar notmuch-hello-hidden-sections nil\r
++ "List of sections titles whose contents are hidden")\r
++\r
++(defvar notmuch-hello-first-run t\r
++ "True if `notmuch-hello' is run for the first time, set to nil\r
++afterwards.")\r
++\r
+ (defun notmuch-hello-nice-number (n)\r
+ (let (result)\r
+ (while (> n 0)\r
+@@ -201,8 +303,8 @@ International Bureau of Weights and Measures."\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
+@@ -266,12 +368,70 @@ 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 query. If nil is returned,\r
++the entry is hidden.\r
++\r
++Otherwise, FILTER is ignored.\r
++"\r
++ (cond\r
++ ((functionp filter) (funcall filter query))\r
++ ((stringp filter)\r
++ (concat "(" query ") and (" filter ")"))\r
++ (t 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 :show-empty-searches, :filter and :filter-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 :filter-count)\r
++ (plist-get options :filter)))))))\r
++ (and (or (plist-get options :show-empty-searches) (> message-count 0))\r
++ (list name (notmuch-hello-filtered-query\r
++ (car query-and-count) (plist-get options :filter))\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
+@@ -281,13 +441,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
++ (msg-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 msg-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
+@@ -359,29 +519,240 @@ Complete list of currently available key bindings:\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
++ mode-name "notmuch-hello")\r
+ (run-mode-hooks 'notmuch-hello-mode-hook)\r
+ ;;(setq buffer-read-only t)\r
+ )\r
+ \r
+-(defun notmuch-hello-generate-tag-alist ()\r
++(defun notmuch-hello-generate-tag-alist (&optional hide-tags)\r
+ "Return an alist from tags to queries to display in the all-tags section."\r
+- (notmuch-remove-if-not\r
+- #'cdr\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
+- (notmuch-remove-if-not\r
+- (lambda (tag)\r
+- (not (member tag notmuch-hello-hide-tags)))\r
+- (process-lines notmuch-command "search-tags")))))\r
++ (mapcar (lambda (tag)\r
++ (cons tag (format "tag:%s" tag)))\r
++ (notmuch-remove-if-not\r
++ (lambda (tag)\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.\n")))\r
++\r
++\r
++(defun notmuch-hello-insert-saved-searches ()\r
++ "Insert the saved-searches section."\r
++ (let ((searches (notmuch-hello-query-counts\r
++ (if notmuch-saved-search-sort-function\r
++ (funcall notmuch-saved-search-sort-function\r
++ notmuch-saved-searches)\r
++ notmuch-saved-searches)\r
++ :show-empty-searches notmuch-show-empty-saved-searches))\r
++ found-target-pos)\r
++ (when searches\r
++ (widget-insert "Saved 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
++ (let ((start (point)))\r
++ (setq found-target-pos\r
++ (notmuch-hello-insert-buttons searches))\r
++ (indent-rigidly start (point) notmuch-hello-indent)\r
++ found-target-pos))))\r
++\r
++(defun notmuch-hello-insert-search ()\r
++ "Insert a search widget."\r
++ (widget-insert "Search: ")\r
++ (setq notmuch-hello-search-pos (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
++ ;; Add an invisible dot to make `widget-end-of-line' ignore\r
++ ;; trailing spaces in the search widget field. A dot is used\r
++ ;; instead of a space to make `show-trailing-whitespace'\r
++ ;; happy, i.e. avoid it marking the whole line as trailing\r
++ ;; spaces.\r
++ (widget-insert ".")\r
++ (put-text-property (1- (point)) (point) 'invisible t)\r
++ (widget-insert "\n"))\r
++\r
++(defun notmuch-hello-insert-recent-searches ()\r
++ "Insert recent searches."\r
++ (when notmuch-search-history\r
++ (widget-insert "Recent searches: ")\r
++ (widget-create 'push-button\r
++ :notify (lambda (&rest ignore)\r
++ (setq notmuch-search-history nil)\r
++ (notmuch-hello-update))\r
++ "clear")\r
++ (widget-insert "\n\n")\r
++ (let ((start (point)))\r
++ (loop for i from 1 to notmuch-hello-recent-searches-max\r
++ for search in notmuch-search-history do\r
++ (let ((widget-symbol (intern (format "notmuch-hello-search-%d" i))))\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
++ (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
++:show-empty-searches - show buttons with no matching messages\r
++:hide-if-empty - hide if no buttons would be shown\r
++ (only makes sense without :show-empty-searches)\r
++:filter - This can be a function that takes the search query as its argument and\r
++ returns a filter to be used in conjuction with the query for that search or nil\r
++ to hide the element. This can also be a string that is used as a combined with\r
++ each query using \"and\".\r
++:filter-count - Separate filter to generate the count displayed each search. Accepts\r
++ the same values as :filter. If :filter and :filter-count are specified, this\r
++ will be used instead of :filter, not in conjunction with it."\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 with message counts.\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 (plist-get options :hide-tags))\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
++ :filter "tag:inbox"))\r
++\r
++(defun notmuch-hello-insert-alltags ()\r
++ "Insert a section displaying all tags and associated message counts"\r
++ (notmuch-hello-insert-tags-section\r
++ nil\r
++ :initially-hidden (not notmuch-show-all-tags-list)\r
++ :hide-tags notmuch-hello-hide-tags\r
++ :filter notmuch-hello-tag-list-make-query))\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-search-history\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 "`=' to refresh this screen. `s' to search messages. `q' to quit.\n")\r
++ (widget-create 'link\r
++ :notify (lambda (&rest ignore)\r
++ (customize-variable 'notmuch-hello-sections))\r
++ :button-prefix "" :button-suffix ""\r
++ "Customize")\r
++ (widget-insert " this page.")\r
++ (let ((fill-column (- (window-width) notmuch-hello-indent)))\r
++ (center-region start (point)))))\r
+ \r
+ ;;;###autoload\r
+ (defun notmuch-hello (&optional no-display)\r
+@@ -397,13 +768,13 @@ Complete list of currently available key bindings:\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
+ (inhibit-read-only t))\r
+ \r
+ ;; Delete all editable widget fields. Editable widget fields are\r
+@@ -422,168 +793,20 @@ 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
+- (default-pos))\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
+- ;; Sort saved searches if required.\r
+- (when notmuch-saved-search-sort-function\r
+- (setq saved-alist\r
+- (funcall notmuch-saved-search-sort-function 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 default-pos (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
+- ;; Add an invisible dot to make `widget-end-of-line' ignore\r
+- ;; trailing spaces in the search widget field. A dot is used\r
+- ;; instead of a space to make `show-trailing-whitespace'\r
+- ;; happy, i.e. avoid it marking the whole line as trailing\r
+- ;; spaces.\r
+- (widget-insert ".")\r
+- (put-text-property (1- (point)) (point) 'invisible t)\r
+- (widget-insert "\n")\r
+-\r
+- (when notmuch-search-history\r
+- (widget-insert "\nRecent searches: ")\r
+- (widget-create 'push-button\r
+- :notify (lambda (&rest ignore)\r
+- (setq notmuch-search-history nil)\r
+- (notmuch-hello-update))\r
+- "clear")\r
+- (widget-insert "\n\n")\r
+- (let ((start (point)))\r
+- (loop for i from 1 to notmuch-hello-recent-searches-max\r
+- for search in notmuch-search-history do\r
+- (let ((widget-symbol (intern (format "notmuch-hello-search-%d" i))))\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
+- (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
+- (unless 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
+- (unless 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-search-history\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 "`=' to refresh this screen. `s' to search messages. `q' to quit.\n")\r
+- (let ((fill-column (- (window-width) notmuch-hello-indent)))\r
+- (center-region start (point))))\r
+-\r
++ (let (final-target-pos)\r
++ (mapc\r
++ (lambda (section)\r
++ (let ((point-before (point))\r
++ (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
++ ;; don't insert a newline when the previous section didn't show\r
++ ;; anything.\r
++ (unless (eq (point) point-before)\r
++ (widget-insert "\n"))))\r
++ notmuch-hello-sections)\r
+ (widget-setup)\r
+ \r
+ (when final-target-pos\r
+@@ -592,9 +815,10 @@ Complete list of currently available key bindings:\r
+ (widget-forward 1)))\r
+ \r
+ (unless (widget-at)\r
+- (goto-char default-pos))))\r
+-\r
+- (run-hooks 'notmuch-hello-refresh-hook))\r
++ (when notmuch-hello-search-pos\r
++ (goto-char notmuch-hello-search-pos)))))\r
++ (run-hooks 'notmuch-hello-refresh-hook)\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.9\r
+\r