From 444c8efc564d7de6f852c44e79fb7e5b19400af3 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Sun, 30 Apr 2017 16:52:59 -0400 Subject: 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. --- snakemake.el | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'snakemake.el') 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 --{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. -- cgit v1.2.3