@@ -474,8 +474,20 @@ Possible results are \\='section-header \\='subsection-header \\='section-data
474
474
:end (save-match-data (haskell-cabal-subsection-end))
475
475
:data-start-column (save-excursion (goto-char (match-end 0 ))
476
476
(current-column ))
477
+ ; ; Note: Redundant leading commas are allowed since Cabal 2.2.
478
+ ; ; Example:
479
+ ; ; build-depends:
480
+ ; ; , base
481
+ ; ; , text
482
+ ; ;
483
+ ; ; Note: More than one newlines are allowed after the subsection name.
484
+ ; ; Example:
485
+ ; ; build-depends:
486
+ ; ;
487
+ ; ;
488
+ ; ; base
477
489
:data-indent-column (save-excursion (goto-char (match-end 0 ))
478
- (when (looking-at " \n +\\ (\\ w*\\ )" ) (goto-char (match-beginning 1 )))
490
+ (when (looking-at " \n [ \n\t ]* +\\ ([ \\ w,] *\\ )" ) (goto-char (match-beginning 1 )))
479
491
(current-column )
480
492
)))))
481
493
@@ -1058,11 +1070,24 @@ Source names from main-is and c-sources sections are left untouched
1058
1070
(cl-case (haskell-cabal-classify-line)
1059
1071
(section-data
1060
1072
(save-excursion
1061
- (let ((indent (haskell-cabal-section-data-indent-column
1062
- (haskell-cabal-subsection))))
1063
- (indent-line-to indent)
1073
+ (let* ((subsection (haskell-cabal-subsection))
1074
+ (beginning (haskell-cabal-section-start subsection))
1075
+ (indent-column (haskell-cabal-section-data-indent-column subsection))
1076
+ (subsection-leading-comma-p (save-excursion
1077
+ (goto-char beginning)
1078
+ (looking-at " ,\\ |\n [ \t\n ]*," ))))
1079
+ (indent-line-to indent-column)
1064
1080
(beginning-of-line )
1065
- (when (looking-at " [ ]*\\ ([ ]\\ {2\\ },[ ]*\\ )" )
1081
+ ; ; Only do extra adjustment if the first item is not comma leading.
1082
+ ; ; Example of the two cases:
1083
+ ; ;
1084
+ ; ; | aaa | aaa
1085
+ ; ; | , bbb | , bbb
1086
+ ; ;
1087
+ ; ; | , aaa | , aaa
1088
+ ; ; | , bbb | , bbb
1089
+ (when (and (not subsection-leading-comma-p)
1090
+ (looking-at " [ ]*\\ ([ ]\\ {2\\ },[ ]*\\ )" ))
1066
1091
(replace-match " , " t t nil 1 )))))
1067
1092
(empty
1068
1093
(indent-relative )))
0 commit comments