summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2017-04-30 16:52:59 -0400
committerKyle Meyer <kyle@kyleam.com>2017-04-30 17:35:16 -0400
commit444c8efc564d7de6f852c44e79fb7e5b19400af3 (patch)
tree4965dee1a6c63e6174365f45ad230b69d09599d3
parent8d81c74ab650bd4dad11edce4b164cf5c9b91cd0 (diff)
downloadsnakemake-mode-444c8efc564d7de6f852c44e79fb7e5b19400af3.tar.gz
graphs: Display file if Emacs lacks ImageMagick support
To display the graph, snakemake-graph and snakemake-graph-this-file call image-mode in a buffer with the snakemake graph output. This is convenient because it works without using an output file, but displaying the graph fails if Emacs was compiled without ImageMagick support. When Emacs doesn't have ImageMagick support, fall back to saving the file and then displaying it.
-rw-r--r--snakemake.el20
1 files changed, 13 insertions, 7 deletions
diff --git a/snakemake.el b/snakemake.el
index 830da96..f8f636b 100644
--- a/snakemake.el
+++ b/snakemake.el
@@ -444,6 +444,13 @@ targets."
(defvar-local snakemake-graph-id nil)
+(defun snakemake-graph--display ()
+ (require 'image)
+ (if (not (image-type-available-p 'imagemagick))
+ (find-file (snakemake-graph-save))
+ (image-mode)
+ (pop-to-buffer (current-buffer))))
+
;;;###autoload
(defun snakemake-graph (rules &optional rule-graph)
"Display graph for DAG of RULES.
@@ -470,10 +477,9 @@ $ snakemake --{dag,rulegraph} -- RULES | display"
(apply #'call-process snakemake-program nil t nil
(if rule-graph "--rulegraph" "--dag")
rules))
- (image-mode)
(snakemake-graph-mode)
(setq snakemake-graph-id (mapconcat #'file-name-nondirectory rules "-"))
- (pop-to-buffer (current-buffer)))))
+ (snakemake-graph--display))))
;;;###autoload
(defun snakemake-graph-this-file (&optional rule-graph directory)
@@ -521,12 +527,12 @@ $ snakemake -s <current file> --{dag,rulegraph} | display"
(if rule-graph "--rulegraph" "--dag")
"--snakefile" file)))
(if (zerop ret-val)
- (progn (image-mode)
- (snakemake-graph-mode)
- (setq snakemake-graph-id file))
+ (progn (snakemake-graph-mode)
+ (setq snakemake-graph-id file)
+ (snakemake-graph--display))
(goto-char (point-min))
- (insert (format "Error in snakemake call from %s:\n\n" dir)))
- (pop-to-buffer (current-buffer)))))
+ (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.