2017-08-28 15:33:55 +00:00
#+TITLE : Lua layer
2015-06-10 16:44:30 +00:00
2019-05-07 08:53:56 +00:00
#+TAGS : general|layer|multi-paradigm|programming
2019-05-05 17:26:40 +00:00
2015-06-10 16:44:30 +00:00
[[file:img/lua.gif ]]
2019-05-07 20:05:06 +00:00
* Table of Contents :TOC_5_gh:noexport:
2017-05-22 14:16:12 +00:00
- [[#description ][Description ]]
- [[#features ][Features: ]]
- [[#install ][Install ]]
2019-11-12 03:29:50 +00:00
- [[#layer ][Layer ]]
- [[#backends ][Backends ]]
- [[#lsp ][LSP ]]
2019-11-30 23:39:37 +00:00
- [[#lua-mode ][Lua mode ]]
2018-12-05 03:03:03 +00:00
- [[#key-bindings ][Key bindings ]]
2019-11-12 03:29:50 +00:00
- [[#lsp-1 ][LSP ]]
2017-05-22 14:16:12 +00:00
- [[#commands ][Commands ]]
2015-06-10 16:44:30 +00:00
* Description
This layer adds support for editing Lua.
2015-06-10 21:16:01 +00:00
** Features:
2015-06-10 16:44:30 +00:00
- Editing lua files using [[https://github.com/immerrr/lua-mode ][lua-mode ]]
2020-04-02 16:41:28 +00:00
- Code-Completion with =lsp= or =company-lua=
2015-06-10 16:44:30 +00:00
- Sending code to a lua REPL
2016-02-17 14:01:10 +00:00
- Code linting using [[https://github.com/mpeterv/luacheck ][Luacheck ]]
2019-11-30 23:39:37 +00:00
- Cross references (definitions, references, rename...)
2015-06-10 16:44:30 +00:00
* Install
2019-11-12 03:29:50 +00:00
** Layer
2016-01-06 05:21:55 +00:00
To use this configuration layer, add it to your =~/.spacemacs= . You will need to
add =lua= to the existing =dotspacemacs-configuration-layers= list in this
file.
2015-06-10 16:44:30 +00:00
2016-02-17 14:01:10 +00:00
In order to enable code linting, install [[https://github.com/mpeterv/luacheck ][Luacheck ]].
2015-06-10 16:44:30 +00:00
2019-11-12 03:29:50 +00:00
** Backends
Supported backends are:
2021-01-20 22:20:32 +00:00
- =lsp-emmy-lua= using emmy LSP server
- =lsp-lua-language-server= using lua-language-server.
- =lsp-lua-lsp= using lua-lsp.
2019-11-30 23:39:37 +00:00
- =lua-mode= using emacs package
2019-11-12 03:29:50 +00:00
*** LSP
2021-01-20 22:20:32 +00:00
LSP support is provided via the [[file:../../+tools/lsp/README.org ][LSP layer ]], currently [[https://github.com/EmmyLua/EmmyLua-LanguageServer ][EmmyLua ]], [[https://github.com/sumneko/lua-language-server ][lua-language-server ]] and [[https://github.com/Alloyed/lua-lsp ][lua-lsp ]] are supported.
2019-11-12 03:29:50 +00:00
2021-01-20 22:20:32 +00:00
To use the =lsp-emmy-lua= backend, please download the [[https://github.com/EmmyLua/EmmyLua-LanguageServer ][EmmyLua-LS-all.jar ]] and put it into =~/.emacs.d/= ,
and then set the layer variable lua-backend to =lsp-emmy-lua= .
2019-11-12 03:29:50 +00:00
2021-01-20 22:20:32 +00:00
=lsp-emmy-lua= requires a working java installation in the path as well as the path to the LSP server jar.
2019-11-30 23:39:37 +00:00
The java path and the path to the server executable can be configured as is shown below:
2019-11-30 23:48:29 +00:00
#+BEGIN_SRC elisp
2019-11-12 03:29:50 +00:00
(lua :variables
2019-11-30 23:39:37 +00:00
lua-backend 'lsp-emmy
2021-01-20 22:20:32 +00:00
lsp-clients-emmy-lua-jar-path "~/.emacs.d/ .cache/lsp/EmmyLua-LS-all.jar" ; default path
lsp-clients-emmy-lua-java-path "java") ; default path
#+END_SRC
To use the =lsp-lua-language-server= backend, please follow [[https://github.com/sumneko/lua-language-server ][lua-language-server ]] to compile the standalone binary,
and then set the layer variable =lua-backend= to =lsp-lua-language-server= , and the variables for binary and main entry such as the example below:
#+BEGIN_SRC elisp
(lua :variables
lua-backend 'lsp-lua-language-server
lsp-clients-lua-language-server-bin "~/.emacs.d/ .cache/lsp/lua-language-server/bin/Linux/lua-language-server" ; default path
lsp-clients-lua-language-server-main-location "~/.emacs.d/ .cache/lsp/lua-language-server/main.lua") ; default path
2019-11-30 23:48:29 +00:00
#+END_SRC
2019-11-12 03:29:50 +00:00
2019-11-30 23:39:37 +00:00
*** Lua mode
2020-04-02 16:41:28 +00:00
This backend provides support via pure emacs packages. It requires less setup than a full blown LSP setup
2019-11-30 23:39:37 +00:00
but also provides less features. To enable it just set the =lua-backend= to =nil= .
2019-11-12 03:29:50 +00:00
2018-12-05 03:03:03 +00:00
* Key bindings
2019-11-12 03:29:50 +00:00
** LSP
The default key bindings for the LSP implementations are defined and documented in
the [[file:../../+tools/lsp/README.org ][LSP layer ]].
2015-06-10 16:44:30 +00:00
** Commands
2018-12-05 03:03:03 +00:00
| Key binding | Description |
2015-06-10 16:44:30 +00:00
|-------------+--------------------------------------------|
| ~SPC m d~ | lookup thing at point in lua documentation |
| ~SPC m s b~ | send buffer contents to REPL |
| ~SPC m s f~ | send current function to REPL |
| ~SPC m s l~ | send current line to REPL |
| ~SPC m s r~ | send current region to REPL |
2019-11-30 23:39:37 +00:00
| ~SPC m '~ | open repl buffer |