aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS2
-rw-r--r--snakemake-mode.el19
-rw-r--r--snakemake-test.el28
3 files changed, 49 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index 1f73c4f..900f995 100644
--- a/NEWS
+++ b/NEWS
@@ -19,6 +19,8 @@ NEWS -- history of user-visible changes -*- mode: org; -*-
- ~beginning-of-defun~ and ~end-of-defun~ implementations for rule
blocks are now defined.
+- Rule blocks are now recognized by ~add-log-current-defun~.
+
* v0.4.0
** New features
diff --git a/snakemake-mode.el b/snakemake-mode.el
index a598aca..a8d0539 100644
--- a/snakemake-mode.el
+++ b/snakemake-mode.el
@@ -206,6 +206,23 @@ forward rather than backward."
"Move to end of current rule block or function."
(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)
+ (python-info-current-defun)))
+
;;; Indentation
@@ -400,6 +417,8 @@ embedded R, you need to set mmm-global-mode to a non-nil value such as 'maybe.")
#'snakemake-beginning-of-defun)
(set (make-local-variable 'end-of-defun-function)
#'snakemake-end-of-defun)
+ (set (make-local-variable 'add-log-current-defun-function)
+ #'python-info-current-defun)
(set (make-local-variable 'font-lock-defaults)
`(,(append snakemake-font-lock-keywords python-font-lock-keywords))))
diff --git a/snakemake-test.el b/snakemake-test.el
index d725345..fc063c6 100644
--- a/snakemake-test.el
+++ b/snakemake-test.el
@@ -681,6 +681,34 @@ rule xyz:
(snakemake-end-of-block)
(buffer-substring (point-min) (point))))))
+(ert-deftest snakemake-test-block-or-defun-name ()
+ (should
+ (string= "abc"
+ (snakemake-with-temp-text
+ "
+rule abc:
+<point> output: 'file'
+"
+ (snakemake-block-or-defun-name))))
+ (should
+ (string= "xyz"
+ (snakemake-with-temp-text
+ "
+rule abc:
+ output: 'file'
+
+<point>def xyz():
+ pass
+"
+ (snakemake-block-or-defun-name))))
+ (should-not
+ (snakemake-with-temp-text
+ "
+rule abc:
+ output: 'file'
+"
+ (snakemake-block-or-defun-name))))
+
;;; snakemake.el