From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 824EB431FC2 for ; Sat, 5 Apr 2014 22:45:10 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 2.7 X-Spam-Level: ** X-Spam-Status: No, score=2.7 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001, FREEMAIL_REPLY=2.499, 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 muHs4sMzqnAx for ; Sat, 5 Apr 2014 22:45:05 -0700 (PDT) Received: from mail-wi0-f176.google.com (mail-wi0-f176.google.com [209.85.212.176]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id A7DC7431FAF for ; Sat, 5 Apr 2014 22:45:04 -0700 (PDT) Received: by mail-wi0-f176.google.com with SMTP id r20so3354329wiv.3 for ; Sat, 05 Apr 2014 22:45:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=W4rjkiAAHOI4J9zsDwrGYyYIPPUircbWpiot3yyIoro=; b=TdQWzMyNfBV8SADbCLvH6UIjjMbk7Gapr7Ogc/XjNsvZIlemI1zLKi0kmqDpjbxZLf vnReenYPn4D/8qECHZp7WMj/obykThnaLtngwGuwKMu0S37+1CtWwS6PcyEtGR1e/OLP Qc/vfoqXNXrtF+egB/AMWjePLpljDTJokbO2K1mfNlntHdLT1ojZoctkubwRbLZRDldP NZCpBLUrsuDL4rhKTiu5DHV87+efpznkJE5jhzRAqwDUn7XLeVhUsHOrhWx96bNFuH3K cy7uvkY8HqJK0iv0X5+UajK4CEns2IYPQDsZ/EXbIodaqNqFjn/Q+4IwwyJ3TE4bIP1i C+Iw== X-Received: by 10.194.82.9 with SMTP id e9mr32622726wjy.45.1396763103078; Sat, 05 Apr 2014 22:45:03 -0700 (PDT) Received: from localhost (93-97-24-31.zone5.bethere.co.uk. [93.97.24.31]) by mx.google.com with ESMTPSA id t1sm7454979wia.1.2014.04.05.22.45.02 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sat, 05 Apr 2014 22:45:02 -0700 (PDT) From: Mark Walters To: notmuch@notmuchmail.org, amdragon@MIT.EDU Subject: [PATCH v2 0/5] emacs: hello: convert saved-searches to plists Date: Sun, 6 Apr 2014 06:44:44 +0100 Message-Id: <1396763089-32452-1-git-send-email-markwalters1009@gmail.com> X-Mailer: git-send-email 1.7.10.4 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: Sun, 06 Apr 2014 05:45:10 -0000 This is v2 of the series; v1 is at id:1396733065-32602-1-git-send-email-markwalters1009@gmail.com I have made all the changes suggested by Austin in his review of v1. I include the diff from v1 below. There is now one slight oddity in the patch ordering: the documentation for the plist form appears in patch 3 while the users and references to that documentation appear in patch 2. Best wishes Mark Mark Walters (5): emacs: hello: add helper functions for saved-searches emacs: hello: use the saved-search helper functions emacs: hello: add a customize for saved-searches emacs: hello: switch notmuch-hello-insert-buttons to plists emacs: Add a sort-order option to saved-searches emacs/notmuch-hello.el | 127 ++++++++++++++++++++++++++++++++---------------- emacs/notmuch-lib.el | 54 ++++++++++++++++++-- emacs/notmuch.el | 6 +-- 3 files changed, 139 insertions(+), 48 deletions(-) diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el index 6a28372..f0675f2 100644 --- a/emacs/notmuch-hello.el +++ b/emacs/notmuch-hello.el @@ -272,17 +272,17 @@ (defun notmuch-hello-search (&optional search) (defun notmuch-saved-search-get (saved-search field) "Get FIELD from SAVED-SEARCH. -In the new style saved-search (a plist) this is just plist-get -but, for backwards compatibility, this deals with the two -old-style forms: cons cells (NAME . QUERY) and lists (NAME QUERY -COUNT-QUERY)." +If SAVED-SEARCH is a plist, this is just `plist-get', but for +backwards compatibility, this also deals with the two other +possible formats for SAVED-SEARCH: cons cells (NAME . QUERY) and +lists (NAME QUERY COUNT-QUERY)." (cond - ((plist-get saved-search :name) + ((keywordp (car saved-search)) (plist-get saved-search field)) ;; It is not a plist so it is an old-style entry. ((consp (cdr saved-search)) ;; It is a list (NAME QUERY COUNT-QUERY) (case field - (:name (car saved-search)) + (:name (first saved-search)) (:query (second saved-search)) (:count-query (third saved-search)) (t nil))) @@ -293,16 +293,15 @@ (defun notmuch-saved-search-get (saved-search field) (t nil))))) (defun notmuch-hello-saved-search-to-plist (saved-search) - "Convert a saved-search variable into plist form. + "Return a copy of SAVED-SEARCH in plist form. -The new style saved search is just a plist, but for backwards -compatatibility we use this function to give them in -plist-form. In all cases a new copy is returned so it is safe to -modify the returned value." - (if (and (listp (cdr saved-search)) (plist-member saved-search :name)) +If saved search is a plist then just return a copy. In other +cases, for backwards compatability, convert to plist form and +return that." + (if (keywordp (car saved-search)) (copy-seq saved-search) (let ((fields (list :name :query :count-query)) - (plist-search)) + plist-search) (dolist (field fields plist-search) (let ((string (notmuch-saved-search-get saved-search field))) (when string @@ -424,11 +423,11 @@ (defun notmuch-hello-query-counts (query-list &rest options) QUERY-LIST must be a list of saved-searches. Ideally each of these is a plist but other options are available for backwards -compatibility: see notmuch-saved-search-get for details. +compatibility: see `notmuch-saved-searches' for details. The result is a list of plists each of which includes the -pairs :name NAME, :query QUERY and :count COUNT, together with -any pairs in the original saved-search. +properties :name NAME, :query QUERY and :count COUNT, together +with any properties in the original saved-search. The values :show-empty-searches, :filter and :filter-count from options will be handled as specified for @@ -464,20 +463,20 @@ (defun notmuch-hello-query-counts (query-list &rest options) search-query (plist-get options :filter))) (message-count (prog1 (read (current-buffer)) (forward-line 1)))) - (and (or (plist-get options :show-empty-searches) (> message-count 0)) - (setq elem-plist (plist-put elem-plist :query filtered-query)) - (plist-put elem-plist :count message-count)))) + (when (and filtered-query (or (plist-get options :show-empty-searches) (> message-count 0))) + (setq elem-plist (plist-put elem-plist :query filtered-query)) + (plist-put elem-plist :count message-count)))) query-list)))) (defun notmuch-hello-insert-buttons (searches) "Insert buttons for SEARCHES. SEARCHES must be a list of plists each of which should contain at -least pairs for :name NAME :query QUERY and :count COUNT, where -QUERY is the query to start when the button for the corresponding -entry is activated, and COUNT should be the number of messages -matching the query. Such a plist can be computed with -`notmuch-hello-query-counts'." +least the properties :name NAME :query QUERY and :count COUNT, +where QUERY is the query to start when the button for the +corresponding entry is activated, and COUNT should be the number +of messages matching the query. Such a plist can be computed +with `notmuch-hello-query-counts'." (let* ((widest (notmuch-hello-longest-label searches)) (tags-and-width (notmuch-hello-tags-per-line widest)) (tags-per-line (car tags-and-width)) @@ -497,13 +496,10 @@ (defun notmuch-hello-insert-buttons (searches) (widget-insert (make-string column-indent ? ))) (let* ((name (plist-get elem :name)) (query (plist-get elem :query)) - (oldest-first (cond - ((eq (plist-get elem :sort-order) 'newest-first) - nil) - ((eq (plist-get elem :sort-order) 'oldest-first) - t) - (t - notmuch-search-oldest-first))) + (oldest-first (case (plist-get elem :sort-order) + (newest-first nil) + (oldest-first t) + (otherwise notmuch-search-oldest-first))) (msg-count (plist-get elem :count))) (widget-insert (format "%8s " (notmuch-hello-nice-number msg-count))) @@ -741,7 +737,7 @@ (defun notmuch-hello-insert-searches (title query-list &rest options) QUERY-LIST should ideally be a plist but for backwards compatibility other forms are also accepted (see -`notmuch-saved-search-get' for details). The plist should +`notmuch-saved-searches' for details). The plist should contain keys :name and :query; if :count-query is also present then it specifies an alternate query to be used to generate the count for the associated search. diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el index 8aa8cfc..3a3c69d 100644 --- a/emacs/notmuch-lib.el +++ b/emacs/notmuch-lib.el @@ -134,7 +134,26 @@ (define-widget 'notmuch-saved-search-plist 'list (defcustom notmuch-saved-searches '((:name "inbox" :query "tag:inbox") (:name "unread" :query "tag:unread")) - "A list of saved searches to display." + "A list of saved searches to display. + +The saved search can be given in 3 forms. The preferred way is as +a plist. Supported properties are + + :name Name of the search (required). + :query Search to run (required). + :count-query Optional extra query to generate the count + shown. If not present then the :query property + is used. + :sort-order Specify the sort order to be used for the search. + Possible values are 'oldest-first 'newest-first or + nil. Nil means use the default sort order. + +Other accepted forms are a cons cell of the form (NAME . QUERY) +or a list of the form (NAME QUERY COUNT-QUERY)." +;; The saved-search format is also used by the all-tags notmuch-hello +;; section. This section generates its own saved-search list in one of +;; the latter two forms. + :get 'notmuch--saved-searches-to-plist :type '(repeat notmuch-saved-search-plist) :tag "List of Saved Searches" -- 1.7.10.4