Get rid of LSP for Lua and add command to run lua-format

This commit is contained in:
Camden Dixie O'Brien 2023-12-08 11:35:09 +00:00
parent 5cbae91478
commit bf734ca1aa

View File

@ -1178,11 +1178,43 @@
#+end_src
** Lua
Using a pretty standard LSP setup for Lua:
Just using basic =lua-mode= package:
#+begin_src emacs-lisp
(use-package lua-mode)
(add-hook 'lua-mode-hook #'lsp-deferred)
#+end_src
I want to indent with tabs (set to 4 characters wide):
#+begin_src emacs-lisp
(setq lua-indent-level 4)
#+end_src
I also want to be able to run =lua-format= on files with =C-c f=
like I have with =clang-format=. The first step for this is to make
an interactive function to run the formatter; this can be done with
[[help:call-process-region][call-process-region]].
#+begin_src emacs-lisp
(defvar lua-format-binary "lua-format")
(defun lua-format ()
(interactive)
(if (executable-find lua-format-binary)
(let ((start (if (region-active-p) (region-beginning) (point-min)))
(end (if (region-active-p) (region-end) (point-max))))
(call-process-region start end lua-format-binary t '(t nil)))
(error "%s" (concat lua-format-binary " not found."))))
#+end_src
This then needs to be assigned to the keybinding:
#+begin_src emacs-lisp
(add-hook
'lua-mode-hook
(lambda () (define-key lua-mode-map (kbd "C-c f") 'lua-format)))
#+end_src
#+end_src
* Tool Integrations