From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: haj@posteo.de (Harald =?UTF-8?Q?J=C3=B6rg?=) Newsgroups: gmane.emacs.bugs Subject: bug#47902: 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="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="17422"; mail-complaints-to="usenet@ciao.gmane.io" To: 47902@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Apr 20 00:31:13 2021 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 1lYcQB-0004Qz-Mx for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 20 Apr 2021 00:31:11 +0200 Original-Received: from localhost ([::1]:57108 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lYcQA-0008So-Ge for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 19 Apr 2021 18:31:10 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:33062) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lYcQ2-0008Se-A7 for bug-gnu-emacs@gnu.org; Mon, 19 Apr 2021 18:31:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:40755) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lYcQ2-0000B7-1y for bug-gnu-emacs@gnu.org; Mon, 19 Apr 2021 18:31:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lYcQ1-0001Pv-U5 for bug-gnu-emacs@gnu.org; Mon, 19 Apr 2021 18:31:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: haj@posteo.de (Harald =?UTF-8?Q?J=C3=B6rg?=) Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 19 Apr 2021 22:31:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 47902 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.16188714175394 (code B ref -1); Mon, 19 Apr 2021 22:31:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 19 Apr 2021 22:30:17 +0000 Original-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 Original-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 Original-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 Original-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 Original-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== Original-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) 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-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" Xref: news.gmane.io gmane.emacs.bugs:204517 Archived-At: --=-=-= 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 --=-=-=--