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 C5E8D431FCF for ; Sat, 5 Apr 2014 22:45:12 -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 xmGrUZpI4jbd for ; Sat, 5 Apr 2014 22:45:07 -0700 (PDT) Received: from mail-we0-f175.google.com (mail-we0-f175.google.com [74.125.82.175]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 0CACC431FB6 for ; Sat, 5 Apr 2014 22:45:06 -0700 (PDT) Received: by mail-we0-f175.google.com with SMTP id q58so5179777wes.6 for ; Sat, 05 Apr 2014 22:45:04 -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=geHyb0nfA8DIJQxfbcGsSKgqAyKyYhZxIjOtq2TgKuI=; b=WPLSOsyxO8vCXBy3utaOqdFitNxlK4Gt1Ok9SvFnrn0VQePGgJHDc/+CNEcCxehE+k MqAVlEaeY4BNa77dp29jazmrK99Z/eaR0Rz4HbC+6L5Dd836cFwrVlOM1T46aWnYjwyF lFb2WWdsNGSJuV8H3poDQGwKkbd7wpRS9gJ9vMtoeDB4Qa778WyXPO70ymKJpzRvusoT 3rcKZ0Y9WH9N4l7DxcVZyCxl6g1UGP1yW4yJZRnP3yoEclkYdknNBmN+dlbmEyDVUR/W DJsPAQTgQjgGgm/PNzJFuy6Gzr2IZZFmdj0aVuhJlA/xUUhQFWz0AKs/NBpdIPTngd4w 2bXw== X-Received: by 10.180.10.164 with SMTP id j4mr4106453wib.51.1396763104681; Sat, 05 Apr 2014 22:45:04 -0700 (PDT) Received: from localhost (93-97-24-31.zone5.bethere.co.uk. [93.97.24.31]) by mx.google.com with ESMTPSA id er4sm20118660wjd.38.2014.04.05.22.45.03 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sat, 05 Apr 2014 22:45:04 -0700 (PDT) From: Mark Walters To: notmuch@notmuchmail.org, amdragon@MIT.EDU Subject: [PATCH v2 1/5] emacs: hello: add helper functions for saved-searches Date: Sun, 6 Apr 2014 06:44:45 +0100 Message-Id: <1396763089-32452-2-git-send-email-markwalters1009@gmail.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1396763089-32452-1-git-send-email-markwalters1009@gmail.com> References: <1396763089-32452-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: Sun, 06 Apr 2014 05:45:13 -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 | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el index e325cd3..f81ec27 100644 --- a/emacs/notmuch-hello.el +++ b/emacs/notmuch-hello.el @@ -269,6 +269,44 @@ (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. + +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 + ((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 (first 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) + "Return a copy of SAVED-SEARCH in plist form. + +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) + (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