diff options
author | Kyle Meyer <kyle@kyleam.com> | 2017-04-01 01:11:31 -0400 |
---|---|---|
committer | Kyle Meyer <kyle@kyleam.com> | 2017-04-01 01:20:56 -0400 |
commit | 83323d47463a5c0597c9eef4f22d2d833314bd54 (patch) | |
tree | 296180beed949b9bb9019c86b0407e57e9c0ef07 | |
parent | 43f8536aee86d52e52cfa4cfc6d2e00e2ca4b04c (diff) | |
download | snakemake-mode-83323d47463a5c0597c9eef4f22d2d833314bd54.tar.gz |
Add a user option to always send commands to a terminal
The primary motivation behind having a terminal interface is that it
works better with tools like Guix because the environment persists
across calls. And the primary reason one would want to use Guix with
Snakemake is so that the dependencies to a workflow/analysis can be
specified and tightly controlled.
However, the user can accidentally step outside of this controlled
environment by running a build command before running
snakemake-term-start. The changes from this mistake can be hard to
confidently reverse and may require a wide removal of output files.
If a user wanted to make sure to only use the Guix-controlled
environment, one approach would be to remove the Snakemake executable
from the environment in which Emacs is started (most likely the
default environment), exposing it only in the workflow environments.
The problem with this is that snakemake.el requires the Snakemake
executable for things like generating lists of targets. Also, it
would be a global change, but a user could reasonably want to control
dependencies with Guix for one project but go through the compile
interface for another.
Add a user option that allows the user to avoid the compile interface
at a global or per-project level.
-rw-r--r-- | snakemake.el | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/snakemake.el b/snakemake.el index 278afcd..fb8d59d 100644 --- a/snakemake.el +++ b/snakemake.el @@ -121,6 +121,21 @@ (string :tag "Program")) :package-version '(snakemake-mode . "0.4.0")) +(defcustom snakemake-always-use-term nil + "Whether commands should be sent to the terminal only. + +When nil, commands are sent to the terminal if there is an active +terminal for the current Snakefile directory. If there isn't an +active terminal, commands are executed through `compile'. + +When this variable is non-nil, always try to send the command to +the terminal. If no terminal is found, the command will be +aborted with a message telling you to first run +`\\[snakemake-term-start]'." + :type 'boolean + :safe #'booleanp + :package-version '(snakemake-mode . "1.2.0")) + (defcustom snakemake-root-dir-function nil "Function used to find root directory of the current \"project\". This function will be called with no arguments and should return @@ -581,6 +596,9 @@ Snakemake-graph mode is a minor mode that provides a key, "Return the terminal process of the current directory." (get-process (concat "*" (snakemake-term--name) "*"))) +(defun snakemake-term-use-p () + (or snakemake-always-use-term (snakemake-term-process))) + ;;;###autoload (defun snakemake-term-start () "Start a terminal session for the current Snakefile directory. @@ -629,7 +647,7 @@ If a terminal is associated with the current Snakefile directory, send the command there. Otherwise, run the command with `compile'." (let ((default-directory (snakemake-snakefile-directory))) - (funcall (if (snakemake-term-process) + (funcall (if (snakemake-term-use-p) #'snakemake-term-build-targets #'snakemake-compile-targets) targets @@ -686,7 +704,7 @@ $ snakemake [ARGS] -- <targets>" (list "")) args)) (default-directory (snakemake-snakefile-directory))) - (if (snakemake-term-process) + (if (snakemake-term-use-p) (snakemake-term-send (read-from-minibuffer "Command to send to terminal: " cmd)) (let ((compile-command cmd) |