Emacs mode for Lua

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Emacs mode for Lua

Daniel Silverstone
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 <[hidden email]>
;;

(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)
  
Reply | Threaded
Open this post in threaded view
|

Re: Emacs mode for Lua

Eric Tetz-2
On a related note, I was pleased to discover that VI (or at least VIM and GVIM) already has syntax
highlighting for Lua.  Comes installed by default with Redhat Linux, anyway, I'm not sure about
other Unixes.

--- Daniel Silverstone <[hidden email]> wrote:
> 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 <[hidden email]>
> ;;
> 
> (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)
>   
> 


__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/

Reply | Threaded
Open this post in threaded view
|

Re: Emacs mode for Lua

Alex Sandro Queiroz e Silva
On Thu, 15 Feb 2001, Eric Tetz wrote:

> On a related note, I was pleased to discover that VI (or at least VIM
> and GVIM) already has syntax highlighting for Lua.  Comes installed by
> default with Redhat Linux, anyway, I'm not sure about other Unixes.

Hallo,
	It's part of the vim standard distribution.

  --Alex	[hidden email]		Lab. de Computação Gráfica/UFC
+----------------------------------------------------------------------------+
|"Minha força vem da solidão. Não tenho medo das chuvas tempestuosas nem das |
| grandes ventanias soltas, pois eu também sou o escuro da noite."	     |
|	- Clarice Lispector						     |
+----------------------------------------------------------------------------+