julia-repl: run an inferior Julia REPL in Emacs
This is a minor mode for interacting with a Julia REPL running inside Emacs. The
julia process is started in an ANSI terminal (
term), which allows text formatting and colors, and interaction with the help system and the debugger.
It is recommended that you use this minor mode with julia-mode.
Installation and loading
Please make sure you have at least Emacs 25. The
term code changed a bit since Emacs 24, and the package does not support that and earlier versions. For example, Ubuntu has had Emacs 25 since 18.04LTS.
Place this in your Emacs initialization files (eg
(add-to-list 'load-path path-to-julia-repl) (require 'julia-repl) (add-hook 'julia-mode-hook 'julia-repl-mode) ;; always use minor mode
If you want to use a Julia executable other than
julia in your path, see below.
If you are experiencing problems with Unicode characters in the Julia REPL, try setting the relevant coding/language environment, eg
M-x julia-repl, or
C-c C-z from a buffer in which the
julia-repl minor mode is active starts a new inferior Julia process. The keys below can be used to interact with this process.
||activate if there is a
||activate home project|
||send whole buffer to REPL (using include)|
||send whole buffer to REPL (directly)|
||send region (when applicable) or line to REPL|
||list methods of a function|
||change directory to that of the buffer|
||prompt for buffer name suffix|
||send whole buffer to REPL (using Revise.includet)|
||prompt for Julia executable|
||raise the REPL or create a new one|
||send line to REPL (without bracketed paste)|
All actions that send something to the REPL terminate with a newline, triggering evaluation. If you want to avoid sending a newline (eg maybe because you want to edit an expression), use prefix arguments (
C-u, currently both have the same effect). This of course does not apply to
All commands send code using bracketed paste. When Julia is waiting for input, control characters like
^[[200~ may show up in your buffer, this is innocuous. If you input takes a long time to evaluate, you can step through it line-by-line with
You can set environment variables directly from your
init.el in Emacs, eg
(setenv "JULIA_NUM_THREADS" "4")
Buffer-local inferior REPL and Julia executable
The minor mode allows the user to select a particular Julia executable and optionally a different inferior buffer for each source code buffer. This allows running two versions (eg stable and master) of Julia simultaneously, and/or running multiple inferior REPLs of the same Julia version. A typical use case is trying out something quickly, without changing the state of the current process.
julia-repl-executable-records to a list of keys and executables. For example,
(setq julia-repl-executable-records '((default "julia") ; in the executable path (master "~/src/julia-git/julia"))) ; compiled from the repository
provides two executables. The first entry is always the default (it can have any other key).
C-c C-v to select one of these (
julia-repl-prompt-executable). You can also set the value of
julia-repl-executable-key directly to a key in the
julia-repl-executable-records, eg using file variables, but make sure you select a correct value.
The name of the inferior buffer will reflect your choice: the default is
*julia* (indicator omitted), while the
master executable would map to
*julia-master*, and so on.
You can also set a suffix for the inferior buffer, if you want multiple ones in parallel. This can be a number, which will show up as
<number>, or a symbol, which appears as
It is recommended that you use
C-c C-s (
julia-repl-prompt-inferior-buffer-name-suffix), which prompts for a string by default. Prefix arguments modify it like this:
numerical prefixes select that integer: eg
C-3 C-c C-sset the suffix to
the negative prefix picks the next unused integer: eg
C- C-c C-ssets the suffix to
3are in use.
Switches to the
julia process can be provided in the global variable
julia-repl-switches, for example
(setq julia-repl-switches "-p 4")
julia-repl-prompt-switches will prompt for new switches, you can bind it to a key.
File local variables
If you are using the same settings for a specific file, consider using file variables. For example, if you use
add-file-local-variable to create a block at the end of the Julia source file similar to
# Local Variables: # julia-repl-executable-key: master # julia-repl-inferior-buffer-name-suffix: tests # julia-repl-switches: "-p 4" # End:
then the next time you open a REPL, it will have the name
*julia-master-tests*, and 4 worker processes.
julia-repl can use the terminal in different ways. The default is
ansi-term, which is included in Emacs. There is experimental support for
Some hints on interacting with
Note some keybindings for
C-x C-jswitches to line mode, where you can kill/yank, move around the buffer, use standard Emacs keybindings,
C-c C-kswitches back to char mode,
- for scrolling, use
See the help of
term for more.
Support for the vterm backend is WIP. In the long run it is hoped that it will replace
ansi-term as the default backend for this package, fixing many outstanding issues.
emacs-libvtermand make sure you have a working installation (eg
M-x vterm) should start a terminal
(julia-repl-set-terminal-backend 'vterm)in your config file after you load
julia-repl, but before you use it (and of course
vtermshould be loaded at some point). Switching terminal backends with already running Julia processes is not supported.
You may want to
(setq vterm-kill-buffer-on-exit nil)to prevent the buffers associated with terminated Julia processes being killed automatically. This allows you to retain output and see error messages if the process does not start.
Using the @edit macro
@edit macro can be called with
C-c C-e when the
julia-repl-mode minor mode is enabled. The behavior depends on the value of the
JULIA_EDITOR envoronment variable in the Julia session. The command
julia-repl-set-julia-editor is provided to conveniently control this from emacs.
To use "emacsclient" as a default in each Julia REPL you open in emacs, add the following code to your
if haskey(ENV, "INSIDE_EMACS") ENV["JULIA_EDITOR"] = "emacsclient" end
If you cannot edit your
startup.jl, you can configure the editor in each repl after starting it with:
(add-hook 'julia-repl-hook #'julia-repl-use-emacsclient)
Julia uses more colors than the ones supported by
term by default. To get the full range of colors, use eterm-256color, available from MELPA.
Note for Windows users
ansi-term is not supported on some (most?) Windows versions of Emacs. It has been confirmed to work with Emacs running in Cygwin. You can test whether your version works with
M-x ansi-term; if this errors then this package will not work for you.
Cygwin may require some rewriting of paths for
include to work. After loading this package, customize the rewrite rules as
(setq julia-repl-path-rewrite-rules julia-repl-cygwin-path-rewrite-rules)
as a reasonable default, or write custom rules for
See the issues.
Comparison to ESS
A well-known alternative is ESS, which also supports Julia. ESS is however based on
comint, which does not allow a fully functioning terminal and therefore does not support the Julia REPL modes (shell, Pkg, debuggers...) and features.
julia-repl is instead based on
term, and so gets all the features from Julia's native REPL for free.