chiark / gitweb /
dot/emacs, el/dot-emacs.el: Add support for Lua programming.
authorMark Wooding <mdw@distorted.org.uk>
Sat, 15 Jul 2017 00:12:04 +0000 (01:12 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 15 Jul 2017 00:12:04 +0000 (01:12 +0100)
I don't love Lua, but it's better for writing Wireshark dissectors than
C.  So let's have some configuration.

dot/emacs
el/dot-emacs.el

index 1062254ce6c90f703d974d79ef4ee961c52c7a1d..3de26941c0b5a48c58badc8e8933854da6ebd10c 100644 (file)
--- a/dot/emacs
+++ b/dot/emacs
        lisp-mode-hook lisp-interaction-mode-hook makefile-mode-hook
        inferior-lisp-mode-hook slime-repl-mode-hook
        sml-mode-hook haskell-mode-hook erlang-mode-hook
-       smalltalk-mode-hook rexx-mode-hook
+       smalltalk-mode-hook rexx-mode-hook lua-mode-hook
        arm-assembler-mode-hook))
 
 (global-font-lock-mode t)
   (add-hook 'go-mode-hook 'mdw-fontify-go t)
   (add-hook 'rust-mode-hook 'mdw-fontify-rust t)
 
+  (add-hook 'lua-mode-hook 'mdw-fontify-lua t)
   (add-hook 'icon-mode-hook 'mdw-fontify-icon t)
 
   (add-hook 'apcalc-mode-hook 'mdw-misc-mode-config t)
index 403a5e42b9a9b9a07904a3b6a9d2b2207d37b985..cd8b407644dd4bbbf64d0fed1b413b8d095b8728 100644 (file)
@@ -2550,6 +2550,49 @@ (defun mdw-fontify-pyrex ()
                "raise" "return" "struct" "try" "while" "with"
                "yield")))
 
+;;;--------------------------------------------------------------------------
+;;; Lua programming style.
+
+(setq lua-indent-level 2)
+
+(defun mdw-fontify-lua ()
+
+  ;; Miscellaneous fiddling.
+  (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
+
+  ;; Now define fontification things.
+  (make-local-variable 'font-lock-keywords)
+  (let ((lua-keywords
+        (mdw-regexps "and" "break" "do" "else" "elseif" "end"
+                     "false" "for" "function" "goto" "if" "in" "local"
+                     "nil" "not" "or" "repeat" "return" "then" "true"
+                     "until" "while")))
+    (setq font-lock-keywords
+         (list
+
+          ;; Set up the keywords defined above.
+          (list (concat "\\_<\\(" lua-keywords "\\)\\_>")
+                '(0 font-lock-keyword-face))
+
+          ;; At least numbers are simpler than C.
+          (list (concat "\\_<\\(" "0[xX]"
+                                  "\\(" "[0-9a-fA-F]+"
+                                        "\\(\\.[0-9a-fA-F]*\\)?"
+                                  "\\|" "\\.[0-9a-fA-F]+"
+                                  "\\)"
+                                  "\\([pP][-+]?[0-9]+\\)?"
+                            "\\|" "\\(" "[0-9]+"
+                                        "\\(\\.[0-9]*\\)?"
+                                  "\\|" "\\.[0-9]+"
+                                  "\\)"
+                                  "\\([eE][-+]?[0-9]+\\)?"
+                            "\\)")
+                '(0 mdw-number-face))
+
+          ;; And anything else is punctuation.
+          (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
+                '(0 mdw-punct-face))))))
+
 ;;;--------------------------------------------------------------------------
 ;;; Icon programming style.