monotone

monotone Mtn Source Tree

Root/contrib/lua-mode.el

1;; Major mode for editing Lua files.
2;; For info on Lua, see http://www.lua.org/
3;;
4;; Copyright (C) 2007 Stephen Leake
5;;
6;; Author : Stephen Leake <stephen.leake@gsfc.nasa.gov>
7;; Web Site : http://www.stephe-leake.org/
8;;
9;; Keywords: script, lua
10;;
11;; lua-mode requires GNU Emacs 22.1 or newer
12;;
13;; This file is NOT part of GNU Emacs, but is distributed under
14;; the GNU General Public License as published by the Free Software
15;; Foundation; either version 2, or (at your option) any later
16;; version.
17
18;; This code is distributed in the hope that it will be useful,
19;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21;; GNU General Public License for more details.
22
23;; You should have received a copy of the GNU General Public License
24;; along with GNU Emacs; see the file COPYING. If not, write to the
25;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26;; Boston, MA 02111-1307, USA.
27
28;;; USAGE
29;;; =====
30;;; The main starting point is lua-mode; it sets up fontification and
31;;; comment syntax.
32
33;;;--------------------
34;;; USER OPTIONS
35;;;--------------------
36
37(defgroup lua nil
38 "Major mode for editing LUA script files"
39 :group 'languages)
40
41(defcustom lua-mode-hook nil
42 "*List of functions to call when lua mode is invoked."
43 :type 'hook
44 :group 'lua)
45
46;;; ---- end of user configurable variables
47
48(defvar lua-mode-map (make-sparse-keymap)
49 "Local keymap for lua mode.")
50
51(require 'align)
52
53(defvar lua-align-modes
54 '((lua-assignment
55 (regexp . "[^=]\\(\\s-+\\)=[^=]")
56 (valid . (lambda() (not (lua-in-comment-p))))
57 (modes . '(lua-mode)))
58 (lua-comment
59 (regexp . "--")
60 (modes . '(lua-mode)))
61 )
62 "lua support for align.el >= 2.8.")
63
64;; main entry point
65;;;###autoload
66(defun lua-mode ()
67 "lua mode is a very simple major mode for editing Lua script files.
68Keybindings:
69\\{lua-mode-map}"
70 (interactive)
71 (kill-all-local-variables)
72 (set (make-local-variable 'comment-start) "-- ")
73 (set (make-local-variable 'comment-start-skip) "-- ")
74 (set (make-local-variable 'font-lock-defaults)
75 '((lua-font-lock-keywords) ; keywords
76 nil ; keywords-only
77 t ; case-fold-font
78 nil ; syntax-alist
79 nil)) ; syntax-begin
80
81 (setq major-mode 'lua-mode)
82 (setq mode-name "Lua")
83 (use-local-map lua-mode-map)
84 (set-syntax-table lua-mode-syntax-table)
85
86 (add-to-list 'align-open-comment-modes 'lua-mode)
87 (set (make-variable-buffer-local 'align-region-separate)
88 'group)
89 (setq align-mode-rules-list lua-align-modes)
90
91 (run-hooks 'lua-mode-hook) )
92
93;;; general support
94
95;; syntax
96(defvar lua-mode-syntax-table (make-syntax-table)
97 "Syntax table for editing Lua script files.")
98
99(modify-syntax-entry ?\_ "w" lua-mode-syntax-table) ; underscore is a word constituent
100(modify-syntax-entry ?\- ". 12" lua-mode-syntax-table) ; comment start
101(modify-syntax-entry ?\n "> " lua-mode-syntax-table) ; comment end
102
103;; font lock
104(defconst lua-identifier-regexp "\\([A-Za-z0-9_]+\\)"
105 "Regexp for extracting lua identifiers.")
106
107(defconst lua-file-regexp "\\([A-Za-z0-9_./:]+\\)"
108 "Regexp for extracting lua identifiers.")
109
110(defconst lua-string-simple-keywords
111 '("and" "break" "do" "else" "elseif" "end" "false" "for" "function" "if"
112 "in" "local" "nil" "not" "or" "repeat" "return" "then" "true" "until" "while")
113 "All Lua keywords that don't need special treatment in font-lock")
114
115(defconst lua-simple-keywords
116 (concat "\\<" (regexp-opt lua-string-simple-keywords t) "\\>")
117 "Optimized regexp for simple Lua keywords.")
118
119(defconst lua-font-lock-keywords
120 (list
121 (list lua-simple-keywords
122 '(1 font-lock-keyword-face))
123 )
124 "highlighting for lua mode")
125
126(defsubst lua-in-comment-p (&optional parse-result)
127 "Returns t if inside a comment."
128 (nth 4 (or parse-result
129 (parse-partial-sexp
130 (line-beginning-position) (point)))))
131
132;;; pages
133(defconst lua-page-marker "----------" ; exactly 10 dashes
134 "Lua page delimiter.")
135
136(defun lua-prev-page ()
137 "Move to previous page boundary; `lua-page-marker' or beginning of buffer."
138 (interactive)
139 (if (re-search-backward lua-page-marker (point-min) t)
140 (goto-char (match-beginning 0))
141 (goto-char (point-min))))
142
143(defun lua-next-page ()
144 "Move to next page boundary; `lua-page-marker' or end of buffer."
145 (interactive)
146 (end-of-line)
147 (if (re-search-forward lua-page-marker (point-max) t)
148 (goto-char (match-beginning 0))
149 (goto-char (point-max))))
150
151(define-key lua-mode-map [prior] 'lua-prev-page)
152(define-key lua-mode-map [next] 'lua-next-page)
153
154(provide 'lua-mode)
155;;; end of file

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status