unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: haj@posteo.de (Harald Jörg)
To: 30393@debbugs.gnu.org
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	[thread overview]
Message-ID: <87r1pak0zz.fsf@hajtower> (raw)
In-Reply-To: <20180208152552.GL13340@hodi>

[-- Attachment #1: Type: text/plain, Size: 674 bytes --]

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

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Fix indentation for Emacs 26 --]
[-- Type: text/x-diff, Size: 4079 bytes --]

From 59430b8b2b288c36cec8b32e941b82e7bf7a88cb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Harald=20J=C3=B6rg?= <haj@posteo.de>
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


  parent reply	other threads:[~2020-11-03 13:45 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-08 15:25 bug#30393: 24.4; cperl-mode: indentation failure paulusm
2018-02-09  1:44 ` Noam Postavsky
     [not found] ` <mailman.8766.1518140709.27995.bug-gnu-emacs@gnu.org>
2018-02-09 17:50   ` Alan Mackenzie
2018-02-10  3:55     ` Noam Postavsky
2018-02-10  8:53     ` Dmitry Gutov
2018-02-10 11:26       ` Alan Mackenzie
2018-02-10 12:08         ` Eli Zaretskii
2018-02-11 12:49           ` Alan Mackenzie
2018-02-11 16:16             ` Eli Zaretskii
2018-02-14 21:00               ` Alan Mackenzie
2018-02-15 17:39                 ` Eli Zaretskii
2018-02-16 11:52                 ` Dmitry Gutov
2018-02-16 17:43                   ` Alan Mackenzie
2018-02-17  2:16                     ` Dmitry Gutov
2018-02-17 10:54                       ` Alan Mackenzie
2018-02-10 14:58         ` Stefan Monnier
2018-02-11 10:36           ` Alan Mackenzie
2018-02-11 22:53             ` Stefan Monnier
2018-02-12 18:38               ` Alan Mackenzie
2018-02-12 20:45                 ` Stefan Monnier
2018-03-05  8:42                   ` Alan Mackenzie
2018-03-05 16:14                     ` Eli Zaretskii
2018-03-06 18:09                       ` Alan Mackenzie
2018-04-08 10:52                       ` Alan Mackenzie
2018-04-09 18:41                         ` Eli Zaretskii
2018-04-10 17:31                           ` Alan Mackenzie
2018-04-16 19:21                           ` bug#30393: 24.4; cperl-mode: indentation failure - Documentation enhancements Alan Mackenzie
2018-04-19  7:52                             ` Eli Zaretskii
2020-08-22 16:07                               ` Lars Ingebrigtsen
2020-11-03 13:45 ` Harald Jörg [this message]
2020-11-03 14:29   ` bug#30393: [PATCH] Add a test to verify that the bug is gone (and a fix for Emacs 26) Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r1pak0zz.fsf@hajtower \
    --to=haj@posteo.de \
    --cc=30393@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).