[WIP PATCH] emacs: hello: bugfix for saved searches defcustom
authorMark Walters <markwalters1009@gmail.com>
Wed, 16 Apr 2014 05:58:47 +0000 (06:58 +0100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 18:01:38 +0000 (10:01 -0800)
fe/7b77fa5d286fceee8b83a7935441498c89ef05 [new file with mode: 0644]

diff --git a/fe/7b77fa5d286fceee8b83a7935441498c89ef05 b/fe/7b77fa5d286fceee8b83a7935441498c89ef05
new file mode 100644 (file)
index 0000000..304c39f
--- /dev/null
@@ -0,0 +1,300 @@
+Return-Path: <markwalters1009@gmail.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 10AC4431FBF\r
+       for <notmuch@notmuchmail.org>; Tue, 15 Apr 2014 22:59:23 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.201\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.201 tagged_above=-999 required=5\r
+       tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+       FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001,\r
+       RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id va9GTo+jp7cW for <notmuch@notmuchmail.org>;\r
+       Tue, 15 Apr 2014 22:59:17 -0700 (PDT)\r
+Received: from mail-ee0-f46.google.com (mail-ee0-f46.google.com\r
+ [74.125.83.46])       (using TLSv1 with cipher RC4-SHA (128/128 bits))        (No client\r
+ certificate requested)        by olra.theworths.org (Postfix) with ESMTPS id\r
+ D87B1431FBD   for <notmuch@notmuchmail.org>; Tue, 15 Apr 2014 22:59:16 -0700\r
+ (PDT)\r
+Received: by mail-ee0-f46.google.com with SMTP id t10so8330817eei.19\r
+       for <notmuch@notmuchmail.org>; Tue, 15 Apr 2014 22:59:13 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+       h=from:to:cc:subject:date:message-id;\r
+       bh=ZASDUhcj98hz7oizIrrI32xcB7po2l/jjFK+4y3kzS8=;\r
+       b=NhGVuy1dXGymLPIFZF+RbbEXiPGqF45TFAH/kdUUcHwVKkrFq0EOUd3HnMNvchV6tC\r
+       D8AuDnKyhRiohG6XkLzsPht4c0UvgNKJVnkwnJcOoPlfbgXhanofwLFwCVjedL4MKrDh\r
+       kIx+YEiGLiVig810rGPqtsIWO4JQJiwxZcQntP8gho5CGHuYeYBWoFoSZ/vq4gnENj9y\r
+       86b/q2RSBXHUJSFzB7YGCs7D6ckqpH6+Dx+xqEAk5fowiNi2ZXWuTqTTwrviH6a+BytQ\r
+       2tH4cYZLqZj89XHUvGnYHC+QaM4QFO2UnY6NFxZQ280FXyJyTW2mo1DJakaxSgntEask\r
+       fEPA==\r
+X-Received: by 10.15.73.134 with SMTP id h6mr2394662eey.3.1397627952543;\r
+       Tue, 15 Apr 2014 22:59:12 -0700 (PDT)\r
+Received: from localhost ([217.17.137.178])\r
+       by mx.google.com with ESMTPSA id q41sm54837105eez.7.2014.04.15.22.59.11\r
+       for <multiple recipients>\r
+       (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+       Tue, 15 Apr 2014 22:59:11 -0700 (PDT)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [WIP PATCH] emacs: hello: bugfix for saved searches defcustom\r
+Date: Wed, 16 Apr 2014 06:58:47 +0100\r
+Message-Id: <1397627927-9692-1-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 1.7.10.4\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Wed, 16 Apr 2014 05:59:23 -0000\r
+\r
+---\r
+Hi\r
+\r
+David found a bug in the recent notmuch hello saved searches and\r
+reduced to a small test case. The problem occurs if the user sets\r
+notmuch-saved-searches and then loads notmuch. The reason is that the\r
+defcustom calls some utility functions and these need to be defined\r
+(not just declared) when the defcustom is encountered.\r
+\r
+This patch moves the code around so that they are defined first. I\r
+have marked the patch WIP as I am not sure what the best reordering\r
+is, and we may want to rename some functions which have changed file\r
+for namespace reasons.\r
+\r
+Anyway this fixes the test case. If it fixes the original bug too then\r
+I will provide a better version.\r
+\r
+Best wishes \r
+\r
+Mark\r
+\r
+\r
+\r
+ emacs/notmuch-hello.el |  128 ++++++++++++++++++++++++++++++++++--------------\r
+ emacs/notmuch-lib.el   |   52 --------------------\r
+ 2 files changed, 90 insertions(+), 90 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el\r
+index 4900a24..27eac72 100644\r
+--- a/emacs/notmuch-hello.el\r
++++ b/emacs/notmuch-hello.el\r
+@@ -29,6 +29,96 @@\r
+ (declare-function notmuch-search "notmuch" (&optional query oldest-first target-thread target-line continuation))\r
+ (declare-function notmuch-poll "notmuch" ())\r
\r
++(defun notmuch-saved-search-get (saved-search field)\r
++  "Get FIELD from SAVED-SEARCH.\r
++\r
++If SAVED-SEARCH is a plist, this is just `plist-get', but for\r
++backwards compatibility, this also deals with the two other\r
++possible formats for SAVED-SEARCH: cons cells (NAME . QUERY) and\r
++lists (NAME QUERY COUNT-QUERY)."\r
++  (cond\r
++   ((keywordp (car saved-search))\r
++    (plist-get saved-search field))\r
++   ;; It is not a plist so it is an old-style entry.\r
++   ((consp (cdr saved-search)) ;; It is a list (NAME QUERY COUNT-QUERY)\r
++    (case field\r
++      (:name (first saved-search))\r
++      (:query (second saved-search))\r
++      (:count-query (third saved-search))\r
++      (t nil)))\r
++   (t  ;; It is a cons-cell (NAME . QUERY)\r
++    (case field\r
++      (:name (car saved-search))\r
++      (:query (cdr saved-search))\r
++      (t nil)))))\r
++\r
++(defun notmuch-hello-saved-search-to-plist (saved-search)\r
++  "Return a copy of SAVED-SEARCH in plist form.\r
++\r
++If saved search is a plist then just return a copy. In other\r
++cases, for backwards compatability, convert to plist form and\r
++return that."\r
++  (if (keywordp (car saved-search))\r
++      (copy-seq saved-search)\r
++    (let ((fields (list :name :query :count-query))\r
++        plist-search)\r
++      (dolist (field fields plist-search)\r
++      (let ((string (notmuch-saved-search-get saved-search field)))\r
++        (when string\r
++          (setq plist-search (append plist-search (list field string)))))))))\r
++\r
++(defun notmuch--saved-searches-to-plist (symbol)\r
++  "Extract a saved-search variable into plist form.\r
++\r
++The new style saved search is just a plist, but for backwards\r
++compatatibility we use this function to extract old style saved\r
++searches so they still work in customize."\r
++  (let ((saved-searches (default-value symbol)))\r
++    (mapcar #'notmuch-hello-saved-search-to-plist saved-searches)))\r
++\r
++(define-widget 'notmuch-saved-search-plist 'list\r
++  "A single saved search property list."\r
++  :tag "Saved Search"\r
++  :args '((list :inline t\r
++              :format "%v"\r
++              (group :format "%v" :inline t (const :format "   Name: " :name) (string :format "%v"))\r
++              (group :format "%v" :inline t (const :format "  Query: " :query) (string :format "%v")))\r
++        (checklist :inline t\r
++                   :format "%v"\r
++                   (group :format "%v" :inline t (const :format "Count-Query: " :count-query) (string :format "%v"))\r
++                   (group :format "%v" :inline t (const :format "" :sort-order)\r
++                          (choice :tag " Sort Order"\r
++                                  (const :tag "Default" nil)\r
++                                  (const :tag "Oldest-first" oldest-first)\r
++                                  (const :tag "Newest-first" newest-first))))))\r
++\r
++(defcustom notmuch-saved-searches '((:name "inbox" :query "tag:inbox")\r
++                                  (:name "unread" :query "tag:unread"))\r
++  "A list of saved searches to display.\r
++\r
++The saved search can be given in 3 forms. The preferred way is as\r
++a plist. Supported properties are\r
++\r
++  :name            Name of the search (required).\r
++  :query           Search to run (required).\r
++  :count-query     Optional extra query to generate the count\r
++                   shown. If not present then the :query property\r
++                   is used.\r
++  :sort-order      Specify the sort order to be used for the search.\r
++                   Possible values are 'oldest-first 'newest-first or\r
++                   nil. Nil means use the default sort order.\r
++\r
++Other accepted forms are a cons cell of the form (NAME . QUERY)\r
++or a list of the form (NAME QUERY COUNT-QUERY)."\r
++;; The saved-search format is also used by the all-tags notmuch-hello\r
++;; section. This section generates its own saved-search list in one of\r
++;; the latter two forms.\r
++\r
++  :get 'notmuch--saved-searches-to-plist\r
++  :type '(repeat notmuch-saved-search-plist)\r
++  :tag "List of Saved Searches"\r
++  :group 'notmuch-hello)\r
++\r
+ (defcustom notmuch-hello-recent-searches-max 10\r
+   "The number of recent searches to display."\r
+   :type 'integer\r
+@@ -269,44 +359,6 @@ afterwards.")\r
+       (add-to-history 'notmuch-search-history search)))\r
+   (notmuch-search search notmuch-search-oldest-first))\r
\r
+-(defun notmuch-saved-search-get (saved-search field)\r
+-  "Get FIELD from SAVED-SEARCH.\r
+-\r
+-If SAVED-SEARCH is a plist, this is just `plist-get', but for\r
+-backwards compatibility, this also deals with the two other\r
+-possible formats for SAVED-SEARCH: cons cells (NAME . QUERY) and\r
+-lists (NAME QUERY COUNT-QUERY)."\r
+-  (cond\r
+-   ((keywordp (car saved-search))\r
+-    (plist-get saved-search field))\r
+-   ;; It is not a plist so it is an old-style entry.\r
+-   ((consp (cdr saved-search)) ;; It is a list (NAME QUERY COUNT-QUERY)\r
+-    (case field\r
+-      (:name (first saved-search))\r
+-      (:query (second saved-search))\r
+-      (:count-query (third saved-search))\r
+-      (t nil)))\r
+-   (t  ;; It is a cons-cell (NAME . QUERY)\r
+-    (case field\r
+-      (:name (car saved-search))\r
+-      (:query (cdr saved-search))\r
+-      (t nil)))))\r
+-\r
+-(defun notmuch-hello-saved-search-to-plist (saved-search)\r
+-  "Return a copy of SAVED-SEARCH in plist form.\r
+-\r
+-If saved search is a plist then just return a copy. In other\r
+-cases, for backwards compatability, convert to plist form and\r
+-return that."\r
+-  (if (keywordp (car saved-search))\r
+-      (copy-seq saved-search)\r
+-    (let ((fields (list :name :query :count-query))\r
+-        plist-search)\r
+-      (dolist (field fields plist-search)\r
+-      (let ((string (notmuch-saved-search-get saved-search field)))\r
+-        (when string\r
+-          (setq plist-search (append plist-search (list field string)))))))))\r
+-\r
+ (defun notmuch-hello-add-saved-search (widget)\r
+   (interactive)\r
+   (let ((search (widget-value\r
+diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
+index 3a3c69d..2941da3 100644\r
+--- a/emacs/notmuch-lib.el\r
++++ b/emacs/notmuch-lib.el\r
+@@ -107,58 +107,6 @@ Note that the recommended way of achieving the same is using\r
+ (defvar notmuch-search-history nil\r
+   "Variable to store notmuch searches history.")\r
\r
+-(defun notmuch--saved-searches-to-plist (symbol)\r
+-  "Extract a saved-search variable into plist form.\r
+-\r
+-The new style saved search is just a plist, but for backwards\r
+-compatatibility we use this function to extract old style saved\r
+-searches so they still work in customize."\r
+-  (let ((saved-searches (default-value symbol)))\r
+-    (mapcar #'notmuch-hello-saved-search-to-plist saved-searches)))\r
+-\r
+-(define-widget 'notmuch-saved-search-plist 'list\r
+-  "A single saved search property list."\r
+-  :tag "Saved Search"\r
+-  :args '((list :inline t\r
+-              :format "%v"\r
+-              (group :format "%v" :inline t (const :format "   Name: " :name) (string :format "%v"))\r
+-              (group :format "%v" :inline t (const :format "  Query: " :query) (string :format "%v")))\r
+-        (checklist :inline t\r
+-                   :format "%v"\r
+-                   (group :format "%v" :inline t (const :format "Count-Query: " :count-query) (string :format "%v"))\r
+-                   (group :format "%v" :inline t (const :format "" :sort-order)\r
+-                          (choice :tag " Sort Order"\r
+-                                  (const :tag "Default" nil)\r
+-                                  (const :tag "Oldest-first" oldest-first)\r
+-                                  (const :tag "Newest-first" newest-first))))))\r
+-\r
+-(defcustom notmuch-saved-searches '((:name "inbox" :query "tag:inbox")\r
+-                                  (:name "unread" :query "tag:unread"))\r
+-  "A list of saved searches to display.\r
+-\r
+-The saved search can be given in 3 forms. The preferred way is as\r
+-a plist. Supported properties are\r
+-\r
+-  :name            Name of the search (required).\r
+-  :query           Search to run (required).\r
+-  :count-query     Optional extra query to generate the count\r
+-                   shown. If not present then the :query property\r
+-                   is used.\r
+-  :sort-order      Specify the sort order to be used for the search.\r
+-                   Possible values are 'oldest-first 'newest-first or\r
+-                   nil. Nil means use the default sort order.\r
+-\r
+-Other accepted forms are a cons cell of the form (NAME . QUERY)\r
+-or a list of the form (NAME QUERY COUNT-QUERY)."\r
+-;; The saved-search format is also used by the all-tags notmuch-hello\r
+-;; section. This section generates its own saved-search list in one of\r
+-;; the latter two forms.\r
+-\r
+-  :get 'notmuch--saved-searches-to-plist\r
+-  :type '(repeat notmuch-saved-search-plist)\r
+-  :tag "List of Saved Searches"\r
+-  :group 'notmuch-hello)\r
+-\r
+ (defcustom notmuch-archive-tags '("-inbox")\r
+   "List of tag changes to apply to a message or a thread when it is archived.\r
\r
+-- \r
+1.7.10.4\r
+\r