diff --git a/README.md b/README.md index 54134b4..658dd94 100644 --- a/README.md +++ b/README.md @@ -167,6 +167,15 @@ If you cannot edit your `startup.jl`, you can configure the editor in each repl ```elisp (add-hook 'julia-repl-hook #'julia-repl-use-emacsclient) ``` +## Passing command line arguments, i.e. `push!` to `ARGS` + +If you need to pass some command line arguments, you can raise the REPL with `C-u C-c C-z` and you will be promted to write you command line arguments. They will be sent to the REPL in a `push!(ARGS,[...])` call. + +This is equivalent of running in the terminal + +``` +$ julia -i .jl arg1 args2 ... +``` ## More colors diff --git a/julia-repl.el b/julia-repl.el index fb99ae2..f50bf37 100644 --- a/julia-repl.el +++ b/julia-repl.el @@ -642,19 +642,30 @@ Valid keys are the first items in ‘julia-repl-executable-records’." (setq-local julia-repl--inferior-buffer-suffix suffix)) inferior-buffer))))) +(defun julia-repl--push-args (args) + (s-prepend + (s-prepend "push!(ARGS,\"" + (s-join"\",\"" (s-split " " args t))) "\")" )) + +(defun julia-repl--ask-for-args () + (let ((str (read-from-minibuffer "Command line args: "))) + (if (s-present? str) + (julia-repl--send-string (julia-repl--push-args str))))) + ;;;###autoload -(defun julia-repl () +(defun julia-repl (args) "Raise the Julia REPL inferior buffer, creating one if it does not exist. This is the standard entry point for using this package." - (interactive) + (interactive "P") (let ((script-buffer (current-buffer)) (inferior-buffer (julia-repl-inferior-buffer))) (with-current-buffer inferior-buffer (setq julia-repl--script-buffer script-buffer)) (if julia-repl-pop-to-buffer (pop-to-buffer inferior-buffer) - (switch-to-buffer inferior-buffer)))) + (switch-to-buffer inferior-buffer))) + (if args (julia-repl--ask-for-args))) (defun julia-repl--switch-back () "Switch to the buffer that was active before last call to `julia-repl'."