diff options
author | Austin Clements <amdragon@MIT.EDU> | 2012-10-26 16:18:10 -0400 |
---|---|---|
committer | David Bremner <bremner@debian.org> | 2012-10-27 09:33:55 -0300 |
commit | 1a4cb8fd29c52445fc3de70e92de377f00cdc4a7 (patch) | |
tree | 3a2c42b9c3b122692212d9299daaff150f2a8ce4 /emacs | |
parent | 05c87b5d18794290f4746218d1ea93c2990ba43d (diff) |
emacs: Introduce generic boolean term escaping function
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.
Diffstat (limited to 'emacs')
-rw-r--r-- | emacs/notmuch-lib.el | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el index 69867ada..eeb005ff 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))) ;; |