From bf734ca1aaf32c64b2bef52ed0a5667d32b8a2ba Mon Sep 17 00:00:00 2001 From: Camden Dixie O'Brien Date: Fri, 8 Dec 2023 11:35:09 +0000 Subject: [PATCH] Get rid of LSP for Lua and add command to run lua-format --- config.org | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/config.org b/config.org index 4faeb97..8ce2cd2 100644 --- a/config.org +++ b/config.org @@ -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