From: Mark Walters Date: Sun, 4 May 2014 12:45:21 +0000 (+0100) Subject: [PATCH] emacs: hello: allow extras to add to saved-search defcustom X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=c610e9c95bdc81a421e9234fb57da35068a381e4;p=notmuch-archives.git [PATCH] emacs: hello: allow extras to add to saved-search defcustom --- diff --git a/47/8a03e3a3925bc39b17133c7c78d61a86eb268b b/47/8a03e3a3925bc39b17133c7c78d61a86eb268b new file mode 100644 index 000000000..5fc98beb3 --- /dev/null +++ b/47/8a03e3a3925bc39b17133c7c78d61a86eb268b @@ -0,0 +1,154 @@ +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 F20EE429E37 + for ; Sun, 4 May 2014 05:45:36 -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 W9tOsXlm+oH4 for ; + Sun, 4 May 2014 05:45:31 -0700 (PDT) +Received: from mail-we0-f173.google.com (mail-we0-f173.google.com + [74.125.82.173]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 47514431E64 + for ; Sun, 4 May 2014 05:45:31 -0700 (PDT) +Received: by mail-we0-f173.google.com with SMTP id w61so6494478wes.32 + for ; Sun, 04 May 2014 05:45:30 -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=5XWkDVPffRn0QzYBAgtO6L8e9+prHWWV7izMFFif/M0=; + b=U+AjpYA+U30PwXm6yFtTr3SlD17F91uEdKenCmp94avKhL+YShIW/fGa9BoJDVVFOk + VNCOvHRy2fgTaCgkVgHCkmqqxemeUOqqf+ZOk1VfgHwuehbzi3Pef1AriBFZOnmbpugf + 9AqR2tYRMPXewenjAlWq4bPxSlSj0pIqpw9Ivc02VzQWVnh0+Hd68kOMezAtEQIalwnk + sruB74h52nyFHufvX+q94kuNN4yseQJjTGqM/YO2lkrLWOp4uxUXlTVgjBkPuq8CkmGw + ntFGTBvDsAmEtu0NwSHaQVEqr/iVh4ZYCQkjMnGE7iBVLZroieuQ6f7TeudmMFq2deHr + UOVQ== +X-Received: by 10.180.211.207 with SMTP id ne15mr11416866wic.31.1399207529903; + Sun, 04 May 2014 05:45:29 -0700 (PDT) +Received: from localhost (5751dfa2.skybroadband.com. [87.81.223.162]) + by mx.google.com with ESMTPSA id ej7sm10658697wib.9.2014.05.04.05.45.28 + for + (version=TLSv1.2 cipher=RC4-SHA bits=128/128); + Sun, 04 May 2014 05:45:28 -0700 (PDT) +From: Mark Walters +To: notmuch@notmuchmail.org +Subject: [PATCH] emacs: hello: allow extras to add to saved-search defcustom +Date: Sun, 4 May 2014 13:45:21 +0100 +Message-Id: <1399207521-24611-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, 04 May 2014 12:45:37 -0000 + +This adds an extra variable notmuch-saved-search-extras that allows +the user to add extra options to the saved-search customize +variable. Of course it is up to them to make these extra options do +anything afterwards. + +The difficulty is that the code definining a defcustom is executed +when the the file is first read which would normally occur before any +optional extras are loaded. + +To get around this I suggest that extras that wish to use this +infrastucture add a helper loader file that does something like +the following (this example is for a tweaked version of Austin's notmuch-go) + +(defvar notmuch-saved-search-extras nil) + +(setq notmuch-saved-search-extras + (append notmuch-saved-search-extras + '((checklist :inline t + :format "%v" + (group :format "%v" + :inline t + (const :format " Go key: " :go.key) + (key-sequence :format "%v")))))) + +(eval-after-load 'notmuch '(require 'notmuch-go)) + +(provide 'notmuch-go-loader) + +The user should then (require 'notmuch-go-loader) before loading notmuch. +--- + +The patch below is quite simple: almost all of the diff is +whitespace. The more difficult part to get right was the above code +snippet. It would be nice if a single file could say "don't read the +following code until feature 'notmuch is present" but I don't know how +to do that cleanly. + +The above at least means that it is simple from a user's +perspective. And all that happens if they do load the extension after +notmuch is that the defcustom is not updated and that is unavoidable. + +Best wishes + +Mark + + emacs/notmuch-hello.el | 28 ++++++++++++++++------------ + 1 file changed, 16 insertions(+), 12 deletions(-) + +diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el +index 3de5238..e627f42 100644 +--- a/emacs/notmuch-hello.el ++++ b/emacs/notmuch-hello.el +@@ -76,21 +76,25 @@ (defun notmuch-hello--saved-searches-to-plist (symbol) + (let ((saved-searches (default-value symbol))) + (mapcar #'notmuch-hello-saved-search-to-plist saved-searches))) + ++(defvar notmuch-saved-search-extras nil ++ "Extra formats to add to defcustom saved search widget") ++ + (define-widget 'notmuch-saved-search-plist 'list + "A single saved search property list." + :tag "Saved Search" +- :args '((list :inline t +- :format "%v" +- (group :format "%v" :inline t (const :format " Name: " :name) (string :format "%v")) +- (group :format "%v" :inline t (const :format " Query: " :query) (string :format "%v"))) +- (checklist :inline t +- :format "%v" +- (group :format "%v" :inline t (const :format "Count-Query: " :count-query) (string :format "%v")) +- (group :format "%v" :inline t (const :format "" :sort-order) +- (choice :tag " Sort Order" +- (const :tag "Default" nil) +- (const :tag "Oldest-first" oldest-first) +- (const :tag "Newest-first" newest-first)))))) ++ :args (append '((list :inline t ++ :format "%v" ++ (group :format "%v" :inline t (const :format " Name: " :name) (string :format "%v")) ++ (group :format "%v" :inline t (const :format " Query: " :query) (string :format "%v"))) ++ (checklist :inline t ++ :format "%v" ++ (group :format "%v" :inline t (const :format "Count-Query: " :count-query) (string :format "%v")) ++ (group :format "%v" :inline t (const :format "" :sort-order) ++ (choice :tag " Sort Order" ++ (const :tag "Default" nil) ++ (const :tag "Oldest-first" oldest-first) ++ (const :tag "Newest-first" newest-first))))) ++ notmuch-saved-search-extras)) + + (defcustom notmuch-saved-searches '((:name "inbox" :query "tag:inbox") + (:name "unread" :query "tag:unread")) +-- +1.7.10.4 +