unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [RFC PATCH 0/2] emacs proof-of-concept: functions in saved searches
@ 2011-11-23 21:08 Jani Nikula
  2011-11-23 21:08 ` [RFC PATCH 1/2] emacs: allow functions as " Jani Nikula
  2011-11-23 21:08 ` [RFC PATCH 2/2] emacs: a couple of example functions that might be useful with " Jani Nikula
  0 siblings, 2 replies; 3+ messages in thread
From: Jani Nikula @ 2011-11-23 21:08 UTC (permalink / raw)
  To: notmuch

Hi, this is a quick proof-of-concept implementation of an idea by m1lkc0w on IRC
(transcript below) to allow functions in saved searches. I'm not quite sure
whether I'm for or against the idea, though it's kind of neat... :)

Patch 1 adds the implementation. The (if (functionp ...)) parts should obviously
be abstracted, but otherwise there's not much to it.

Patch 2 has a couple of crude example functions (that I just shoved into
notmuch-hello.el) that might be useful in saved searches. One to match
everything that the other saved searches don't, another a building block to
combine existing saved searches.

Comments are welcome, though I don't think I'll be pursuing this much further.

BR,
Jani.


PS. For the original problem of date range searches there's also
id:"cover.1312964528.git.jani@nikula.org" if you're willing to live with such
out of tree patches (they won't be merged).


[2011-11-23 UTC+2]
 00:43         m1lkc0w   How difficult would it be to allow functions in "saved 
                         searches"?
 00:46         m1lkc0w   This could be helpful to define functions for 
                         calculating search timestamps
 00:48         bremner   m1lkc0w: personally I'd like to get away from saved 
                         searches being emacs specific
 00:48         bremner   for dates, would it solve your problem if notmuch had 
                         a sensible date parser?
 00:49         m1lkc0w   bremner: sure.
 00:49         m1lkc0w   bremner: I just thought that in the meantime, I can 
                         calculate the timespamps in elisp
 00:50         m1lkc0w   bremner: Just wanted to list last week's email - 
                         that's hwo the idea came up
 00:51         bremner   I guess it wouldn't be that hard for someone with 
                         elisp skillz to make saved searches have a ("name" . 
                         function ) in addition to (name . string)


Jani Nikula (2):
  emacs: allow functions as saved searches
  emacs: a couple of example functions that might be useful with saved
    searches

 emacs/notmuch-hello.el |   27 +++++++++++++++++++++++++--
 emacs/notmuch-lib.el   |    8 ++++++--
 emacs/notmuch.el       |    9 +++++++--
 3 files changed, 38 insertions(+), 6 deletions(-)

-- 
1.7.5.4

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [RFC PATCH 1/2] emacs: allow functions as saved searches
  2011-11-23 21:08 [RFC PATCH 0/2] emacs proof-of-concept: functions in saved searches Jani Nikula
@ 2011-11-23 21:08 ` Jani Nikula
  2011-11-23 21:08 ` [RFC PATCH 2/2] emacs: a couple of example functions that might be useful with " Jani Nikula
  1 sibling, 0 replies; 3+ messages in thread
From: Jani Nikula @ 2011-11-23 21:08 UTC (permalink / raw)
  To: notmuch

Signed-off-by: Jani Nikula <jani@nikula.org>
---
 emacs/notmuch-hello.el |    9 +++++++--
 emacs/notmuch-lib.el   |    8 ++++++--
 emacs/notmuch.el       |    9 +++++++--
 3 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index 0582cae..ad3ae74 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -274,7 +274,9 @@ should be. Returns a cons cell `(tags-per-line width)'."
 	    ;; (not elem) indicates an empty slot in the matrix.
 	    (when elem
 	      (let* ((name (car elem))
-		     (query (cdr elem))
+		     (query (if (functionp (cdr elem))
+				(funcall (cdr elem) elem)
+				(cdr elem)))
 		     (formatted-name (format "%s " name)))
 		(widget-insert (format "%8s "
 				       (notmuch-hello-nice-number
@@ -452,7 +454,10 @@ Complete list of currently available key bindings:
 	      (if notmuch-show-empty-saved-searches
 		  notmuch-saved-searches
 		(loop for elem in notmuch-saved-searches
-		      if (> (string-to-number (notmuch-saved-search-count (cdr elem))) 0)
+		      if (> (string-to-number (notmuch-saved-search-count
+					       (if (functionp (cdr elem))
+						   (funcall (cdr elem) elem)
+						 (cdr elem)))) 0)
 		      collect elem)))
 	     (saved-widest (notmuch-hello-longest-label saved-alist))
 	     (alltags-alist (if notmuch-show-all-tags-list (notmuch-hello-generate-tag-alist)))
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 0f856bf..2ecb3fc 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -36,8 +36,12 @@
 ;;
 
 (defcustom notmuch-saved-searches nil
-  "A list of saved searches to display."
-  :type '(alist :key-type string :value-type string)
+  "A list of saved searches to display.
+
+The list of saved searches is a list of key/value pairs, where
+the key is the name of the saved search, and value is either a
+query string, or a function that should return a query string."
+  :type '(alist :key-type string :value-type (choice string function))
   :group 'notmuch)
 
 (defvar notmuch-folders nil
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index c1827cc..62f33e9 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -854,14 +854,19 @@ characters as well as `_.+-'.
 	  (let (longest
 		(longest-length 0))
 	    (loop for tuple in notmuch-saved-searches
-		  if (let ((quoted-query (regexp-quote (cdr tuple))))
+		  if (let ((quoted-query (regexp-quote
+					  (if (functionp (cdr tuple))
+					      (funcall (cdr tuple) tuple)
+					    (cdr tuple)))))
 		       (and (string-match (concat "^" quoted-query) query)
 			    (> (length (match-string 0 query))
 			       longest-length)))
 		  do (setq longest tuple))
 	    longest))
 	 (saved-search-name (car saved-search))
-	 (saved-search-query (cdr saved-search)))
+	 (saved-search-query (if (functionp (cdr saved-search))
+				 (funcall (cdr saved-search) saved-search)
+			       (cdr saved-search))))
     (cond ((and saved-search (equal saved-search-query query))
 	   ;; Query is the same as saved search (ignoring case)
 	   (concat "*notmuch-saved-search-" saved-search-name "*"))
-- 
1.7.5.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [RFC PATCH 2/2] emacs: a couple of example functions that might be useful with saved searches
  2011-11-23 21:08 [RFC PATCH 0/2] emacs proof-of-concept: functions in saved searches Jani Nikula
  2011-11-23 21:08 ` [RFC PATCH 1/2] emacs: allow functions as " Jani Nikula
@ 2011-11-23 21:08 ` Jani Nikula
  1 sibling, 0 replies; 3+ messages in thread
From: Jani Nikula @ 2011-11-23 21:08 UTC (permalink / raw)
  To: notmuch

Signed-off-by: Jani Nikula <jani@nikula.org>
---
 emacs/notmuch-hello.el |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index ad3ae74..f03e4b9 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -26,6 +26,24 @@
 (require 'notmuch-lib)
 (require 'notmuch-mua)
 
+(defun notmuch-no-saved-search-match (this)
+  (mapconcat (lambda (arg) (concat "(not ("
+				   (if (functionp (cdr arg))
+				       (funcall (cdr arg) arg)
+				     (cdr arg)) "))"))
+	     (loop for elem in notmuch-saved-searches
+		   if (not (equal (car this) (car elem)))
+		   collect elem)
+	     " and "))
+
+(defun notmuch-get-saved-search (name)
+  (let ((elem (assoc name notmuch-saved-searches)))
+    (if elem
+	(if (functionp (cdr elem))
+	    (funcall (cdr elem) elem)
+	  (cdr elem))
+      "")))
+
 (declare-function notmuch-search "notmuch" (query &optional oldest-first target-thread target-line continuation))
 (declare-function notmuch-poll "notmuch" ())
 
-- 
1.7.5.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-11-23 21:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-23 21:08 [RFC PATCH 0/2] emacs proof-of-concept: functions in saved searches Jani Nikula
2011-11-23 21:08 ` [RFC PATCH 1/2] emacs: allow functions as " Jani Nikula
2011-11-23 21:08 ` [RFC PATCH 2/2] emacs: a couple of example functions that might be useful with " Jani Nikula

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).