From 8d81c74ab650bd4dad11edce4b164cf5c9b91cd0 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Sun, 30 Apr 2017 16:52:59 -0400 Subject: snakemake-graph-save: Return the name of the output file This will allow the graphing commands to save and display the graph when the user is running an Emacs that was not built with ImageMagick support. When the user provides all-blank input or does not confirm an overwrite, raise a user error so that the caller doesn't have to check for a nil return value. --- snakemake.el | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'snakemake.el') diff --git a/snakemake.el b/snakemake.el index fb8d59d..830da96 100644 --- a/snakemake.el +++ b/snakemake.el @@ -530,23 +530,31 @@ $ snakemake -s --{dag,rulegraph} | display" (defun snakemake-graph-save () "Save graph in current buffer to file. + The graph will be processed by `snakemake-dot-program'. The default extension of the output file is `snakemake-graph-default-extension', but you can enter any -extension that the dot program supports." +extension that the dot program supports. + +Return the name of the output file." (interactive) (unless snakemake-graph-id (user-error "Not in Snakemake graph buffer")) (let ((file (read-file-name "To file: " nil nil nil (concat snakemake-graph-id snakemake-graph-default-extension)))) - (unless (or (string-match-p "\\`\\s-*\\'" file) - (and (file-exists-p file) - (not (y-or-n-p - (concat file " already exists. Overwrite?"))))) + (cond + ((string-match-p "\\`\\s-*\\'" file) + (user-error "No output file specified")) + ((and (file-exists-p file) + (not (y-or-n-p + (concat file " already exists. Overwrite?")))) + (user-error "Aborted")) + (t (call-process-region (point-min) (point-max) snakemake-dot-program nil (list :file file) nil - "-T" (file-name-extension file))))) + "-T" (file-name-extension file)) + file)))) (defvar snakemake-graph-mode-map (let ((map (make-sparse-keymap))) -- cgit v1.2.3