yeet
This commit is contained in:
109
.config/emacs/modules/lang/julia/README.org
Normal file
109
.config/emacs/modules/lang/julia/README.org
Normal file
@@ -0,0 +1,109 @@
|
||||
#+TITLE: lang/julia
|
||||
#+DATE: April 8, 2020
|
||||
#+SINCE: v1.3
|
||||
#+STARTUP: inlineimages nofold
|
||||
|
||||
* Table of Contents :TOC_3:noexport:
|
||||
- [[#description][Description]]
|
||||
- [[#module-flags][Module Flags]]
|
||||
- [[#plugins][Plugins]]
|
||||
- [[#prerequisites][Prerequisites]]
|
||||
- [[#language-server][Language Server]]
|
||||
- [[#lsp-julia][~lsp-julia~]]
|
||||
- [[#eglot-jl][~eglot-jl~]]
|
||||
- [[#features][Features]]
|
||||
- [[#language-server-1][Language Server]]
|
||||
- [[#configuration][Configuration]]
|
||||
- [[#change-the-default-environment-for-the-julia-language-server][Change the default environment for the Julia language server]]
|
||||
|
||||
* Description
|
||||
This module adds support for [[https://julialang.org/][the Julia language]] to Doom Emacs.
|
||||
|
||||
+ Syntax highlighting and latex symbols from ~julia-mode~
|
||||
+ REPL integration from ~julia-repl~
|
||||
+ Code completion and syntax checking, requires ~:tools lsp~ and ~+lsp~
|
||||
|
||||
** Module Flags
|
||||
+ =+lsp= Enable LSP server support.
|
||||
|
||||
** Plugins
|
||||
+ [[https://github.com/JuliaEditorSupport/julia-emacs/][julia-mode]]
|
||||
+ [[https://github.com/tpapp/julia-repl][julia-repl]]
|
||||
+ =+lsp= and =:tools lsp=
|
||||
+ [[https://github.com/non-jedi/lsp-julia][lsp-julia]]
|
||||
+ [[https://github.com/emacs-lsp/lsp-mode][lsp]]
|
||||
+ =+lsp= and =:tools lsp +eglot=
|
||||
+ [[https://github.com/non-jedi/eglot-jl][eglot-jl]]
|
||||
+ [[https://github.com/joaotavora/eglot][eglot]]
|
||||
|
||||
* Prerequisites
|
||||
This module requires =julia= and an language server if =+lsp= is enabled.
|
||||
|
||||
** Language Server
|
||||
~+lsp~ requires ~LanguageServer.jl~ and ~SymbolServer.jl~. The =lsp-julia= and
|
||||
=eglot-jl= packages both come bundled with their own versions of these servers,
|
||||
which is used by default. If you're happy with that, no further configuration is
|
||||
necessary.
|
||||
|
||||
However, to use your own installation you will need to install then configure
|
||||
them. To install them, execute these commands in a Julia REPL:
|
||||
|
||||
#+BEGIN_SRC julia
|
||||
using Pkg
|
||||
Pkg.add("LanguageServer")
|
||||
Pkg.add("SymbolServer")
|
||||
#+END_SRC
|
||||
|
||||
Then configure =lsp-julia= or =eglot-jl= depending on whether you have enabled
|
||||
=:tools lsp= or =:tools (lsp +eglot)=, respectively:
|
||||
|
||||
*** ~lsp-julia~
|
||||
To instruct =lsp-julia= not to use the built-in package:
|
||||
|
||||
#+BEGIN_SRC elisp
|
||||
;; ~/.doom.d/config.el
|
||||
(setq lsp-julia-package-dir nil)
|
||||
#+END_SRC
|
||||
|
||||
To find your installation of ~LanguageServer.jl~, ~eglot-jl~ needs to know the
|
||||
environment in which it is installed. This is set to v1.0 by default as it is
|
||||
the current LTS:
|
||||
|
||||
#+BEGIN_SRC elisp
|
||||
(setq lsp-julia-default-environment "~/.julia/environments/v1.0")
|
||||
#+END_SRC
|
||||
|
||||
*** ~eglot-jl~
|
||||
To find your installation of ~LanguageServer.jl~, ~eglot-jl~ must know the
|
||||
environment in which it is installed. This is set to v1.0 by default as it is
|
||||
the current LTS:
|
||||
|
||||
#+BEGIN_SRC elisp
|
||||
;; ~/.doom.d/config.el
|
||||
(setq eglot-jl-language-server-project "~/.julia/environments/v1.0")
|
||||
#+END_SRC
|
||||
|
||||
But to let ~eglot-jl~ use the environment bundled with it, set it to
|
||||
~eglot-jl-base~ instead:
|
||||
|
||||
#+BEGIN_SRC elisp
|
||||
;; ~/.doom.d/config.el
|
||||
(after! eglot-jl
|
||||
(setq eglot-jl-language-server-project eglot-jl-base))
|
||||
#+END_SRC
|
||||
|
||||
* Features
|
||||
** Language Server
|
||||
~+lsp~ adds code completion, syntax checking, formatting and other ~lsp-mode~ or
|
||||
~eglot~ features. It requires ~LanguageServer.jl~, the installation of which is
|
||||
described above.
|
||||
|
||||
* Configuration
|
||||
** Change the default environment for the Julia language server
|
||||
~lsp-julia~ requires a variable be set for the Julia environment. This is set to
|
||||
v1.0 by default as it is the current LTS.
|
||||
|
||||
#+BEGIN_SRC elisp
|
||||
;; ~/.doom.d/config.el
|
||||
(setq lsp-julia-default-environment "~/.julia/environments/v1.0")
|
||||
#+END_SRC
|
||||
21
.config/emacs/modules/lang/julia/autoload.el
Normal file
21
.config/emacs/modules/lang/julia/autoload.el
Normal file
@@ -0,0 +1,21 @@
|
||||
;;; lang/julia/autoload.el -*- lexical-binding: t; -*-
|
||||
|
||||
;; `ob-julia' needs this variable to be defined, but it's defined in
|
||||
;; `ess-custom', which won't be available if you're using :lang julia and not
|
||||
;; :lang ess.
|
||||
;;;###autoload (defvar inferior-julia-program-name (or (executable-find "julia-basic") "julia"))
|
||||
|
||||
;;;###autoload
|
||||
(defun +julia/open-repl ()
|
||||
"Run an inferior instance of `julia' inside Emacs."
|
||||
(interactive)
|
||||
(if (require 'julia-repl nil t)
|
||||
(prog1 (julia-repl)
|
||||
(julia-repl-use-emacsclient))
|
||||
(let ((buffer (get-buffer-create "*Julia*")))
|
||||
(unless (comint-check-proc "*Julia*")
|
||||
(apply #'make-comint-in-buffer "Julia" "*Julia*" julia-program julia-arguments))
|
||||
(pop-to-buffer buffer)
|
||||
(with-current-buffer buffer
|
||||
(inferior-julia-mode))
|
||||
buffer)))
|
||||
101
.config/emacs/modules/lang/julia/config.el
Normal file
101
.config/emacs/modules/lang/julia/config.el
Normal file
@@ -0,0 +1,101 @@
|
||||
;;; lang/julia/config.el -*- lexical-binding: t; -*-
|
||||
|
||||
(use-package! julia-mode
|
||||
:interpreter "julia"
|
||||
:config
|
||||
(set-repl-handler! 'julia-mode #'+julia/open-repl)
|
||||
|
||||
;; Borrow matlab.el's fontification of math operators. From
|
||||
;; <https://web.archive.org/web/20170326183805/https://ogbe.net/emacsconfig.html>
|
||||
(dolist (mode '(julia-mode ess-julia-mode))
|
||||
(font-lock-add-keywords
|
||||
mode
|
||||
`((,(let ((OR "\\|"))
|
||||
(concat "\\(" ; stolen `matlab.el' operators first
|
||||
;; `:` defines a symbol in Julia and must not be highlighted
|
||||
;; as an operator. The only operators that start with `:` are
|
||||
;; `:<` and `::`. This must be defined before `<`.
|
||||
"[:<]:" OR
|
||||
"[<>]=?" OR
|
||||
"\\.[/*^']" OR
|
||||
"===" OR
|
||||
"==" OR
|
||||
"=>" OR
|
||||
"\\<xor\\>" OR
|
||||
"[-+*\\/^&|$]=?" OR ; this has to come before next (updating operators)
|
||||
"[-^&|*+\\/~]" OR
|
||||
;; Julia variables and names can have `!`. Thus, `!` must be
|
||||
;; highlighted as a single operator only in some
|
||||
;; circumstances. However, full support can only be
|
||||
;; implemented by a full parser. Thus, here, we will handle
|
||||
;; only the simple cases.
|
||||
"[[:space:]]!=?=?" OR "^!=?=?" OR
|
||||
;; The other math operators that starts with `!`.
|
||||
;; more extra julia operators follow
|
||||
"[%$]" OR
|
||||
;; bitwise operators
|
||||
">>>" OR ">>" OR "<<" OR
|
||||
">>>=" OR ">>" OR "<<" OR
|
||||
"\\)"))
|
||||
1 font-lock-type-face)))))
|
||||
|
||||
|
||||
(use-package! julia-repl
|
||||
:preface (defvar +julia-repl-start-hook nil)
|
||||
:hook (julia-mode . julia-repl-mode)
|
||||
:hook (+julia-repl-start . +julia-override-repl-escape-char-h)
|
||||
:hook (+julia-repl-start . julia-repl-use-emacsclient)
|
||||
:config
|
||||
(set-popup-rule! "^\\*julia.*\\*$" :ttl nil)
|
||||
|
||||
(when (featurep! :ui workspaces)
|
||||
(defadvice! +julia--namespace-repl-buffer-to-workspace-a (&optional executable-key suffix)
|
||||
"Name for a Julia REPL inferior buffer. Uses workspace name for doom emacs"
|
||||
:override #'julia-repl--inferior-buffer-name
|
||||
(concat julia-repl-inferior-buffer-name-base ":" (+workspace-current-name))))
|
||||
|
||||
(defadvice! +julia--run-start-hook-a (inferior-buffer)
|
||||
"Run `+julia-repl-start-hook' before displaying the REPL."
|
||||
:after #'julia-repl--setup-term
|
||||
(with-current-buffer inferior-buffer
|
||||
(run-hooks '+julia-repl-start-hook)))
|
||||
|
||||
(defun +julia-override-repl-escape-char-h ()
|
||||
"Use C-c instead of C-x for escaping."
|
||||
(term-set-escape-char ?\C-c)))
|
||||
|
||||
|
||||
(when (featurep! +lsp)
|
||||
(add-hook 'julia-mode-local-vars-hook #'lsp!))
|
||||
|
||||
|
||||
(use-package! lsp-julia
|
||||
:when (featurep! +lsp)
|
||||
:unless (featurep! :tools lsp +eglot)
|
||||
:after lsp-mode
|
||||
:preface (setq lsp-julia-default-environment nil)
|
||||
:init
|
||||
;; If no environment is set, then auto-detect one in ~/.julia/environments/,
|
||||
;; falling back to `lsp-julia-default-environment's default.
|
||||
(unless lsp-julia-default-environment
|
||||
(setq lsp-julia-default-environment
|
||||
(or (car (last (doom-glob "~/.julia/environments/v*")))
|
||||
"~/.julia/environments/v1.0")))
|
||||
:config
|
||||
;; See non-Jedi/lsp-julia#35
|
||||
(setq-hook! 'julia-mode-hook
|
||||
lsp-enable-folding t
|
||||
lsp-folding-range-limit 100))
|
||||
|
||||
|
||||
(use-package! eglot-jl
|
||||
:when (featurep! +lsp)
|
||||
:when (featurep! :tools lsp +eglot)
|
||||
:after eglot
|
||||
:preface
|
||||
;; Prevent auto-install of LanguageServer.jl
|
||||
(setq eglot-jl-language-server-project "~/.julia/environments/v1.0")
|
||||
:init
|
||||
;; Prevent timeout while installing LanguageServer.jl
|
||||
(setq-hook! 'julia-mode-hook eglot-connect-timeout (max eglot-connect-timeout 60))
|
||||
:config (eglot-jl-init))
|
||||
19
.config/emacs/modules/lang/julia/doctor.el
Normal file
19
.config/emacs/modules/lang/julia/doctor.el
Normal file
@@ -0,0 +1,19 @@
|
||||
;;; lang/julia/doctor.el -*- lexical-binding: t; -*-
|
||||
|
||||
(assert! (or (not (featurep! +lsp))
|
||||
(featurep! :tools lsp))
|
||||
"This module requires (:tools lsp)")
|
||||
|
||||
(when (featurep! +lsp)
|
||||
(let ((args
|
||||
(cond ((require 'eglot-jl nil t)
|
||||
`(,eglot-jl-julia-command
|
||||
,(concat "--project=" eglot-jl-language-server-project)
|
||||
,@eglot-jl-julia-flags
|
||||
"-e" "empty!(LOAD_PATH); push!(LOAD_PATH, \"@\"); using LanguageServer, SymbolServer"))
|
||||
((require 'lsp-julia nil t)
|
||||
`(,lsp-julia-command
|
||||
,@lsp-julia-flags
|
||||
"-e" "using LanguageServer, SymbolServer")))))
|
||||
(unless (zerop (car (apply #'doom-call-process args)))
|
||||
(warn! "Couldn't find LanguageServer.jl and/or SymbolServer.jl"))))
|
||||
10
.config/emacs/modules/lang/julia/packages.el
Normal file
10
.config/emacs/modules/lang/julia/packages.el
Normal file
@@ -0,0 +1,10 @@
|
||||
;; -*- no-byte-compile: t; -*-
|
||||
;;; lang/julia/packages.el
|
||||
|
||||
(package! julia-mode :pin "47f43f7d839019cac3ba6559d93b29487ca118cb")
|
||||
(package! julia-repl :pin "e90b1ed2cc806262b0ee772dcc88f8da693d9210")
|
||||
|
||||
(when (featurep! +lsp)
|
||||
(if (featurep! :tools lsp +eglot)
|
||||
(package! eglot-jl :pin "2e35cf9768d97a0429a72deddbe30d6d7722d454")
|
||||
(package! lsp-julia :pin "d6688bb131ff4a5a0201f6d3826ef0b018265389")))
|
||||
Reference in New Issue
Block a user