From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#36516: Wrong dynamic abbrev expansion after space Date: Sun, 28 Jul 2019 23:47:53 +0300 Organization: LINKOV.NET Message-ID: <87k1c2qazy.fsf@mail.linkov.net> References: <8736jks4wg.fsf@mail.linkov.net> <83imsg9tfk.fsf@gnu.org> <87zhlp33kh.fsf@mail.linkov.net> <83k1ct6yrl.fsf@gnu.org> <87o9241a6n.fsf@mail.linkov.net> <20190727171831.GB81205@breton.holly.idiocy.org> 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="241027"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (x86_64-pc-linux-gnu) Cc: 36516@debbugs.gnu.org To: Alan Third Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Jul 28 23:24:21 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 1hrqeR-0010ZI-7r for geb-bug-gnu-emacs@m.gmane.org; Sun, 28 Jul 2019 23:24:20 +0200 Original-Received: from localhost ([::1]:46884 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hrqeQ-0004fz-5E for geb-bug-gnu-emacs@m.gmane.org; Sun, 28 Jul 2019 17:24:18 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:36983) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hrqeC-0004SS-Hn for bug-gnu-emacs@gnu.org; Sun, 28 Jul 2019 17:24:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hrqeB-0003EC-57 for bug-gnu-emacs@gnu.org; Sun, 28 Jul 2019 17:24:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:38436) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hrqeB-0003E7-1Q for bug-gnu-emacs@gnu.org; Sun, 28 Jul 2019 17:24:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hrqeA-0006q8-Sx for bug-gnu-emacs@gnu.org; Sun, 28 Jul 2019 17:24:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 28 Jul 2019 21:24:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 36516 X-GNU-PR-Package: emacs Original-Received: via spool by 36516-submit@debbugs.gnu.org id=B36516.156434903226265 (code B ref 36516); Sun, 28 Jul 2019 21:24:02 +0000 Original-Received: (at 36516) by debbugs.gnu.org; 28 Jul 2019 21:23:52 +0000 Original-Received: from localhost ([127.0.0.1]:47256 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hrqdz-0006pY-Sx for submit@debbugs.gnu.org; Sun, 28 Jul 2019 17:23:52 -0400 Original-Received: from brown.elm.relay.mailchannels.net ([23.83.212.23]:29462) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hrqdx-0006pO-Ne for 36516@debbugs.gnu.org; Sun, 28 Jul 2019 17:23:50 -0400 X-Sender-Id: dreamhost|x-authsender|jurta@jurta.org Original-Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id AD33C21692; Sun, 28 Jul 2019 21:23:48 +0000 (UTC) Original-Received: from pdx1-sub0-mail-a90.g.dreamhost.com (100-96-15-27.trex.outbound.svc.cluster.local [100.96.15.27]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 3A4AC212FB; Sun, 28 Jul 2019 21:23:48 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|jurta@jurta.org Original-Received: from pdx1-sub0-mail-a90.g.dreamhost.com ([TEMPUNAVAIL]. [64.90.62.162]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384) by 0.0.0.0:2500 (trex/5.17.3); Sun, 28 Jul 2019 21:23:48 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|jurta@jurta.org X-MailChannels-Auth-Id: dreamhost X-Skirt-Zesty: 7fdc71dc29370b17_1564349028536_2782874952 X-MC-Loop-Signature: 1564349028536:2912931654 X-MC-Ingress-Time: 1564349028535 Original-Received: from pdx1-sub0-mail-a90.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a90.g.dreamhost.com (Postfix) with ESMTP id 330DE7FD00; Sun, 28 Jul 2019 14:23:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=linkov.net; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=linkov.net; bh=d97U71A55edx7+Er9RL+R0IJJQU=; b= pmMzdgTFq5y4nY7WDH5a7/MnpGUWWhycX25qt92QI/lUzoeYI/o4h0z4q0dOvVZf YYaSoAlO53I2ctrlGj5cC+G6F5hivDUDLUEDNxCk7mcdqGAZvp4YigNZUnIvO7un rtzQvJpZ3hTdFqyswfkkdC+q1Oue4XzwOv/QxzGCOko= Original-Received: from mail.jurta.org (m91-129-103-76.cust.tele2.ee [91.129.103.76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: jurta@jurta.org) by pdx1-sub0-mail-a90.g.dreamhost.com (Postfix) with ESMTPSA id 973AE7FCF0; Sun, 28 Jul 2019 14:23:40 -0700 (PDT) X-DH-BACKEND: pdx1-sub0-mail-a90 In-Reply-To: <20190727171831.GB81205@breton.holly.idiocy.org> (Alan Third's message of "Sat, 27 Jul 2019 18:18:31 +0100") X-VR-OUT-STATUS: OK X-VR-OUT-SCORE: -100 X-VR-OUT-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeduvddrkeelgdduieefucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuggftfghnshhusghstghrihgsvgdpffftgfetoffjqffuvfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvufhofhffjgfkfgggtgesmhdtreertderjeenucfhrhhomheplfhurhhiucfnihhnkhhovhcuoehjuhhriheslhhinhhkohhvrdhnvghtqeenucfkphepledurdduvdelrddutdefrdejieenucfrrghrrghmpehmohguvgepshhmthhppdhhvghlohepmhgrihhlrdhjuhhrthgrrdhorhhgpdhinhgvthepledurdduvdelrddutdefrdejiedprhgvthhurhhnqdhprghthheplfhurhhiucfnihhnkhhovhcuoehjuhhriheslhhinhhkohhvrdhnvghtqedpmhgrihhlfhhrohhmpehjuhhriheslhhinhhkohhvrdhnvghtpdhnrhgtphhtthhopegrlhgrnhesihguihhotgihrdhorhhgnecuvehluhhsthgvrhfuihiivgeptd 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:163992 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable >> 0. emacs -Q >> 1. Type these two lines: >> str 1 >> str 2 >> 2. On the third line type: >> s ;; self-insert-command >> M-/ ;; dabbrev-expand >> SPC ;; self-insert-command >> C-M-/ ;; dabbrev-completion >> >> This correctly displays all available completions >> =E2=80=9Cstr 1=E2=80=9D and =E2=80=9Cstr 2=E2=80=9D. But =E2=80=98s M= -/ SPC M-/ M-/=E2=80=99 doesn't get >> the second completion. > > =E2=80=99s M-/ SPC M-/=E2=80=99 doesn=E2=80=99t do a normal completion,= it does this (from=20 > the manual): > > After you have expanded a dynamic abbrev, you can copy additional > words that follow the expansion in its original context. Simply typ= e > M-/ for each additional word you want to copy. The spacing an= d > punctuation between words is copied along with the words. Oh, this special-casing unfortunately breaks the natural workflow. > I suppose that subsequent M-/=E2=80=99s are undocumented, but the curre= nt > behaviour is, IMO, definitely confusing as it seems to search other > buffers for completions even though there are valid completions in the > current buffer. Maybe it's possible to break out of the vicious cycle of =E2=80=98SPC M-/= =E2=80=99 repetitions by making =E2=80=98SPC M-/=E2=80=99 look like a normal expans= ion, e.g.: --=-=-= Content-Type: text/x-diff; charset=utf-8 Content-Disposition: inline; filename=dabbrev.patch Content-Transfer-Encoding: quoted-printable diff --git a/test/lisp/dabbrev-tests.el b/test/lisp/dabbrev-tests.el index a6ab2e7201..39fd37db1d 100644 --- a/test/lisp/dabbrev-tests.el +++ b/test/lisp/dabbrev-tests.el @@ -40,3 +40,27 @@ ;; M-/ SPC M-/ M-/ (execute-kbd-macro "\257 \257\257")) (should (string=3D (buffer-string) "ab x\nab y\nab y")))) + +(ert-deftest dabbrev-with-space-word () + "Test for bug#36516. +Check that the =E2=80=98 M-/=E2=80=99 feature still works as docume= nted +in `(emacs) Dynamic Abbrevs'." + (with-temp-buffer + (insert "sub a b\nstr a c\ns") + (save-window-excursion + (set-window-buffer nil (current-buffer)) + ;; M-/ M-/ SPC M-/ SPC M-/ + (execute-kbd-macro "\257\257 \257 \257")) + (should (string=3D (buffer-string) "sub a b\nstr a c\nsub a b")))) + +(ert-deftest dabbrev-without-space-word () + "Test for bug#36516. +Check that =E2=80=98 M-/ M-/=E2=80=99 doesn't conflict with the =E2= =80=98 M-/=E2=80=99 feature +documented in `(emacs) Dynamic Abbrevs'." + (with-temp-buffer + (insert "str 1\nstr 2\ns") + (save-window-excursion + (set-window-buffer nil (current-buffer)) + ;; M-/ SPC M-/ M-/ + (execute-kbd-macro "\257 \257\257")) + (should (string=3D (buffer-string) "str 1\nstr 2\nstr 1")))) diff --git a/lisp/dabbrev.el b/lisp/dabbrev.el index 23abe7ae16..ffb1b7d819 100644 --- a/lisp/dabbrev.el +++ b/lisp/dabbrev.el @@ -472,43 +472,35 @@ dabbrev-expand (markerp dabbrev--last-abbrev-location) (marker-position dabbrev--last-abbrev-location) (=3D (point) (1+ dabbrev--last-abbrev-location))) - (progn - ;; The "abbrev" to expand is just the space. - (setq abbrev " ") - (save-excursion - (save-restriction - (widen) - (if dabbrev--last-buffer - (set-buffer dabbrev--last-buffer)) - ;; Find the end of the last "expansion" word. - (if (or (eq dabbrev--last-direction 1) - (and (eq dabbrev--last-direction 0) - (< dabbrev--last-expansion-location (point)))) - (setq dabbrev--last-expansion-location - (+ dabbrev--last-expansion-location - (length dabbrev--last-expansion)))) - (goto-char dabbrev--last-expansion-location) - ;; Take the following word, with intermediate separators, - ;; as our expansion this time. - (re-search-forward - (concat "\\(?:" dabbrev--abbrev-char-regexp "\\)+")) - (setq expansion (buffer-substring-no-properties - dabbrev--last-expansion-location (point))) - - ;; Record the end of this expansion, in case we repeat this. - (setq dabbrev--last-expansion-location (point)))) - ;; Indicate that dabbrev--last-expansion-location is - ;; at the end of the expansion. - (setq dabbrev--last-direction -1)) + (save-excursion + (save-restriction + (widen) + (if dabbrev--last-buffer + (set-buffer dabbrev--last-buffer)) + ;; Find the end of the last "expansion" word. + (if (or (eq dabbrev--last-direction 1) + (and (eq dabbrev--last-direction 0) + (< dabbrev--last-expansion-location (point)))) + (setq dabbrev--last-expansion-location + (+ dabbrev--last-expansion-location + (length dabbrev--last-expansion)))) + (goto-char dabbrev--last-expansion-location) + ;; Take the following word, with intermediate separators, + ;; as our expansion this time. + (re-search-forward + (concat "\\(?:" dabbrev--abbrev-char-regexp "\\)+")) =20 + ;; Record the end of this expansion, in case we repeat this. + (setq dabbrev--last-expansion-location (point)))) ;; We have a different abbrev to expand. - (dabbrev--reset-global-variables) - (setq direction (if (null arg) - (if dabbrev-backward-only 1 0) - (prefix-numeric-value arg))) - (setq abbrev (dabbrev--abbrev-at-point)) - (setq record-case-pattern t) - (setq old nil))) + (dabbrev--reset-global-variables)) + + (setq direction (if (null arg) + (if dabbrev-backward-only 1 0) + (prefix-numeric-value arg))) + (setq abbrev (dabbrev--abbrev-at-point)) + (setq record-case-pattern t) + (setq old nil)) =20 ;;-------------------------------- ;; Find the expansion --=-=-=--