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#30393: [PATCH] Add a test to verify that the bug is gone (and a fix for Emacs 26) Date: Tue, 03 Nov 2020 14:45:20 +0100 Message-ID: <87r1pak0zz.fsf@hajtower> References: <20180208152552.GL13340@hodi> 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="37270"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) To: 30393@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Nov 03 14:46:34 2020 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 1kZwdu-0009dA-Ir for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 03 Nov 2020 14:46:34 +0100 Original-Received: from localhost ([::1]:43546 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZwdt-0008Ty-Kh for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 03 Nov 2020 08:46:33 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:45386) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZwdP-0008Tf-3U for bug-gnu-emacs@gnu.org; Tue, 03 Nov 2020 08:46:05 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:60527) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kZwdO-0005sI-AX for bug-gnu-emacs@gnu.org; Tue, 03 Nov 2020 08:46:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kZwdO-0001IS-79 for bug-gnu-emacs@gnu.org; Tue, 03 Nov 2020 08:46:02 -0500 X-Loop: help-debbugs@gnu.org In-Reply-To: <20180208152552.GL13340@hodi> 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: Tue, 03 Nov 2020 13:46:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 30393 X-GNU-PR-Package: emacs Original-Received: via spool by 30393-submit@debbugs.gnu.org id=B30393.16044111303271 (code B ref 30393); Tue, 03 Nov 2020 13:46:02 +0000 Original-Received: (at 30393) by debbugs.gnu.org; 3 Nov 2020 13:45:30 +0000 Original-Received: from localhost ([127.0.0.1]:43840 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kZwcr-0000qD-J6 for submit@debbugs.gnu.org; Tue, 03 Nov 2020 08:45:29 -0500 Original-Received: from mout02.posteo.de ([185.67.36.66]:45531) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kZwcq-0000im-26 for 30393@debbugs.gnu.org; Tue, 03 Nov 2020 08:45:29 -0500 Original-Received: from submission (posteo.de [89.146.220.130]) by mout02.posteo.de (Postfix) with ESMTPS id 561DA2400FB for <30393@debbugs.gnu.org>; Tue, 3 Nov 2020 14:45:21 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1604411121; bh=X/NDqFrOl+hKlsQ/0Tx2+DgDLWn+5ZpLYYVytli2VQY=; h=From:To:Subject:Date:From; b=nLVtqdqJtjyZGd1L6zWqHoyF1wHVmgJ/jEKzw9IDUzipyH3ZUiRxT7CwcO7yofZ/X yy3RH/SVBVg0jla/5702PMZi0DHoOT4N9VO/M2MydmKET2D/tm4TC0D+Uqy+J2/WiU EPMwpgPdlMQHjsf66tgdNOp/w26QQYzr10Q+fwW0F+IkhlKgsBPtiWiTkiufkCjm4d 2YpQw+0mR/ObAewm6ujMZ8ctPH+RznMCfmLLyD8yRHDlejpdu5w7vKkZlwi0kgf4BU ltHUtFqpkFWMiJWbRoohE7cfFOtuzTCTLt68vi2eZOvnQKxEHxGAxVDQqmkjYz2B77 VLzHqi4wtq34g== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4CQWJ05bFvz9rxY for <30393@debbugs.gnu.org>; Tue, 3 Nov 2020 14:45:20 +0100 (CET) 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:192602 Archived-At: --=-=-= Content-Type: text/plain This bug had a rather long discussion, but apparently no conclusion so far. I found that the indentation is correct in Emacs 27 and 28, so apparently it has been fixed elsewhere. The patch contains a test (suitable for cperl-mode and perl-mode) to verify correct indentation for the example source code from the bug report. In Emacs 26 the bug still exists. I find it serious enough to add the workaround given by Noam Postavsky in the discussion of Bug#25480. When the opening paren in column 0 is within a string variable (as it is in the code from the bug report), indenting changed the value of that variable. This should not be allowed to happen. -- Cheers, haj --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-cperl-mode-Fix-indentation-for-Emacs-26-Bug-30393.patch Content-Description: Fix indentation for Emacs 26 >From 59430b8b2b288c36cec8b32e941b82e7bf7a88cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Harald=20J=C3=B6rg?= Date: Tue, 3 Nov 2020 14:27:50 +0100 Subject: [PATCH] cperl-mode: Fix indentation for Emacs 26 (Bug#30393) * lisp/progmodes/cperl-mode.el (cperl-mode): Add a fix which is only required for Emacs versions older than 27. * test/lisp/progmodes/cperl-mode-tests.el (cperl-bug30393): Add a test to verify correct indentation. --- lisp/progmodes/cperl-mode.el | 3 ++ .../cperl-mode-resources/cperl-bug-30393.pl | 19 ++++++++++++ test/lisp/progmodes/cperl-mode-tests.el | 29 +++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 test/lisp/progmodes/cperl-mode-resources/cperl-bug-30393.pl diff --git a/lisp/progmodes/cperl-mode.el b/lisp/progmodes/cperl-mode.el index ebbea6bed9..6178cdfc9b 100644 --- a/lisp/progmodes/cperl-mode.el +++ b/lisp/progmodes/cperl-mode.el @@ -1606,6 +1606,9 @@ cperl-mode (if (cperl-val 'cperl-electric-keywords) (abbrev-mode 1)) (set-syntax-table cperl-mode-syntax-table) + ;; Workaround for Bug#30393, needed for Emacs 26. + (when (< emacs-major-version 27) + (setq-local open-paren-in-column-0-is-defun-start nil)) ;; Until Emacs is multi-threaded, we do not actually need it local: (make-local-variable 'cperl-font-lock-multiline-start) (make-local-variable 'cperl-font-locking) diff --git a/test/lisp/progmodes/cperl-mode-resources/cperl-bug-30393.pl b/test/lisp/progmodes/cperl-mode-resources/cperl-bug-30393.pl new file mode 100644 index 0000000000..01db7b5206 --- /dev/null +++ b/test/lisp/progmodes/cperl-mode-resources/cperl-bug-30393.pl @@ -0,0 +1,19 @@ +# -------- bug#30393: input -------- +# + my $sql = "insert into jobs (id, priority) values (1, 2);"; + my $sth = $dbh->prepare($sql) or die "bother"; + + my $sql = "insert into jobs +(id, priority) +values (1, 2);"; + my $sth = $dbh->prepare($sql) or die "bother"; +# -------- bug#30393: expected output -------- +# +my $sql = "insert into jobs (id, priority) values (1, 2);"; +my $sth = $dbh->prepare($sql) or die "bother"; + +my $sql = "insert into jobs +(id, priority) +values (1, 2);"; +my $sth = $dbh->prepare($sql) or die "bother"; +# -------- bug#30393: end -------- diff --git a/test/lisp/progmodes/cperl-mode-tests.el b/test/lisp/progmodes/cperl-mode-tests.el index dcde3b68a0..2977f10813 100644 --- a/test/lisp/progmodes/cperl-mode-tests.el +++ b/test/lisp/progmodes/cperl-mode-tests.el @@ -220,6 +220,35 @@ cperl-mode-fontify-punct-vars (should (equal (nth 3 (syntax-ppss)) nil)) (should (equal (nth 4 (syntax-ppss)) t)))))) +(ert-deftest cperl-bug30393 () + "Verify that indentation is not disturbed by an open paren in col 0. +Perl is not Lisp: An open paren in column 0 does not start a function." + (let ((file (ert-resource-file "cperl-bug-30393.pl"))) + (with-temp-buffer + (insert-file-contents file) + (goto-char (point-min)) + (while (re-search-forward + (concat "^# ?-+ \\_<\\(?1:.+?\\)\\_>: input ?-+\n" + "\\(?2:\\(?:.*\n\\)+?\\)" + "# ?-+ \\1: expected output ?-+\n" + "\\(?3:\\(?:.*\n\\)+?\\)" + "# ?-+ \\1: end ?-+") + nil t) + (let ((name (match-string 1)) + (code (match-string 2)) + (expected (match-string 3)) + got) + (with-temp-buffer + (insert code) + (funcall cperl-test-mode) + (goto-char (point-min)) + (while (null (eobp)) + (cperl-indent-command) + (next-line)) + (setq expected (concat "test case " name ":\n" expected)) + (setq got (concat "test case " name ":\n" (buffer-string))) + (should (equal got expected)))))))) + (ert-deftest cperl-bug37127 () "Verify that closing a paren in a regex goes without a message. Also check that the message is issued if the regex terminator is -- 2.20.1 --=-=-=--