diff options
| author | Harald Jörg | 2023-07-02 00:35:31 +0200 |
|---|---|---|
| committer | Harald Jörg | 2023-07-02 00:37:10 +0200 |
| commit | 9b9dcc146ba8132ef02afd12f20b302a78c7bbe2 (patch) | |
| tree | b82e2d16cc9960da54a994e2d76ce5adaaf05db1 | |
| parent | a371e1def79dcb2a6448f4b673aea0920c9788d3 (diff) | |
| download | emacs-9b9dcc146ba8132ef02afd12f20b302a78c7bbe2.tar.gz emacs-9b9dcc146ba8132ef02afd12f20b302a78c7bbe2.zip | |
; cperl-mode.el: Fix two indentation bugs (Bug#11733)
* lisp/progmodes/cperl-mode.el (cperl-sniff-for-indent): Detect
whether we have a label or a regex/string.
(cperl-calculate-indent): Check for things which look like labels
but aren't.
* test/lisp/progmodes/cperl-mode-tests.el (cperl-test-bug-11733):
Test the examples provided in the bug report.
* test/lisp/progmodes/cperl-mode-resources/cperl-bug-11733.pl:
Examples from the bug report.
| -rw-r--r-- | lisp/progmodes/cperl-mode.el | 10 | ||||
| -rw-r--r-- | test/lisp/progmodes/cperl-mode-resources/cperl-bug-11733.pl | 50 | ||||
| -rw-r--r-- | test/lisp/progmodes/cperl-mode-tests.el | 11 |
3 files changed, 68 insertions, 3 deletions
diff --git a/lisp/progmodes/cperl-mode.el b/lisp/progmodes/cperl-mode.el index c1e55944b7e..1abe57c15ea 100644 --- a/lisp/progmodes/cperl-mode.el +++ b/lisp/progmodes/cperl-mode.el | |||
| @@ -2866,10 +2866,13 @@ Will not look before LIM." | |||
| 2866 | ;; Back up over label lines, since they don't | 2866 | ;; Back up over label lines, since they don't |
| 2867 | ;; affect whether our line is a continuation. | 2867 | ;; affect whether our line is a continuation. |
| 2868 | ;; (Had \, too) | 2868 | ;; (Had \, too) |
| 2869 | (while (and (eq (preceding-char) ?:) | 2869 | (while (save-excursion |
| 2870 | (and (eq (preceding-char) ?:) | ||
| 2870 | (re-search-backward | 2871 | (re-search-backward |
| 2871 | (rx (sequence (eval cperl--label-rx) point)) | 2872 | (rx (sequence (eval cperl--label-rx) point)) |
| 2872 | nil t)) | 2873 | nil t) |
| 2874 | ;; Ignore if in comment or RE | ||
| 2875 | (not (nth 3 (syntax-ppss))))) | ||
| 2873 | ;; This is always FALSE? | 2876 | ;; This is always FALSE? |
| 2874 | (if (eq (preceding-char) ?\,) | 2877 | (if (eq (preceding-char) ?\,) |
| 2875 | ;; Will go to beginning of line, essentially. | 2878 | ;; Will go to beginning of line, essentially. |
| @@ -3129,7 +3132,8 @@ and closing parentheses and brackets." | |||
| 3129 | ;; Now it is a hash reference | 3132 | ;; Now it is a hash reference |
| 3130 | (+ cperl-indent-level cperl-close-paren-offset)) | 3133 | (+ cperl-indent-level cperl-close-paren-offset)) |
| 3131 | ;; Labels do not take :: ... | 3134 | ;; Labels do not take :: ... |
| 3132 | (if (looking-at "\\(\\w\\|_\\)+[ \t]*:[^:]") | 3135 | (if (and (looking-at "\\(\\w\\|_\\)+[ \t]*:[^:]") |
| 3136 | (not (looking-at (rx (eval cperl--false-label-rx))))) | ||
| 3133 | (if (> (current-indentation) cperl-min-label-indent) | 3137 | (if (> (current-indentation) cperl-min-label-indent) |
| 3134 | (- (current-indentation) cperl-label-offset) | 3138 | (- (current-indentation) cperl-label-offset) |
| 3135 | ;; Do not move `parse-data', this should | 3139 | ;; Do not move `parse-data', this should |
diff --git a/test/lisp/progmodes/cperl-mode-resources/cperl-bug-11733.pl b/test/lisp/progmodes/cperl-mode-resources/cperl-bug-11733.pl new file mode 100644 index 00000000000..a474e431222 --- /dev/null +++ b/test/lisp/progmodes/cperl-mode-resources/cperl-bug-11733.pl | |||
| @@ -0,0 +1,50 @@ | |||
| 1 | # This resource file can be run with cperl--run-testcases from | ||
| 2 | # cperl-tests.el and works with both perl-mode and cperl-mode. | ||
| 3 | |||
| 4 | # -------- Multiline declaration: input ------- | ||
| 5 | #!/usr/bin/env perl | ||
| 6 | # -*- mode: cperl -*- | ||
| 7 | |||
| 8 | sub foo | ||
| 9 | { | ||
| 10 | } | ||
| 11 | |||
| 12 | sub bar | ||
| 13 | { | ||
| 14 | } | ||
| 15 | # -------- Multiline declaration: expected output ------- | ||
| 16 | #!/usr/bin/env perl | ||
| 17 | # -*- mode: cperl -*- | ||
| 18 | |||
| 19 | sub foo | ||
| 20 | { | ||
| 21 | } | ||
| 22 | |||
| 23 | sub bar | ||
| 24 | { | ||
| 25 | } | ||
| 26 | # -------- Multiline declaration: end ------- | ||
| 27 | |||
| 28 | # -------- Fred Colon at work: input -------- | ||
| 29 | #!/usr/bin/env perl | ||
| 30 | # -*- mode: cperl -*- | ||
| 31 | |||
| 32 | while (<>) | ||
| 33 | { | ||
| 34 | m:^ \d+ p: | ||
| 35 | or die; | ||
| 36 | m:^ \d+ : | ||
| 37 | or die; | ||
| 38 | } | ||
| 39 | # -------- Fred Colon at work: expected output -------- | ||
| 40 | #!/usr/bin/env perl | ||
| 41 | # -*- mode: cperl -*- | ||
| 42 | |||
| 43 | while (<>) | ||
| 44 | { | ||
| 45 | m:^ \d+ p: | ||
| 46 | or die; | ||
| 47 | m:^ \d+ : | ||
| 48 | or die; | ||
| 49 | } | ||
| 50 | # -------- Fred Colon at work: end -------- | ||
diff --git a/test/lisp/progmodes/cperl-mode-tests.el b/test/lisp/progmodes/cperl-mode-tests.el index fced2171767..8162953cefb 100644 --- a/test/lisp/progmodes/cperl-mode-tests.el +++ b/test/lisp/progmodes/cperl-mode-tests.el | |||
| @@ -855,6 +855,17 @@ under timeout control." | |||
| 855 | (should (string-match | 855 | (should (string-match |
| 856 | "poop ('foo', \n 'bar')" (buffer-string)))))) | 856 | "poop ('foo', \n 'bar')" (buffer-string)))))) |
| 857 | 857 | ||
| 858 | (ert-deftest cperl-test-bug-11733 () | ||
| 859 | "Verify indentation of braces after newline and non-labels." | ||
| 860 | (skip-unless (eq cperl-test-mode #'cperl-mode)) | ||
| 861 | (cperl--run-test-cases | ||
| 862 | (ert-resource-file "cperl-bug-11733.pl") | ||
| 863 | (goto-char (point-min)) | ||
| 864 | (while (null (eobp)) | ||
| 865 | (cperl-indent-command) | ||
| 866 | (forward-line 1)))) | ||
| 867 | |||
| 868 | |||
| 858 | (ert-deftest cperl-test-bug-11996 () | 869 | (ert-deftest cperl-test-bug-11996 () |
| 859 | "Verify that we give the right syntax property to a backslash operator." | 870 | "Verify that we give the right syntax property to a backslash operator." |
| 860 | (with-temp-buffer | 871 | (with-temp-buffer |