unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: haj@posteo.de (Harald Jörg)
To: 19709@debbugs.gnu.org
Subject: bug#19709: [PATCH] Verify that indentation works with current cperl-mode
Date: Wed, 04 Nov 2020 21:01:33 +0100	[thread overview]
Message-ID: <87361ouc0y.fsf@hajtower> (raw)
In-Reply-To: <CACxbc=BgnKsb=KYQez74XQ30KbXChOqmyAyo8wf_63URDp5VBA@mail.gmail.com>

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

This bug apparently can no longer be reproduced.

Using quick'n'dirty bisection (avoiding recompilations of the whole
source tree) I could track the fix back to commit 1bcbcb7e,
"lisp/progmodes/cperl-mode.el: Merge from Jonathan Rockway's version" by
Stefan Monnier, 21st Dec 2017.  This makes sense since this commit
introduced a new function 'cperl-calculate-indent' to cperl-mode.el.

The patch adds a test to verify correct behavior, and also adds the
relevant variable cperl-close-paren-offset (which is explicitly set in
the bug report) to the scope of the cperl-set-style setting "PBP".  This
variable is documented in the book, but wasn't included yet.
--
Cheers,
haj


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Indentation obeys customisation --]
[-- Type: text/x-diff, Size: 5034 bytes --]

From 91761ee3e83cfad9ccabdd75dd364e9bc84db145 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Harald=20J=C3=B6rg?= <haj@posteo.de>
Date: Wed, 4 Nov 2020 18:39:24 +0100
Subject: [PATCH] ; cperl-mode: Indentation of ')' follows customisation

* test/lisp/progmodes/cperl-mode-tests.el (cperl-bug19709):
New test to verify correct indentation of closing parentheses (Bug#19709).

* test/lisp/progmodes/cperl-mode-resources/cperl-bug-19709.pl:
New test case with code from the bug report.

* lisp/progmodes/cperl-mode.el (cperl-style-alist): Add
cperl-close-paren-offset to the settings for PBP style.

* test/lisp/progmodes/cperl-mode-resources/cperl-indent-styles.pl:
Add a new test clause for cperl-close-paren-offset.
---
 lisp/progmodes/cperl-mode.el                  |  1 +
 .../cperl-mode-resources/cperl-bug-19709.pl   | 25 ++++++++++++
 .../cperl-indent-styles.pl                    | 10 +++++
 test/lisp/progmodes/cperl-mode-tests.el       | 38 +++++++++++++++++++
 4 files changed, 74 insertions(+)
 create mode 100644 test/lisp/progmodes/cperl-mode-resources/cperl-bug-19709.pl

diff --git a/lisp/progmodes/cperl-mode.el b/lisp/progmodes/cperl-mode.el
index 6178cdfc9b..d5b30025e7 100644
--- a/lisp/progmodes/cperl-mode.el
+++ b/lisp/progmodes/cperl-mode.el
@@ -5983,6 +5983,7 @@ cperl-style-alist
      (cperl-continued-brace-offset     .  0)
      (cperl-label-offset               . -2)
      (cperl-continued-statement-offset .  4)
+     (cperl-close-paren-offset         . -4)
      (cperl-extra-newline-before-brace .  nil)
      (cperl-extra-newline-before-brace-multiline .  nil)
      (cperl-merge-trailing-else        .  nil)
diff --git a/test/lisp/progmodes/cperl-mode-resources/cperl-bug-19709.pl b/test/lisp/progmodes/cperl-mode-resources/cperl-bug-19709.pl
new file mode 100644
index 0000000000..f7c51a2ce5
--- /dev/null
+++ b/test/lisp/progmodes/cperl-mode-resources/cperl-bug-19709.pl
@@ -0,0 +1,25 @@
+# -------- bug#19709: input --------
+my $a = func1(
+    Module::test()
+  );
+
+my $b = func2(
+    test()
+);
+
+my $c = func3(
+    Module::test(),
+);
+# -------- bug#19709: expected output --------
+my $a = func1(
+    Module::test()
+);
+
+my $b = func2(
+    test()
+);
+
+my $c = func3(
+    Module::test(),
+);
+# -------- bug#19709: end --------
diff --git a/test/lisp/progmodes/cperl-mode-resources/cperl-indent-styles.pl b/test/lisp/progmodes/cperl-mode-resources/cperl-indent-styles.pl
index 0832f86828..371b19b730 100644
--- a/test/lisp/progmodes/cperl-mode-resources/cperl-indent-styles.pl
+++ b/test/lisp/progmodes/cperl-mode-resources/cperl-indent-styles.pl
@@ -42,3 +42,13 @@
     }
 }
 # -------- PBP uncuddle else: end --------
+
+# -------- PBP closing paren offset: input --------
+my $a = func1(
+    Module::test()
+  );
+# -------- PBP closing paren offset: expected output --------
+my $a = func1(
+    Module::test()
+);
+# -------- PBP closing paren offset: end --------
diff --git a/test/lisp/progmodes/cperl-mode-tests.el b/test/lisp/progmodes/cperl-mode-tests.el
index 2977f10813..a262db3136 100644
--- a/test/lisp/progmodes/cperl-mode-tests.el
+++ b/test/lisp/progmodes/cperl-mode-tests.el
@@ -249,6 +249,44 @@ cperl-bug30393
             (setq got (concat "test case " name ":\n" (buffer-string)))
             (should (equal got expected))))))))
 
+(ert-deftest cperl-bug19709 ()
+  "Verify that indentation of closing paren works as intended.
+Note that Perl mode has no setting for close paren offset, per
+documentation it does the right thing anyway."
+  (let ((file (ert-resource-file "cperl-bug-19709.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)
+            (setq-local
+             ;; settings from the bug report
+             cperl-indent-level 4
+             cperl-indent-parens-as-block t
+             cperl-close-paren-offset -4
+             ;; same, adapted for per-mode
+             perl-indent-level 4
+             perl-indent-parens-as-block t)
+            (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-04 20:01 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-28  7:30 bug#19709: Problem with indentation for the closing parenthesis in cperl-mode version 6.1 Håkon Hægland
2019-07-05 20:14 ` Stefan Kangas
2020-11-04 20:01 ` Harald Jörg [this message]
2020-11-09 14:28   ` bug#19709: [PATCH] Verify that indentation works with current cperl-mode Lars Ingebrigtsen
2020-11-09 16:06     ` Harald Jörg
2020-11-10 13:56       ` 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=87361ouc0y.fsf@hajtower \
    --to=haj@posteo.de \
    --cc=19709@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).