aboutsummaryrefslogtreecommitdiff
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:33:48 -0400
commit8d81c74ab650bd4dad11edce4b164cf5c9b91cd0 (patch)
treee504d11c1a1c7ec75a7786c294f99a875160d86c
parent15803162483e635f3e22b2efea33ccad725e0535 (diff)
downloadsnakemake-mode-8d81c74ab650bd4dad11edce4b164cf5c9b91cd0.tar.gz
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.
-rw-r--r--snakemake.el20
1 files changed, 14 insertions, 6 deletions
diff --git a/snakemake.el b/snakemake.el
index fb8d59d..830da96 100644
--- a/snakemake.el
+++ b/snakemake.el
@@ -530,23 +530,31 @@ $ snakemake -s <current file> --{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)))