branch: externals/corfu
commit 3cacdaf3701d349656415756173f484d798a2bfd
Author: Daniel Mendler <[email protected]>
Commit: Daniel Mendler <[email protected]>
New corfu-mouse extension
---
CHANGELOG.org | 1 +
README.org | 2 ++
corfu.el | 8 +++--
extensions/corfu-mouse.el | 81 +++++++++++++++++++++++++++++++++++++++++++
extensions/corfu-popupinfo.el | 2 +-
5 files changed, 91 insertions(+), 3 deletions(-)
diff --git a/CHANGELOG.org b/CHANGELOG.org
index a009a7817a7..69c5e7757ef 100644
--- a/CHANGELOG.org
+++ b/CHANGELOG.org
@@ -6,6 +6,7 @@
- More reliable child frame resizing and positioning.
- Fix EXWM =delete-frame= problem.
+- New =corfu-mouse= extension.
* Version 2.10 (2026-05-19)
diff --git a/README.org b/README.org
index 62e27e19f09..daecc280fa8 100644
--- a/README.org
+++ b/README.org
@@ -135,6 +135,7 @@ Here is an example configuration:
;; Enable optional extension modes:
;; (corfu-history-mode)
+ ;; (corfu-mouse-mode)
;; (corfu-popupinfo-mode)
)
@@ -525,6 +526,7 @@ Corfu package:
-
[[https://github.com/minad/corfu/blob/main/extensions/corfu-indexed.el][corfu-indexed]]:
=corfu-indexed-mode= allows you to select indexed candidates with
prefix arguments.
-
[[https://github.com/minad/corfu/blob/main/extensions/corfu-info.el][corfu-info]]:
Actions to access the candidate location and documentation.
+-
[[https://github.com/minad/corfu/blob/main/extensions/corfu-mouse.el][corfu-mouse]]:
=corfu-mouse-mode= enables mouse support.
-
[[https://github.com/minad/corfu/blob/main/extensions/corfu-popupinfo.el][corfu-popupinfo]]:
Display candidate documentation or source in a popup next to
the candidate menu.
-
[[https://github.com/minad/corfu/blob/main/extensions/corfu-quick.el][corfu-quick]]:
Commands to select using Avy-style quick keys.
diff --git a/corfu.el b/corfu.el
index 41cec09d495..13d7e06a0c8 100644
--- a/corfu.el
+++ b/corfu.el
@@ -348,12 +348,16 @@ It is recommended to avoid changing these parameters.")
(indicate-empty-lines . nil)
(indicate-buffer-boundaries . nil)
(buffer-read-only . t)
- (pixel-scroll-precision-mode . nil))
+ (pixel-scroll-precision-mode . nil)
+ (x-pointer-shape . 2))
"Default child frame buffer parameters.
It is recommended to avoid changing these parameters.")
(defvar corfu--mouse-ignore-map
- (let ((map (define-keymap "<touchscreen-begin>" #'ignore)))
+ (let ((map (define-keymap
+ "<touchscreen-begin>" #'ignore
+ "<right-fringe> <t>" #'ignore
+ "<left-fringe> <t>" #'ignore)))
(dotimes (i 7)
(dolist (k '(mouse down-mouse drag-mouse double-mouse triple-mouse))
(keymap-set map (format "<%s-%s>" k (1+ i)) #'ignore)))
diff --git a/extensions/corfu-mouse.el b/extensions/corfu-mouse.el
new file mode 100644
index 00000000000..226bbbe10b3
--- /dev/null
+++ b/extensions/corfu-mouse.el
@@ -0,0 +1,81 @@
+;;; corfu-mouse.el --- Mouse support -*- lexical-binding: t -*-
+
+;; Copyright (C) 2026 Free Software Foundation, Inc.
+
+;; Author: Daniel Mendler <[email protected]>
+;; Maintainer: Daniel Mendler <[email protected]>
+;; Created: 2026
+;; Version: 2.10
+;; Package-Requires: ((emacs "29.1") (compat "31") (corfu "2.10"))
+;; URL: https://github.com/minad/corfu
+
+;; This file is part of GNU Emacs.
+
+;; This program is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This package is a Corfu extension, which adds mouse support if
+;; enabled via `corfu-mouse-mode'.
+
+;;; Code:
+
+(require 'corfu)
+(eval-when-compile
+ (require 'cl-lib))
+
+(defface corfu-mouse
+ '((t :inherit highlight))
+ "Face used for mouse highlighting."
+ :group 'corfu-faces)
+
+(defvar-keymap corfu-mouse-map
+ :doc "Additional keymap activated by `corfu-mouse-mode'."
+ :parent corfu--mouse-ignore-map
+ "<mouse-1>" #'corfu-mouse-complete
+ "<mouse-2>" #'corfu-mouse-complete
+ "<wheel-up>" #'corfu-previous
+ "<wheel-down>" #'corfu-next)
+
+;;;###autoload
+(define-minor-mode corfu-mouse-mode
+ "Mouse support."
+ :global t :group 'corfu)
+
+(defun corfu-mouse-complete ()
+ "Call `corfu-complete' with candidate at mouse position."
+ (declare (completion ignore))
+ (interactive)
+ (when-let* ((row (cdr (posn-col-row (event-end last-input-event))))
+ ((fixnump row))
+ (index (+ corfu--scroll row))
+ ((and (>= index 0) (< index corfu--total))))
+ (corfu--goto index)
+ (corfu-complete)))
+
+(cl-defmethod corfu--popup-show :around (pos off width lines
+ &context (corfu-mouse-mode (eql
t))
+ &rest args)
+ (apply #'cl-call-next-method pos off width
+ (cl-loop
+ for line in lines
+ for padded = (concat line #(" " 0 1 (display (space :align-to
right))))
+ do (put-text-property 0 (length padded) 'mouse-face 'corfu-mouse
padded)
+ collect padded)
+ args)
+ (with-current-buffer (get-buffer " *corfu*")
+ (use-local-map corfu-mouse-map)))
+
+(provide 'corfu-mouse)
+;;; corfu-mouse.el ends here
diff --git a/extensions/corfu-popupinfo.el b/extensions/corfu-popupinfo.el
index afe8179adf8..3cab997b3a0 100644
--- a/extensions/corfu-popupinfo.el
+++ b/extensions/corfu-popupinfo.el
@@ -122,7 +122,7 @@ documentation from the backend is usually expensive."
:group 'corfu)
(defvar-keymap corfu-popupinfo-map
- :doc "Additional keymap activated in popupinfo mode."
+ :doc "Additional keymap activated by `corfu-popupinfo-mode'."
"M-t" #'corfu-popupinfo-toggle
"<remap> <corfu-info-documentation>" #'corfu-popupinfo-documentation
"<remap> <corfu-info-location>" #'corfu-popupinfo-location