Julia and Emacs - gher-uliege/Documentation GitHub Wiki

Install Emacs (tested with version 29.3) and julia

Configure Emacs

Copy the following in your ~/.emacs file (create the file if it does not already exist):

(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(package-initialize)

(require 'use-package)
(use-package company  :ensure t)
(use-package julia-mode  :ensure t  :mode "\\.jl$")
(use-package julia-repl  :ensure t)
(use-package eglot-jl  :ensure t)

(setq eglot-connect-timeout 6000)
(setq eglot-autoreconnect nil)
(setq ring-bell-function 'ignore)

(add-hook 'julia-mode-hook 'julia-repl-mode)
(add-hook 'julia-mode-hook 'company-mode)

(add-hook 'julia-mode-hook (lambda ()
                             (eglot-jl-init)
                             (eglot-ensure)))

[!NOTE]
Check the package information about the minimum Emacs version supported

Key bindings

julia-repl

  • C-c C-a: activate if there is a Project.toml in parent directories
  • C-u C-c C-a: activate home project
  • C-c C-b: send whole buffer to REPL (using include)
  • C-u C-c C-b: send whole buffer to REPL (directly)
  • C-c C-c: send region (when applicable) or line to REPL
  • C-c C-d: invoke @doc on symbol
  • C-c C-e: invoke @edit on region (when applicable) or line
  • C-c C-l: list methods of a function
  • C-c C-m: expand macro
  • C-c C-p: change directory to that of the buffer
  • C-c C-s: prompt for buffer name suffix
  • C-c C-t: send whole buffer to REPL (using Revise.includet)
  • C-c C-v: prompt for Julia executable
  • C-c C-z: raise the REPL or create a new one (or switch back from REPL – only in vterm backend)
  • C-RET: send line to REPL (without bracketed paste)

Eglot

  • M-.: go to definition
  • M-?: find references
  • C-c C-d: show documentation
  • M-x eglot-format: format buffer
  • M-x eglot-rename: rename symbol

References: