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 34CA26DE0173 for ; Thu, 3 Nov 2016 10:08:59 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: 0.164 X-Spam-Level: X-Spam-Status: No, score=0.164 tagged_above=-999 required=5 tests=[AWL=0.034, 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 a_epxd2R86nU for ; Thu, 3 Nov 2016 10:08:58 -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 0CE936DE00D3 for ; Thu, 3 Nov 2016 10:08:57 -0700 (PDT) Received: by mail-wm0-f65.google.com with SMTP id p190so9025109wmp.1 for ; Thu, 03 Nov 2016 10:08:57 -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=xx8/+SNf9qr7nQcgSaxM+phR9jNNrfpwSNjtfqDWlv0=; b=dkWswMHnoFBY7+XGMKLaINd6Q//qM4WepwCfE8lujUMOKY0gIfR/y7tVo5qVcGnSLK p8icecVc8tPzv7azS70Z0jUxu7wpjIOcXO2bnJrssvfIXNZh5j0HV4f50zIEgU9rvxZ+ Nto1n5tom5NpPE091GyLULobh5y9A4ebqibrrtM0+Cu5g5n1x3x46cp6WAtdXDl7oA+5 u7eshQrcHNCZ1icH79GDOW3H1EMRQtBQ86hVi/PP1olv7y2KEEA9V/Wv7L00kXrzNdlL zRcryfteiPXszE+LBKBPdNk0SeBiMUomdel46MFilt90aMOKqZ3XJDEupSTeS9g1gRqm kdFw== 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=xx8/+SNf9qr7nQcgSaxM+phR9jNNrfpwSNjtfqDWlv0=; b=Ewfrn57tyMGDALUI8Hb0haszkS8geLjxvyTvv3uuupDVFWLVtYLitAmXrQqNJxzU2B GJZVbaaDN1iS2OURkiV2IXtM5Bc+6/gIaue9QigfVhFBYE3vUp3dn9gHZu4BccArM3gN ljWwLRPcHhRokppG0rvBltwvSeyM8G5eZtzWUbfmYU2Xz7EV8owb/LMXLdnYLpW1BFKQ tMbA1gofkS68gwOKVPyvhsoCRwELlHhagQjUIp5+5KK5G6X74ikCpZbHt8zAplL0+Peq jUsBu4lCSlGKggi3SFrZr4m4Umgg+b+sOlxbjqiIR7zmfIQ16kQRra9NJj8a8xWHZWm7 n6cA== X-Gm-Message-State: ABUngveEVpY7KUKyc0BtqP7/Q7SO1pt3AzvXgzwM+ChRmE96ukAyYAXqVnkl4kV6RKOXxA== X-Received: by 10.194.235.7 with SMTP id ui7mr8275512wjc.66.1478192934905; Thu, 03 Nov 2016 10:08:54 -0700 (PDT) Received: from localhost (188.28.91.110.threembb.co.uk. [188.28.91.110]) by smtp.gmail.com with ESMTPSA id e2sm9631080wjw.14.2016.11.03.10.08.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 03 Nov 2016 10:08:54 -0700 (PDT) From: Mark Walters To: David Bremner , David Bremner , notmuch@notmuchmail.org Subject: Re: [PATCH v3] emacs: add notmuch-address-post-completion-hook In-Reply-To: <20161103115645.31075-1-david@tethera.net> References: <878tt09amd.fsf@qmul.ac.uk> <20161103115645.31075-1-david@tethera.net> Date: Thu, 03 Nov 2016 17:08:50 +0000 Message-ID: <87twbo7aot.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 17:08:59 -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 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