summaryrefslogtreecommitdiff
path: root/.emacs.d/lisp/lua-mode.el
diff options
context:
space:
mode:
Diffstat (limited to '.emacs.d/lisp/lua-mode.el')
-rw-r--r--.emacs.d/lisp/lua-mode.el63
1 files changed, 60 insertions, 3 deletions
diff --git a/.emacs.d/lisp/lua-mode.el b/.emacs.d/lisp/lua-mode.el
index 2d6a2d5..4c543f5 100644
--- a/.emacs.d/lisp/lua-mode.el
+++ b/.emacs.d/lisp/lua-mode.el
@@ -12,7 +12,7 @@
12;; Aaron Smith <aaron-lua@gelatinous.com>. 12;; Aaron Smith <aaron-lua@gelatinous.com>.
13;; 13;;
14;; URL: https://immerrr.github.io/lua-mode 14;; URL: https://immerrr.github.io/lua-mode
15;; Version: 20210802 15;; Version: 20221027
16;; Package-Requires: ((emacs "24.3")) 16;; Package-Requires: ((emacs "24.3"))
17;; 17;;
18;; This file is NOT part of Emacs. 18;; This file is NOT part of Emacs.
@@ -41,7 +41,8 @@
41 41
42;; lua-mode provides support for editing Lua, including automatic 42;; lua-mode provides support for editing Lua, including automatic
43;; indentation, syntactical font-locking, running interactive shell, 43;; indentation, syntactical font-locking, running interactive shell,
44;; interacting with `hs-minor-mode' and online documentation lookup. 44;; Flymake checks with luacheck, interacting with `hs-minor-mode' and
45;; online documentation lookup.
45 46
46;; The following variables are available for customization (see more via 47;; The following variables are available for customization (see more via
47;; `M-x customize-group lua`): 48;; `M-x customize-group lua`):
@@ -85,6 +86,10 @@
85;; - Cmd `lua-send-region': send active region 86;; - Cmd `lua-send-region': send active region
86;; - Cmd `lua-restart-with-whole-file': restart REPL and send whole buffer 87;; - Cmd `lua-restart-with-whole-file': restart REPL and send whole buffer
87 88
89;; To enable on-the-fly linting, make sure you have the luacheck
90;; program installed (available from luarocks) and activate
91;; `flymake-mode'.
92
88;; See "M-x apropos-command ^lua-" for a list of commands. 93;; See "M-x apropos-command ^lua-" for a list of commands.
89;; See "M-x customize-group lua" for a list of customizable variables. 94;; See "M-x customize-group lua" for a list of customizable variables.
90 95
@@ -710,7 +715,7 @@ index of respective Lua reference manuals.")
710 ;; via `lua-mode-map'. 715 ;; via `lua-mode-map'.
711 (setq-local electric-indent-chars 716 (setq-local electric-indent-chars
712 (append electric-indent-chars lua--electric-indent-chars))) 717 (append electric-indent-chars lua--electric-indent-chars)))
713 718 (add-hook 'flymake-diagnostic-functions #'lua-flymake nil t)
714 719
715 ;; setup menu bar entry (XEmacs style) 720 ;; setup menu bar entry (XEmacs style)
716 (if (and (featurep 'menubar) 721 (if (and (featurep 'menubar)
@@ -2194,6 +2199,58 @@ left out."
2194 (forward-sexp 1)) 2199 (forward-sexp 1))
2195 (setq count (1- count)))))) 2200 (setq count (1- count))))))
2196 2201
2202;; Flymake integration
2203
2204(defcustom lua-luacheck-program "luacheck"
2205 "Name of the luacheck executable."
2206 :type 'string
2207 :group 'lua)
2208
2209(defvar-local lua--flymake-process nil)
2210
2211(defun lua-flymake (report-fn &rest _args)
2212 "Flymake backend using the luacheck program.
2213Takes a Flymake callback REPORT-FN as argument, as expected of a
2214member of `flymake-diagnostic-functions'."
2215 (when (process-live-p lua--flymake-process)
2216 (kill-process lua--flymake-process))
2217 (let ((source (current-buffer)))
2218 (save-restriction
2219 (widen)
2220 (setq lua--flymake-process
2221 (make-process
2222 :name "luacheck" :noquery t :connection-type 'pipe
2223 :buffer (generate-new-buffer " *flymake-luacheck*")
2224 :command `(,lua-luacheck-program
2225 "--codes" "--ranges" "--formatter" "plain" "-")
2226 :sentinel
2227 (lambda (proc _event)
2228 (when (eq 'exit (process-status proc))
2229 (unwind-protect
2230 (if (with-current-buffer source
2231 (eq proc lua--flymake-process))
2232 (with-current-buffer (process-buffer proc)
2233 (goto-char (point-min))
2234 (cl-loop
2235 while (search-forward-regexp
2236 "^\\([^:]*\\):\\([0-9]+\\):\\([0-9]+\\)-\\([0-9]+\\): \\(.*\\)$"
2237 nil t)
2238 for line = (string-to-number (match-string 2))
2239 for col1 = (string-to-number (match-string 3))
2240 for col2 = (1+ (string-to-number (match-string 4)))
2241 for msg = (match-string 5)
2242 for type = (if (string-match-p "\\`(E" msg) :error :warning)
2243 collect (flymake-make-diagnostic source
2244 (cons line col1)
2245 (cons line col2)
2246 type
2247 msg)
2248 into diags
2249 finally (funcall report-fn diags)))
2250 (flymake-log :warning "Canceling obsolete check %s" proc))
2251 (kill-buffer (process-buffer proc)))))))
2252 (process-send-region lua--flymake-process (point-min) (point-max))
2253 (process-send-eof lua--flymake-process))))
2197 2254
2198;; menu bar 2255;; menu bar
2199 2256