[PATCH v3] emacs: add notmuch-address-post-completion-hook

Mark Walters markwalters1009 at gmail.com
Thu Nov 3 10:08:50 PDT 2016


On Thu, 03 Nov 2016, David Bremner <david at tethera.net> wrote:
> This hook can be used to update the message based on the results of
> address completion. For example using message-templ or gnus-alias 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.
> ---
>
> Sorry for the false send. My fingers somehow mix up Debian's
> "reportbug" and git-send-email.
>
> Here is a simplified version. As far as I could tell during testing
> with company-mode the hook is only called via the post-completion
> command, and always with a single argument. This might indicate a
> separate bug, since I noticed in one fairly long running emacs session
> (11 days), notmuch-address-history is nil.
>
> I guess the docstring for notmuch-address-completion-hook should have
> a '.' at the end, or probably ' function.'
>
>
>  emacs/notmuch-address.el | 7 +++++++
>  emacs/notmuch-company.el | 1 +
>  2 files changed, 8 insertions(+)
>
> diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
> index b2e1fba..d1abb21 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)"
> @@ -205,6 +211,7 @@ external commands."
>        (if chosen
>  	  (progn
>  	    (push chosen notmuch-address-history)
> +	    (run-hook-with-args 'notmuch-address-completion-hook chosen)
>  	    (delete-region beg end)
>  	    (insert chosen))

Hi

Would it be worth putting the run-hook after the (insert chosen) rather
than before? That would mean that the hook had access to the full new
header. It would also mean that it wouldn't matter if the hook changed
the buffer -- as it is I think the replace might go wrong as we replace
beg to end and those seem to be integer-points not markers

One final query -- this function will be called when completing any of
To: Cc: Bcc: From: and some other less common headers. We could pass an
argument which says which header we are on but that is probably more
complexity than necessary. However, it is probably worth documenting
that it may be called from these headers in the defcustom for the hook.

But otherwise it looks good to me.

Best wishes

Mark



>  	(message "No matches.")
> 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


More information about the notmuch mailing list