unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* Address completion in Emacs
@ 2014-12-12  8:22 Lele Gaifax
  2014-12-12 12:14 ` David Edmondson
  2014-12-14 17:27 ` Tomi Ollila
  0 siblings, 2 replies; 9+ messages in thread
From: Lele Gaifax @ 2014-12-12  8:22 UTC (permalink / raw)
  To: notmuch

Hi all,

Yesterday I tweaked my Emacs configuration to use "ido-completing-read"
to select the right address in the minibuffer, and noticed what seems a
glitch in the related code.

To accomplish the goal, I implemented my own selection function

  (defun esk-notmuch-address-selection-function (prompt addresses first)
    "Use `ido-completing-read' to select one of the addresses."
    (ido-completing-read prompt (cons first addresses)
                         nil nil nil 'notmuch-address-history))

and then assigned it to `notmuch-address-selection-function':

  (setq notmuch-address-selection-function 'esk-notmuch-address-selection-function)

As you can see, I had to `cons' the two arguments, because the caller of
that function does something similar to the following (where `orig' is
the text entered before TAB-completion):

  (options (notmuch-address-options orig))
  (num-options (length options))
  (chosen (funcall notmuch-address-selection-function
              (format "Address (%s matches): " num-options)
              (cdr options) (car options)))

and the standard `notmuch-address-selection-function' is defined like:

  (defun notmuch-address-selection-function (prompt collection initial-input)
    "Call (`completing-read'
        PROMPT COLLECTION nil nil INITIAL-INPUT 'notmuch-address-history)"
    (completing-read
     prompt collection nil nil initial-input 'notmuch-address-history))

where that `initial-input' is not what I initially thought, the text
entered by the user, but rather the first completion candidate.

Wouldn't it be more "correct" to pass the unchanged `options' list and
the "real" `orig' text as `initial-input' to the customizable function
instead?

I understand that it may be undesiderable to break existing
configurations by rectifying the arguments in that way, and in such case
could we change the `initial-input' argument name to better reflect the
fact that it actually contains one possible candidate instead?

Thanks in advance for any clarification,
ciao, lele.
-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
lele@metapensiero.it  |                 -- Fortunato Depero, 1929.

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

* Re: Address completion in Emacs
  2014-12-12  8:22 Address completion in Emacs Lele Gaifax
@ 2014-12-12 12:14 ` David Edmondson
  2014-12-12 12:45   ` Lele Gaifax
  2014-12-14 17:27 ` Tomi Ollila
  1 sibling, 1 reply; 9+ messages in thread
From: David Edmondson @ 2014-12-12 12:14 UTC (permalink / raw)
  To: Lele Gaifax, notmuch

On Fri, Dec 12 2014, Lele Gaifax wrote:
> Hi all,
>
> Yesterday I tweaked my Emacs configuration to use "ido-completing-read"
> to select the right address in the minibuffer, and noticed what seems a
> glitch in the related code.
>
> To accomplish the goal, I implemented my own selection function
>
>   (defun esk-notmuch-address-selection-function (prompt addresses first)
>     "Use `ido-completing-read' to select one of the addresses."
>     (ido-completing-read prompt (cons first addresses)
>                          nil nil nil 'notmuch-address-history))
>
> and then assigned it to `notmuch-address-selection-function':
>
>   (setq notmuch-address-selection-function 'esk-notmuch-address-selection-function)
>
> As you can see, I had to `cons' the two arguments, because the caller of
> that function does something similar to the following (where `orig' is
> the text entered before TAB-completion):
>
>   (options (notmuch-address-options orig))
>   (num-options (length options))
>   (chosen (funcall notmuch-address-selection-function
>               (format "Address (%s matches): " num-options)
>               (cdr options) (car options)))
>
> and the standard `notmuch-address-selection-function' is defined like:
>
>   (defun notmuch-address-selection-function (prompt collection initial-input)
>     "Call (`completing-read'
>         PROMPT COLLECTION nil nil INITIAL-INPUT 'notmuch-address-history)"
>     (completing-read
>      prompt collection nil nil initial-input 'notmuch-address-history))
>
> where that `initial-input' is not what I initially thought, the text
> entered by the user, but rather the first completion candidate.
>
> Wouldn't it be more "correct" to pass the unchanged `options' list and
> the "real" `orig' text as `initial-input' to the customizable function
> instead?

Would I then have to press TAB twice to get the first result?

> I understand that it may be undesiderable to break existing
> configurations by rectifying the arguments in that way, and in such case
> could we change the `initial-input' argument name to better reflect the
> fact that it actually contains one possible candidate instead?

From the perspective of `notmuch-address-selection-function', it _is_
the `initial-input', as that is what is presented to the user.

> Thanks in advance for any clarification,
> ciao, lele.
> -- 
> nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
> real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
> lele@metapensiero.it  |                 -- Fortunato Depero, 1929.
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch

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

* Re: Address completion in Emacs
  2014-12-12 12:14 ` David Edmondson
@ 2014-12-12 12:45   ` Lele Gaifax
  2014-12-12 13:08     ` David Edmondson
  0 siblings, 1 reply; 9+ messages in thread
From: Lele Gaifax @ 2014-12-12 12:45 UTC (permalink / raw)
  To: notmuch

David Edmondson <dme@dme.org> writes:

> On Fri, Dec 12 2014, Lele Gaifax wrote:
>> Wouldn't it be more "correct" to pass the unchanged `options' list and
>> the "real" `orig' text as `initial-input' to the customizable function
>> instead?
>
> Would I then have to press TAB twice to get the first result?

No, why? The customizable `notmuch-address-selection-function' would be
free to pass (car options) as the initial-input of `completing-read', if
needed. When using `ido-completing-read', the first option is
pre-selected, so a RET confirms that.

>> I understand that it may be undesiderable to break existing
>> configurations by rectifying the arguments in that way, and in such case
>> could we change the `initial-input' argument name to better reflect the
>> fact that it actually contains one possible candidate instead?
>
> From the perspective of `notmuch-address-selection-function', it _is_
> the `initial-input', as that is what is presented to the user.

IMHO no, it's not: what it receives as `initial-input' is not what the
user actually wrote, but rather just the (somewhat arbitrary) first
candidate address found by `notmuch-address-command'.

thanks&bye, lele.
-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
lele@metapensiero.it  |                 -- Fortunato Depero, 1929.

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

* Re: Address completion in Emacs
  2014-12-12 12:45   ` Lele Gaifax
@ 2014-12-12 13:08     ` David Edmondson
  0 siblings, 0 replies; 9+ messages in thread
From: David Edmondson @ 2014-12-12 13:08 UTC (permalink / raw)
  To: Lele Gaifax, notmuch

On Fri, Dec 12 2014, Lele Gaifax wrote:
> David Edmondson <dme@dme.org> writes:
>
>> On Fri, Dec 12 2014, Lele Gaifax wrote:
>>> Wouldn't it be more "correct" to pass the unchanged `options' list and
>>> the "real" `orig' text as `initial-input' to the customizable function
>>> instead?
>>
>> Would I then have to press TAB twice to get the first result?
>
> No, why? The customizable `notmuch-address-selection-function' would be
> free to pass (car options) as the initial-input of `completing-read', if
> needed. When using `ido-completing-read', the first option is
> pre-selected, so a RET confirms that.

Understood.

>>> I understand that it may be undesiderable to break existing
>>> configurations by rectifying the arguments in that way, and in such case
>>> could we change the `initial-input' argument name to better reflect the
>>> fact that it actually contains one possible candidate instead?
>>
>> From the perspective of `notmuch-address-selection-function', it _is_
>> the `initial-input', as that is what is presented to the user.
>
> IMHO no, it's not: what it receives as `initial-input' is not what the
> user actually wrote, but rather just the (somewhat arbitrary) first
> candidate address found by `notmuch-address-command'.

I think that we're at cross
purposes. `notmuch-address-selection-function' will use the
`initial-input' as the initial input of the completion, so that's what
it chooses to call the argument. It can't be blamed if whatever is
passed to it is not something that you would consider the initial input.

> thanks&bye, lele.
> -- 
> nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
> real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
> lele@metapensiero.it  |                 -- Fortunato Depero, 1929.
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch

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

* Re: Address completion in Emacs
  2014-12-12  8:22 Address completion in Emacs Lele Gaifax
  2014-12-12 12:14 ` David Edmondson
@ 2014-12-14 17:27 ` Tomi Ollila
  1 sibling, 0 replies; 9+ messages in thread
From: Tomi Ollila @ 2014-12-14 17:27 UTC (permalink / raw)
  To: Lele Gaifax, notmuch

On Fri, Dec 12 2014, Lele Gaifax wrote:

> Hi all,
>
> Yesterday I tweaked my Emacs configuration to use "ido-completing-read"
> to select the right address in the minibuffer, and noticed what seems a
> glitch in the related code.
>
> To accomplish the goal, I implemented my own selection function
>
>   (defun esk-notmuch-address-selection-function (prompt addresses first)
>     "Use `ido-completing-read' to select one of the addresses."
>     (ido-completing-read prompt (cons first addresses)
>                          nil nil nil 'notmuch-address-history))
>
> and then assigned it to `notmuch-address-selection-function':
>
>   (setq notmuch-address-selection-function 'esk-notmuch-address-selection-function)
>
> As you can see, I had to `cons' the two arguments, because the caller of
> that function does something similar to the following (where `orig' is
> the text entered before TAB-completion):
>
>   (options (notmuch-address-options orig))
>   (num-options (length options))
>   (chosen (funcall notmuch-address-selection-function
>               (format "Address (%s matches): " num-options)
>               (cdr options) (car options)))
>
> and the standard `notmuch-address-selection-function' is defined like:
>
>   (defun notmuch-address-selection-function (prompt collection initial-input)
>     "Call (`completing-read'
>         PROMPT COLLECTION nil nil INITIAL-INPUT 'notmuch-address-history)"
>     (completing-read
>      prompt collection nil nil initial-input 'notmuch-address-history))
>
> where that `initial-input' is not what I initially thought, the text
> entered by the user, but rather the first completion candidate.
>
> Wouldn't it be more "correct" to pass the unchanged `options' list and
> the "real" `orig' text as `initial-input' to the customizable function
> instead?

I think I am to be blamed why that is like this -- initially there were
no notmuch-address-selection-function ... I added as I needed it, in

Stashed: id:1365001734-3160-1-git-send-email-tomi.ollila@iki.fi
Stashed: http://mid.gmane.org/1365001734-3160-1-git-send-email-tomi.ollila@iki.fi

and I was not smart enough to do the splitting in "standard
notmuch-address-selection-function".  

Later, someone(*) provided patch which would make the "standard" interface
work better with ido-completing-read -- unfortunately that made the
default, original interface which uses completing-read borken.

Personally I'd like to see leaner interface there, but that is incompatible
change and in this particular case I don't see compelling reason to do that... 

(*) cannot remember who and when, and I am writing this mail on a Mac and
the use is painful enough now (keybindings, focus behaviour, etc...);/

>
> I understand that it may be undesiderable to break existing
> configurations by rectifying the arguments in that way, and in such case
> could we change the `initial-input' argument name to better reflect the
> fact that it actually contains one possible candidate instead?

Naming change would indeed be a good idea... (probably?!)  

>
> Thanks in advance for any clarification,
> ciao, lele.

Tomi

> -- 
> nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
> real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
> lele@metapensiero.it  |                 -- Fortunato Depero, 1929.
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch

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

* Address Completion in Emacs
@ 2023-12-08 13:26 David Wen Riccardi-Zhu
  2023-12-08 16:40 ` Sandra Snan
  0 siblings, 1 reply; 9+ messages in thread
From: David Wen Riccardi-Zhu @ 2023-12-08 13:26 UTC (permalink / raw)
  To: notmuch

Hello,

I had working address completion in Emacs with company-mode, but
recently switched to corfu. Has anyone been able to get address
completion to work with it?

Alternatively, I'm wondering how the internal completion style works. Is
there a function I can call to get internal address completion to kick
in?

Lastly, is it possible to remove addresses from the list of candidates?
I have a few addresses that were consistently recommended even though
they had typos in them.

I have this in my config:

(setq notmuch-address-command 'internal
  notmuch-address-internal-completion '(sent nil)
  notmuch-address-save-filename "~/org/contacts/notmuch-contacts"
  ;; ... 
)

Can I manually clean up my notmuch-contacts file? 

If yes, is it possible to add newlines to the file, to make it easier to
search and edit?

Thank you!

David

-- 
dwrz|朱为文\r

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

* Re: Address Completion in Emacs
  2023-12-08 13:26 Address Completion " David Wen Riccardi-Zhu
@ 2023-12-08 16:40 ` Sandra Snan
  2023-12-09  2:05   ` David Wen Riccardi-Zhu
  0 siblings, 1 reply; 9+ messages in thread
From: Sandra Snan @ 2023-12-08 16:40 UTC (permalink / raw)
  To: David Wen Riccardi-Zhu, notmuch

David, I have message-completion-alist set to this value:

(("^\\(Resent-\\)?\\(To\\|B?Cc\\|Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):" 
  .  notmuch-address-expand-name) 
 ("^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):" . 
 message-expand-group) ("^\\([^ :]*-\\)?\\(To\\|B?Cc\\|From\\):" . 
 message-expand-name)) 

That way, when I hit tab in the sender field, which is bound to 
message-tab, it'll run notmuch-address-expand-name which can find 
pretty much everyone I've ever heard of.

I additionally have an old BBDB that I've been using for ages that 
I can access with ESC TAB which is set to bbdb-complete-mail but I 
literally only have 16 people in there (I just checked). I use 
them for my most common faves so I can get their most canonical 
address with just a few letters.

As for weeding through the list of candidates, there are packages 
such as orderless and vertico that can enhance all calls to 
completing-read, including the one in notmuch-address-expand-name. 
After using it a while it does a good job at giving me the 
relevantest ones at the top and letting me filter through them 
further.

Corfu and company-mode, I have never heard of! So this is more of 
an answer to the "alternatively" part you asked.

Sandra


David Wen Riccardi-Zhu <dwrz@dwrz.net> writes:

> Hello,
>
> I had working address completion in Emacs with company-mode, but
> recently switched to corfu. Has anyone been able to get address
> completion to work with it?
>
> Alternatively, I'm wondering how the internal completion style works. Is
> there a function I can call to get internal address completion to kick
> in?
>
> Lastly, is it possible to remove addresses from the list of candidates?
> I have a few addresses that were consistently recommended even though
> they had typos in them.
>
> I have this in my config:
>
> (setq notmuch-address-command 'internal
>   notmuch-address-internal-completion '(sent nil)
>   notmuch-address-save-filename "~/org/contacts/notmuch-contacts"
>   ;; ... 
> )
>
> Can I manually clean up my notmuch-contacts file? 
>
> If yes, is it possible to add newlines to the file, to make it easier to
> search and edit?
>
> Thank you!
>
> David
>
> -- 
> dwrz|朱为文
> _______________________________________________
> notmuch mailing list -- notmuch@notmuchmail.org
> To unsubscribe send an email to notmuch-leave@notmuchmail.org\r

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

* Re: Address Completion in Emacs
  2023-12-08 16:40 ` Sandra Snan
@ 2023-12-09  2:05   ` David Wen Riccardi-Zhu
  2023-12-09  8:26     ` Keith Amidon
  0 siblings, 1 reply; 9+ messages in thread
From: David Wen Riccardi-Zhu @ 2023-12-09  2:05 UTC (permalink / raw)
  To: Sandra Snan, notmuch

Thank you, Sandra! With your advice, I was able to figure out that corfu
was overriding the Tab key from notmuch. If I disable it,
notmuch-address-expand-name works (with orderless and vertico). I'll see
if I can find a way to pipe it into corfu somehow.

Sandra Snan <sandra.snan@idiomdrottning.org> writes:

> David, I have message-completion-alist set to this value:
>
> (("^\\(Resent-\\)?\\(To\\|B?Cc\\|Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):" 
>   .  notmuch-address-expand-name) 
>  ("^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):" . 
>  message-expand-group) ("^\\([^ :]*-\\)?\\(To\\|B?Cc\\|From\\):" . 
>  message-expand-name)) 
>
> That way, when I hit tab in the sender field, which is bound to 
> message-tab, it'll run notmuch-address-expand-name which can find 
> pretty much everyone I've ever heard of.
>
> I additionally have an old BBDB that I've been using for ages that 
> I can access with ESC TAB which is set to bbdb-complete-mail but I 
> literally only have 16 people in there (I just checked). I use 
> them for my most common faves so I can get their most canonical 
> address with just a few letters.
>
> As for weeding through the list of candidates, there are packages 
> such as orderless and vertico that can enhance all calls to 
> completing-read, including the one in notmuch-address-expand-name. 
> After using it a while it does a good job at giving me the 
> relevantest ones at the top and letting me filter through them 
> further.
>
> Corfu and company-mode, I have never heard of! So this is more of 
> an answer to the "alternatively" part you asked.
>
> Sandra
>
>
> David Wen Riccardi-Zhu <dwrz@dwrz.net> writes:
>
>> Hello,
>>
>> I had working address completion in Emacs with company-mode, but
>> recently switched to corfu. Has anyone been able to get address
>> completion to work with it?
>>
>> Alternatively, I'm wondering how the internal completion style works. Is
>> there a function I can call to get internal address completion to kick
>> in?
>>
>> Lastly, is it possible to remove addresses from the list of candidates?
>> I have a few addresses that were consistently recommended even though
>> they had typos in them.
>>
>> I have this in my config:
>>
>> (setq notmuch-address-command 'internal
>>   notmuch-address-internal-completion '(sent nil)
>>   notmuch-address-save-filename "~/org/contacts/notmuch-contacts"
>>   ;; ... 
>> )
>>
>> Can I manually clean up my notmuch-contacts file? 
>>
>> If yes, is it possible to add newlines to the file, to make it easier to
>> search and edit?
>>
>> Thank you!
>>
>> David
>>
>> -- 
>> dwrz|朱为文
>> _______________________________________________
>> notmuch mailing list -- notmuch@notmuchmail.org
>> To unsubscribe send an email to notmuch-leave@notmuchmail.org

-- 
dwrz|朱为文\r

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

* Re: Address Completion in Emacs
  2023-12-09  2:05   ` David Wen Riccardi-Zhu
@ 2023-12-09  8:26     ` Keith Amidon
  0 siblings, 0 replies; 9+ messages in thread
From: Keith Amidon @ 2023-12-09  8:26 UTC (permalink / raw)
  To: notmuch

This thread inspired me to look a little more deeply into the address 
completion issues I've been having since switching to corfu as well. It 
was a rather long and twisted journey but I ended up getting completion 
using corfu working with the following in my init file:

    ;; Make corfu-based address completion work
    (defun kea/notmuch-address-message-capf ()
      "Return completion data for email addresses in notmuch-address.

Meant for use in `message-completion-alist'."
      (when (and (bound-and-true-p notmuch-address-completions))
        (let ((now (float-time))
              (end (save-excursion
                     (skip-chars-forward "^, \t\n")
                     (point)))
              (start (save-excursion
                       (skip-chars-backward "^, \t\n")
                       (point))))
          (when (> (- now notmuch-address-last-harvest) 86400)
            ;; Synchronously get completions now and update addresses in
            ;; background. Handles startup case where there might not be
            ;; anything in notmuch-address-completions because
            ;; notmuch-address-last-harvest will be 0.
            (notmuch-address-harvest (buffer-substring-no-properties 
start end) t)
            (notmuch-address-harvest-trigger))
          `(,start ,end ,notmuch-address-completions 'mail))))
    (defun kea/setup-notmuch-message-mode ()
      (setq notmuch-address-use-company nil)
      (setq message-completion-alist
            `((,message-newgroups-header-regexp . ,#'message-expand-group)
              (,message-email-recipient-header-regexp . 
,#'kea/notmuch-address-message-capf))))
    (add-hook 'notmuch-message-mode-hook #'kea/setup-notmuch-message-mode)

Note that I set mail-user-agent to notmuch-user-agent.

Cheers!   --- Keith
\r

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

end of thread, other threads:[~2023-12-09  8:44 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-12  8:22 Address completion in Emacs Lele Gaifax
2014-12-12 12:14 ` David Edmondson
2014-12-12 12:45   ` Lele Gaifax
2014-12-12 13:08     ` David Edmondson
2014-12-14 17:27 ` Tomi Ollila
  -- strict thread matches above, loose matches on Subject: below --
2023-12-08 13:26 Address Completion " David Wen Riccardi-Zhu
2023-12-08 16:40 ` Sandra Snan
2023-12-09  2:05   ` David Wen Riccardi-Zhu
2023-12-09  8:26     ` Keith Amidon

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).