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 85BF2431FD0 for ; Fri, 3 Jun 2011 06:46:15 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.799 X-Spam-Level: X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled 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 CwmAzRG32lU4 for ; Fri, 3 Jun 2011 06:46:13 -0700 (PDT) Received: from mail-bw0-f53.google.com (mail-bw0-f53.google.com [209.85.214.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id B5589431FB6 for ; Fri, 3 Jun 2011 06:46:12 -0700 (PDT) Received: by bwg12 with SMTP id 12so1942134bwg.26 for ; Fri, 03 Jun 2011 06:46:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:from:to:subject:in-reply-to:references :user-agent:date:message-id:mime-version:content-type; bh=elyFdZpGSBSVGe7reUktidxptd8bCxKl3qqvwnNP4B8=; b=jCqL+DPVyQiwFZoKQXUtqWVqbCF6Adjke6ZVfhrRu/nmd8owdpObZcBhVk6tJP0vNk TgH9kw32yyF3jSr9Rrguk+dUEmdzFWkad1NJZK/3G9SN3UJx3uIl5Lmvweq46qWblApF CcLio2M3LtswB06uqrii4aIKNXYqWFCpJ+5mU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=from:to:subject:in-reply-to:references:user-agent:date:message-id :mime-version:content-type; b=cWmKOdEKu3frw16c+B84VqK7sM4amJU1MTmIk3Sx+528Y1wpksmOR6fQA4pcFMJDkc SvOJpIvf+IPv9+mxrCrjiEcp6L/WudloRHe+/WEg1/Car14jFQFFurMFNBRLaRxXe8W4 S7NmuAsqHZKzzvtUoN40JDXQZRCqXvw3JmKTE= Received: by 10.204.71.193 with SMTP id i1mr2002573bkj.102.1307108770782; Fri, 03 Jun 2011 06:46:10 -0700 (PDT) Received: from localhost (dslb-088-069-146-026.pools.arcor-ip.net [88.69.146.26]) by mx.google.com with ESMTPS id k16sm1283227bks.13.2011.06.03.06.46.06 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 03 Jun 2011 06:46:08 -0700 (PDT) From: Daniel Schoepe To: notmuch@notmuchmail.org Subject: Re: [PATCH] emacs: User-defined sections in notmuch-hello In-Reply-To: <874o4g563y.fsf@gilead.invalid> References: <874o4g563y.fsf@gilead.invalid> User-Agent: Notmuch/0.5-172-g3faaff1 (http://notmuchmail.org) Emacs/23.3.1 (x86_64-pc-linux-gnu) Date: Fri, 03 Jun 2011 15:46:00 +0200 Message-ID: <87tyc7hvtz.fsf@gilead.invalid> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" 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: Fri, 03 Jun 2011 13:46:15 -0000 --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain On Fri, 27 May 2011 20:52:01 +0200, Daniel Schoepe wrote: > I'll also work on some tests for this functionality, (if no one > has big, structural complaints about the code). I rebased my patch against the current master and wrote some tests. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-emacs-User-defined-sections-in-notmuch-hello.patch Content-Transfer-Encoding: quoted-printable From=2042b87fca9b8b2ca5ba6748185dac4e945d7c594b Mon Sep 17 00:00:00 2001 From: Daniel Schoepe Date: Thu, 26 May 2011 23:03:22 +0200 Subject: [PATCH 1/2] emacs: User-defined sections in notmuch-hello This patch allows the user to define various sections that will be displayed in notmuch-hello. I tried to keep the section description flexible, so it allows different queries for the tag buttons and the counts next to them, as well as hiding items with zero results. The sections are (hopefully) fully editable using customize. I have not yet rewritten the saved-searches portion using this mechanism, to avoid breaking the configurations of many users. =2D-- emacs/notmuch-hello.el | 333 ++++++++++++++++= ---- emacs/notmuch-lib.el | 22 +- test/emacs.expected-output/notmuch-hello | 2 +- .../notmuch-hello-no-saved-searches | 2 +- .../emacs.expected-output/notmuch-hello-with-empty | 2 +- 5 files changed, 282 insertions(+), 79 deletions(-) diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el index 916cda1..f014357 100644 =2D-- a/emacs/notmuch-hello.el +++ b/emacs/notmuch-hello.el @@ -55,24 +55,115 @@ :type 'boolean :group 'notmuch) =20 =2D(defcustom notmuch-hello-tag-list-make-query nil =2D "Function or string to generate queries for the all tags list. =2D =2DThis variable controls which query results are shown for each tag =2Din the \"all tags\" list. If nil, it will use all messages with =2Dthat tag. If this is set to a string, it is used as a filter for =2Dmessages having that tag (equivalent to \"tag:TAG and (THIS-VARIABLE)\"). =2DFinally this can be a function that will be called for each tag and =2Dshould return a filter for that tag, or nil to hide the tag." =2D :type '(choice (const :tag "All messages" nil) =2D (const :tag "Unread messages" "tag:unread") =2D (const :tag "Custom filter" string) =2D (const :tag "Custom filter function" function)) =2D :group 'notmuch) =2D =2D(defcustom notmuch-hello-hide-tags nil =2D "List of tags to be hidden in the \"all tags\"-section." =2D :type '(repeat string) +(defvar notmuch-hello-section-all-tags + (list :title "All tags:" + :type 'eachtag) + "Default section definition for the \"all tags\" section.") + +(defvar notmuch-hello-section-unread-tags + (list :title "All tags, unread only:" + :type 'eachtag + :make-query "tag:unread") + "Show and count only unread messages for each tag.") + +(defvar notmuch-hello-hidden-sections nil + "Sections that are hidden in notmuch-hello") + +(defvar notmuch-hello-first-run t + "Internal variable for hiding sections with :hidden-on-startup") + +(define-widget 'notmuch-section-query-type 'lazy + "Customize-type for query items" + :tag "Query item" + :type '(list (string :tag "Search title") + (string :tag "Query to use") + (choice :tag "Query for message count" + (const :tag "Use previous query" nil) + (string :tag "Different query")))) + +(define-widget 'notmuch-section-make-query-type 'lazy + "Customize-type for query functions" + :tag "Query function" + :type '(choice (const :tag "All messages with tag" nil) + (const :tag "Only unread messages" "tag:unread") + (string :tag "Custom filter string") + (function :tag "Custom filter function"))) + +(define-widget 'notmuch-section-type 'lazy + "Customize-type for sections" + :tag "Custom section" + :type + '(plist :options (((const :tag "Title for this section" :title) + string) + ((const :tag "Type of this section" :type) + (choice (const :tag "One item for each tag" + eachtag) + (const :tag "Custom list of searches" + query-list))) + ((const :tag "Function to generate a query, ignored if custom list" + :make-query) + notmuch-section-make-query) + ((const :tag "Function to generate counts, ignored if custom list" + :make-count) + notmuch-section-make-query) + ((const :tag "Function to create titles for tag entries, ignored if = custom list" + :make-title) + (choice (const :tag "The tag itself" nil) + (function :tag "Custom function"))) + ((const :tag "List of tags to hide, ignored if custom list" + :hide-tags) + (repeat (string :tag "tag"))) + ((const :tag "Search queries, only used if custom list" + :items) + (repeat notmuch-section-query)) + ((const :tag "Hide if there are no results" :hide-empty) + boolean) + ((const :tag "Where should this be positioned" :position) + (choice (const :tag "Before the search input" before) + (const :tag "After the search input" after)))))) + +(defcustom notmuch-hello-sections (list notmuch-hello-section-all-tags) + "Sections to be displayed in notmuch-hello. + +This variable does not include the saved-searches section, which +is handled separately. +This variable should be a list of plists with the following +possible properties: + +:title - The title of the section +:type - Can be 'eachtag or 'query-list, If 'eachtag, generate one + item for each tag, otherwise use a fixed set of items. +The following options are only used when type is 'eachtag: +:make-query - This can be a query string that is used as a filter for all + messages that contain this tag. This can also be a function + that is given is tag and should return a filter query. If + it returns nil, the tag will be hidden. If nil, all + messages having the tag will be used. +:make-count - Query used to generate message counts next to the labels, + same type as :make-query. If this is nil, the same query as + above will be used. +:make-title - Function to generate an alternative title for each tag item. + Can be nil. +:hide-tags - List of tags that will be hidden. + +If :type is 'query-list, the following entry must be set: +:items - List of cons-cells of a title and a query for that item, + and/or of lists of the form (TITLE QUERY COUNT), where COUNT is + used to generate the message count instead of QUERY. (To make + the customize-interface nicer, COUNT is also allowed to be nil). + +The following properties are valid for both :type's: +:hide-empty - If non-nil, hide items that have no matching messages +:position - If 'before, it will be displayed before the search input form,= otherwise + after the recent searches. +:hidden-on-startup - If non-nil, this section will be hidden when notmuch-= hello + is first run." + :type `(repeat + (choice (const :tag "Show all messages for each tag" + ,notmuch-hello-section-all-tags) + (const :tag "Only unread messages for each tag" + ,notmuch-hello-section-unread-tags) + notmuch-section-type)) :group 'notmuch) =20 (defface notmuch-hello-logo-background @@ -238,12 +329,32 @@ should be. Returns a cons cell `(tags-per-line width)= '." (* tags-per-line (+ 9 1)))) tags-per-line)))) =20 =2D(defun notmuch-hello-insert-tags (tag-alist widest target) +(defun notmuch-hello-get-count-query (query-item) + (if (consp (cdr query-item)) + (or (third query-item) (second query-item)) + (cdr query-item))) + +(defun notmuch-hello-insert-tags (tag-alist widest target &optional show-e= mpty) (let* ((tags-and-width (notmuch-hello-tags-per-line widest)) (tags-per-line (car tags-and-width)) + (count-alist + (mapcar + (lambda (tag-entry) + (cons (car tag-entry) + (string-to-number (notmuch-saved-search-count + (notmuch-hello-get-count-query tag-entry))))) + tag-alist)) + (tag-alist-filtered + (if show-empty + tag-alist + (notmuch-remove-if-not + (lambda (tag-entry) + ;; filter out entries that have 0 results + (and (not (eq 0 (cdr (assoc (car tag-entry) count-alist)))) tag-en= try)) + tag-alist))) (widest (cdr tags-and-width)) (count 0) =2D (reordered-list (notmuch-hello-reflect tag-alist tags-per-line)) + (reordered-list (notmuch-hello-reflect tag-alist-filtered tags-per-line)) ;; Hack the display of the buttons used. (widget-push-button-prefix "") (widget-push-button-suffix "") @@ -254,11 +365,14 @@ should be. Returns a cons cell `(tags-per-line width)= '." ;; (not elem) indicates an empty slot in the matrix. (when elem (let* ((name (car elem)) =2D (query (cdr elem)) + (query (if (consp (cdr elem)) + (second elem) + (cdr elem))) + (count-query (notmuch-hello-get-count-query elem)) (formatted-name (format "%s " name))) (widget-insert (format "%8s " (notmuch-hello-nice-number =2D (string-to-number (notmuch-saved-search-count query))))) + (cdr (assoc name count-alist))))) (if (string=3D formatted-name target) (setq found-target-pos (point-marker))) (widget-create 'push-button @@ -338,24 +452,94 @@ Complete list of currently available key bindings: ;;(setq buffer-read-only t) ) =20 =2D(defun notmuch-hello-generate-tag-alist () =2D "Return an alist from tags to queries to display in the all-tags secti= on." =2D (notmuch-remove-if-not =2D #'cdr =2D (mapcar (lambda (tag) =2D (cons tag =2D (cond =2D ((functionp notmuch-hello-tag-list-make-query) =2D (concat "tag:" tag " and (" =2D (funcall notmuch-hello-tag-list-make-query tag) ")")) =2D ((stringp notmuch-hello-tag-list-make-query) =2D (concat "tag:" tag " and (" =2D notmuch-hello-tag-list-make-query ")")) =2D (t (concat "tag:" tag))))) =2D (notmuch-remove-if-not =2D (lambda (tag) =2D (not (member tag notmuch-hello-hide-tags))) =2D (process-lines notmuch-command "search-tags"))))) +(defun notmuch-hello-section-tag-to-title (section tag) + (let ((make-title (plist-get section :make-title))) + (if make-title + (funcall make-title tag) + tag))) + +(defun notmuch-hello-section-get-widest (section) + "Return widest title string in SECTION." + (if (member (plist-get section :title) notmuch-hello-hidden-sections) + 0 + (case (plist-get section :type) + ('eachtag (apply #'max + (mapcar (lambda (tag) + (length (notmuch-hello-section-tag-to-title section tag))) + (notmuch-all-tags)))) + ('query-list (apply #'max + (mapcar (lambda (entry) (length (first entry))) + (plist-get section :items)))) + (t (message (concat "Unknown section type: "=20 + (prin1-to-string (plist-get section :type)))))))) +=20=20 +(defun notmuch-hello-generate-tag-alist (section) + "Generate an alist of tags as expected by notmuch-insert-tags for SECTIO= N. + +This function handles the special case that section is of type 'eachtag" + (let ((make-tag (lambda (make-entry tag) + (cond + ((functionp make-entry) + (let ((query (funcall make-entry tag))) + (and query + (concat "tag:" tag " and (" query ")")))) + ((stringp make-entry) + (concat "tag:" tag " and (" make-entry ")")) + (t (concat "tag:" tag)))))) + ;; remove tags for which make-query returned nil + (delq nil + (mapcar (lambda (tag) + (let ((title + (notmuch-hello-section-tag-to-title section tag)) + (query (funcall make-tag + (plist-get section :make-query) tag)) + (count (plist-get section :make-count))) + (and query + (if count + (list title query (funcall make-tag count tag)) + (cons title query))))) + ;; remove tags from :hide-tags + (notmuch-remove-if-not + (lambda (tag) + (not (member tag (plist-get section :hide-tags)))) + (notmuch-all-tags)))))) + +(defun notmuch-hello-section-to-alist (section) + "Generate an alist of tags as expected by notmuch-insert-tags for SECTIO= N." + (case (plist-get section :type) + ('eachtag (notmuch-hello-generate-tag-alist section)) + ('query-list (plist-get section :items)) + (t (message (concat "Unknown section type: " + (prin1-to-string (plist-get section :type))))))) +=09=20=20=20=20=20=20 + +(defun notmuch-hello-insert-section (section widest target) +"Insert all UI elements for SECTION in the current buffer." + (let* ((tags-alist (notmuch-hello-section-to-alist section)) + (title (plist-get section :title)) + (hidden (member title notmuch-hello-hidden-sections)) + (hide-empty (plist-get section :hide-empty)) + target-pos) + (widget-insert (concat "\n" title " ")) + (when hidden + (widget-create 'push-button + :notify `(lambda (widget &rest ignore) + (setq notmuch-hello-hidden-sections + (delq ,title notmuch-hello-hidden-sections)) + (notmuch-hello-update)) + "show")) + (when (not hidden) + (widget-create 'push-button + :notify `(lambda (widget &rest ignore) + (add-to-list 'notmuch-hello-hidden-sections ,title) + (notmuch-hello-update)) + "hide") + (widget-insert "\n\n") + (let ((start (point))) + (setq target-pos (notmuch-hello-insert-tags tags-alist widest target + (not hide-empty))) + (indent-rigidly start (point) notmuch-hello-indent)) + target-pos))) =20 ;;;###autoload (defun notmuch-hello (&optional no-display) @@ -426,7 +610,30 @@ Complete list of currently available key bindings: (widget-insert " messages.\n")) =20 (let ((found-target-pos nil) =2D (final-target-pos nil)) + (final-target-pos nil) + (upper-sections (notmuch-remove-if-not + (lambda (section) (eq (plist-get section :position) + 'before)) + notmuch-hello-sections)) + (lower-sections (notmuch-remove-if-not + (lambda (section) (not (eq (plist-get section :position) + 'before))) + notmuch-hello-sections))) + + ;; handle sections that should be hidden initially + (when notmuch-hello-first-run + (mapc (lambda (section) + (if (plist-get section :hidden-on-startup) + (add-to-list 'notmuch-hello-hidden-sections + (plist-get section :title)))) + notmuch-hello-sections) + ;; special case for notmuch-show-all-tags-list + (when (and (not notmuch-show-all-tags-list) + (member notmuch-hello-section-all-tags notmuch-hello-sections)) + (add-to-list 'notmuch-hello-hidden-sections + (plist-get notmuch-hello-section-all-tags :title))) + (setq notmuch-hello-first-run nil)) + (let* ((saved-alist ;; Filter out empty saved seaches if required. (if notmuch-show-empty-saved-searches @@ -435,9 +642,9 @@ Complete list of currently available key bindings: if (> (string-to-number (notmuch-saved-search-count (cdr elem))) 0) collect elem))) (saved-widest (notmuch-hello-longest-label saved-alist)) =2D (alltags-alist (if notmuch-show-all-tags-list (notmuch-hello-gener= ate-tag-alist))) =2D (alltags-widest (notmuch-hello-longest-label alltags-alist)) =2D (widest (max saved-widest alltags-widest))) + (sections-widest (apply #'max 0 (mapcar #'notmuch-hello-section-get-= widest + notmuch-hello-sections))) + (widest (max saved-widest sections-widest))) =20 (when saved-alist (widget-insert "\nSaved searches: ") @@ -448,11 +655,19 @@ Complete list of currently available key bindings: (widget-insert "\n\n") (setq final-target-pos (point-marker)) (let ((start (point))) =2D (setq found-target-pos (notmuch-hello-insert-tags saved-alist wides= t target)) + (setq found-target-pos (notmuch-hello-insert-tags saved-alist widest = target + notmuch-show-empty-saved-searches)) (if found-target-pos (setq final-target-pos found-target-pos)) (indent-rigidly start (point) notmuch-hello-indent))) =20 + (mapc (lambda (section) + (setq found-target-pos + (notmuch-hello-insert-section section widest target)) + (unless final-target-pos + (setq final-target-pos found-target-pos))) + upper-sections) + (widget-insert "\nSearch: ") (setq notmuch-hello-search-bar-marker (point-marker)) (widget-create 'editable-field @@ -507,28 +722,12 @@ Complete list of currently available key bindings: notmuch-hello-recent-searches) (indent-rigidly start (point) notmuch-hello-indent))) =20 =2D (when alltags-alist =2D (widget-insert "\nAll tags: ") =2D (widget-create 'push-button =2D :notify (lambda (widget &rest ignore) =2D (setq notmuch-show-all-tags-list nil) =2D (notmuch-hello-update)) =2D "hide") =2D (widget-insert "\n\n") =2D (let ((start (point))) =2D (setq found-target-pos (notmuch-hello-insert-tags alltags-alist wid= est target)) =2D (if (not final-target-pos) =2D (setq final-target-pos found-target-pos)) =2D (indent-rigidly start (point) notmuch-hello-indent))) =2D =2D (widget-insert "\n") =2D =2D (if (not notmuch-show-all-tags-list) =2D (widget-create 'push-button =2D :notify (lambda (widget &rest ignore) =2D (setq notmuch-show-all-tags-list t) =2D (notmuch-hello-update)) =2D "Show all tags"))) + (mapc (lambda (section) + (setq found-target-pos + (notmuch-hello-insert-section section widest target)) + (unless final-target-pos + (setq final-target-pos found-target-pos))) + lower-sections)) =20 (let ((start (point))) (widget-insert "\n\n") diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el index a21dc14..bc46334 100644 =2D-- a/emacs/notmuch-lib.el +++ b/emacs/notmuch-lib.el @@ -103,6 +103,19 @@ the user hasn't set this variable with the old or new = value." (kill-new text) (message "Stashed: %s" text)) =20 +(defun notmuch-all-tags () + "Return a list of all tags in the database" + (process-lines "notmuch" "search-tags")) + +(defun notmuch-remove-if-not (predicate list) + "Return a copy of LIST with all items not satisfying PREDICATE removed." + (let (out) + (while list + (when (funcall predicate (car list)) + (push (car list) out)) + (setq list (cdr list))) + (nreverse out))) + ;; =20 ;; XXX: This should be a generic function in emacs somewhere, not @@ -120,15 +133,6 @@ within the current window." (or (memq prop buffer-invisibility-spec) (assq prop buffer-invisibility-spec))))) =20 =2D(defun notmuch-remove-if-not (predicate list) =2D "Return a copy of LIST with all items not satisfying PREDICATE removed= ." =2D (let (out) =2D (while list =2D (when (funcall predicate (car list)) =2D (push (car list) out)) =2D (setq list (cdr list))) =2D (nreverse out))) =2D ; This lets us avoid compiling these replacement functions when emacs ; is sufficiently new enough to supply them alone. We do the macro ; treatment rather than just wrapping our defun calls in a when form diff --git a/test/emacs.expected-output/notmuch-hello b/test/emacs.expected= -output/notmuch-hello index 64b7e42..f98f132 100644 =2D-- a/test/emacs.expected-output/notmuch-hello +++ b/test/emacs.expected-output/notmuch-hello @@ -6,7 +6,7 @@ Saved searches: [edit] =20 Search:=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 =20 =2D[Show all tags] +All tags: [show] =20 Type a search query and hit RET to view matching threads. Edit saved searches with the `edit' button. diff --git a/test/emacs.expected-output/notmuch-hello-no-saved-searches b/t= est/emacs.expected-output/notmuch-hello-no-saved-searches index 7f8206a..46172ee 100644 =2D-- a/test/emacs.expected-output/notmuch-hello-no-saved-searches +++ b/test/emacs.expected-output/notmuch-hello-no-saved-searches @@ -2,7 +2,7 @@ =20 Search:=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 =20 =2D[Show all tags] +All tags: [show] =20 Type a search query and hit RET to view matching threads. Edit saved searches with the `edit' button. diff --git a/test/emacs.expected-output/notmuch-hello-with-empty b/test/ema= cs.expected-output/notmuch-hello-with-empty index a9ed630..eb563cc 100644 =2D-- a/test/emacs.expected-output/notmuch-hello-with-empty +++ b/test/emacs.expected-output/notmuch-hello-with-empty @@ -6,7 +6,7 @@ Saved searches: [edit] =20 Search:=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 =20 =2D[Show all tags] +All tags: [show] =20 Type a search query and hit RET to view matching threads. Edit saved searches with the `edit' button. =2D-=20 1.7.5.3 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0002-emacs-A-few-tests-for-user-defined-sections.patch Content-Transfer-Encoding: quoted-printable From=205a401e74359eafa9e6fc83c19051402270cb3662 Mon Sep 17 00:00:00 2001 From: Daniel Schoepe Date: Fri, 3 Jun 2011 15:42:35 +0200 Subject: [PATCH 2/2] emacs: A few tests for user-defined sections =2D-- test/emacs | 29 ++++++++++++++++= ++++ .../notmuch-hello-new-section | 17 +++++++++++ .../notmuch-hello-section-before | 18 ++++++++++++ .../notmuch-hello-section-counts | 18 ++++++++++++ .../notmuch-hello-section-hidden-tag | 17 +++++++++++ .../notmuch-hello-section-with-empty | 17 +++++++++++ 6 files changed, 116 insertions(+), 0 deletions(-) create mode 100644 test/emacs.expected-output/notmuch-hello-new-section create mode 100644 test/emacs.expected-output/notmuch-hello-section-before create mode 100644 test/emacs.expected-output/notmuch-hello-section-counts create mode 100644 test/emacs.expected-output/notmuch-hello-section-hidden= -tag create mode 100644 test/emacs.expected-output/notmuch-hello-section-with-e= mpty diff --git a/test/emacs b/test/emacs index 792492f..7fea4ea 100755 =2D-- a/test/emacs +++ b/test/emacs @@ -31,6 +31,35 @@ output=3D$(test_emacs '(notmuch-hello) (goto-char (point= -min)) (re-search-forward expected=3D$(cat $EXPECTED/notmuch-hello-view-inbox) test_expect_equal "$output" "$expected" =20 +test_begin_subtest "User defined section with inbox tag" +output=3D$(test_emacs "(setq notmuch-hello-sections '((:title \"Test:\" :t= ype query-list :items ((\"inbox\" . \"tag:inbox\"))))) (notmuch-hello) (pri= nc (buffer-string))") +expected=3D$(cat $EXPECTED/notmuch-hello-new-section) +test_expect_equal "$output" "$expected" + +test_begin_subtest "User defined section with empty, hidden entry" +output=3D$(test_emacs "(setq notmuch-hello-sections '((:title \"Test-with-= empty:\" :type query-list :items + ((\"inbox\" . \"tag:inbox\") (\"doesnotexist\" . \"tag:doesno= texist\")) + :hide-empty t))) + (notmuch-hello) + (princ (buffer-string))") +expected=3D$(cat $EXPECTED/notmuch-hello-section-with-empty) +test_expect_equal "$output" "$expected" + +test_begin_subtest "User defined section, unread tag filtered out" +output=3D$(test_emacs "(setq notmuch-hello-sections '((:title \"Test-with-= filtered:\" :type eachtag :hide-tags (\"unread\")))) (notmuch-hello) (princ= (buffer-string))") +expected=3D$(cat $EXPECTED/notmuch-hello-section-hidden-tag) +test_expect_equal "$output" "$expected" + +test_begin_subtest "User defined section, different query for counts" +output=3D$(test_emacs "(setq notmuch-hello-sections '((:title \"Test-with-= counts:\" :type eachtag :make-count \"tag:signed\"))) (notmuch-hello) (prin= c (buffer-string))") +expected=3D$(cat $EXPECTED/notmuch-hello-section-counts) +test_expect_equal "$output" "$expected" + +test_begin_subtest "User defined section, positioned before search input" +output=3D$(test_emacs "(setq notmuch-hello-sections '((:title \"Test-befor= e\" :type eachtag :position before))) (notmuch-hello) (princ (buffer-string= ))") +expected=3D$(cat $EXPECTED/notmuch-hello-section-before) +test_expect_equal "$output" "$expected" + test_begin_subtest "Basic notmuch-show view in emacs" maildir_storage_thread=3D$(notmuch search --output=3Dthreads id:2009111719= 0054.GU3165@dottiness.seas.harvard.edu) output=3D$(test_emacs "(notmuch-show \"$maildir_storage_thread\") (princ (= buffer-string))") diff --git a/test/emacs.expected-output/notmuch-hello-new-section b/test/em= acs.expected-output/notmuch-hello-new-section new file mode 100644 index 0000000..23e0068 =2D-- /dev/null +++ b/test/emacs.expected-output/notmuch-hello-new-section @@ -0,0 +1,17 @@ + Welcome to notmuch. You have 50 messages. + +Saved searches: [edit] + + 50 inbox 50 unread=20=20=20=20 + +Search:=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 + +Test: [hide] + + 50 inbox=20=20=20=20=20 + + + Type a search query and hit RET to view matching threads. + Edit saved searches with the `edit' button. + Hit RET or click on a saved search or tag name to view matching threads. + `=3D' refreshes this screen. `s' jumps to the search box. `q' to quit. diff --git a/test/emacs.expected-output/notmuch-hello-section-before b/test= /emacs.expected-output/notmuch-hello-section-before new file mode 100644 index 0000000..a5781ce =2D-- /dev/null +++ b/test/emacs.expected-output/notmuch-hello-section-before @@ -0,0 +1,18 @@ + Welcome to notmuch. You have 50 messages. + +Saved searches: [edit] + + 50 inbox 50 unread=20=20=20=20=20=20=20=20=20=20 + +Test-before [hide] + + 4 attachment 7 signed=20=20=20=20=20=20=20=20=20=20 + 50 inbox 50 unread=20=20=20=20=20=20=20=20=20=20 + +Search:=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 + + + Type a search query and hit RET to view matching threads. + Edit saved searches with the `edit' button. + Hit RET or click on a saved search or tag name to view matching threads. + `=3D' refreshes this screen. `s' jumps to the search box. `q' to quit. diff --git a/test/emacs.expected-output/notmuch-hello-section-counts b/test= /emacs.expected-output/notmuch-hello-section-counts new file mode 100644 index 0000000..c22d491 =2D-- /dev/null +++ b/test/emacs.expected-output/notmuch-hello-section-counts @@ -0,0 +1,18 @@ + Welcome to notmuch. You have 50 messages. + +Saved searches: [edit] + + 50 inbox 50 unread=20=20=20=20=20=20=20=20=20=20 + +Search:=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 + +Test-with-counts: [hide] + + 2 attachment 7 signed=20=20=20=20=20=20=20=20=20=20 + 7 inbox 7 unread=20=20=20=20=20=20=20=20=20=20 + + + Type a search query and hit RET to view matching threads. + Edit saved searches with the `edit' button. + Hit RET or click on a saved search or tag name to view matching threads. + `=3D' refreshes this screen. `s' jumps to the search box. `q' to quit. diff --git a/test/emacs.expected-output/notmuch-hello-section-hidden-tag b/= test/emacs.expected-output/notmuch-hello-section-hidden-tag new file mode 100644 index 0000000..d6d31b3 =2D-- /dev/null +++ b/test/emacs.expected-output/notmuch-hello-section-hidden-tag @@ -0,0 +1,17 @@ + Welcome to notmuch. You have 50 messages. + +Saved searches: [edit] + + 50 inbox 50 unread=20=20=20=20=20=20=20=20=20=20 + +Search:=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 + +Test-with-filtered: [hide] + + 4 attachment 50 inbox 7 signed=20=20=20=20= =20=20=20=20=20=20 + + + Type a search query and hit RET to view matching threads. + Edit saved searches with the `edit' button. + Hit RET or click on a saved search or tag name to view matching threads. + `=3D' refreshes this screen. `s' jumps to the search box. `q' to quit. diff --git a/test/emacs.expected-output/notmuch-hello-section-with-empty b/= test/emacs.expected-output/notmuch-hello-section-with-empty new file mode 100644 index 0000000..7ab80f2 =2D-- /dev/null +++ b/test/emacs.expected-output/notmuch-hello-section-with-empty @@ -0,0 +1,17 @@ + Welcome to notmuch. You have 50 messages. + +Saved searches: [edit] + + 50 inbox 50 unread=20=20=20=20=20=20=20=20=20=20 + +Search:=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 + +Test-with-empty: [hide] + + 50 inbox=20=20=20=20=20=20=20=20=20=20=20 + + + Type a search query and hit RET to view matching threads. + Edit saved searches with the `edit' button. + Hit RET or click on a saved search or tag name to view matching threads. + `=3D' refreshes this screen. `s' jumps to the search box. `q' to quit. =2D-=20 1.7.5.3 --=-=-=-- --==-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iQIcBAEBAgAGBQJN6OWYAAoJEIaTAtce+Z+JPCIP+wagZv/LafBC0u3qORTG1Gbp kkjIMw1/DPdRDZs/MJuQQEWCPD2qgzJOW8XjPhgoHF3QLPwwcxn3YrcEfcWjkn2A eADNzZjjKCqJ98yehQufeLyP5Er7v4uCeVAqEyJJSfJOU4ZbdjpwpP7xpYsxqRpV EeGDKhwz64qJCuaXC0Wg037kT4sZzO4wdIbgjvCYeljJ8EEFd4brBVoVffTkFmij nbRLgEI7Aq7pt5yzl0Qe8VKVPFQLrzzH1Yh6VLP9neW7hETJFpWuAaNxdqey4LcG 1kzkLv48NNE4NUMmed7AinUdwnU9bzOD0XC8bCBExUyX8yTPJatR3VnZjeZHSHVx qoIbZhajJXPcOOk7ZGomy5CZqzCYcNuT/iHK16dzfmveIEt9a/7csUtX75yOwHI6 lvqPlSudAbTOF9sPtdxKPPc5cwlCi55lgV0qjlkuKVsqOZu0YqwbU+RWNGF7cvNr p5F4gOWYP5PnYN/S1I5EL4Csm+hOau+qJqdpaDC3I/RmZfvX65WwH6SHSQW0En30 c42kX3i3wP7NVGWEoE6pBRqhTvLbFphLI77PqtL7/wF+eO4ic8adYJoKOlXu/i2I IiZWrocGoc9s4LeynnsJsWTUf13sXJfgId4pegisb+hMPX3sPk83pMbXJeJ42Op/ MFshrDuucmIYVe7VCYTQ =AFxu -----END PGP SIGNATURE----- --==-=-=--