From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Alan Third Newsgroups: gmane.emacs.bugs Subject: bug#17899: 24.3.92.1; dabbrev-completion incorrectly searches all buffers Date: Thu, 05 Dec 2019 13:19:13 +0000 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="9967"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (darwin) Cc: 17899@debbugs.gnu.org To: Stefan Guath Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Dec 05 14:48:01 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1icrU8-0002RZ-N8 for geb-bug-gnu-emacs@m.gmane.org; Thu, 05 Dec 2019 14:48:00 +0100 Original-Received: from localhost ([::1]:54350 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1icrU5-0008BU-9w for geb-bug-gnu-emacs@m.gmane.org; Thu, 05 Dec 2019 08:47:59 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:56627) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1icrSH-0006qW-1g for bug-gnu-emacs@gnu.org; Thu, 05 Dec 2019 08:46:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1icrSF-00081j-E1 for bug-gnu-emacs@gnu.org; Thu, 05 Dec 2019 08:46:04 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:37343) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1icrSF-0007wY-4Y for bug-gnu-emacs@gnu.org; Thu, 05 Dec 2019 08:46:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1icr33-0006HF-SB for bug-gnu-emacs@gnu.org; Thu, 05 Dec 2019 08:20:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Alan Third Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 05 Dec 2019 13:20:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 17899 X-GNU-PR-Package: emacs Original-Received: via spool by 17899-submit@debbugs.gnu.org id=B17899.157555196624084 (code B ref 17899); Thu, 05 Dec 2019 13:20:01 +0000 Original-Received: (at 17899) by debbugs.gnu.org; 5 Dec 2019 13:19:26 +0000 Original-Received: from localhost ([127.0.0.1]:43301 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1icr2U-0006GO-8b for submit@debbugs.gnu.org; Thu, 05 Dec 2019 08:19:26 -0500 Original-Received: from mail-wr1-f51.google.com ([209.85.221.51]:36795) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1icr2R-0006GB-QJ for 17899@debbugs.gnu.org; Thu, 05 Dec 2019 08:19:25 -0500 Original-Received: by mail-wr1-f51.google.com with SMTP id z3so3576418wru.3 for <17899@debbugs.gnu.org>; Thu, 05 Dec 2019 05:19:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=sender:from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=noHB3tHsVHQCfGnchHqsrfiu2bzaP6guuIDXmZyfvjM=; b=jvPsxOqY2WzonoNYrfddbeKF3ifpe08K84/t9L6NCeMncSyp35f6+3r8apwgBYseMw Hwz0T4C6M+M81LhRZuGaifeEKRyRWkubJlTU6fCkltnr7yAULTLjBH8TNlRf6ogbtuzj IzBYyCNgCyf0FohXjYQJrjyk0cnTwDk/wlrS0rpcQNgEeGmxb5heQPREPZjtSd21ux3x rFW84IABCnZSJmxL6B6FK/YFJxlp8hsckQ1/dKakG9iTqsbuN0Ds7s9yUCAbvjK0gQgE XUCmYuSDEJiNdCsHSBmw/vMKkFDm6KaMXEVyiOEDTXmJh11BHz8Oza+q7eUkULv1Z3mU YRIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:references:date :in-reply-to:message-id:user-agent:mime-version; bh=noHB3tHsVHQCfGnchHqsrfiu2bzaP6guuIDXmZyfvjM=; b=PVMxfGf8100ouG87zHMt0ah2jaoPdFjFY5AtFeIiBFWCXFlvg8y27VOOUMQBxF892U uX0tmQpesuWBraIJs1eHP+HV8l7gxZNNxU4M8UJzsv+45vLHeUWcaDEsC6t5jNjJ4h5Y ToIK8E6QcW767M6OAuEY7hhrml4s4Dw+lIdYxb45/W5XmLSilYo41isSnzU3D0T05A1k bRsY1cw++p7zpTTyOGyvF6xaWnbyFjwUkVUp131qm2rsZ5JwZ7aXjF4/kgSySsjIlBRp kIH+kxdT0JO4krtG0O+OpVRS8FJzFQrP634bee4gK2gsfwzKlPryI6AxR0hLPdg7u6H2 6Mbg== X-Gm-Message-State: APjAAAWN1S1Vdi8ohanvx3Gl7FfD2sHf/GfOyGLtjbhHXZDfU4sk21QL ccqjTgVUC44pCeAc27hVhtuTsgESkvo= X-Google-Smtp-Source: APXvYqzm/d9zyL7BqOLX7YRpIyJFdhshFx3ePg3vzEPiJxZs7l3iNx8CAIuzHaRMzqU/w+dU2z5PLw== X-Received: by 2002:a5d:4692:: with SMTP id u18mr10443627wrq.206.1575551956614; Thu, 05 Dec 2019 05:19:16 -0800 (PST) Original-Received: from breton.holly.idiocy.org (ip6-2001-08b0-03f8-8129-8586-a56f-eccc-754e.holly.idiocy.org. [2001:8b0:3f8:8129:8586:a56f:eccc:754e]) by smtp.gmail.com with ESMTPSA id y10sm1779443wmm.3.2019.12.05.05.19.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Dec 2019 05:19:14 -0800 (PST) In-Reply-To: (Stefan Guath's message of "Wed, 2 Jul 2014 15:54:43 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:172901 Archived-At: --=-=-= Content-Type: text/plain Stefan Guath writes: > TO REPRODUCE BUG: > * emacs -Q > * Create two buffers (C-x b) with the following contents: > foo.el: "idris0 idris1" > bar.el: "ideal0 ideal1" > * Go to end of foo.el, write "id" and execute dabbrev-completion (C-M-/) > > EXPECTED RESULT > "id" should complete to "idris". Hi, sorry it took so long for someone to look at this. I believe the attached patch fixes it. The problem seems to have been switching dabbrev.el over to using lexical scoping. It was previously using let* to temporarily override a couple of global variables, which works with dynamic scoping, but not lexical. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Fix-dabbrev-completion-bug-17899.patch >From 40946b12d9583e87b89a3c942ed418990cc35355 Mon Sep 17 00:00:00 2001 From: Alan Third Date: Thu, 5 Dec 2019 13:14:00 +0000 Subject: [PATCH] Fix dabbrev-completion (bug#17899) * lisp/dabbrev.el (dabbrev--check-all-buffers): Add new variable. (dabbrev-completion): Lexical scoping means we can't use let to override global variables, so use setq. (dabbrev--reset-global-variables): Reset new variable. (dabbrev--make-friend-buffer-list): Use new variable. * test/lisp/dabbrev-tests.el (dabbrev-completion-test): (dabbrev-completion-test-with-argument): New tests. --- lisp/dabbrev.el | 16 ++++++++++------ test/lisp/dabbrev-tests.el | 30 ++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/lisp/dabbrev.el b/lisp/dabbrev.el index 23abe7ae16..0cb9b0b824 100644 --- a/lisp/dabbrev.el +++ b/lisp/dabbrev.el @@ -323,6 +323,9 @@ dabbrev--last-case-pattern ;; Same as dabbrev-check-other-buffers, but is set for every expand. (defvar dabbrev--check-other-buffers dabbrev-check-other-buffers) +;; Same as dabbrev-check-all-buffers, but is set for every expand. +(defvar dabbrev--check-all-buffers dabbrev-check-all-buffers) + ;; The regexp for recognizing a character in an abbreviation. (defvar dabbrev--abbrev-char-regexp nil) @@ -380,10 +383,7 @@ dabbrev-completion then it searches *all* buffers." (interactive "*P") (dabbrev--reset-global-variables) - (let* ((dabbrev-check-other-buffers (and arg t)) - (dabbrev-check-all-buffers - (and arg (= (prefix-numeric-value arg) 16))) - (abbrev (dabbrev--abbrev-at-point)) + (let* ((abbrev (dabbrev--abbrev-at-point)) (beg (progn (search-backward abbrev) (point))) (end (progn (search-forward abbrev) (point))) (ignore-case-p (dabbrev--ignore-case-p abbrev)) @@ -420,6 +420,9 @@ dabbrev-completion (t (mapcar #'downcase completion-list))))))) (complete-with-action a list s p))))) + (setq dabbrev--check-other-buffers (and arg t)) + (setq dabbrev--check-all-buffers + (and arg (= (prefix-numeric-value arg) 16))) (completion-in-region beg end table))) ;;;###autoload @@ -623,7 +626,8 @@ dabbrev--reset-global-variables dabbrev--last-buffer-found nil dabbrev--abbrev-char-regexp (or dabbrev-abbrev-char-regexp "\\sw\\|\\s_") - dabbrev--check-other-buffers dabbrev-check-other-buffers)) + dabbrev--check-other-buffers dabbrev-check-other-buffers + dabbrev--check-all-buffers dabbrev-check-all-buffers)) (defun dabbrev--select-buffers () "Return a list of other buffers to search for a possible abbrev. @@ -772,7 +776,7 @@ dabbrev--make-friend-buffer-list ;; If dabbrev-check-all-buffers, tack on all the other ;; buffers at the end of the list, except those which are ;; specifically to be ignored. - (if dabbrev-check-all-buffers + (if dabbrev--check-all-buffers (setq list (append list (dabbrev-filter-elements diff --git a/test/lisp/dabbrev-tests.el b/test/lisp/dabbrev-tests.el index a6ab2e7201..d26362db3d 100644 --- a/test/lisp/dabbrev-tests.el +++ b/test/lisp/dabbrev-tests.el @@ -40,3 +40,33 @@ dabbrev-expand-test ;; M-/ SPC M-/ M-/ (execute-kbd-macro "\257 \257\257")) (should (string= (buffer-string) "ab x\nab y\nab y")))) + +(ert-deftest dabbrev-completion-test () + "Test for bug#17899. +dabbrev-completion should not look for expansions in other +buffers unless a prefix argument is used." + (with-temp-buffer + (insert "axy") + (with-temp-buffer + (insert "abc\na") + (goto-char 6) + (save-window-excursion + (set-window-buffer nil (current-buffer)) + ;; C-M-/ + (execute-kbd-macro [201326639])) + (should (string= (buffer-string) "abc\nabc"))))) + +(ert-deftest dabbrev-completion-test-with-argument () + "Test for bug#17899. +dabbrev-completion should not complete because it has found +multiple expansions." + (with-temp-buffer + (insert "axy") + (with-temp-buffer + (insert "abc\na") + (goto-char 6) + (save-window-excursion + (set-window-buffer nil (current-buffer)) + ;; C-u C-u C-M-/ + (execute-kbd-macro [21 21 201326639])) + (should (string= (buffer-string) "abc\na"))))) -- 2.21.0 --=-=-= Content-Type: text/plain -- Alan Third --=-=-=--