From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#73880: Master: emacs-lisp-mode: Tab completion for a function position fails in a `let' form. Date: Sun, 20 Oct 2024 10:54:22 +0000 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25221"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Dmitry Gutov , acm@muc.de To: 73880@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Oct 20 12:55:07 2024 Return-path: 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 ) id 1t2TaU-0006Nl-Dp for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 20 Oct 2024 12:55:06 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t2Ta4-0004eO-60; Sun, 20 Oct 2024 06:54:40 -0400 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 ) id 1t2Ta2-0004eD-8h for bug-gnu-emacs@gnu.org; Sun, 20 Oct 2024 06:54:38 -0400 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 ) id 1t2Ta1-0006Lt-SM for bug-gnu-emacs@gnu.org; Sun, 20 Oct 2024 06:54:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=From:In-Reply-To:MIME-Version:References:Date:To:Subject; bh=pwxDw8sUu8XoPppPJrLdM8EjqvkpVQa2JoEHuDqjKEE=; b=mS9kXXp58vxlYqSyhHBCi+hPzgc3AyQERrJ0VDRZkI6yTudZx1WXSu+p9GH3k22HZcodldfMKypR39u7c/bqJ/5ujVmnaEbclb+hYLirtfABHOjjbi3yfxrCxv+g5rbKw253d8+WbrQyQZxRzekBJmZ9jB/5hGnEILIXzKzdoCVG25UgusmCXSO+RQXENBzt1MSpSnq5P2bmK/smf+RucQzPqaKd4n0j/k89ZEiR+PnDYUsFn6QlOGGUY2eCPg5Md5IDEb3AiInaHyXkN04VCKy4I5BRhF4+7jCLhzzigO8ClM8WKGQvB1wPVFp25eJwbI57CoQ0kijLRMsupsGYVw==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1t2TaQ-0000Qy-JC for bug-gnu-emacs@gnu.org; Sun, 20 Oct 2024 06:55:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 20 Oct 2024 10:55:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 73880 X-GNU-PR-Package: emacs Original-Received: via spool by 73880-submit@debbugs.gnu.org id=B73880.17294216971650 (code B ref 73880); Sun, 20 Oct 2024 10:55:02 +0000 Original-Received: (at 73880) by debbugs.gnu.org; 20 Oct 2024 10:54:57 +0000 Original-Received: from localhost ([127.0.0.1]:45988 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t2TaK-0000QY-Tk for submit@debbugs.gnu.org; Sun, 20 Oct 2024 06:54:57 -0400 Original-Received: from mail.muc.de ([193.149.48.3]:21038) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t2TaI-0000QE-Mu for 73880@debbugs.gnu.org; Sun, 20 Oct 2024 06:54:55 -0400 Original-Received: (qmail 34942 invoked by uid 3782); 20 Oct 2024 12:54:22 +0200 Original-Received: from muc.de (pd953a8ba.dip0.t-ipconnect.de [217.83.168.186]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Sun, 20 Oct 2024 12:54:22 +0200 Original-Received: (qmail 29302 invoked by uid 1000); 20 Oct 2024 10:54:22 -0000 Content-Disposition: inline In-Reply-To: X-Submission-Agent: TMDA/1.3.x (Ph3nix) X-Primary-Address: acm@muc.de 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" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-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:293945 Archived-At: Hello, Dmitry and Emacs. On Sat, Oct 19, 2024 at 13:09:00 +0000, Alan Mackenzie wrote: > Hello, Emacs. > In a recent master version, for example this commit: > commit 5340fdaade1f8fe7af08293619cca89ae0796fcf (HEAD -> master, origin/master, origin/HEAD) > Author: Alan Mackenzie > Date: Wed Oct 16 13:17:26 2024 +0000 > CC Mode: Fix dodgy lisp `let' form. > , start emacs -Q, followed by entering the following incomplete form: > (defun foo () > (let ( > ) > (match-b > With point after match-b, type M-TAB. This should complete to > match-beginning or show that function as a completion option. Instead > it signals the error "No match". This is a bug. > It would seem the completion function elisp-completion-at-point thinks > it is completing a variable symbol rather than a function symbol. This is indeed the case. The following patch fixes this by checking that the symbol being completed begins within the binding list. It also adds a test into elisp-mode-tests.el. Dmitry, could you check the patch is OK, please, before I commit it. Thanks! diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el index 2f931daedc7..3233447a996 100644 --- a/lisp/progmodes/elisp-mode.el +++ b/lisp/progmodes/elisp-mode.el @@ -760,7 +760,8 @@ elisp-completion-at-point (forward-sexp) (intern-soft (buffer-substring pt (point)))))))) - (error nil)))) + (error nil))) + (parent-end (point))) (pcase parent ;; FIXME: Rather than hardcode special cases here, ;; we should use something like a symbol-property. @@ -784,18 +785,35 @@ elisp-completion-at-point (list t (elisp--completion-local-symbols) :predicate (lambda (sym) (get sym 'error-conditions)))) - ((and (or ?\( 'let 'let* 'cond 'cond* 'bind*) - (guard (save-excursion - (goto-char (1- beg)) - (when (eq parent ?\() - (up-list -1)) - (forward-symbol -1) - (or - (looking-at - "\\_<\\(let\\*?\\|bind\\*\\)\\_>") - (and (not (eq parent ?\()) + ((or + (and (or 'let 'let*) + (guard (save-excursion + (goto-char parent-end) + (forward-comment (point-max)) + (let ((bindings-end + (condition-case nil + (progn (forward-list) + (point)) + (error (point-max))))) + (and + (< beg bindings-end) + (progn + (goto-char (1- beg)) + (forward-symbol -1) (looking-at - "\\_")))))) + "\\_"))))))) + (and (or ?\( 'cond 'cond* 'bind*) + (guard (save-excursion + (goto-char (1- beg)) + (when (eq parent ?\() + (up-list -1)) + (forward-symbol -1) + (or + (looking-at + "\\_<\\(let\\*?\\|bind\\*\\)\\_>") + (and (not (eq parent ?\()) + (looking-at + "\\_"))))))) (list t (elisp--completion-local-symbols) :predicate #'elisp--shorthand-aware-boundp :company-kind (lambda (_) 'variable) diff --git a/test/lisp/progmodes/elisp-mode-tests.el b/test/lisp/progmodes/elisp-mode-tests.el index 591c32a8271..45714b3e7d9 100644 --- a/test/lisp/progmodes/elisp-mode-tests.el +++ b/test/lisp/progmodes/elisp-mode-tests.el @@ -109,6 +109,14 @@ elisp--test-completions (should (member "backup-inhibited" comps)) (should-not (member "backup-buffer" comps)))))) +(ert-deftest elisp-completes-functions-after-empty-let-bindings () + (with-temp-buffer + (emacs-lisp-mode) + (insert "(let () (ba") + (let ((comps (elisp--test-completions))) + (should (member "backup-buffer" comps)) + (should-not (member "backup-inhibited" comps))))) + (ert-deftest elisp-completes-functions-after-let-bindings-2 () (with-temp-buffer (emacs-lisp-mode) -- Alan Mackenzie (Nuremberg, Germany).