unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] emacs: add completion to "tag all" operation ("*" binding)
@ 2012-01-26  1:12 Dmitry Kurochkin
  2012-01-26  1:26 ` [PATCH v2] " Dmitry Kurochkin
                   ` (4 more replies)
  0 siblings, 5 replies; 24+ messages in thread
From: Dmitry Kurochkin @ 2012-01-26  1:12 UTC (permalink / raw)
  To: notmuch

The patch adds <tab> completion to "tag all" operation bound to "*"
(`notmuch-search-operate-all' function).
---
 emacs/notmuch.el |   48 ++++++++++++++++++++++++++++++++++++------------
 1 files changed, 36 insertions(+), 12 deletions(-)

diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index e02966f..71b0221 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -48,6 +48,7 @@
 ;; required, but is available from http://notmuchmail.org).
 
 (eval-when-compile (require 'cl))
+(require 'crm)
 (require 'mm-view)
 (require 'message)
 
@@ -75,12 +76,33 @@ For example:
 (defvar notmuch-query-history nil
   "Variable to store minibuffer history for notmuch queries")
 
-(defun notmuch-select-tag-with-completion (prompt &rest search-terms)
+(defun notmuch-tag-completions (&optional search-terms prefixes)
   (let ((tag-list
 	 (with-output-to-string
 	   (with-current-buffer standard-output
 	     (apply 'call-process notmuch-command nil t nil "search-tags" search-terms)))))
-    (completing-read prompt (split-string tag-list "\n+" t) nil nil nil)))
+    (setq tag-list (split-string tag-list "\n+" t))
+    (if (null prefixes)
+	tag-list
+      (apply #'append
+	     (mapcar (lambda (tag)
+		       (mapcar (lambda (prefix)
+				 (concat prefix tag)) prefixes))
+		     tag-list)))))
+
+(defun notmuch-select-tag-with-completion (prompt &optional search-terms prefixes)
+  (let ((tag-list (notmuch-tag-completions search-terms prefixes)))
+    (completing-read prompt tag-list)))
+
+(defun notmuch-select-tags-with-completion (prompt &optional search-terms prefixes)
+  (let ((tag-list (notmuch-tag-completions search-terms prefixes))
+	(crm-separator " ")
+	(crm-local-completion-map (copy-keymap crm-local-completion-map)))
+    ;; By default, space is bound to "complete word" function.
+    ;; Re-bind it to insert a space instead.  Note that <tab> still
+    ;; does the completion.
+    (define-key crm-local-completion-map " " 'self-insert-command)
+    (completing-read-multiple prompt tag-list)))
 
 (defun notmuch-foreach-mime-part (function mm-handle)
   (cond ((stringp (car mm-handle))
@@ -860,16 +882,18 @@ will prompt for tags to be added or removed. Tags prefixed with
 Each character of the tag name may consist of alphanumeric
 characters as well as `_.+-'.
 "
-  (interactive "sOperation (+add -drop): notmuch tag ")
-  (let ((action-split (split-string action " +")))
-    ;; Perform some validation
-    (let ((words action-split))
-      (when (null words) (error "No operation given"))
-      (while words
-	(unless (string-match-p "^[-+][-+_.[:word:]]+$" (car words))
-	  (error "Action must be of the form `+thistag -that_tag'"))
-	(setq words (cdr words))))
-    (apply 'notmuch-tag notmuch-search-query-string action-split)))
+  (interactive (list (notmuch-select-tags-with-completion
+		      "Operation (+add -drop): notmuch tag " nil
+		      '("+" "-"))))
+  (setq action (delete "" action))
+  ;; Perform some validation
+  (let ((words action))
+    (when (null words) (error "No operation given"))
+    (while words
+      (unless (string-match-p "^[-+][-+_.[:word:]]+$" (car words))
+	(error "Action must be of the form `+thistag -that_tag'"))
+      (setq words (cdr words))))
+  (apply 'notmuch-tag notmuch-search-query-string action))
 
 (defun notmuch-search-buffer-title (query)
   "Returns the title for a buffer with notmuch search results."
-- 
1.7.8.3

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

end of thread, other threads:[~2012-02-19 20:45 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-26  1:12 [PATCH] emacs: add completion to "tag all" operation ("*" binding) Dmitry Kurochkin
2012-01-26  1:26 ` [PATCH v2] " Dmitry Kurochkin
2012-01-26  1:37 ` [PATCH] " Austin Clements
2012-01-26  1:47   ` Dmitry Kurochkin
2012-01-26  8:46     ` David Edmondson
2012-01-26 17:39       ` Dmitry Kurochkin
2012-01-26  2:45 ` [PATCH v3] " Dmitry Kurochkin
2012-01-26  5:06 ` [PATCH v4] " Dmitry Kurochkin
2012-01-26  7:04   ` Austin Clements
2012-01-26 17:37     ` Dmitry Kurochkin
2012-01-26 17:34 ` [PATCH v5 0/2] emacs: add completion to "tag all" operation Dmitry Kurochkin
2012-01-26 17:34   ` [PATCH v5 1/2] emacs: add completion to "tag all" operation ("*" binding) Dmitry Kurochkin
2012-01-27 11:55     ` David Bremner
2012-01-26 17:34   ` [PATCH v5 2/2] emacs: `notmuch-search-operate-all' code cleanup, no functional changes Dmitry Kurochkin
2012-01-27 11:56     ` David Bremner
2012-01-26 18:18   ` [PATCH v5 0/2] emacs: add completion to "tag all" operation David Edmondson
2012-01-26 18:35   ` Austin Clements
2012-01-30  7:45   ` [PATCH v4] test: emacs: add test for `notmuch-search-operate-all' Pieter Praet
2012-01-30  8:13     ` Dmitry Kurochkin
2012-02-01 13:44       ` Pieter Praet
2012-02-01 14:06         ` Dmitry Kurochkin
2012-02-01 20:32           ` Pieter Praet
2012-02-01 23:25             ` Dmitry Kurochkin
2012-02-19 20:42               ` Pieter Praet

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