Function: lua-ts-mode
lua-ts-mode is an autoloaded, interactive and byte-compiled function
defined in lua-ts-mode.el.gz.
Signature
(lua-ts-mode)
Documentation
Major mode for editing Lua files, powered by tree-sitter.
C-c C-c lua-ts-send-buffer
C-c C-l lua-ts-send-file
C-c C-n lua-ts-inferior-lua
C-c C-r lua-ts-send-region
In addition to any hooks its parent mode prog-mode might have run,
this mode runs the hook lua-ts-mode-hook, as the final or penultimate
step during initialization.
Probably introduced at or before Emacs version 30.1.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/lua-ts-mode.el.gz
;;;###autoload
(define-derived-mode lua-ts-mode prog-mode "Lua"
"Major mode for editing Lua files, powered by tree-sitter.
\\{lua-ts-mode-map}"
:syntax-table lua-ts--syntax-table
(use-local-map lua-ts-mode-map)
;; `treesit-ready-p' also checks for buffer size.
(when (and (treesit-ensure-installed 'lua)
(treesit-ready-p 'lua))
(setq treesit-primary-parser (treesit-parser-create 'lua))
;; Comments.
(setq-local comment-start "--")
(setq-local comment-start-skip "--\\s-*")
(setq-local comment-start-line-regexp
(rx (seq "--" (or (not (any "["))
(seq "[" (zero-or-more "=")
(not (any "=[")))))))
(setq-local comment-end "")
;; Pairs.
(when (and lua-ts-auto-close-block-comments
(boundp 'electric-pair-pairs))
(setq-local electric-pair-pairs
(cons
'("--\\[\\[" . "\n]")
electric-pair-pairs)))
;; Font-lock.
(setq-local treesit-font-lock-settings lua-ts--font-lock-settings)
(setq-local treesit-font-lock-feature-list
'((comment definition)
(keyword string)
(assignment builtin constant number)
(bracket
delimiter
escape
function
operator
property
punctuation
variable)))
;; Indent.
(setq-local c-ts-common-indent-offset 'lua-ts-indent-offset)
(setq-local c-ts-common-list-indent-style 'simple)
(setq-local treesit-simple-indent-rules lua-ts--simple-indent-rules)
;; Navigation.
(setq-local treesit-defun-name-function #'lua-ts--defun-name-function)
(setq-local treesit-defun-type-regexp
(rx (or "function_declaration" "function_definition")))
(setq-local treesit-thing-settings
`((lua
(function (or "function_declaration"
"function_definition"))
(keyword ,(regexp-opt lua-ts--keywords 'symbols))
(loop-statement (or "do_statement"
"for_statement"
"repeat_statement"
"while_statement"))
(sentence (or function
loop-statement
comment
"assignment_statement"
"field"
"function_call"
"if_statement"
"return_statement"
"variable_declaration"))
(sexp (or function
keyword
loop-statement
"arguments"
"parameters"
"parenthesized_expression"
"string"
"table_constructor"))
(list (or function
loop-statement
"arguments"
"parameters"
"table_constructor"
"parenthesized_expression"
,(rx bos "if_statement" eos)))
(text (or comment "string"))
(comment ,(rx bos "comment" eos)))))
;; Imenu/Outline/Which-function.
(setq-local treesit-simple-imenu-settings
`(("Requires"
"\\`function_call\\'"
lua-ts--require-p
lua-ts--require-name-function)
("Variables" "\\`variable_declaration\\'" nil nil)
(nil
"\\`\\(?:f\\(?:ield\\|unction_declaration\\)\\)\\'"
lua-ts--named-function-p
nil)))
;; Align.
(setq-local align-indent-before-aligning t)
(treesit-major-mode-setup))
(add-hook 'flymake-diagnostic-functions #'lua-ts-flymake-luacheck nil 'local))