branch: elpa/lua-mode
commit 94aadfd8f7b0414ba58de2c10b0a52da5832f43f
Author: immerrr <[email protected]>
Commit: immerrr <[email protected]>
Font-lock "nil", "true" and "false" as constants rather than keywords
---
Makefile | 4 +++-
ert-tests/test-builtin-font-lock.el | 18 ++++++++++++++++++
lua-mode.el | 12 ++++++++----
3 files changed, 29 insertions(+), 5 deletions(-)
diff --git a/Makefile b/Makefile
index 921b196..18b230a 100644
--- a/Makefile
+++ b/Makefile
@@ -6,7 +6,9 @@ DISTFILE = lua-mode-$(VERSION).zip
# EMACS value may be overridden
EMACS?=emacs
-TESTS=ert-tests/test-defun-font-lock.el
+TESTS=
+TESTS += ert-tests/test-defun-font-lock.el
+TESTS += ert-tests/test-builtin-font-lock.el
default:
@echo version is $(VERSION)
diff --git a/ert-tests/test-builtin-font-lock.el
b/ert-tests/test-builtin-font-lock.el
new file mode 100644
index 0000000..f170c83
--- /dev/null
+++ b/ert-tests/test-builtin-font-lock.el
@@ -0,0 +1,18 @@
+(require 'ert)
+(require 'lua-font-lock-test-helpers
+ ;; let's try a bit to help Emacs find the helpers, just in case
+ (concat (file-name-directory (or load-file-name (buffer-file-name)
+ default-directory))
+ "lua-font-lock-test-helpers.el"))
+
+
+(ert-deftest lua-font-lock-builtin-constants()
+ (should-lua-font-lock-equal
+ "a = { nil, true, false}"
+ '(("nil" constant "true" constant "false" constant)))
+
+ (should-lua-font-lock-equal
+ "a = { foo.true, foo:false }"
+ '(;; This case won't work while '.' has symbol syntax
+ ;; ("true" constant "false" constant)
+ ("false" constant))))
diff --git a/lua-mode.el b/lua-mode.el
index ca99bb8..bf20c05 100644
--- a/lua-mode.el
+++ b/lua-mode.el
@@ -508,11 +508,15 @@ Groups 6-9 can be used in any of argument regexps."
`(;; highlight the hash-bang line "#!/foo/bar/lua" as comment
("^#!.*$" . font-lock-comment-face)
- ;; Keywords.
+ ;; Builtin constants
+ (,(rx symbol-start (or "true" "false" "nil") symbol-end)
+ . font-lock-constant-face)
+
+ ;; Keywords
(,(rx symbol-start
- (or "and" "break" "do" "else" "elseif" "end" "false"
- "for" "function" "if" "in" "local" "nil" "not"
- "or" "repeat" "return" "then" "true" "until"
+ (or "and" "break" "do" "else" "elseif" "end"
+ "for" "function" "if" "in" "local" "not"
+ "or" "repeat" "return" "then" "until"
"while")
symbol-end)
. font-lock-keyword-face)