aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2014-11-16 00:43:44 -0500
committerKyle Meyer <kyle@kyleam.com>2014-11-16 00:43:44 -0500
commit56571dceffa581bcaee6329c97a1608638bd44be (patch)
treee60b781701039f692c956aff6f06324a3ee27488
parentb3134d154c8e9cc6fcb6f947a293399fe81e0faa (diff)
downloadsnakemake-mode-56571dceffa581bcaee6329c97a1608638bd44be.tar.gz
Add snakemake-compile-rule command
-rw-r--r--NEWS3
-rw-r--r--snakemake-mode.el42
2 files changed, 44 insertions, 1 deletions
diff --git a/NEWS b/NEWS
index 672aa9b..f5483f1 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,9 @@
- Both the executable and flags for the Snakemake `compile-command' are
now customizable.
+- New command `snakemake-compile-rule' runs Snakemake with the rule at
+ point as the target.
+
- Subworkflow blocks are now supported.
- The 'ruleorder' keyword is now recognized.
diff --git a/snakemake-mode.el b/snakemake-mode.el
index f251d8e..1848159 100644
--- a/snakemake-mode.el
+++ b/snakemake-mode.el
@@ -230,9 +230,44 @@ Flags are taken from `snakemake-compile-command-options'."
(cons snakemake-executable snakemake-compile-command-options)
" "))
+(defun snakemake-compile-rule (jobs)
+ "Run Snakemake with the rule at point as the target.
+
+The numeric prefix JOBS controls the number of jobs that
+Snakemake runs (defaults to 1). If JOBS is zero, perform a dry
+run.
+
+Customize `snakemake-executable' and
+`snakemake-compile-command-options' to control the compilation
+command."
+ (interactive "p")
+ (unless (snakemake-in-rule-or-subworkflow-block-p)
+ (user-error "Not in rule block"))
+ (save-excursion
+ (end-of-line)
+ (re-search-backward snakemake-rule-or-subworkflow-re)
+ (let ((block-type (match-string-no-properties 1))
+ (rule-name (match-string-no-properties 2)))
+ (pcase block-type
+ ("rule"
+ (let* ((job-flag (if (zerop jobs)
+ " -n "
+ (format " -j%s " jobs)))
+ (compile-command (concat (snakemake-compile-command) job-flag
+ rule-name)))
+ (call-interactively #'compile)))
+ ("subworkflow" (user-error "Cannot compile a subworkflow"))))))
+
;;; Mode
+(defvar snakemake-mode-map
+ (let ((map (make-sparse-keymap)))
+ (set-keymap-parent map python-mode-map)
+ (define-key map (kbd "C-c C-b") 'snakemake-compile-rule)
+ map)
+ "Keymap for `snakemake-mode'.")
+
(defvar snakemake-font-lock-keywords
`((,snakemake-rule-or-subworkflow-line-re (1 font-lock-keyword-face)
(2 font-lock-function-name-face))
@@ -252,7 +287,12 @@ Flags are taken from `snakemake-compile-command-options'."
;;;###autoload
(define-derived-mode snakemake-mode python-mode "Snakemake"
- "Mode for editing Snakemake files."
+ "Mode for editing Snakemake files.
+
+\\<snakemake-mode-map>\
+Type \\[snakemake-compile-rule] to run Snakemake with the rule of
+the block at point as the target.
+\n\\{snakemake-mode-map}"
(set (make-local-variable 'indent-line-function) 'snakemake-indent-line)
(font-lock-add-keywords nil snakemake-font-lock-keywords)
(set (make-local-variable 'compile-command) (snakemake-compile-command)))