lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I have been working on a lua mode for emacs.

Right now, I have a very simple syntax highlighter.

It works reasonably well. Notably, it fails to do [[ ]] strings,
and a few of the operators, variables aren't highlighted properly, etc.

still, it should help.

<attached: lua.el>


Daniel Silverstone                     
Hostmaster, Webmaster, and Chief Code Wibbler          Digital-Scurf Unlimited
GPG Public key available from            KeyId: 20687895
You get what you pay for.
		-- Gabriel Biel
;;; -*- Emacs-Lisp -*-
;; $Id$
;; @author Daniel Silverstone <>

(defvar lua-mode-syntax-table nil
  "Lua-mode's syntax table.")

(defun lua-mode-load-time-setup ()
  "init lua-mode stuff"
  (setq lua-mode-syntax-table (make-syntax-table))


(defconst lua-mode-font-lock-keywords
    ("--.*$" . font-lock-comment-face)
    ("\\( \\|\\t\\|\\n\\|^\\)\\(if\\|end\\|for\\|\\do\\|while\\|repeat\\|until\\|then\\|else\\(if\\)?\\|return\\|break\\|in\\|function\\|local\\)\\( \\|(\\|\\t\\|\\n\\|$\\|;\\)" . font-lock-keyword-face)
    ("\\(\\[\\|\\]\\|=\\|\\+\\|-\\|\\{\\|\\}\\|(\\|)\\|\\.\\.\\|;\\)" . font-lock-builtin-face)
    "Font-lock keyword highlights for Lua mode"

(define-derived-mode lua-mode fundamental-mode "Lua"
  "A mode for editing Lua sources"

  (if (null lua-mode-syntax-table)
      (lua-mode-load-time-setup)) ;; should have been run at load-time

  ;; font-lock support:
  (make-local-variable 'comment-start)
  (setq comment-start "--")
  (make-local-variable 'parse-sexp-ignore-comments)
  (setq parse-sexp-ignore-comments t)
  (setq font-lock-defaults '(lua-mode-font-lock-keywords nil))

;; Force lua-mode to be loaded for any file ending in .lua

(setq auto-mode-alist
 (cons '("\\.lua\\'" . lua-mode)

(provide 'lua)