From debbugs-submit-bounces@debbugs.gnu.org Mon Apr 19 18:30:17 2021 Received: (at submit) by debbugs.gnu.org; 19 Apr 2021 22:30:17 +0000 Received: from localhost ([127.0.0.1]:52301 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lYcPI-0001Ow-Rm for submit@debbugs.gnu.org; Mon, 19 Apr 2021 18:30:17 -0400 Received: from lists.gnu.org ([209.51.188.17]:58560) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lYcPE-0001Oi-QA for submit@debbugs.gnu.org; Mon, 19 Apr 2021 18:30:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:32838) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lYcPD-0008HI-7Q for bug-gnu-emacs@gnu.org; Mon, 19 Apr 2021 18:30:11 -0400 Received: from mout01.posteo.de ([185.67.36.65]:47169) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lYcPA-00087o-Ob for bug-gnu-emacs@gnu.org; Mon, 19 Apr 2021 18:30:10 -0400 Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id 426AD240026 for ; Tue, 20 Apr 2021 00:30:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1618871405; bh=G28djn23kYSFiGGw6MaQef4xx55z5iFWY+ygtfeb15k=; h=From:To:Subject:Date:From; b=gj5hLbi/VGQU4N7ysBpg02QrnoCfU9LwGbAUNXg5Js5FqjVa/+l9e9rSh5v5rWJC+ rMIJcARIpV4m7at3ncGwMItt60tvD9OUmP/O6N1RNf46U37CWbQCqjCKXeT8FDrMsj oX8otgK4Z5ezozH/bdmeZC7LoJXhTQppkaNMaXYZNhAGBsREHgnpr+9HNlxEU37j4U oUrelyqkWUYi7rxVAewuj8IelVxLTm7OQvoaM99anwGxCaxw3lx9HGVLCmS3ZqMu0A ZpdrM5P+qbKC0cDwf7z2Ti5DeN/E3xFsGgc8M+9sYa05KeDrDCG49wyXwDYN4H+6k5 WYmywCMAYf1BA== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4FPM2N5RdNz9rxN for ; Tue, 20 Apr 2021 00:30:04 +0200 (CEST) From: haj@posteo.de (Harald =?utf-8?Q?J=C3=B6rg?=) To: bug-gnu-emacs@gnu.org Subject: cperl-mode: unwanted expansion of '$continue' [PATCH] Date: Mon, 19 Apr 2021 22:30:04 +0000 Message-ID: <87a6ptgb6b.fsf@hajtower> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=185.67.36.65; envelope-from=haj@posteo.de; helo=mout01.posteo.de X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) --=-=-= Content-Type: text/plain The symptom: When typing "$continue", abbrev expansion kicks in and converts this to "$continue { }" - which immediately catches the eye as suddenly it is formatted as a hash access. How to reproduce from Emacs -Q: C-x b demo.pl M-: (setq cperl-electric-keywords t) cperl-mode $continue = 1; It is quite usual to activate 'cperl-electric-keywords', either directly or with the catch-all customization value 'cperl-hairy'. Root cause: The expansion routine in 'cperl-electric-else' attempts to verify that the keyword starts a statement, by jumping back over the keyword with (backward-sexp 1). For a scalar variable "$else" or "$continue", this expression also skips back over the dollar (which has syntax type "escape" in CPerl mode), and "$continue" does start a statement, so unwanted expansion happens. The patch replaces (backward-sexp 1) by (skip-chars-backward "[:alpha:]") and avoids skipping over anything which doesn't belong to the keyword. -- Cheers, haj --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-cperl-mode-Avoid-abbrev-expansion-in-variable-names.patch Content-Description: Avoid expansion of "$continue" >From 753c185393b399059d348a6277b46c2203c47886 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Harald=20J=C3=B6rg?= Date: Tue, 20 Apr 2021 00:25:39 +0200 Subject: [PATCH] ; cperl-mode: Avoid abbrev expansion in variable names * lisp/progmodes/cperl-mode.el (cperl-electric-else): don't expand keywords which are scalar variables like '$continue'. * test/lisp/progmodes/cperl-mode-tests.el (cperl-test-hyperactive-electric-else): Verify that keywords are expanded but variable names aren't. --- lisp/progmodes/cperl-mode.el | 2 +- test/lisp/progmodes/cperl-mode-tests.el | 28 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lisp/progmodes/cperl-mode.el b/lisp/progmodes/cperl-mode.el index 7878e91096..bff3e60e90 100644 --- a/lisp/progmodes/cperl-mode.el +++ b/lisp/progmodes/cperl-mode.el @@ -2224,7 +2224,7 @@ cperl-electric-else to nil." (let ((beg (point-at-bol))) (and (save-excursion - (backward-sexp 1) + (skip-chars-backward "[:alpha:]") (cperl-after-expr-p nil "{;:")) (save-excursion (not diff --git a/test/lisp/progmodes/cperl-mode-tests.el b/test/lisp/progmodes/cperl-mode-tests.el index 14bc48b92f..1a13aec36a 100644 --- a/test/lisp/progmodes/cperl-mode-tests.el +++ b/test/lisp/progmodes/cperl-mode-tests.el @@ -495,4 +495,32 @@ cperl-test-bug-47112 'font-lock-constant-face font-lock-string-face)))))) +(ert-deftest cperl-test-hyperactive-electric-else () + "Demonstrate cperl-electric-else behavior. +If `cperl-electric-keywords' is true, keywords like \"else\" and +\"continue\" are expanded by a following empty block, with the +cursor in the appropriate position to write that block. This, +however, must not happen when the keyword occurs in a variable +\"$else\" or \"$continue\"." + (skip-unless (eq cperl-test-mode #'cperl-mode)) + ;; `self-insert-command' takes a second argument only since Emacs 27 + (skip-unless (not (< emacs-major-version 27))) + (with-temp-buffer + (setq cperl-electric-keywords t) + (cperl-mode) + (insert "continue") + (self-insert-command 1 ?\ ) + (indent-region (point-min) (point-max)) + (goto-char (point-min)) + ;; cperl-mode creates a block here + (should (search-forward-regexp "continue {\n[[:blank:]]+\n}"))) + (with-temp-buffer + (setq cperl-electric-keywords t) + (cperl-mode) + (insert "$continue") + (self-insert-command 1 ?\ ) + (indent-region (point-min) (point-max)) + (goto-char (point-min)) + ;; No block should have been created here + (should-not (search-forward-regexp "{" nil t)))) ;;; cperl-mode-tests.el ends here -- 2.20.1 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Tue Apr 20 16:56:51 2021 Received: (at 47902) by debbugs.gnu.org; 20 Apr 2021 20:56:51 +0000 Received: from localhost ([127.0.0.1]:56182 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lYxQQ-0002Kk-PT for submit@debbugs.gnu.org; Tue, 20 Apr 2021 16:56:51 -0400 Received: from mail-pf1-f171.google.com ([209.85.210.171]:46736) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lYxQO-0002KO-6l for 47902@debbugs.gnu.org; Tue, 20 Apr 2021 16:56:49 -0400 Received: by mail-pf1-f171.google.com with SMTP id d124so26478013pfa.13 for <47902@debbugs.gnu.org>; Tue, 20 Apr 2021 13:56:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:in-reply-to:references:user-agent :mime-version:date:message-id:subject:to:cc :content-transfer-encoding; bh=O2pFRo1z9CnwtDfQjK6tG7NoP6TQ70zCG5aotTRHMeM=; b=U3a4KRoUavPF7oyefmQILiLcvalBhtuoqeVMQ3wQPU8KTmZfXtDP3vGZMpS1iB7b1h 9HBV8lBzPidwF0QU0GqjlNjLxDuE+X31d7MSqdpQLKxOj3dY7iBFng7TqDok7iKWmsqB EEAXR9u12wsKMh/qm9yANJTeDpowE4Hy1G/XXwJyrPk8ln4f4zXxjEhQB7/4nnKhqEFF 4CxqBJwrge7Niw7dWfj0NoSsKWrdntTtEJ9X/YpdFnOinPC25l+Ppdrz1UwkUHdo4Jyl 0qh1/qC+zz3hVVBsvWFEpEqDhKaXESQJcCH1x+GY1q15CwGRxYcxWrTWfHpO2UEywJsk qNZQ== X-Gm-Message-State: AOAM533G4Sd7ObLiNB3vgAu9v0U5EPmnZedaQ5w7XSpn74RnaqKwKkNn ZVfHnbQQv+A82ikMpvTSjbx0T2K1fceZb6EJD7w= X-Google-Smtp-Source: ABdhPJxdbP4uU1n3o8V0j9i6MjDVtu4KpDs1WteS0Pm3CAbhY1KXgOqyaLJ6euHvtDycziGHUcELOHO+VlQbnlMOcqs= X-Received: by 2002:a63:942:: with SMTP id 63mr19230739pgj.67.1618952202285; Tue, 20 Apr 2021 13:56:42 -0700 (PDT) Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Tue, 20 Apr 2021 15:56:41 -0500 From: Stefan Kangas In-Reply-To: =?UTF-8?B?PDg3YTZwdGdiNmIuZnNmQGhhanRvd2VyPiAoIkhhcmFsZCBKw7ZyZyIncyBtZXNz?= =?UTF-8?B?YWdlIG9mICJNb24sIDE5IEFwciAyMDIxIDIyOjMwOjA0ICswMDAwIik=?= References: <87a6ptgb6b.fsf@hajtower> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) MIME-Version: 1.0 Date: Tue, 20 Apr 2021 15:56:41 -0500 Message-ID: Subject: Re: bug#47902: cperl-mode: unwanted expansion of '$continue' [PATCH] To: =?UTF-8?B?SGFyYWxkIErDtnJn?= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Score: 0.5 (/) X-Debbugs-Envelope-To: 47902 Cc: 47902@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.5 (/) tags 47902 fixed close 47902 28.1 thanks haj@posteo.de (Harald J=C3=B6rg) writes: > The symptom: When typing "$continue", abbrev expansion kicks in and > converts this to "$continue { }" - which immediately catches the eye as > suddenly it is formatted as a hash access. > > How to reproduce from Emacs -Q: > > C-x b demo.pl > M-: (setq cperl-electric-keywords t) > cperl-mode > $continue =3D 1; > > It is quite usual to activate 'cperl-electric-keywords', either directly > or with the catch-all customization value 'cperl-hairy'. > > Root cause: The expansion routine in 'cperl-electric-else' attempts to > verify that the keyword starts a statement, by jumping back over the > keyword with (backward-sexp 1). For a scalar variable "$else" or > "$continue", this expression also skips back over the dollar (which has > syntax type "escape" in CPerl mode), and "$continue" does start a > statement, so unwanted expansion happens. > > The patch replaces (backward-sexp 1) by (skip-chars-backward "[:alpha:]") > and avoids skipping over anything which doesn't belong to the keyword. Thanks! This makes sense and works fine here so I've pushed this to master as commit c4c9a60c13. I've made some minor adjustment of the commit message and added the bug number. I also added a blank line before the "ends here" line as a minor stylistic point. From unknown Sat Jun 14 03:54:10 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Wed, 19 May 2021 11:24:04 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator