From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 009956DE0173 for ; Thu, 3 Nov 2016 02:27:29 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: 0.153 X-Spam-Level: X-Spam-Status: No, score=0.153 tagged_above=-999 required=5 tests=[AWL=0.023, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id CQno6Ewszk-y for ; Thu, 3 Nov 2016 02:27:28 -0700 (PDT) Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by arlo.cworth.org (Postfix) with ESMTPS id E55166DE00D3 for ; Thu, 3 Nov 2016 02:27:27 -0700 (PDT) Received: by mail-wm0-f65.google.com with SMTP id u144so6995295wmu.0 for ; Thu, 03 Nov 2016 02:27:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:in-reply-to:references:date:message-id:mime-version; bh=HfuhVfwpiFJfDF3fzAham3dEKc6nInxQoJ+uXAvxka8=; b=xraEx0BJd7VF5JRwqeDm4S1VIxK+HSPGMHtcZad1c2e1S+GqlmEhVLwj5KrNfzlXSx gvM+vWZr1Lnuvd1I8q06gg9YfHOnQeZTUUenu09eMQnAlcTIi5SsHpuf8lRb9Ifj0t9e 4Gd5aTPb4wFiWXu+fL8IRHB9q2b8obBKurkLWyhSxIc4WfVE/nL3WOBesCLMJrfmG65O YAi3N2uFwbGLPs7qlHaLeJeqVYbIa5Sp2tapDU/cXnflumRSS4qLCenfj+8xQfPTDTPo L412cy5fCKSFJz7K6DNWxm5pBANbyTwWZlXja7pmBIjRxC/piMC7pJ/f14viutsCzCuA lzOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:in-reply-to:references:date :message-id:mime-version; bh=HfuhVfwpiFJfDF3fzAham3dEKc6nInxQoJ+uXAvxka8=; b=LzAy0lnuzgeYrRaoyRQ6/vRfgsTAMYIlloHLt3nQB0o9rPWMlTDaQPUsPHIBWMuaVI QP2bVEj/ij/MJDB9Z7Q6hyP3HU2S+1AVxyVOkEAPklQI29LhMOXsAqIncM4oJYsMz6PZ NM/sUX6QSqq6H+yUHiOEX6nzFofrYUvY1Q84yBQ6Ih/3km6WvuDZqJRsoE13rSBhzEpK 0EmHkgo00MAY0RC6I/51FvEghpag6LxqekMwsa//aVE3rjztHHEdpl/ClinfAFz4I4wp r1cICixAl47WBhbxbPR2+8777vyiWNdHa1F3isayY/G6SHGkdpt4knYfD95TBXz9H/1X YYIA== X-Gm-Message-State: ABUngvd6nsVWoMd6h/LUmJ095vthEngmTlnoLEIgBAzn+tnCBo7hLyzRpGOIJ/BYZaEZtQ== X-Received: by 10.194.117.10 with SMTP id ka10mr8310274wjb.148.1478165243932; Thu, 03 Nov 2016 02:27:23 -0700 (PDT) Received: from localhost (188.28.69.27.threembb.co.uk. [188.28.69.27]) by smtp.gmail.com with ESMTPSA id f3sm20581773wmf.10.2016.11.03.02.27.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 03 Nov 2016 02:27:23 -0700 (PDT) From: Mark Walters To: David Bremner , notmuch@notmuchmail.org Subject: Re: [PATCH] emacs: add notmuch-address-post-completion-hook In-Reply-To: <20161103003603.17798-1-david@tethera.net> References: <20161103003603.17798-1-david@tethera.net> Date: Thu, 03 Nov 2016 09:27:22 +0000 Message-ID: <878tt09amd.fsf@qmul.ac.uk> MIME-Version: 1.0 Content-Type: text/plain X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Nov 2016 09:27:29 -0000 On Thu, 03 Nov 2016, David Bremner 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