summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2015-12-24 01:37:32 -0500
committerKyle Meyer <kyle@kyleam.com>2015-12-24 01:37:32 -0500
commit3c6ed16930c0c18c4f5fddbe181ba407df681a07 (patch)
treea9be7ff959ae400c086436c610b6362d1ccd9db5
parent17fcea0f0e3f87e09df566c256791b424e2cdefd (diff)
downloadsnakemake-mode-3c6ed16930c0c18c4f5fddbe181ba407df681a07.tar.gz
Recognize blank lines in rule docstrings
-rw-r--r--snakemake-mode.el21
-rw-r--r--test-snakemake-mode.el12
2 files changed, 25 insertions, 8 deletions
diff --git a/snakemake-mode.el b/snakemake-mode.el
index 2dc00f8..49e9320 100644
--- a/snakemake-mode.el
+++ b/snakemake-mode.el
@@ -213,14 +213,19 @@ Indent according the the first case below that is true.
(defun snakemake-in-rule-or-subworkflow-block-p ()
"Return non-nil if point is in block or on first blank line following one."
- (save-excursion
- (beginning-of-line)
- (when (looking-at-p "^\\s-*$")
- (forward-line -1))
- (end-of-line)
- (let ((start (point)))
- (and (re-search-backward snakemake-rule-or-subworkflow-re nil t)
- (not (re-search-forward "^\\s-*$" start t))))))
+ (let ((blank-p (lambda nil
+ (and (looking-at-p "^\\s-*$")
+ ;; Ignore newlines in docstrings.
+ (not (nth 3 (syntax-ppss)))))))
+ (save-excursion
+ (beginning-of-line)
+ (when (funcall blank-p)
+ (forward-line -1))
+ (catch 'in-block
+ (while (not (or (bobp) (funcall blank-p)))
+ (when (looking-at-p snakemake-rule-or-subworkflow-re)
+ (throw 'in-block t))
+ (forward-line -1))))))
(defun snakemake-below-naked-field-p ()
"Return non-nil if point is on first line below a naked field key."
diff --git a/test-snakemake-mode.el b/test-snakemake-mode.el
index 859c28a..df8b353 100644
--- a/test-snakemake-mode.el
+++ b/test-snakemake-mode.el
@@ -475,6 +475,18 @@ rule abc:
<point>"
(should-not (snakemake-in-rule-or-subworkflow-block-p)))
+
+ ;; Blank line in docstring
+ (snakemake-with-temp-text
+ "
+rule abc:
+ \"\"\"docstring header
+
+ docstring line
+ \"\"\"
+ output: 'file'<point>"
+ (should (snakemake-in-rule-or-subworkflow-block-p)))
+
;; Before
(snakemake-with-temp-text
"<point>