unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] implement a capf for address completion
@ 2024-03-19 19:59 Antoine Beaupré
  2024-03-19 20:12 ` Antoine Beaupré
  2024-08-06 10:30 ` David Bremner
  0 siblings, 2 replies; 12+ messages in thread
From: Antoine Beaupré @ 2024-03-19 19:59 UTC (permalink / raw)
  To: notmuch; +Cc: Antoine Beaupré

I recently enabled corfu-mode everywhere, and was disappointed to find
out that I lost tab-completion on my message buffers. At most, corfu
would pop suggestions about existing words in the buffer, but no
address completion, even when I would hit TAB. I believe this is
because `message-tab' won't attempt completion if something else
already did it, and also because, somehow,
`notmuch-address-expand-name' ends up in
`message--old-style-completion-functions'.

Now, it seems to me a simple fix is to implement a proper
capf (`completion-at-point-function') for notmuch. And that, in turn,
is actually pretty simple compared to the code hidden underneath
`notmuch-address-expand-name', which not only finds completion
candidates, but also does the whole trouble of editing the buffer.

So this patch turns `notmuch-address-expand-name' into a wrapper
around the capf, and hooks the capf instead of the old function in the
message-mode completion hooks.

This ... works. Now I have popup completion, automatically (even
before hitting TAB), in my message-mode buffers. It's a bit jarring
because I'm so used to having completion in the minibuffer, but I
think I'll get used to it.

I haven't figured out how to make an escape hatch for this, to get
autocompletion in the minibuffer the same wauy way we did
before. Maybe we'd need something like the
`notmuch-address-from-minibuffer', but interactive somehow. Not
sure. But for now, this allows me to keep corfu globally active, and I
suspect will make things easier and faster going forward.
---
 emacs/notmuch-address.el | 33 +++++++++++++++++++++++----------
 1 file changed, 23 insertions(+), 10 deletions(-)

diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index f756254c..0c57add8 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -171,7 +171,7 @@ matching `notmuch-address-completion-headers-regexp'."
 	       (require 'company nil t))
       (notmuch-company-setup))
     (cl-pushnew (cons notmuch-address-completion-headers-regexp
-		      #'notmuch-address-expand-name)
+		      #'notmuch-address-complete-at-point)
 		message-completion-alist :test #'equal)))
 
 (defun notmuch-address-toggle-internal-completion ()
@@ -225,15 +225,10 @@ requiring external commands."
 	 (bound-and-true-p company-mode))
     (company-manual-begin))
    (notmuch-address-command
-    (let* ((end (point))
-	   (beg (save-excursion
-		  (re-search-backward "\\(\\`\\|[\n:,]\\)[ \t]*")
-		  (goto-char (match-end 0))
-		  (point)))
-	   (orig (buffer-substring-no-properties beg end))
-	   (completion-ignore-case t)
-	   (options (with-temp-message "Looking for completion candidates..."
-		      (notmuch-address-options orig)))
+    (let* ((capf (notmuch-address-complete-at-point))
+	   (beg (pop capf))
+	   (end (pop capf))
+	   (options (pop capf))
 	   (num-options (length options))
 	   (chosen (cond
 		    ((eq num-options 0)
@@ -256,6 +251,24 @@ requiring external commands."
 	(ding))))
    (t nil)))
 
+(defun notmuch-address-complete-at-point ()
+  "Complete the address using `notmuch-address-command'.
+
+This replaces the old `notmuch-address-expand-name' with the new
+`completion-at-point-functions' (capf) system that's compatible
+with corfu, company and friends."
+  (when notmuch-address-command
+    (let* ((end (point))
+	   (beg (save-excursion
+		  (re-search-backward "\\(\\`\\|[\n:,]\\)[ \t]*")
+		  (goto-char (match-end 0))
+		  (point)))
+	   (orig (buffer-substring-no-properties beg end))
+	   (completion-ignore-case t)
+	   (options (with-temp-message "Looking for completion candidates..."
+		      (notmuch-address-options orig))))
+      (list beg end options))))
+
 ;;; Harvest
 
 (defun notmuch-address-harvest-addr (result)
-- 
2.39.2

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

end of thread, other threads:[~2024-08-23 16:42 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-19 19:59 [PATCH] implement a capf for address completion Antoine Beaupré
2024-03-19 20:12 ` Antoine Beaupré
2024-03-19 20:34   ` Antoine Beaupré
2024-08-06 10:30 ` David Bremner
2024-08-10 19:27   ` Antoine Beaupré
2024-08-10 20:35     ` David Bremner
2024-08-11 15:36     ` Liam Hupfer
2024-08-12  0:52       ` Antoine Beaupré
2024-08-13 13:05         ` David Bremner
2024-08-13 14:30           ` Antoine Beaupré
2024-08-17 17:14             ` David Bremner
2024-08-23 16:32               ` Alexander Adolf

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