summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS5
-rw-r--r--snakemake-mode.el26
-rw-r--r--test-snakemake-mode.el51
3 files changed, 70 insertions, 12 deletions
diff --git a/NEWS b/NEWS
index e7f01db..63065c4 100644
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,11 @@
- The 'onsuccess' and 'onerror' keywords (introduced in Snakemake
version 3.2.1) are now recognized.
+- Indentation for field values starting on the line below a field key
+ is now supported. New variable `snakemake-indent-value-offset'
+ controls the offset for the value and replaces the variable
+ `snakemake-indent-run-offset'.
+
* v0.2.0
** New features
diff --git a/snakemake-mode.el b/snakemake-mode.el
index 358db22..d8914e2 100644
--- a/snakemake-mode.el
+++ b/snakemake-mode.el
@@ -62,8 +62,8 @@
:group 'snakemake
:type 'integer)
-(defcustom snakemake-indent-run-offset 2
- "Additional offset for 'run' field value."
+(defcustom snakemake-indent-value-offset 4
+ "Offset for field values that the line below the field key."
:group 'snakemake
:type 'integer)
@@ -132,12 +132,14 @@ rule blocks (or on a blank line directly below), call
Indent the line to `snakemake-indent-field-offset'.
-- Below a 'run' subkey
+- On first line below a naked field key.
- Indent the first line below 'run'
- `snakemake-indent-field-offset' plus
- `snakemake-indent-run-offset'. Indent other lines with
- `python-indent-line-function'.
+ Indent the line with `snakemake-indent-field-offset' plus
+ `snakemake-indent-value-offset'.
+
+- On any 'run' field value line except for the first value line.
+
+ Indent with `python-indent-line-function'.
- Otherwise
@@ -153,10 +155,10 @@ rule blocks (or on a blank line directly below), call
((looking-at-p (concat "^[ \t]*" snakemake-field-key-re))
(delete-horizontal-space)
(indent-to snakemake-indent-field-offset))
- ((snakemake-run-field-first-line-p)
+ ((snakemake-below-naked-field-p)
(delete-horizontal-space)
(indent-to (+ snakemake-indent-field-offset
- snakemake-indent-run-offset)))
+ snakemake-indent-value-offset)))
((snakemake-run-field-line-p)
(python-indent-line-function))
((< start-indent snakemake-indent-field-offset)
@@ -182,12 +184,12 @@ rule blocks (or on a blank line directly below), call
(and (re-search-backward snakemake-rule-or-subworkflow-re nil t)
(not (re-search-forward "^ *$" start t))))))
-(defun snakemake-run-field-first-line-p ()
- "Return non-nil if point is on the first line below a run field key."
+(defun snakemake-below-naked-field-p ()
+ "Return non-nil if point is on first line below a naked field key."
(save-excursion
(forward-line -1)
(beginning-of-line)
- (looking-at-p "^[ \t]+run:")))
+ (looking-at-p (concat snakemake-field-key-indented-re " *$"))))
(defun snakemake-run-field-line-p ()
"Return non-nil if point is on any line below a run field key.
diff --git a/test-snakemake-mode.el b/test-snakemake-mode.el
index a3afa7b..51a8a7e 100644
--- a/test-snakemake-mode.el
+++ b/test-snakemake-mode.el
@@ -120,6 +120,37 @@ rule abc:
(snakemake-indent-line)
(buffer-string))))
+ ;; Below a naked rule field key
+ (should
+ (string=
+ "
+rule abc:
+ output:
+ "
+ (snakemake-with-temp-text
+ "
+rule abc:
+ output:
+<point>"
+ (snakemake-indent-line)
+ (buffer-string))))
+
+ ;; Below a naked rule field key, repeated
+ (should
+ (string=
+ "
+rule abc:
+ output:
+ "
+ (snakemake-with-temp-text
+ "
+rule abc:
+ output:
+<point>"
+ (snakemake-indent-line)
+ (snakemake-indent-line)
+ (buffer-string))))
+
;; Below a filled rule field key
(should
(string=
@@ -247,6 +278,26 @@ subworkflow otherworkflow:
snakefile: '../path/to/otherworkflow/Snakefile'"
(should (snakemake-in-rule-or-subworkflow-block-p))))
+(ert-deftest test-snakemake-mode/below-naked-field-p ()
+ "Test `snakemake-below-naked-field-p'."
+ (snakemake-with-temp-text
+ "
+rule abc:
+ output:
+<point>"
+ (should (snakemake-below-naked-field-p)))
+ (snakemake-with-temp-text
+ "
+rule abc:
+ output: 'file'
+<point>"
+ (should-not (snakemake-below-naked-field-p)))
+ (snakemake-with-temp-text
+ "
+rule abc:
+ output: <point>"
+ (should-not (snakemake-below-naked-field-p))))
+
(ert-deftest test-snakemake-mode/run-field-line-p ()
"Test `snakemake-run-field-line-p'."
(snakemake-with-temp-text