[PATCH 0/2] Address completion configuration

Mark Walters markwalters1009 at gmail.com
Fri May 20 13:13:01 PDT 2016


These two patches allow some customization of the notmuch-address
completion.

The first patch is very similar to the patch at
id:1463558813-23603-1-git-send-email-markwalters1009 at gmail.com

The second allows the user to use the internal completion on a case by
case basis. Typically this would be useful for users who normally use
some external command for completion, but would like to use the
internal completion when that fails.

This necessitated some changes to the first patch: it made sense to
separate the customisation of the internal address (as this will be
also used for the case by case uses of the internal completion) from
the choice of whether to use internal or external completion by
default. I include the inter-diff of the first patch and the previous
version at
id:1463558813-23603-1-git-send-email-markwalters1009 at gmail.com at the
end of this email.

The downside is that it does mean there is an extra defcustom, but the
code is slightly cleaner.

It might make sense to have a keybinding for company-complete
and/or notmuch-address-toggle-internal-completion in
notmuch-mesage-mode but I had no idea what bindings would make sense.

I don't know how many people still use external completion -- but the
extra complexity on top of the previous version is fairly small. Also,
I haven't tested this heavily -- and there are quite a lot of cases.

Best wishes

Mark




Mark Walters (2):
  emacs: address completion, allow sender/recipient and filters
  emacs: address: allow internal completion on an individual basis

 emacs/notmuch-address.el | 154 ++++++++++++++++++++++++++++++++++-------------
 emacs/notmuch-company.el |  10 ++-
 emacs/notmuch-mua.el     |   3 +-
 3 files changed, 121 insertions(+), 46 deletions(-)


inter-diff from id:1463558813-23603-1-git-send-email-markwalters1009 at gmail.com 

diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index 62df8ba..3e7bdab 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -39,34 +39,45 @@
   "t indicates that full completion address harvesting has been
 finished")
 
-(defcustom notmuch-address-command '(sent nil)
-  "Determines how to generate address completion candidates.
+(defcustom notmuch-address-command 'internal
+  "Determines how address completion candidates are generated.
 
 If it is a string then that string should be an external program
 which must take a single argument (searched string) and output a
 list of completion candidates, one per line.
 
-Alternatively, it can be a (non-nil) list, in which case internal
-completion is used; in this case the list should have form
-'(DIRECTION FILTER), where DIRECTION is either sent or received
-and specifies whether the candidates are searched in messages
-sent by the user or received by the user (note received by is
-much faster), and FILTER is either nil or a filter-string, such
-as \"date:1y..\" to append to the query.
+Alternatively, it can be the symbol 'internal, in which case
+internal completion is used; the variable
+`notmuch-address-internal-completion` can be used to customize
+this case.
 
-If this variable is nil then address completion is disabled."
+Finally, if this variable is nil then address completion is
+disabled."
   :type '(radio
-	  (list :tag "Use internal address completion"
-		(radio
-		 :tag "Base completion on messages you have"
-		 :value sent
-		 (const :tag "sent (more accurate)" sent)
-		 (const :tag "received (faster)" received))
-		(radio :tag "Filter messages used for completion"
-		       (const :tag "Use all messages" nil)
-		       (string :tag "Filter query")))
+	  (const :tag "Use internal address completion" internal)
 	  (const :tag "Disable address completion" nil)
 	  (string :tag "Use external completion command"))
+  :group 'notmuch-send
+  :group 'notmuch-external)
+
+(defcustom notmuch-address-internal-completion '(sent nil)
+  "Determines how internal address completion generates candidates.
+
+This should be a list of the form '(DIRECTION FILTER), where
+ DIRECTION is either sent or received and specifies whether the
+ candidates are searched in messages sent by the user or received
+ by the user (note received by is much faster), and FILTER is
+ either nil or a filter-string, such as \"date:1y..\" to append
+ to the query."
+  :type '(list :tag "Use internal address completion"
+	       (radio
+		:tag "Base completion on messages you have"
+		:value sent
+		(const :tag "sent (more accurate)" sent)
+		(const :tag "received (faster)" received))
+	       (radio :tag "Filter messages used for completion"
+		      (const :tag "Use all messages" nil)
+		      (string :tag "Filter query")))
   ;; We override set so that we can clear the cache when this changes
   :set (lambda (symbol value)
 	 (set-default symbol value)
@@ -108,13 +119,10 @@ to know how address selection is made by default."
 
 (defun notmuch-address-setup ()
   (let* ((use-company (and notmuch-address-use-company
-			   notmuch-address-command
-			   (listp notmuch-address-command)
+			   (eq notmuch-address-command 'internal)
 			   (require 'company nil t)))
 	 (pair (cons notmuch-address-completion-headers-regexp
-		     (if use-company
-			 #'company-manual-begin
-		       #'notmuch-address-expand-name))))
+		       #'notmuch-address-expand-name)))
       (when use-company
 	(notmuch-company-setup))
       (unless (memq pair message-completion-alist)
@@ -137,7 +145,7 @@ The candidates are taken from `notmuch-address-completions'."
 elisp-based implementation or older implementation requiring
 external commands."
   (cond
-   ((and notmuch-address-command (listp notmuch-address-command))
+   ((eq notmuch-address-command 'internal)
     (when (not notmuch-address-full-harvest-finished)
       ;; First, run quick synchronous harvest based on what the user
       ;; entered so far
@@ -149,7 +157,12 @@ external commands."
     (process-lines notmuch-address-command original))))
 
 (defun notmuch-address-expand-name ()
-  (when notmuch-address-command
+  (cond
+   ((and (eq notmuch-address-command 'internal)
+	 notmuch-address-use-company
+	 (bound-and-true-p company-mode))
+    (company-manual-begin))
+   (notmuch-address-command
     (let* ((end (point))
 	   (beg (save-excursion
 		  (re-search-backward "\\(\\`\\|[\n:,]\\)[ \t]*")
@@ -175,7 +188,8 @@ external commands."
 	    (delete-region beg end)
 	    (insert chosen))
 	(message "No matches.")
-	(ding)))))
+	(ding))))
+   (t nil)))
 
 ;; Copied from `w3m-which-command'.
 (defun notmuch-address-locate-command (command)
@@ -232,8 +246,8 @@ Address harvesting may take some time so the address collection runs
 asynchronously unless SYNCHRONOUS is t. In case of asynchronous
 execution, CALLBACK is called when harvesting finishes."
 
-  (let* ((sent (eq (car notmuch-address-command) 'sent))
-	 (config-query (cadr notmuch-address-command))
+  (let* ((sent (eq (car notmuch-address-internal-completion) 'sent))
+	 (config-query (cadr notmuch-address-internal-completion))
 	 (prefix-query (when addr-prefix
 			 (format "%s:%s*" (if sent "to" "from") addr-prefix)))
 	 (from-or-to-me-query
diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index 399e138..93a4d4b 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -276,8 +276,7 @@ mutiple parts get a header."
 
 (define-derived-mode notmuch-message-mode message-mode "Message[Notmuch]"
   "Notmuch message composition mode. Mostly like `message-mode'"
-  (when notmuch-address-command
-    (notmuch-address-setup)))
+  (notmuch-address-setup))
 
 (put 'notmuch-message-mode 'flyspell-mode-predicate 'mail-mode-flyspell-verify)
 



More information about the notmuch mailing list