summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2016-05-24 23:56:42 -0400
committerKyle Meyer <kyle@kyleam.com>2016-05-24 23:56:42 -0400
commit9ed551af664fc0ffc7346db5308328524457de0a (patch)
treea32e3812d78ba08f8a89b098dd465d0f034e785c
parent2e71246aa406b2d51441a961ec468833656b6798 (diff)
downloadsnakemake-mode-9ed551af664fc0ffc7346db5308328524457de0a.tar.gz
indentation: Account for trailing comments
-rw-r--r--snakemake-mode.el11
-rw-r--r--snakemake-test.el28
2 files changed, 35 insertions, 4 deletions
diff --git a/snakemake-mode.el b/snakemake-mode.el
index 5b4fb28..512b103 100644
--- a/snakemake-mode.el
+++ b/snakemake-mode.el
@@ -255,7 +255,8 @@ returned."
(skip-chars-backward " \t\n")
(beginning-of-line)
(cond
- ((cl-some (lambda (re) (looking-at-p (concat re "\\s-*$")))
+ ((cl-some (lambda (re)
+ (looking-at-p (concat re "\\s-*\\(?:#.*\\)?$")))
(list snakemake-field-key-indented-re
snakemake-rule-or-subworkflow-re
snakemake-toplevel-command-re))
@@ -284,9 +285,11 @@ returned."
(not (equal (match-string-no-properties 1)
"run"))
(cond (goto-first-p
- (if (equal (match-string-no-properties 2) "")
- above-indent
- (- (match-beginning 2) (line-beginning-position))))
+ (let ((field-val (match-string-no-properties 2)))
+ (if (or (equal field-val "")
+ (string-match-p "\\`#" field-val))
+ above-indent
+ (- (match-beginning 2) (line-beginning-position)))))
((< field-indent initial-indent)
field-indent)))))))))))))
diff --git a/snakemake-test.el b/snakemake-test.el
index 80850d7..f70b284 100644
--- a/snakemake-test.el
+++ b/snakemake-test.el
@@ -394,6 +394,19 @@ rule abc:
(string=
"
rule abc:
+ output: # comment
+ "
+ (snakemake-with-temp-text
+ "
+rule abc:
+ output: # comment
+ <point>"
+ (snakemake-indent-line)
+ (buffer-string))))
+ (should
+ (string=
+ "
+rule abc:
output:
'file{}{}'.format('one',
'two'"
@@ -502,6 +515,21 @@ rule abc:
(string=
"
rule abc:
+ output: # comment
+ 'file'
+ 'text'"
+ (snakemake-with-temp-text
+ "
+rule abc:
+ output: # comment
+ 'file'
+<point> 'text'"
+ (snakemake-indent-line)
+ (buffer-string))))
+ (should
+ (string=
+ "
+rule abc:
run:
with this:
"