summaryrefslogtreecommitdiff
path: root/snakemake-mode.el
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2016-05-11 01:37:25 -0400
committerKyle Meyer <kyle@kyleam.com>2016-05-11 01:39:04 -0400
commit97b008e65f0402388cfacd32aee3b4dd4fbaf2ff (patch)
tree6f39a0512ffa6f658e51a8c32a8fcf173df83e0a /snakemake-mode.el
parentc4c05088e98179ab1ff5e90155b297fd2be9a087 (diff)
downloadsnakemake-mode-97b008e65f0402388cfacd32aee3b4dd4fbaf2ff.tar.gz
Add snakemake-block-bounds function
Diffstat (limited to 'snakemake-mode.el')
-rw-r--r--snakemake-mode.el45
1 files changed, 27 insertions, 18 deletions
diff --git a/snakemake-mode.el b/snakemake-mode.el
index cd8a421..853f356 100644
--- a/snakemake-mode.el
+++ b/snakemake-mode.el
@@ -132,6 +132,33 @@
"Regexp matching a call to a builtin Snakemake function.")
+;;; Info and navigation
+
+(defun snakemake-block-bounds ()
+ "Return bounds of rule or subworkflow block at point."
+ (save-excursion
+ (save-restriction
+ (prog-widen)
+ (let ((pos (point)))
+ (end-of-line)
+ (and (re-search-backward snakemake-rule-or-subworkflow-re nil t)
+ (let ((rule-start (or (match-beginning 1)
+ (match-beginning 3)))
+ (rule-indent (current-indentation))
+ rule-end)
+ (beginning-of-line)
+ (forward-line)
+ (while (and (or (< rule-indent (current-indentation))
+ (looking-at-p "^\\s-*$"))
+ (or (not (eobp))
+ (progn (setq rule-end (point-max))
+ nil)))
+ (setq rule-end (line-end-position))
+ (forward-line))
+ (when (<= rule-start pos rule-end)
+ (cons rule-start rule-end))))))))
+
+
;;; Indentation
(defun snakemake--calculate-indentation (&optional previous)
@@ -224,24 +251,6 @@ returned."
(and (memq this-command python-indent-trigger-commands)
(eq last-command this-command))))
-(defun snakemake-in-rule-or-subworkflow-block-p ()
- "Return non-nil if point is in block or on first blank line following one."
- (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 (funcall blank-p))
- (cond ((looking-at-p snakemake-rule-or-subworkflow-re)
- (throw 'in-block t))
- ((bobp)
- (throw 'in-block nil)))
- (forward-line -1))))))
-
;;; Imenu