unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH 1/3] emacs: Introduce generic boolean term escaping function
@ 2012-10-26 20:18 Austin Clements
  2012-10-26 20:18 ` [PATCH 2/3] emacs: Escape tag queries performed by hello Austin Clements
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Austin Clements @ 2012-10-26 20:18 UTC (permalink / raw)
  To: notmuch

Currently, we only properly escape stashed id queries, but there are
other places where the Emacs UI constructs queries for boolean terms.
Since this escaping function is meant to be used in other places, it
avoids escaping strings that don't need escaping.
---
 emacs/notmuch-lib.el |   16 +++++++++++++++-
 test/emacs           |    2 +-
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 69867ad..eeb005f 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -161,9 +161,23 @@ the user hasn't set this variable with the old or new value."
 	"[No Subject]"
       subject)))
 
+(defun notmuch-escape-boolean-term (term)
+  "Escape a boolean term for use in a query.
+
+The caller is responsible for prepending the term prefix and a
+colon.  This performs minimal escaping in order to produce
+user-friendly queries."
+
+  (save-match-data
+    (if (or (equal term "")
+	    (string-match "[ ()]\\|^\"" term))
+	;; Requires escaping
+	(concat "\"" (replace-regexp-in-string "\"" "\"\"" term t t) "\"")
+      term)))
+
 (defun notmuch-id-to-query (id)
   "Return a query that matches the message with id ID."
-  (concat "id:\"" (replace-regexp-in-string "\"" "\"\"" id t t) "\""))
+  (concat "id:" (notmuch-escape-boolean-term id)))
 
 ;;
 
diff --git a/test/emacs b/test/emacs
index 21f1d16..44f641e 100755
--- a/test/emacs
+++ b/test/emacs
@@ -667,7 +667,7 @@ Some One <someone@somewhere.org>
 Some One Else <notsomeone@somewhere.org>
 Notmuch <notmuch@notmuchmail.org>
 Stash my stashables
-id:"bought"
+id:bought
 bought
 inbox,stashtest
 ${gen_msg_filename}
-- 
1.7.10

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

* [PATCH 2/3] emacs: Escape tag queries performed by hello
  2012-10-26 20:18 [PATCH 1/3] emacs: Introduce generic boolean term escaping function Austin Clements
@ 2012-10-26 20:18 ` Austin Clements
  2012-10-26 20:18 ` [PATCH 3/3] emacs: Escape tag queries suggested by tab completion Austin Clements
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Austin Clements @ 2012-10-26 20:18 UTC (permalink / raw)
  To: notmuch

---
 emacs/notmuch-hello.el |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index 052aaeb..be50aae 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -500,7 +500,7 @@ Complete list of currently available key bindings:
 (defun notmuch-hello-generate-tag-alist (&optional hide-tags)
   "Return an alist from tags to queries to display in the all-tags section."
   (mapcar (lambda (tag)
-	    (cons tag (format "tag:%s" tag)))
+	    (cons tag (concat "tag:" (notmuch-escape-boolean-term tag))))
 	  (notmuch-remove-if-not
 	   (lambda (tag)
 	     (not (member tag hide-tags)))
-- 
1.7.10

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

* [PATCH 3/3] emacs: Escape tag queries suggested by tab completion
  2012-10-26 20:18 [PATCH 1/3] emacs: Introduce generic boolean term escaping function Austin Clements
  2012-10-26 20:18 ` [PATCH 2/3] emacs: Escape tag queries performed by hello Austin Clements
@ 2012-10-26 20:18 ` Austin Clements
  2012-10-26 21:12 ` [PATCH 1/3] emacs: Introduce generic boolean term escaping function Tomi Ollila
  2012-10-27 12:46 ` David Bremner
  3 siblings, 0 replies; 6+ messages in thread
From: Austin Clements @ 2012-10-26 20:18 UTC (permalink / raw)
  To: notmuch

---
 emacs/notmuch.el |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index a8a85ce..60e8bf9 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -917,7 +917,7 @@ PROMPT is the string to prompt with."
 	(append (list "folder:" "thread:" "id:" "date:" "from:" "to:"
 		      "subject:" "attachment:")
 		(mapcar (lambda (tag)
-			  (concat "tag:" tag))
+			  (concat "tag:" (notmuch-escape-boolean-term tag)))
 			(process-lines notmuch-command "search" "--output=tags" "*")))))
     (let ((keymap (copy-keymap minibuffer-local-map))
 	  (minibuffer-completion-table
-- 
1.7.10

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

* Re: [PATCH 1/3] emacs: Introduce generic boolean term escaping function
  2012-10-26 20:18 [PATCH 1/3] emacs: Introduce generic boolean term escaping function Austin Clements
  2012-10-26 20:18 ` [PATCH 2/3] emacs: Escape tag queries performed by hello Austin Clements
  2012-10-26 20:18 ` [PATCH 3/3] emacs: Escape tag queries suggested by tab completion Austin Clements
@ 2012-10-26 21:12 ` Tomi Ollila
  2012-10-27 15:18   ` Ethan Glasser-Camp
  2012-10-27 12:46 ` David Bremner
  3 siblings, 1 reply; 6+ messages in thread
From: Tomi Ollila @ 2012-10-26 21:12 UTC (permalink / raw)
  To: Austin Clements, notmuch

On Fri, Oct 26 2012, Austin Clements wrote:

> Currently, we only properly escape stashed id queries, but there are
> other places where the Emacs UI constructs queries for boolean terms.
> Since this escaping function is meant to be used in other places, it
> avoids escaping strings that don't need escaping.
> ---

These 3 patches LGTM.

Tomi


>  emacs/notmuch-lib.el |   16 +++++++++++++++-
>  test/emacs           |    2 +-
>  2 files changed, 16 insertions(+), 2 deletions(-)
>
> diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
> index 69867ad..eeb005f 100644
> --- a/emacs/notmuch-lib.el
> +++ b/emacs/notmuch-lib.el
> @@ -161,9 +161,23 @@ the user hasn't set this variable with the old or new value."
>  	"[No Subject]"
>        subject)))
>  
> +(defun notmuch-escape-boolean-term (term)
> +  "Escape a boolean term for use in a query.
> +
> +The caller is responsible for prepending the term prefix and a
> +colon.  This performs minimal escaping in order to produce
> +user-friendly queries."
> +
> +  (save-match-data
> +    (if (or (equal term "")
> +	    (string-match "[ ()]\\|^\"" term))
> +	;; Requires escaping
> +	(concat "\"" (replace-regexp-in-string "\"" "\"\"" term t t) "\"")
> +      term)))
> +
>  (defun notmuch-id-to-query (id)
>    "Return a query that matches the message with id ID."
> -  (concat "id:\"" (replace-regexp-in-string "\"" "\"\"" id t t) "\""))
> +  (concat "id:" (notmuch-escape-boolean-term id)))
>  
>  ;;
>  
> diff --git a/test/emacs b/test/emacs
> index 21f1d16..44f641e 100755
> --- a/test/emacs
> +++ b/test/emacs
> @@ -667,7 +667,7 @@ Some One <someone@somewhere.org>
>  Some One Else <notsomeone@somewhere.org>
>  Notmuch <notmuch@notmuchmail.org>
>  Stash my stashables
> -id:"bought"
> +id:bought
>  bought
>  inbox,stashtest
>  ${gen_msg_filename}
> -- 
> 1.7.10
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch

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

* Re: [PATCH 1/3] emacs: Introduce generic boolean term escaping function
  2012-10-26 20:18 [PATCH 1/3] emacs: Introduce generic boolean term escaping function Austin Clements
                   ` (2 preceding siblings ...)
  2012-10-26 21:12 ` [PATCH 1/3] emacs: Introduce generic boolean term escaping function Tomi Ollila
@ 2012-10-27 12:46 ` David Bremner
  3 siblings, 0 replies; 6+ messages in thread
From: David Bremner @ 2012-10-27 12:46 UTC (permalink / raw)
  To: Austin Clements, notmuch

Austin Clements <amdragon@MIT.EDU> writes:

> Currently, we only properly escape stashed id queries, but there are
> other places where the Emacs UI constructs queries for boolean terms.
> Since this escaping function is meant to be used in other places, it
> avoids escaping strings that don't need escaping.

Pushed all 3.

d

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

* Re: [PATCH 1/3] emacs: Introduce generic boolean term escaping function
  2012-10-26 21:12 ` [PATCH 1/3] emacs: Introduce generic boolean term escaping function Tomi Ollila
@ 2012-10-27 15:18   ` Ethan Glasser-Camp
  0 siblings, 0 replies; 6+ messages in thread
From: Ethan Glasser-Camp @ 2012-10-27 15:18 UTC (permalink / raw)
  To: Tomi Ollila, Austin Clements, notmuch

Tomi Ollila <tomi.ollila@iki.fi> writes:

> These 3 patches LGTM.

Me too. But I wouldn't be averse to some tests :)

Ethan

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

end of thread, other threads:[~2012-10-27 15:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-26 20:18 [PATCH 1/3] emacs: Introduce generic boolean term escaping function Austin Clements
2012-10-26 20:18 ` [PATCH 2/3] emacs: Escape tag queries performed by hello Austin Clements
2012-10-26 20:18 ` [PATCH 3/3] emacs: Escape tag queries suggested by tab completion Austin Clements
2012-10-26 21:12 ` [PATCH 1/3] emacs: Introduce generic boolean term escaping function Tomi Ollila
2012-10-27 15:18   ` Ethan Glasser-Camp
2012-10-27 12:46 ` David Bremner

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).