diff options
author | Kyle Meyer <kyle@kyleam.com> | 2014-11-16 00:44:21 -0500 |
---|---|---|
committer | Kyle Meyer <kyle@kyleam.com> | 2014-11-16 00:44:21 -0500 |
commit | 5c2678f1e42adcae4652550270c333f93307859e (patch) | |
tree | e60b781701039f692c956aff6f06324a3ee27488 /snakemake-mode.el | |
parent | e1fb1f91dd6b557d23d97dd3dc376edf8773d8e6 (diff) | |
parent | 56571dceffa581bcaee6329c97a1608638bd44be (diff) | |
download | snakemake-mode-5c2678f1e42adcae4652550270c333f93307859e.tar.gz |
Merge branch 'run-rule'
Diffstat (limited to 'snakemake-mode.el')
-rw-r--r-- | snakemake-mode.el | 59 |
1 files changed, 51 insertions, 8 deletions
diff --git a/snakemake-mode.el b/snakemake-mode.el index 62dcea7..1848159 100644 --- a/snakemake-mode.el +++ b/snakemake-mode.el @@ -221,8 +221,53 @@ column of the first non-blank character." (1- (current-column)))))) +;;; Compilation + +(defun snakemake-compile-command () + "Return Snakemake compile command. +Flags are taken from `snakemake-compile-command-options'." + (mapconcat 'identity + (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)) @@ -240,16 +285,14 @@ column of the first non-blank character." (add-hook 'snakemake-mode-hook 'snakemake-set-imenu-generic-expression) -(defun snakemake-compile-command () - "Return Snakemake compile command. -Flags are taken from `snakemake-compile-command-options'." - (mapconcat 'identity - (cons snakemake-executable 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))) |