; 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.
This commit is contained in:
parent
a371e1def7
commit
9b9dcc146b
3 changed files with 68 additions and 3 deletions
|
@ -2866,10 +2866,13 @@ Will not look before LIM."
|
|||
;; Back up over label lines, since they don't
|
||||
;; affect whether our line is a continuation.
|
||||
;; (Had \, too)
|
||||
(while (and (eq (preceding-char) ?:)
|
||||
(while (save-excursion
|
||||
(and (eq (preceding-char) ?:)
|
||||
(re-search-backward
|
||||
(rx (sequence (eval cperl--label-rx) point))
|
||||
nil t))
|
||||
nil t)
|
||||
;; Ignore if in comment or RE
|
||||
(not (nth 3 (syntax-ppss)))))
|
||||
;; This is always FALSE?
|
||||
(if (eq (preceding-char) ?\,)
|
||||
;; Will go to beginning of line, essentially.
|
||||
|
@ -3129,7 +3132,8 @@ and closing parentheses and brackets."
|
|||
;; Now it is a hash reference
|
||||
(+ cperl-indent-level cperl-close-paren-offset))
|
||||
;; Labels do not take :: ...
|
||||
(if (looking-at "\\(\\w\\|_\\)+[ \t]*:[^:]")
|
||||
(if (and (looking-at "\\(\\w\\|_\\)+[ \t]*:[^:]")
|
||||
(not (looking-at (rx (eval cperl--false-label-rx)))))
|
||||
(if (> (current-indentation) cperl-min-label-indent)
|
||||
(- (current-indentation) cperl-label-offset)
|
||||
;; Do not move `parse-data', this should
|
||||
|
|
50
test/lisp/progmodes/cperl-mode-resources/cperl-bug-11733.pl
Normal file
50
test/lisp/progmodes/cperl-mode-resources/cperl-bug-11733.pl
Normal file
|
@ -0,0 +1,50 @@
|
|||
# This resource file can be run with cperl--run-testcases from
|
||||
# cperl-tests.el and works with both perl-mode and cperl-mode.
|
||||
|
||||
# -------- Multiline declaration: input -------
|
||||
#!/usr/bin/env perl
|
||||
# -*- mode: cperl -*-
|
||||
|
||||
sub foo
|
||||
{
|
||||
}
|
||||
|
||||
sub bar
|
||||
{
|
||||
}
|
||||
# -------- Multiline declaration: expected output -------
|
||||
#!/usr/bin/env perl
|
||||
# -*- mode: cperl -*-
|
||||
|
||||
sub foo
|
||||
{
|
||||
}
|
||||
|
||||
sub bar
|
||||
{
|
||||
}
|
||||
# -------- Multiline declaration: end -------
|
||||
|
||||
# -------- Fred Colon at work: input --------
|
||||
#!/usr/bin/env perl
|
||||
# -*- mode: cperl -*-
|
||||
|
||||
while (<>)
|
||||
{
|
||||
m:^ \d+ p:
|
||||
or die;
|
||||
m:^ \d+ :
|
||||
or die;
|
||||
}
|
||||
# -------- Fred Colon at work: expected output --------
|
||||
#!/usr/bin/env perl
|
||||
# -*- mode: cperl -*-
|
||||
|
||||
while (<>)
|
||||
{
|
||||
m:^ \d+ p:
|
||||
or die;
|
||||
m:^ \d+ :
|
||||
or die;
|
||||
}
|
||||
# -------- Fred Colon at work: end --------
|
|
@ -855,6 +855,17 @@ under timeout control."
|
|||
(should (string-match
|
||||
"poop ('foo', \n 'bar')" (buffer-string))))))
|
||||
|
||||
(ert-deftest cperl-test-bug-11733 ()
|
||||
"Verify indentation of braces after newline and non-labels."
|
||||
(skip-unless (eq cperl-test-mode #'cperl-mode))
|
||||
(cperl--run-test-cases
|
||||
(ert-resource-file "cperl-bug-11733.pl")
|
||||
(goto-char (point-min))
|
||||
(while (null (eobp))
|
||||
(cperl-indent-command)
|
||||
(forward-line 1))))
|
||||
|
||||
|
||||
(ert-deftest cperl-test-bug-11996 ()
|
||||
"Verify that we give the right syntax property to a backslash operator."
|
||||
(with-temp-buffer
|
||||
|
|
Loading…
Add table
Reference in a new issue