[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/lua-mode b1dc70c 158/468: lua-font-lock-keywords: highligh
From: |
Philip Kaludercic |
Subject: |
[nongnu] elpa/lua-mode b1dc70c 158/468: lua-font-lock-keywords: highlight builtin symbols (issue #15) |
Date: |
Thu, 5 Aug 2021 04:58:27 -0400 (EDT) |
branch: elpa/lua-mode
commit b1dc70cf2f45d14feb487bad118f1b8bf3b8befd
Author: immerrr <immerrr+lua@gmail.com>
Commit: immerrr <immerrr+lua@gmail.com>
lua-font-lock-keywords: highlight builtin symbols (issue #15)
---
lua-mode.el | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 63 insertions(+)
diff --git a/lua-mode.el b/lua-mode.el
index 27a7517..8c499af 100644
--- a/lua-mode.el
+++ b/lua-mode.el
@@ -266,6 +266,65 @@ traceback location."
["Search Documentation" lua-search-documentation t])
"Emacs menu for Lua mode.")
+(defconst
+ lua--builtins
+ (eval-and-compile
+ (let*
+ ((modules
+ '("_G" "_VERSION" "assert" "collectgarbage" "dofile" "error"
"getfenv" "getmetatable"
+ "ipairs" "load" "loadfile" "loadstring" "module" "next" "pairs"
"pcall" "print"
+ "rawequal" "rawget" "rawlen" "rawset" "require" "select" "setfenv"
"setmetatable"
+ "tonumber" "tostring" "type" "unpack" "xpcall"
+ ("bit32" . ("arshift" "band" "bnot" "bor" "btest" "bxor" "extract"
"lrotate" "lshift"
+ "replace" "rrotate" "rshift"))
+ ("coroutine" . ("create" "resume" "running" "status" "wrap"
"yield"))
+ ("debug" . ("debug" "getfenv" "gethook" "getinfo" "getlocal"
"getmetatable"
+ "getregistry" "getupvalue" "getuservalue" "setfenv"
"sethook" "setlocal"
+ "setmetatable" "setupvalue" "setuservalue" "traceback"
"upvalueid"
+ "upvaluejoin"))
+ ("io" . ("close" "flush" "input" "lines" "open" "output" "popen"
"read" "stderr"
+ "stdin" "stdout" "tmpfile" "type" "write"))
+ ("math" . ("abs" "acos" "asin" "atan" "atan2" "ceil" "cos" "cosh"
"deg" "exp" "floor"
+ "fmod" "frexp" "huge" "ldexp" "log" "log10" "max" "min"
"modf" "pi" "pow"
+ "rad" "random" "randomseed" "sin" "sinh" "sqrt" "tan"
"tanh"))
+ ("os" . ("clock" "date" "difftime" "execute" "exit" "getenv"
"remove" "rename"
+ "setlocale" "time" "tmpname"))
+ ("package" . ("config" "cpath" "loaded" "loaders" "loadlib" "path"
"preload"
+ "searchers" "searchpath" "seeall"))
+ ("string" . ("byte" "char" "dump" "find" "format" "gmatch" "gsub"
"len" "lower"
+ "match" "rep" "reverse" "sub" "upper"))
+ ("table" . ("concat" "insert" "maxn" "pack" "remove" "sort"
"unpack")))))
+
+ ;; This code uses \\< and \\> to delimit builtin symbols instead of \\_<
and \\_>, because --
+ ;; a necessity -- '.' syntax class is hacked to 'symbol' and \\_> won't
detect a symbol
+ ;; boundary in 'foo.bar' and -- sufficiency -- conveniently, underscore
'_' is hacked to count
+ ;; as word constituent, but only for font-locking. Neither of these
hacks makes sense to me,
+ ;; I'm going to wipe them out as soon as I'm sure that indentation won't
get hurt. --immerrr
+ ;;
+ (flet ((module-name-re (x) (concat "\\(?1:\\<" (if (listp x) (car x) x)
"\\>\\)"))
+ (module-members-re (x) (if (listp x)
+ (concat "\\(?:[ \t]*\\.[ \t]*\\<\\(?2:"
+ (regexp-opt (cdr x))
+ "\\)\\>\\)?")
+ "")))
+
+ (concat
+ ;; common prefix - beginning-of-line or neither of [ '.', ':' ] to
exclude "foo.string.rep"
+ "\\(?:\\`\\|[^:. \n\t]\\)"
+ ;; optional whitespace
+ "[ \n\t]*"
+ "\\(?:"
+ ;; any of modules/functions
+ (mapconcat (lambda (x) (concat "\\(?:" (module-name-re x)
(module-members-re x) "\\)"))
+ modules
+ "\\|")
+ "\\)"))))
+
+ "A regexp that matches lua builtin functions & variables.
+
+This is a compilation of 5.1 and 5.2 builtins taken from the
+index of respective Lua reference manuals.")
+
(defvar lua-font-lock-keywords
(eval-when-compile
(list
@@ -281,6 +340,10 @@ traceback location."
'("^[ \t]*\\_<\\(\\(local[ \t]+\\)?function\\)\\_>[
\t]+\\(\\(\\sw:\\|\\sw\\.\\|\\sw_\\|\\sw\\)+\\)"
(1 font-lock-keyword-face) (3 font-lock-function-name-face nil t))
+ ;; Highlight lua builtin functions and variables
+ `(,lua--builtins
+ (1 font-lock-builtin-face) (2 font-lock-builtin-face nil noerror))
+
;; Handle function names in assignments
'("\\(\\(\\sw:\\|\\sw\\.\\|\\sw_\\|\\sw\\)+\\)[ \t]*=[
\t]*\\(function\\)\\_>"
(1 font-lock-function-name-face nil t) (3 font-lock-keyword-face))
- [nongnu] elpa/lua-mode 68cd23d 292/468: Merge pull request #85 from immerrr/beginning-of-proc-regex, (continued)
- [nongnu] elpa/lua-mode 68cd23d 292/468: Merge pull request #85 from immerrr/beginning-of-proc-regex, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 532701b 298/468: Add missing Lua 5.3 functions and modules, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 445bad6 301/468: Merge pull request #92 from ramnes/master, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 7f8fbf2 308/468: lua-mode: don't remove syntax-table during unfontification, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode b4943f6 313/468: Add luadoc keyword fontification (issue #71), Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode debba6c 317/468: Use electric-indent-mode for per-char electric indentation, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode bdf121b 318/468: New release 20151025, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 4b5aad7 326/468: lua-try-match-multiline-begin: don't do syntax-ppss after the opener, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode a9945c9 340/468: possibility to connect to remote lua process, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 0407042 153/468: Make lua-with-silent-modifications available during byte-compilation, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode b1dc70c 158/468: lua-font-lock-keywords: highlight builtin symbols (issue #15),
Philip Kaludercic <=
- [nongnu] elpa/lua-mode 52dcf7b 167/468: Merge pull request #35 from vhallac/fix-34, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode a3016a2 176/468: Avoid polluting "global namespace" when striving for backward compatibility, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode b124dd0 194/468: Add field containing commit SHA expanded during archive creation., Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 64c1e94 197/468: lua--builtins: add "self" as keyword, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode d6c8419 202/468: Fix incorrect error highlighting in 'for x = ...' statements, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 2d94dee 204/468: Don't unindent comment close-bracket if it doesn't match open-bracket, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode c1fcfb6 211/468: Add NEWS file, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode d0fa50d 217/468: lua-make-delimited-matcher: wrap into eval-and-compile, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode b684790 219/468: Revert "Rename lua--function-name-rx, use it in font-lock keywords init", Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 8e19d23 231/468: Add basic indentation tests, Philip Kaludercic, 2021/08/05