From 1dccdd134022e8deaf5e0d5db8ff15a090ae26a8 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Sun, 17 Apr 2016 18:27:51 -0400 Subject: Add helper for splitting rule lists --- snakemake.el | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/snakemake.el b/snakemake.el index fa200bd..433fd93 100644 --- a/snakemake.el +++ b/snakemake.el @@ -208,28 +208,31 @@ with DIRECTORY and the Snakefile's modification time." "Call `snakemake-program' with ARGS and insert output." (apply #'call-process snakemake-program nil t nil args)) +(defun snakemake--split-rules (type) + "Return rules of TYPE. +TYPE can be `all' or `target'." + (cl-remove-if + (lambda (x) (string-match-p "\\`[0-9]+\\'" x)) + (split-string + (with-temp-buffer + (if (= 0 (snakemake-insert-output + "--nocolor" + (cl-case type + (all "--list") + (target "--list-target-rules") + (t (user-error "Invalid rule type: %s" type))))) + (buffer-string) + (error "Error finding rules")))))) + (defun snakemake-all-rules (&optional directory) "Return list of rules for DIRECTORY's Snakefile." (snakemake-with-cache directory ("all-rules") - (cl-remove-if - (lambda (x) (string-match-p "\\`[0-9]+\\'" x)) - (split-string - (with-temp-buffer - (if (= 0 (snakemake-insert-output "--nocolor" "--list")) - (buffer-string) - (error "Error finding rules"))))))) + (snakemake--split-rules 'all))) (defun snakemake-rule-targets (&optional directory) "Return list of target rules for DIRECTORY's Snakefile." (snakemake-with-cache directory ("target-rules") - (cl-remove-if - (lambda (x) (string-match-p "\\`[0-9]+\\'" x)) - (split-string - (with-temp-buffer - (if (= 0 (snakemake-insert-output - "--nocolor" "--list-target-rules")) - (buffer-string) - (error "Error finding rule targets"))))))) + (snakemake--split-rules 'target))) (defun snakemake-file-targets (&optional directory) "Return list of output files for DIRECTORY's Snakefile. -- cgit v1.2.3