lua-users home
lua-l archive

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


Hello,

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

-- 
Daniel Silverstone                               http://www.digital-scurf.org/
Hostmaster, Webmaster, and Chief Code Wibbler          Digital-Scurf Unlimited
GPG Public key available from pgpkeys.mit.edu:11371            KeyId: 20687895
You get what you pay for.
		-- Gabriel Biel
;;; -*- Emacs-Lisp -*-
;; $Id$
;;
;; @author Daniel Silverstone <dsilvers@digital-scurf.org>
;;

(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))
)
(lua-mode-load-time-setup)

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

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


(provide 'lua)