From 22f51cf70adc423f19f292b22a9960f57cd1f2de Mon Sep 17 00:00:00 2001 From: Guido Kraemer Date: Sun, 8 Sep 2019 11:52:04 +0200 Subject: [PATCH] Update julia-layer --- CHANGELOG.develop | 1 + layers/+lang/julia/README.org | 63 +++++++++++++++++++------------- layers/+lang/julia/funcs.el | 18 ++++++++++ layers/+lang/julia/packages.el | 66 +++++++++++++++++++++++----------- 4 files changed, 103 insertions(+), 45 deletions(-) diff --git a/CHANGELOG.develop b/CHANGELOG.develop index 3f644b477..1e4f39f33 100644 --- a/CHANGELOG.develop +++ b/CHANGELOG.develop @@ -1474,6 +1474,7 @@ Other: - Refactor keybindings for =ess-mode= and =ess-julia-mode= (thanks to Guido Kraemer and bmag) - Added Julia repl to =spacemacs/ess-start-repl= (thanks to Guido Kraemer) +- Optimize Julia layer to provide better dev experience (thanks to Guido Kraemer) - Reorganize key bindings (refer to =ESS= section in Breaking Changes above) - Added =xref= integration (thanks to Guido Kraemer) - Update ess-disable-underscore-assign for ESS 18.10 (thanks to Leonard Lausen) diff --git a/layers/+lang/julia/README.org b/layers/+lang/julia/README.org index 0516abd3d..5dd1c812f 100644 --- a/layers/+lang/julia/README.org +++ b/layers/+lang/julia/README.org @@ -29,30 +29,17 @@ 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. +2. =LanguageServer.jl= should be configured automatically, if not, see the documentation of =lsp-julia=. 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: - -#+BEGIN_SRC julia - julia> Pkg.add("PackageCompiler") - julia> using PackageCompiler - julia> compile_package("LanguageServer") -#+END_SRC +opening files. * Options While =julia-mode= is perfectly usable without configuration or other packages, @@ -83,13 +70,39 @@ using this layer with Julia 1.0, =julia-mode-enable-lsp= should be set to =nil=. * 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). | +| Key binding | Description | +|-------------+----------------------------------------------------------------------------------------| +| ~TAB~ | Expands latex macro (e.g. =\delta=). | +| ~SPC m l~ | Expands latex macro (e.g. =\delta=). | +|-------------+----------------------------------------------------------------------------------------| +| ~SPC m = =~ | Indent line | +| ~SPC m = d~ | Deindent line | +| ~SPC m = q~ | Indent Sexp | +|-------------+----------------------------------------------------------------------------------------| +| ~SPC m '~ | Brings up Julia Repl (starts new one or focuses existing). | +| ~SPC m r~ | Brings up Julia Repl (starts new one or focuses existing). | +| ~SPC m h h~ | Calls ~@doc~ macro on symbol under cursor. | +|-------------+----------------------------------------------------------------------------------------| +| ~SPC m s a~ | Activate the project of the current buffer (call with prefix to activate home project) | +| ~SPC m s d~ | ~cd~ into the buffer directory | +| ~SPC m s i~ | Brings up Julia Repl (starts new one or focuses existing). | +| ~SPC m s b~ | Sends buffer to REPL. | +| ~SPC m s t~ | Sends buffer to REPL via ~Revise.includet~. | +| ~SPC m s l~ | Sends line to REPL. | +| ~SPC m s s~ | Sends line to REPL. | +| ~SPC m s r~ | Sends region or line to REPL. | +| ~SPC m s m~ | Call ~@macroexpand~ on an expression | +| ~SPC m s e~ | Call ~@edit~ on an expression | +| ~SPC m s v~ | Prompt and set a Julia REPL inferior buffer name for the current buffer | +|-------------+----------------------------------------------------------------------------------------| +| ~SPC m e a~ | Activate the project of the current buffer (call with prefix to activate home project) | +| ~SPC m e d~ | ~cd~ into the buffer directory | +| ~SPC m e i~ | Brings up Julia Repl (starts new one or focuses existing). | +| ~SPC m e b~ | Sends buffer to REPL. | +| ~SPC m e t~ | Sends buffer to REPL via ~Revise.includet~. | +| ~SPC m e l~ | Sends line to REPL. | +| ~SPC m e s~ | Sends line to REPL. | +| ~SPC m e r~ | Sends region or line to REPL. | +| ~SPC m e m~ | Call ~@macroexpand~ on an expression | +| ~SPC m e e~ | Call ~@edit~ on an expression | +| ~SPC m e v~ | Prompt and set a Julia REPL inferior buffer name for the current buffer | diff --git a/layers/+lang/julia/funcs.el b/layers/+lang/julia/funcs.el index 5efbcde89..e033b8802 100644 --- a/layers/+lang/julia/funcs.el +++ b/layers/+lang/julia/funcs.el @@ -9,6 +9,24 @@ ;; ;;; License: GPLv3 +(defun spacemacs//julia-hash-to-alist (hash) + "Convert a `hash-table' to an `alist' for the use in a helm buffer." + (let (res) + (maphash (lambda (key value) + (push `(,key . ,value) res)) + hash) + res)) + +(when (configuration-layer/layer-used-p 'helm) + (defun spacemacs//julia-helm-math-insert() + "Insert a utf8 symbol from `julia-latexsubs'" + (interactive) + (helm :sources (helm-build-sync-source "test" + :candidates (spacemacs//julia-hash-to-alist julia-latexsubs) + :fuzzy-match t + :action (lambda (candidate) (insert candidate))) + :buffer "*helm julia latex insert*"))) + (defun spacemacs//julia-setup-buffer () "Setup ESS and/or lsp for buffer depending on config." (when (not julia-mode-enable-ess) diff --git a/layers/+lang/julia/packages.el b/layers/+lang/julia/packages.el index 6a476aef3..5c82375bf 100644 --- a/layers/+lang/julia/packages.el +++ b/layers/+lang/julia/packages.el @@ -14,7 +14,10 @@ (julia-mode :location elpa) (julia-repl :location elpa) (lsp-julia :location (recipe :fetcher github - :repo "non-Jedi/lsp-julia")) + :repo "gdkrmr/lsp-julia" + :files ("*.el" + "README.org" + "languageserver"))) flycheck company-lsp evil-surround @@ -33,37 +36,60 @@ 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/declare-prefix-for-mode 'julia-mode "m=" "format") (spacemacs/set-leader-keys-for-major-mode 'julia-mode - "el" 'julia-latexsub - "==" 'julia-indent-line)))) + "l" 'julia-latexsub-or-indent + "==" 'julia-indent-line + "=d" 'julia-manual-deindent + "=q" 'prog-indent-sexp) + + (when (configuration-layer/package-used-p 'helm) + (spacemacs/declare-prefix-for-mode 'julia-mode "mi" "insert") + (spacemacs/set-leader-keys-for-minor-mode 'julia-mode + "ii" 'spacemacs//julia-helm-math-insert) + ) + + ))) (defun julia/init-julia-repl () (use-package julia-repl :defer t :init (progn - (spacemacs/register-repl 'julia-repl 'julia-repl - "julia-repl")) + (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 + (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 "ms" "send") + (spacemacs/set-leader-keys-for-minor-mode 'julia-repl-mode + "'" 'julia-repl + "r" 'julia-repl "hh" 'julia-repl-doc - "w" 'julia-repl-workspace - "em" 'julia-repl-macroexpand - "r" 'julia-repl + + "sa" 'julia-repl-activate-parent + "sd" 'julia-repl-cd "si" 'julia-repl "sb" 'julia-repl-send-buffer + "st" 'julia-repl-includet-buffer "sl" 'julia-repl-send-line + "ss" 'julia-repl-send-line "sr" 'julia-repl-send-region-or-line - "em" 'julia-repl-macroexpand)))) + "sm" 'julia-repl-macroexpand + "se" 'julia-repl-edit + "sv" 'julia-repl-prompt-set-inferior-buffer-name-suffix + + "ea" 'julia-repl-activate-parent + "ed" 'julia-repl-cd + "eb" 'julia-repl-send-buffer + "et" 'julia-repl-includet-buffer + "el" 'julia-repl-send-line + "es" 'julia-repl-send-line + "er" 'julia-repl-send-region-or-line + "em" 'julia-repl-macroexpand + "ee" 'julia-repl-edit + "ev" 'julia-repl-prompt-set-inferior-buffer-name-suffix + + )))) + (defun julia/post-init-evil-surround () (with-eval-after-load 'evil-surround