aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2016-05-11 21:27:45 -0400
committerKyle Meyer <kyle@kyleam.com>2016-05-11 21:29:43 -0400
commitee2bd9aab5b8e9503eb4c24f90d7b0b9817bad53 (patch)
tree99d2035fa9f731fc5f18bf30b68d8febe366ef95
parent001fc4ad589893515375f439d56e5a1ee169d527 (diff)
downloadsnakemake-mode-ee2bd9aab5b8e9503eb4c24f90d7b0b9817bad53.tar.gz
Extend snakemake-block-bounds function
Include name and block type.
-rw-r--r--snakemake-mode.el37
-rw-r--r--snakemake-test.el4
-rw-r--r--snakemake.el17
3 files changed, 24 insertions, 34 deletions
diff --git a/snakemake-mode.el b/snakemake-mode.el
index df4f607..c181290 100644
--- a/snakemake-mode.el
+++ b/snakemake-mode.el
@@ -134,29 +134,32 @@
;;; Info and navigation
-(defun snakemake-block-bounds ()
- "Return bounds of rule or subworkflow block at point."
+(defun snakemake-block-info ()
+ "Return description 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)))
+ (let ((type (or (match-string-no-properties 1)
+ "rule"))
+ (name (match-string-no-properties 2))
+ (start (or (match-beginning 1)
+ (match-beginning 3)))
(rule-indent (current-indentation))
- rule-end)
+ 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))
+ (progn (setq end (point-max))
nil)))
- (setq rule-end (line-end-position))
+ (setq end (line-end-position))
(forward-line))
- (when (<= rule-start pos rule-end)
- (cons rule-start rule-end))))))))
+ (when (<= start pos end)
+ (list type name start end))))))))
(defun snakemake-beginning-of-block (&optional arg)
"Move to beginning of rule block.
@@ -176,9 +179,8 @@ forward rather than backward."
(defun snakemake-end-of-block ()
"Move to end of rule or subworkflow block."
- (let ((bounds (snakemake-block-bounds)))
- (when bounds
- (goto-char (cdr bounds)))))
+ (let ((end (nth 3 (snakemake-block-info))))
+ (when end (goto-char end))))
(defun snakemake-beginning-of-defun (&optional arg)
"Move to beginning of current rule block or function.
@@ -207,20 +209,11 @@ forward rather than backward."
(or (snakemake-end-of-block)
(python-nav-end-of-defun)))
-(defun snakemake-block-name ()
- "Return rule name for current block."
- (let ((bounds (snakemake-block-bounds)))
- (when bounds
- (save-excursion
- (goto-char (car bounds))
- (and (looking-at snakemake-rule-or-subworkflow-re)
- (match-string-no-properties 2))))))
-
(defun snakemake-block-or-defun-name ()
"Return name of current rule or function.
This function is appropriate to use as the value of
`add-log-current-defun-function'."
- (or (snakemake-block-name)
+ (or (nth 1 (snakemake-block-info))
(python-info-current-defun)))
diff --git a/snakemake-test.el b/snakemake-test.el
index fc063c6..fd4daac 100644
--- a/snakemake-test.el
+++ b/snakemake-test.el
@@ -567,13 +567,13 @@ x = [1,
;;;; Info and navigation
-(ert-deftest snakemake-test-block-bounds ()
+(ert-deftest snakemake-test-block-info ()
(should-not
(snakemake-with-temp-text
"
rule abc:
output: 'file'"
- (snakemake-block-bounds))))
+ (snakemake-block-info))))
(ert-deftest snakemake-test-beginning-of-block ()
(should
diff --git a/snakemake.el b/snakemake.el
index 47df68d..213a8c1 100644
--- a/snakemake.el
+++ b/snakemake.el
@@ -328,16 +328,13 @@ target.
This function returns a list for consistency with other
target-returning functions, but any non-nil return value is
currently limited to a single-item list."
- (when (and (derived-mode-p 'snakemake-mode)
- (snakemake-block-bounds))
- (save-excursion
- (end-of-line)
- (re-search-backward snakemake-rule-or-subworkflow-re)
- (let ((rule (and (string= (match-string-no-properties 1) "rule")
- (match-string-no-properties 2))))
- (when rule
- (and (or (not targets-only) (snakemake-check-target rule))
- (list rule)))))))
+ (when (derived-mode-p 'snakemake-mode)
+ (let* ((info (snakemake-block-info))
+ (rule (and (equal (nth 0 info) "rule")
+ (nth 1 info))))
+ (when rule
+ (and (or (not targets-only) (snakemake-check-target rule))
+ (list rule))))))
(defun snakemake--prompt (prompt default)
(concat prompt