unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Mark Walters <markwalters1009@gmail.com>
To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org
Subject: Re: [PATCH] emacs: add notmuch-address-post-completion-hook
Date: Thu, 03 Nov 2016 09:27:22 +0000	[thread overview]
Message-ID: <878tt09amd.fsf@qmul.ac.uk> (raw)
In-Reply-To: <20161103003603.17798-1-david@tethera.net>


On Thu, 03 Nov 2016, David Bremner <david@tethera.net> wrote:
> 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"

Hi when testing this with company I think the following happens: if you
trigger it manually with tab then I think the hook gets passed a list of
possible addresses, not just one.

> +  :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)))

I think you need to return return-value here? But you also need to
modify notmuch-address-real-expand-name to return chosen. Around line
217 of notmuch-address.el

      (if chosen
	  (progn
	    (push chosen notmuch-address-history)
	    (delete-region beg end)
	    (insert chosen))

should become 

      (if chosen
	  (progn
	    (push chosen notmuch-address-history)
	    (delete-region beg end)
	    (insert chosen)
            ;; Return completed address 
            chosen)

I guess an alternative would to just run the hook there, and then you
wouldn't need to the notmuch-address-real-expand-name function at
all. (Sorry for misleading you about this on irc yesterday.)


> +
> +(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))))

To fix the list of addresses case you might be able to just put a
(unless (listp arg) or something round the run-hook-with-args

Best wishes

Mark

  reply	other threads:[~2016-11-03  9:27 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-03  0:36 [PATCH] emacs: add notmuch-address-post-completion-hook David Bremner
2016-11-03  9:27 ` Mark Walters [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=878tt09amd.fsf@qmul.ac.uk \
    --to=markwalters1009@gmail.com \
    --cc=david@tethera.net \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).