unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] emacs: add notmuch-address-post-completion-hook
@ 2016-11-03  0:36 David Bremner
  2016-11-03  9:27 ` Mark Walters
  0 siblings, 1 reply; 15+ messages in thread
From: David Bremner @ 2016-11-03  0:36 UTC (permalink / raw)
  To: notmuch

This hook can be used to update the message based on the results of
address completion. For example I use it to set the From address based
on the To address just completed.

The post-completion command is added to the notmuch-company backend to
ensure that the hook is also called company completion is started
without going through notmuch-address-expand-name. See the docstring of
`company-backends' for more information.
---
 emacs/notmuch-address.el | 10 ++++++++++
 emacs/notmuch-company.el |  1 +
 2 files changed, 11 insertions(+)

diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index b2e1fba..17960bf 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -98,6 +98,12 @@ to know how address selection is made by default."
   :group 'notmuch-send
   :group 'notmuch-external)
 
+(defcustom notmuch-address-completion-hook nil
+  "Functions called after completing address. The completed address is passed as an argument to each"
+  :type 'hook
+  :group 'notmuch-address
+  :group 'notmuch-hooks)
+
 (defun notmuch-address-selection-function (prompt collection initial-input)
   "Call (`completing-read'
       PROMPT COLLECTION nil nil INITIAL-INPUT 'notmuch-address-history)"
@@ -170,6 +176,10 @@ external commands."
     (process-lines notmuch-address-command original))))
 
 (defun notmuch-address-expand-name ()
+  (let ((return-value (notmuch-address-real-expand-name)))
+    (run-hook-with-args 'notmuch-address-completion-hook)))
+
+(defun notmuch-address-real-expand-name ()
   (cond
    ((and (eq notmuch-address-command 'internal)
 	 notmuch-address-use-company
diff --git a/emacs/notmuch-company.el b/emacs/notmuch-company.el
index 168315f..91c4804 100644
--- a/emacs/notmuch-company.el
+++ b/emacs/notmuch-company.el
@@ -86,6 +86,7 @@
       (match (if (string-match notmuch-company-last-prefix arg)
 		 (match-end 0)
 	       0))
+      (post-completion (run-hook-with-args 'notmuch-address-completion-hook arg))
       (no-cache t))))
 
 
-- 
2.10.1

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

end of thread, other threads:[~2016-11-13 17:28 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-03  0:36 [PATCH] emacs: add notmuch-address-post-completion-hook David Bremner
2016-11-03  9:27 ` Mark Walters
2016-11-03 11:38   ` David Bremner
2016-11-03 11:56   ` [PATCH v3] " David Bremner
2016-11-03 17:08     ` Mark Walters
2016-11-03 18:00       ` David Bremner
2016-11-04  1:02         ` [PATCH v4] " David Bremner
2016-11-04  6:33           ` Mark Walters
2016-11-04 15:53           ` David Bremner
2016-11-12 19:07           ` Tomi Ollila
2016-11-12 21:39             ` David Bremner
2016-11-13  7:34               ` Mark Walters
2016-11-13 12:39                 ` Tomi Ollila
2016-11-13 13:03                   ` [PATCH] emacs: rename notmuch-address-completion-hook to notmuch-address-post-completion-functions David Bremner
2016-11-13 17:28                     ` 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).