* lisp/progmodes/perl-mode.el (perl-calculate-indent): Indent qw(...)

Fix initialization of `state`.
Special-case `qw(...)` because we do want to indent its contents.
This commit is contained in:
Stefan Monnier 2019-11-15 13:19:21 -05:00
parent 904146cf79
commit 87347a5bbc
2 changed files with 28 additions and 9 deletions

View file

@ -935,15 +935,24 @@ changed by, or (parse-state) if line starts in a quoted string."
In usual case returns an integer: the column to indent to.
Returns (parse-state) if line starts inside a string."
(save-excursion
(let ((indent-point (point))
(case-fold-search nil)
(colon-line-end 0)
prev-char
state containing-sexp)
(setq containing-sexp (nth 1 (syntax-ppss indent-point)))
(let* ((indent-point (point))
(case-fold-search nil)
(colon-line-end 0)
prev-char
(state (syntax-ppss))
(containing-sexp (nth 1 state))
;; Don't auto-indent in a quoted string or a here-document.
(unindentable (or (nth 3 state) (eq 2 (nth 7 state)))))
(when (and (eq t (nth 3 state))
(save-excursion
(goto-char (nth 8 state))
(looking-back "qw[ \t]*" (- (point) 4))))
;; qw(...) is a list of words so the spacing is not meaningful,
;; and makes indentation possible (and desirable).
(setq unindentable nil)
(setq containing-sexp (nth 8 state)))
(cond
;; Don't auto-indent in a quoted string or a here-document.
((or (nth 3 state) (eq 2 (nth 7 state))) 'noindent)
(unindentable 'noindent)
((null containing-sexp) ; Line is at top level.
(skip-chars-forward " \t\f")
(if (memq (following-char)
@ -965,7 +974,11 @@ Returns (parse-state) if line starts inside a string."
;; arg2
;; );
(progn
(skip-syntax-backward "(")
;; Go just before the open paren (don't rely on the
;; skip-syntax-backward to jump over it, because it could
;; have string-fence syntax instead!).
(goto-char containing-sexp)
(skip-syntax-backward "(") ;FIXME: Not sure if still want this.
(condition-case nil
(while (save-excursion
(skip-syntax-backward " ") (not (bolp)))

View file

@ -5,6 +5,12 @@ ($)
return 0;
}
# qw(...) is a quoted list of words, so we can and should indent its content!
my @tutu = qw[
tata
titi
];
my $hash = {
foo => 'bar',
format => 'some',