summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS10
-rw-r--r--snakemake.el53
2 files changed, 63 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index f29cadb..5198ccd 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,15 @@
NEWS -- history of user-visible changes -*- mode: org; -*-
+* v0.5.0 (unreleased)
+
+** New features
+
+- New command ~snakemake-graph-this-file~ displays the graph for the
+ first rule of the current file. Similar functionality is available
+ from ~snakemake-graph~, which supports graphing any target in the
+ file, but you may find the new command useful if your workflow
+ involves frequently using Snakemake's ~--snakefile~ option.
+
* v0.4.0
** New features
diff --git a/snakemake.el b/snakemake.el
index 7a01613..6f9059b 100644
--- a/snakemake.el
+++ b/snakemake.el
@@ -421,6 +421,59 @@ $ snakemake --{dag,rulegraph} -- RULES | display"
(setq snakemake-graph-rule (mapconcat #'file-name-nondirectory rules "-"))
(pop-to-buffer (current-buffer)))))
+;;;###autoload
+(defun snakemake-graph-this-file (&optional rule-graph directory)
+ "Display graph of DAG for the first rule of the current file.
+
+The graph will be displayed with `image-mode'. From this buffer,
+you can call \\<snakemake-graph-mode-map>\\[snakemake-graph-save] \
+to save the graph.
+
+If RULE-GRAPH is non-nil, pass --rulegraph instead of --dag to
+the Snakemake call. Snakemake is called from DIRECTORY or, if
+DIRECTORY is nil, from the current file's directory.
+
+Interactively, \\[universal-argument] indicates to use \
+--rulegraph instead of --dag,
+whereas \\[universal-argument] \\[universal-argument] signals to \
+prompt user for a directory from which
+to call Snakemake. With any other non-nil prefix value, both of the
+above actions are performed.
+
+$ snakemake -s <current file> --{dag,rulegraph} | display"
+ (interactive
+ (let ((read-dir (lambda ()
+ (read-directory-name "Call from directory: "
+ nil nil t))))
+ (cond ((equal current-prefix-arg '(4))
+ (list t nil))
+ ((equal current-prefix-arg '(16))
+ (list nil (funcall read-dir)))
+ (current-prefix-arg
+ (list t (funcall read-dir)))
+ (t
+ (list nil nil)))))
+ (unless (derived-mode-p 'snakemake-mode)
+ (user-error "Current buffer is not in Snakemake mode"))
+ (let* ((file (or (buffer-file-name (buffer-base-buffer))
+ (user-error "Buffer is not visiting a file")))
+ (dir (or directory (file-name-directory file)))
+ ret-val)
+ (with-current-buffer (get-buffer-create "*Snakemake graph*")
+ (setq default-directory dir)
+ (let ((inhibit-read-only t))
+ (erase-buffer)
+ (setq ret-val (call-process snakemake-program nil t nil
+ (if rule-graph "--rulegraph" "--dag")
+ "--snakefile" file)))
+ (if (= 0 ret-val)
+ (progn (image-mode)
+ (snakemake-graph-mode)
+ (setq snakemake-graph-rule file))
+ (goto-char (point-min))
+ (insert (format "Error in snakemake call from %s:\n\n" dir)))
+ (pop-to-buffer (current-buffer)))))
+
(defun snakemake-graph-save ()
"Save graph in current buffer to file.
The graph will be processed by `snakemake-dot-program'. The