]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/progmodes/perl-mode.el (perl-calculate-indent): Indent qw(...)
authorStefan Monnier <monnier@iro.umontreal.ca>
Fri, 15 Nov 2019 18:19:21 +0000 (13:19 -0500)
committerStefan Monnier <monnier@iro.umontreal.ca>
Fri, 15 Nov 2019 18:19:37 +0000 (13:19 -0500)
Fix initialization of `state`.
Special-case `qw(...)` because we do want to indent its contents.

lisp/progmodes/perl-mode.el
test/manual/indent/perl.perl

index ab3680bfb7682a8f86e2194fda2d1f04e1140d30..2dcd0406277d5903e3e3d211179bef4bb06f4070 100644 (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)))
index 06f32e7f090dbf28edecbfd8373a7522422b762a..853aec492454d29fa1cf8d3a135a2051760a0ca1 100755 (executable)
@@ -5,6 +5,12 @@ sub add_funds($) {
     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',