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 it. For example, Ubuntu users can get the latest Emacs snapshot here.
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.
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.
||send region (when applicable) or line to REPL|
||send whole buffer to REPL (using include)|
||send whole buffer to REPL (directly)|
||raise the REPL or create a new one|
||send line to REPL (without bracketed paste)|
||change directory to that of the buffer|
||activate if there is a
||activate home project|
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.
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.
See the issues.
Comparison to ESS
A well-known alternative is ESS, which also supports Julia.
julia-repl was written because I could not use Gallium from ESS, which is based on
comint, and thus does not allow a fully functioning terminal. Also, relying on the interactive features of the Julia REPL implies that I would not need to change this library to incorporate extensions and changes that rely on the terminal.