Skip to content

Add Julia layer separate from ESS #10444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions layers/+lang/ess/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
("\\.do\\'" . STA-mode)
("\\.ado\\'" . STA-mode)
("\\.[Ss][Aa][Ss]\\'" . SAS-mode)
;; ("\\.jl\\'" . ess-julia-mode)
("\\.[Ss]t\\'" . S-transcript-mode)
("\\.Sout" . S-transcript-mode)
("\\.[Rr]out" . R-transcript-mode)
Expand All @@ -47,11 +46,10 @@
("\\.[Jj][Aa][Gg]\\'" . ess-jags-mode)
("\\.[Jj][Oo][Gg]\\'" . ess-jags-mode)
("\\.[Jj][Mm][Dd]\\'" . ess-jags-mode))
;; :commands (R stata julia SAS)
:commands (R stata SAS)
:commands (R stata julia SAS ess-julia-mode)
:init
(progn
;; (spacemacs/register-repl 'ess-site 'julia)
(spacemacs/register-repl 'ess-site 'julia)
(spacemacs/register-repl 'ess-site 'R)
(spacemacs/register-repl 'ess-site 'SAS)
(spacemacs/register-repl 'ess-site 'stata)
Expand Down
87 changes: 87 additions & 0 deletions layers/+lang/julia/README.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#+TITLE: julia layer

# The maximum height of the logo should be 200 pixels.
[[file:img/julia.png]]
# TOC links should be GitHub style anchors.

* Table of Contents :TOC_4_gh:noexport:
- [[#description][Description]]
- [[#features][Features:]]
- [[#install][Install]]
- [[#lsp][LSP]]
- [[#options][Options]]
- [[#key-bindings][Key bindings]]

* Description
This layer adds support for [[https://julialang.org][Julia]] to Spacemacs.

** Features:
- Syntax highlighting
- Repl support
- Linting
- Completion
- Jump-to-definition
- Documentation on hover

* Install
To use this configuration layer, add it to your =~/.spacemacs=. You will need to
add =julia= to the existing =dotspacemacs-configuration-layers= list in this
file.

** LSP
Warning: enabling the LSP functionality within this package can cause emacs to
hang for significant lengths of time when opening a Julia file. See tip below on
using PackageCompiler.jl to mitigate this issue.

This layer can be used with [[https://github.com/JuliaEditorSupport/LanguageServer.jl][=LanguageServer.jl=]] and emacs [[https://github.com/emacs-lsp/lsp-mode][=lsp-mode=]] to provide
richer, IDE-like capabilities. To use this layer with lsp, you must do the
following:

1. Add =lsp= to =dotspacemacs-configuration-layers=.
2. Install =LanguageServer.jl= by invoking =Pkg.add("LanguageServer") in the
Julia REPL.
3. Enable layer integration with lsp as described in section below.

=LanguageServer.jl= tends to have a very long startup time. In the worst case,
=lsp-mode= might give up on the language server before its started, but
regardless usage of =lsp-mode= with Julia can cause long delays when first
opening files. To mitigate this issue, you can try compiling =LanguageServer.jl=
ahead of time using [[https://github.com/JuliaLang/PackageCompiler.jl][=PackageCompiler.jl=]] this drastically reduces startup time
if successful.

* Options
While =julia-mode= is perfectly usable without configuration or other packages,
you can choose to replace the default functionality of using [[https://github.com/tpapp/julia-repl/][=julia-repl=]] as the
layer's interactive REPL with the ess REPL and other functionality that comes
with it. To do so, install this layer with:

#+BEGIN_SRC emacs-lisp
(setq-default
dotspacemacs-configuration-layers
'(
(julia :variables julia-mode-enable-ess t)))
#+END_SRC

This layer also includes experimental support for =lsp-mode=. To enable language
server functionality with this layer, follow [[#lsp][the instructions for installation]],
and then install this layer with:

#+BEGIN_SRC emacs-lisp
(setq-default
dotspacemacs-configuration-layers
'(
(julia :variables julia-mode-enable-lsp t)))
#+END_SRC

* Key bindings

| Key Binding | Description |
|-------------+------------------------------------------------------------|
| ~SPC m h h~ | Calls ~@doc~ macro on symbol under cursor. |
| ~SPC m e m~ | Expands macro under cursor. |
| ~SPC m w~ | Calls ~workspace()~ in Repl to give clean namespace. |
| ~SPC e l~ | Expands latex macro (e.g. =\delta=). |
| ~SPC m s b~ | Sends buffer to REPL. |
| ~SPC m s l~ | Sends line to REPL. |
| ~SPC m s r~ | Sends region to REPL. |
| ~SPC m r~ | Brings up Julia Repl (starts new one or focuses existing). |
22 changes: 22 additions & 0 deletions layers/+lang/julia/config.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
;;; config.el --- Python Layer Configuration File for Spacemacs
;;
;; Copyright (c) 2012-2018 Sylvain Benner & Contributors
;;
;; Author: Adam Beckmeyer <[email protected]>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3

;; variables

(spacemacs|define-jump-handlers julia-mode)

;; ess-mode is what the majority of people developing julia in emacs currently use
(defvar julia-mode-enable-ess nil
"If non-nil, enable ESS in julia-mode buffers and disable julia-repl.")

;; disabled by default since most won't have lsp-mode working
(defvar julia-mode-enable-lsp nil
"If non-nil, enable lsp-mode in julia-mode buffers.")
27 changes: 27 additions & 0 deletions layers/+lang/julia/funcs.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
;;; funcs.el --- Julia Layer functions File for Spacemacs
;;
;; Copyright (c) 2012-2018 Sylvain Benner & Contributors
;;
;; Author: Adam Beckmeyer <[email protected]>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3

(defun spacemacs//julia-setup-buffer ()
"Setup ESS and/or lsp for buffer depending on config."
(if (not julia-mode-enable-ess)
(spacemacs//julia-setup-repl))
(if julia-mode-enable-lsp
(spacemacs//julia-setup-lsp)))

(defun spacemacs//julia-setup-repl ()
"Start julia-repl minor mode and configure for buffer."
(julia-repl-mode))

(defun spacemacs//julia-setup-lsp ()
"Start lsp-mode and configure for buffer."
(if (configuration-layer/layer-used-p 'lsp)
(lsp-julia-enable)
(message "`lsp' layer is not installed, please add `lsp' layer to your dotfile.")))
Binary file added layers/+lang/julia/img/julia.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
83 changes: 83 additions & 0 deletions layers/+lang/julia/packages.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
;;; packages.el --- julia layer packages file for Spacemacs.
;;
;; Copyright (c) 2012-2018 Sylvain Benner & Contributors
;;
;; Author: Adam Beckmeyer <[email protected]>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3

(defconst julia-packages
'(
(julia-mode :location elpa)
(julia-repl :location elpa)
(lsp-julia :location (recipe :fetcher github
:repo "non-Jedi/lsp-julia"))
flycheck
company-lsp
))

(defun julia/init-julia-mode ()
(use-package julia-mode
:defer t
:init (progn
(add-hook 'julia-mode-hook #'spacemacs//julia-setup-buffer)
(if (and (configuration-layer/layer-used-p 'ess)
julia-mode-enable-ess)
(add-to-list 'auto-mode-alist
'("\\.jl\\'" . ess-julia-mode)))
(if (and (not (configuration-layer/layer-used-p 'ess))
julia-mode-enable-ess)
(message "`ess' layer is not installed. Please add `ess' layer to your dotfile.")))
:config (progn
(spacemacs/declare-prefix-for-mode 'julia-mode
"mh" "help")
(spacemacs/declare-prefix-for-mode 'julia-mode
"me" "eval")
(spacemacs/declare-prefix-for-mode 'julia-mode
"m=" "format")
(spacemacs/set-leader-keys-for-major-mode 'julia-mode
"el" 'julia-latexsub
"==" 'julia-indent-line))))

(defun julia/init-julia-repl ()
(use-package julia-repl
:defer t
:init (progn
(spacemacs/register-repl 'julia-repl 'julia-repl
"julia-repl"))
:config (progn
(spacemacs/declare-prefix-for-mode 'julia-repl-mode
"ms" "send")
(spacemacs/set-leader-keys-for-minor-mode
'julia-repl-mode
"'" 'julia-repl-edit
"hh" 'julia-repl-doc
"w" 'julia-repl-workspace
"em" 'julia-repl-macroexpand
"r" 'julia-repl
"si" 'julia-repl
"sb" 'julia-repl-send-buffer
"sl" 'julia-repl-send-line
"sr" 'julia-repl-send-region-or-line
"em" 'julia-repl-macroexpand))))

(defun julia/init-lsp-julia ()
(use-package lsp-julia
:config (progn
(push 'xref-find-definitions spacemacs-jump-handlers-julia-mode))
:commands lsp-julia-enable))

(defun julia/post-init-company-lsp ()
(spacemacs|add-company-backends
:backends company-lsp
:modes julia-mode
:variables
company-minimum-prefix-length 0
company-idle-delay 0.5))

(defun julia/post-init-flycheck ()
(spacemacs/enable-flycheck 'julia-mode))
;;; packages.el ends here
1 change: 0 additions & 1 deletion layers/+lang/major-modes/README.org
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ This layer adds a number of packages for less common languages and major modes.
- Android Logcat (not associated with any file types by default)
- Gentoo ebuilds
- Hoon
- Julia
- Kivy
- MATLAB
- QML
Expand Down
3 changes: 0 additions & 3 deletions layers/+lang/major-modes/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
arduino-mode
(ebuild-mode :location (recipe :fetcher github :repo "emacsmirror/ebuild-mode"))
(hoon-mode :location (recipe :fetcher github :repo "urbit/hoon-mode.el"))
julia-mode
kivy-mode
(logcat :location (recipe :fetcher github :repo "dcolascione/logcat-mode"))
matlab-mode
Expand Down Expand Up @@ -32,8 +31,6 @@

(defun major-modes/init-hoon-mode ())

(defun major-modes/init-julia-mode ())

(defun major-modes/init-logcat ()
(use-package logcat
:commands (logcat logcat-mode)))
Expand Down