From mboxrd@z Thu Jan  1 00:00:00 1970
Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail
From: Stefan Monnier via "Bug reports for GNU Emacs,
 the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
Newsgroups: gmane.emacs.bugs
Subject: bug#74410: 31.0.50; completion-at-point doesn't work in custom buffers
Date: Sun, 17 Nov 2024 18:15:36 -0500
Message-ID: <jwvplmtjwc8.fsf-monnier+@gnu.org>
Reply-To: Stefan Monnier <monnier@iro.umontreal.ca>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214";
	logging-data="1870"; mail-complaints-to="usenet@ciao.gmane.io"
Cc: monnier@iro.umontreal.ca
To: 74410@debbugs.gnu.org
Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Nov 18 00:17:19 2024
Return-path: <bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org>
Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org
Original-Received: from lists.gnu.org ([209.51.188.17])
	by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
	(Exim 4.92)
	(envelope-from <bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org>)
	id 1tCoW6-0000Lv-Tm
	for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 18 Nov 2024 00:17:19 +0100
Original-Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <bug-gnu-emacs-bounces@gnu.org>)
	id 1tCoVt-0005tq-5p; Sun, 17 Nov 2024 18:17:05 -0500
Original-Received: from eggs.gnu.org ([2001:470:142:3::10])
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <Debian-debbugs@debbugs.gnu.org>)
 id 1tCoVq-0005ta-MZ
 for bug-gnu-emacs@gnu.org; Sun, 17 Nov 2024 18:17:03 -0500
Original-Received: from debbugs.gnu.org ([2001:470:142:5::43])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <Debian-debbugs@debbugs.gnu.org>)
 id 1tCoVq-0005bh-DQ
 for bug-gnu-emacs@gnu.org; Sun, 17 Nov 2024 18:17:02 -0500
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;
 d=debbugs.gnu.org; s=debbugs-gnu-org; 
 h=MIME-Version:Date:From:To:Subject;
 bh=OPCuJtFtmLxBE5DAu/vyVP52jjk31qJWcgEFCIEIaME=; 
 b=uRuH0OnIr4BdUJc8Ax27g4COT+F7Y1InGUGoEfHByN/UEy7cRiP1g+WC9XsbTaJs97TBw7RT/fGzTOVJc4yToaZ8x0cZHUCIIodtTKZhKMmjjbJE43b6CPD4i3yUk0ZZJZRtatoBIs9QPcxi6+K5T12ZTGQBp8+DBemXEfBIu6Sg477WZS/q9YXvUD3CQti4/eXwwVPuWqGbRGLdIPTXISPjhsBS2a45kBhno/W64ezNWpr+yRznEmkbUjKbB3MFSfMnJ01C44bGB72OwNPRZ8pZc5M2oXhlfuitASCwie3IhJvB/mGf8ties11NfX1oWBdaPDW/AbZWntNQOdhLug==;
Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2)
 (envelope-from <Debian-debbugs@debbugs.gnu.org>)
 id 1tCoVq-0004YG-2z; Sun, 17 Nov 2024 18:17:02 -0500
X-Loop: help-debbugs@gnu.org
Resent-From: Stefan Monnier <monnier@iro.umontreal.ca>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: monnier@iro.umontreal.ca, bug-gnu-emacs@gnu.org
Resent-Date: Sun, 17 Nov 2024 23:17:01 +0000
Resent-Message-ID: <handler.74410.B.173188536317396@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: report 74410
X-GNU-PR-Package: emacs
X-Debbugs-Original-To: bug-gnu-emacs@gnu.org
X-Debbugs-Original-Xcc: monnier@iro.umontreal.ca
Original-Received: via spool by submit@debbugs.gnu.org id=B.173188536317396
 (code B ref -1); Sun, 17 Nov 2024 23:17:01 +0000
Original-Received: (at submit) by debbugs.gnu.org; 17 Nov 2024 23:16:03 +0000
Original-Received: from localhost ([127.0.0.1]:59064 helo=debbugs.gnu.org)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
 id 1tCoUs-0004WV-Pd
 for submit@debbugs.gnu.org; Sun, 17 Nov 2024 18:16:03 -0500
Original-Received: from lists.gnu.org ([209.51.188.17]:52280)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <monnier@iro.umontreal.ca>) id 1tCoUo-0004W4-Bi
 for submit@debbugs.gnu.org; Sun, 17 Nov 2024 18:16:00 -0500
Original-Received: from eggs.gnu.org ([2001:470:142:3::10])
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <monnier@iro.umontreal.ca>)
 id 1tCoUZ-0005nz-8S
 for bug-gnu-emacs@gnu.org; Sun, 17 Nov 2024 18:15:44 -0500
Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <monnier@iro.umontreal.ca>)
 id 1tCoUX-0005YR-1v
 for bug-gnu-emacs@gnu.org; Sun, 17 Nov 2024 18:15:43 -0500
Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1])
 by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 48FDC8053B
 for <bug-gnu-emacs@gnu.org>; Sun, 17 Nov 2024 18:15:39 -0500 (EST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca;
 s=mail; t=1731885338;
 bh=L3Wnwuak8KWWGa+SaePJ7/af5vv9d/9phfU/EFyP+ME=;
 h=From:To:Subject:Date:From;
 b=TVh9FILjRN/rdNLT+egU80sD35WipC+259JXnOHj2YS9tE/Q+OYKsACxe2KOzntYo
 IIV7r/4oBqOs2pCkvOmgwJF3TS0t5mXLaZZ1TTDAXbpRkMsNh+1vWPNWIC2r/uSRte
 NignxDgYFJqnwDIy2D1yw8yORvHvbw4rrSZoL00E7wgbKb+1DiyJzdzkhfesudQUrZ
 oLSCVhHoZTtIwQds9ZhyAPoXdNkSH7xax+omBxFDfdoRtVjUgh4q8ie8PRG+LlO/DF
 LK4kftpAklGT1A1kR05TFOz6hqX2rpmm2NywEgCgVNJk4SWCrh3UC+oROAxL4J4lLb
 CKcuceyC01daA==
Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1])
 by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id F03148075E
 for <bug-gnu-emacs@gnu.org>; Sun, 17 Nov 2024 18:15:37 -0500 (EST)
Original-Received: from alfajor (104-195-225-43.cpe.teksavvy.com [104.195.225.43])
 by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id CFCD412024D
 for <bug-gnu-emacs@gnu.org>; Sun, 17 Nov 2024 18:15:37 -0500 (EST)
Received-SPF: pass client-ip=132.204.25.50;
 envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca
X-Spam_score_int: -42
X-Spam_score: -4.3
X-Spam_bar: ----
X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3,
 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, 
 SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
X-BeenThere: bug-gnu-emacs@gnu.org
List-Id: "Bug reports for GNU Emacs,
 the Swiss army knife of text editors" <bug-gnu-emacs.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-gnu-emacs>,
 <mailto:bug-gnu-emacs-request@gnu.org?subject=unsubscribe>
List-Archive: <https://lists.gnu.org/archive/html/bug-gnu-emacs>
List-Post: <mailto:bug-gnu-emacs@gnu.org>
List-Help: <mailto:bug-gnu-emacs-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-gnu-emacs>,
 <mailto:bug-gnu-emacs-request@gnu.org?subject=subscribe>
Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org
Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org
Xref: news.gmane.io gmane.emacs.bugs:295571
Archived-At: <http://permalink.gmane.org/gmane.emacs.bugs/295571>

Package: Emacs
Version: 31.0.50


For example:

    src/emacs -Q --eval '(customize-face `fixed-pitch)'
    ... move point to the font family field ...
    ... delete the "space" from "Monospace" then do:
    M-x completion-at-point RET

This will presumably do nothing at all.
`widget-complete` completes it back to "Monospace" (at least on
`master` where I installed a patch for that).

The problem is that cus-edit doesn't setup
`completion-at-point-functions`.  Instead it sets up a special keymap to
remap M-TAB to `widget-complete` instead of relying on the
global binding.

It works OK for a default config, but it doesn't interact well with
setups that use different keybindings or different completion UIs based
on `completion-at-point-functions`.  E.g. `corfu-mode` partly works but
not fully (e.g. `corfu-auto` doesn't have any effect).

The patch below leaves the key remapping for now, but adds an
appropriate function to `completion-at-point-functions` so that
other UIs such as `completion-at-point` can do their job properly.

Comments/objection?


        Stefan


diff --git a/lisp/cus-edit.el b/lisp/cus-edit.el
index e0668d4ba86..02e0b541f05 100644
--- a/lisp/cus-edit.el
+++ b/lisp/cus-edit.el
@@ -5503,7 +5503,8 @@ Custom-mode
   (make-local-variable 'custom-options)
   (make-local-variable 'custom-local-buffer)
   (custom--initialize-widget-variables)
-  (add-hook 'widget-edit-functions 'custom-state-buffer-message nil t))
+  (add-hook 'completion-at-point-functions #'widget-completions-at-point nil t)
+  (add-hook 'widget-edit-functions #'custom-state-buffer-message nil t))
 
 (defun custom--revert-buffer (_ignore-auto _noconfirm)
   (unless custom--invocation-options
diff --git a/lisp/wid-edit.el b/lisp/wid-edit.el
index 58a36820ac7..1538720adef 100644
--- a/lisp/wid-edit.el
+++ b/lisp/wid-edit.el
@@ -1399,7 +1399,7 @@ widget-complete
   "Complete content of editable field from point.
 When not inside a field, signal an error."
   (interactive)
-  (let ((data (widget-completions-at-point)))
+  (let ((data (widget-completions-at-point 'error)))
     (cond
      ((functionp data) (funcall data))
      ((consp data)
@@ -1414,11 +1414,11 @@ widget-complete
 ;; so it's not really obsolete (yet).
 ;; (make-obsolete 'widget-complete 'completion-at-point "24.1")
 
-(defun widget-completions-at-point ()
+(defun widget-completions-at-point (&optional error)
   (let ((field (widget-field-find (point))))
     (if field
         (widget-apply field :completions-function)
-      (error "Not in an editable field"))))
+      (if error (error "Not in an editable field")))))
 
 ;;; Setting up the buffer.