From: Mark Walters Date: Sat, 5 Apr 2014 21:24:21 +0000 (+0100) Subject: [PATCH 1/5] emacs: hello: add helper functions for saved-searches X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=eea682be03b35db949dd3e2dfc57bb24131c89db;p=notmuch-archives.git [PATCH 1/5] emacs: hello: add helper functions for saved-searches --- diff --git a/d8/9e7893ca411825ae23864fc745ebbece6eac30 b/d8/9e7893ca411825ae23864fc745ebbece6eac30 new file mode 100644 index 000000000..3b32cdf50 --- /dev/null +++ b/d8/9e7893ca411825ae23864fc745ebbece6eac30 @@ -0,0 +1,123 @@ +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 57389431FC7 + for ; Sat, 5 Apr 2014 14:24:52 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 0.201 +X-Spam-Level: +X-Spam-Status: No, score=0.201 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, + 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 JNMFvRJTGPNT for ; + Sat, 5 Apr 2014 14:24:46 -0700 (PDT) +Received: from mail-wi0-f171.google.com (mail-wi0-f171.google.com + [209.85.212.171]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 9AD69431FAF + for ; Sat, 5 Apr 2014 14:24:46 -0700 (PDT) +Received: by mail-wi0-f171.google.com with SMTP id q5so3098582wiv.10 + for ; Sat, 05 Apr 2014 14:24:45 -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:in-reply-to:references; + bh=sXN0e30DKMzSQdAzlHeB7T7l6fbaI3z0oV++oHNt1FY=; + b=GAUC65LOhvVBQkrZ0FXXyexLY4cZNbWST3yr5uBT+7fEGMwEYDG9/AUH/PjLkMESjQ + c0142kgoMDi5KkKiWlUVLFEf8QgLAoMjMCItLx/5DXmTNgYDeWNjxkVTG3BkVGdic8D1 + miGj40B99/PNRvsAmlb8s9UR454wdzCvyPaWIEA2koywxgymrebMPHjqy3IMJGQOs+O1 + 7oXWlUZ+oqDgeLygfMKAC+lOzdXCcDxtMd9yY9e2CQPS5yISU5PA1qsSgjhEy9p9yQDW + jnyDDlP+iXGz6qMVr2bOLfHhFiqk7/7pKiGYVxTnXMSATmCmee2o5oHOU5+AKD8xKUlR + wHgA== +X-Received: by 10.194.76.10 with SMTP id g10mr30350660wjw.67.1396733085160; + Sat, 05 Apr 2014 14:24:45 -0700 (PDT) +Received: from localhost (93-97-24-31.zone5.bethere.co.uk. [93.97.24.31]) + by mx.google.com with ESMTPSA id + l12sm18567425wjr.35.2014.04.05.14.24.44 for + (version=TLSv1.2 cipher=RC4-SHA bits=128/128); + Sat, 05 Apr 2014 14:24:44 -0700 (PDT) +From: Mark Walters +To: notmuch@notmuchmail.org +Subject: [PATCH 1/5] emacs: hello: add helper functions for saved-searches +Date: Sat, 5 Apr 2014 22:24:21 +0100 +Message-Id: <1396733065-32602-2-git-send-email-markwalters1009@gmail.com> +X-Mailer: git-send-email 1.7.10.4 +In-Reply-To: <1396733065-32602-1-git-send-email-markwalters1009@gmail.com> +References: <1396733065-32602-1-git-send-email-markwalters1009@gmail.com> +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: Sat, 05 Apr 2014 21:24:52 -0000 + +Add helper functions to for saved searches to ease the transition to +the new plist form while maintaining backwards compatibility. They +will be used in the next patch. +--- + emacs/notmuch-hello.el | 39 +++++++++++++++++++++++++++++++++++++++ + 1 file changed, 39 insertions(+) + +diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el +index e325cd3..0b9ed16 100644 +--- a/emacs/notmuch-hello.el ++++ b/emacs/notmuch-hello.el +@@ -269,6 +269,45 @@ (defun notmuch-hello-search (&optional search) + (add-to-history 'notmuch-search-history search))) + (notmuch-search search notmuch-search-oldest-first)) + ++(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)." ++ (cond ++ ((plist-get saved-search :name) ++ (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)) ++ (:query (second saved-search)) ++ (:count-query (third saved-search)) ++ (t nil))) ++ (t ;; It is a cons-cell (NAME . QUERY) ++ (case field ++ (:name (car saved-search)) ++ (:query (cdr saved-search)) ++ (t nil))))) ++ ++(defun notmuch-hello-saved-search-to-plist (saved-search) ++ "Convert a saved-search variable into 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)) ++ (copy-seq saved-search) ++ (let ((fields (list :name :query :count-query)) ++ (plist-search)) ++ (dolist (field fields plist-search) ++ (let ((string (notmuch-saved-search-get saved-search field))) ++ (when string ++ (setq plist-search (append plist-search (list field string))))))))) ++ + (defun notmuch-hello-add-saved-search (widget) + (interactive) + (let ((search (widget-value +-- +1.7.10.4 +