[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/lua-mode 1d8dc55 214/468: Rename lua--function-name-rx, us
From: |
Philip Kaludercic |
Subject: |
[nongnu] elpa/lua-mode 1d8dc55 214/468: Rename lua--function-name-rx, use it in font-lock keywords init |
Date: |
Thu, 5 Aug 2021 04:58:39 -0400 (EDT) |
branch: elpa/lua-mode
commit 1d8dc5572be40071b61c5027a9c7fdcb68495e5c
Author: immerrr <immerrr@gmail.com>
Commit: immerrr <immerrr@gmail.com>
Rename lua--function-name-rx, use it in font-lock keywords init
---
lua-mode.el | 190 +++++++++++++++++++++++++++++-------------------------------
1 file changed, 91 insertions(+), 99 deletions(-)
diff --git a/lua-mode.el b/lua-mode.el
index f8f8b9e..ad90cec 100644
--- a/lua-mode.el
+++ b/lua-mode.el
@@ -492,92 +492,94 @@ Groups 6-9 can be used in any of argument regexps."
(re-search-forward "\\(?1:\\(?2:[^ \t]+\\)\\)" parse-stop 'skip)
(prog1 nil (goto-char end))))))))
-(defconst lua-local-defun-regexp
- ;; Function matchers are very crude, need rewrite at some point.
- (rx (or (seq (regexp "\\(?:\\_<function\\_>\\)")
- (* blank)
- (? (regexp "\\(?1:\\_<[[:alpha:]][[:alnum:]]*\\_>\\)"))
- (regexp "\\(?2:.*\\)"))
- (seq (? (regexp "\\(?1:\\_<[[:alpha:]][[:alnum:]]*\\_>\\)"))
- (* blank) "=" (* blank)
- (regexp "\\(?:\\_<function\\_>\\)")
- (regexp "\\(?2:.*\\)")))))
-
-(defvar lua-font-lock-keywords
- `(;; highlight the hash-bang line "#!/foo/bar/lua" as comment
- ("^#!.*$" . font-lock-comment-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"
- "while")
- symbol-end)
- . font-lock-keyword-face)
-
- ;; Highlight lua builtin functions and variables
- (,lua--builtins
- (1 font-lock-builtin-face) (2 font-lock-builtin-face nil noerror))
-
- ;; hexadecimal numbers
- ("\\_<0x[[:xdigit:]]+\\_>" . font-lock-constant-face)
-
- ;; regular numbers
- ;;
- ;; This regexp relies on '.' being symbol constituent. Whenever this
- ;; changes, the regexp needs revisiting --immerrr
- (, (rx symbol-start
- ;; make a digit on either side of dot mandatory
- (or (seq (+ num) (? ".") (* num))
- (seq (* num) (? ".") (+ num)))
- (? (regexp "[eE][+-]?") (+ num))
- symbol-end)
- . font-lock-constant-face)
-
- ("^[ \t]*\\_<for\\_>"
- (,(lua-make-delimited-matcher "\\_<[[:alpha:]_][[:alnum:]_]*\\_>" ","
- "\\(?:\\_<in\\_>\\|=\\(?:[^=]\\|$\\)\\)")
- nil nil
- (1 font-lock-variable-name-face nil noerror)
- (2 font-lock-warning-face t noerror)
- (3 font-lock-warning-face t noerror)))
-
- ;; Handle local variable/function names
- ;; local blalba, xyzzy =
- ;; ^^^^^^ ^^^^^
- ;;
- ;; local function foobar(x,y,z)
- ;; ^^^^^^
- ;; local foobar = function(x,y,z)
- ;; ^^^^^^
- ("^[ \t]*\\_<local\\_>"
- (0 font-lock-keyword-face)
-
- ((lambda (end)
- (re-search-forward
- (rx point (* blank) (regexp ,lua-local-defun-regexp)) end t))
- nil nil
- (1 font-lock-function-name-face nil noerror))
-
- (,(lua-make-delimited-matcher "\\_<[[:alpha:]_][[:alnum:]_]*\\_>" ","
- "=\\(?:[^=]\\|$\\)")
- nil nil
- (1 font-lock-variable-name-face nil noerror)
- (2 font-lock-warning-face t noerror)
- (3 font-lock-warning-face t noerror)))
-
- ;; Function matchers are very crude, need rewrite at some point.
- ;; Function name declarations.
- ("^[ \t]*\\_<function\\_>[
\t]+\\([[:alnum:]_]+\\(?:\\.[[:alnum:]_]+\\)*\\(?::[[:alnum:]_]+\\)?\\)"
- (1 font-lock-function-name-face))
+(eval-and-compile
+ (defconst lua--function-name-rx
+ '(seq symbol-start
+ (+ (any alnum "_"))
+ (* "." (+ (any alnum "_")))
+ (? ":" (+ (any alnum "_")))
+ symbol-end)
+ "Lua function name regexp in `rx'-SEXP format."))
+(eval-and-compile
+ (defconst lua-defun-intro-regexp
;; Function matchers are very crude, need rewrite at some point.
- ;; Handle function names in assignments
- ("^[
\t]*\\([[:alnum:]_]+\\(?:\\.[[:alnum:]_]+\\)*\\(?::[[:alnum:]_]+\\)?\\)[ \t]*=[
\t]*\\_<function\\_>"
- (1 font-lock-function-name-face)))
-
- "Default expressions to highlight in Lua mode.")
+ (rx
+ (or (seq (regexp "\\(?:\\_<function\\_>\\)")
+ (* blank)
+ (? (regexp "\\(?1:") (eval lua--function-name-rx) (regexp
"\\)")))
+ (seq (? (regexp "\\(?1:") (eval lua--function-name-rx) (regexp "\\)"))
+ (* blank) "=" (* blank)
+ (regexp "\\(?:\\_<function\\_>\\)")))))
+
+ (defvar lua-font-lock-keywords
+ `( ;; highlight the hash-bang line "#!/foo/bar/lua" as comment
+ ("^#!.*$" . font-lock-comment-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"
+ "while")
+ symbol-end)
+ . font-lock-keyword-face)
+
+ ;; Highlight lua builtin functions and variables
+ (,lua--builtins
+ (1 font-lock-builtin-face) (2 font-lock-builtin-face nil noerror))
+
+ ;; hexadecimal numbers
+ ("\\_<0x[[:xdigit:]]+\\_>" . font-lock-constant-face)
+
+ ;; regular numbers
+ ;;
+ ;; This regexp relies on '.' being symbol constituent. Whenever this
+ ;; changes, the regexp needs revisiting --immerrr
+ (, (rx symbol-start
+ ;; make a digit on either side of dot mandatory
+ (or (seq (+ num) (? ".") (* num))
+ (seq (* num) (? ".") (+ num)))
+ (? (regexp "[eE][+-]?") (+ num))
+ symbol-end)
+ . font-lock-constant-face)
+
+ ("^[ \t]*\\_<for\\_>"
+ (,(lua-make-delimited-matcher "\\_<[[:alpha:]_][[:alnum:]_]*\\_>" ","
+ "\\(?:\\_<in\\_>\\|=\\(?:[^=]\\|$\\)\\)")
+ nil nil
+ (1 font-lock-variable-name-face nil noerror)
+ (2 font-lock-warning-face t noerror)
+ (3 font-lock-warning-face t noerror)))
+
+ ;; Handle local variable/function names
+ ;; local blalba, xyzzy =
+ ;; ^^^^^^ ^^^^^
+ ;;
+ ;; local function foobar(x,y,z)
+ ;; ^^^^^^
+ ;; local foobar = function(x,y,z)
+ ;; ^^^^^^
+ ("^[ \t]*\\_<local\\_>"
+ (0 font-lock-keyword-face)
+
+ ((lambda (end)
+ (re-search-forward
+ (rx point (* blank) (regexp ,lua-defun-intro-regexp)) end t))
+ nil nil
+ (1 font-lock-function-name-face nil noerror))
+
+ (,(lua-make-delimited-matcher "\\_<[[:alpha:]_][[:alnum:]_]*\\_>" ","
+ "=\\(?:[^=]\\|$\\)")
+ nil nil
+ (1 font-lock-variable-name-face nil noerror)
+ (2 font-lock-warning-face t noerror)
+ (3 font-lock-warning-face t noerror)))
+
+ (,lua-defun-intro-regexp
+ (1 font-lock-function-name-face)))
+
+ "Default expressions to highlight in Lua mode."))
(defvar lua-imenu-generic-expression
;; This regexp matches expressions which look like function
@@ -1362,18 +1364,8 @@ one."
(cdr indentation-info))))
-(eval-when-compile
- (defconst lua--function-name-rx
- '(seq symbol-start
- (+ (any alnum "_"))
- (* "." (+ (any alnum "_")))
- (? ":" (+ (any alnum "_")))
- symbol-end)
- "Lua function name regexp in `rx'-SEXP format."))
-
-
-(defconst lua--left-shifter-regexp
- (eval-when-compile
+(eval-and-compile
+ (defconst lua--left-shifter-regexp
(rx
;; This regexp should answer the following questions:
;; 1. is there a left shifter regexp on that line?
@@ -1396,9 +1388,9 @@ one."
"function"
(seq
(eval lua--function-name-rx) (* blank)
- (regexp "\\(?1:\\)") (any "({")))))))
+ (regexp "\\(?1:\\)") (any "({"))))))
- "Regular expression that matches left-shifter expression.
+ "Regular expression that matches left-shifter expression.
Left-shifter expression is defined as follows. If a block
follows a left-shifter expression, its contents & block-close
@@ -1420,7 +1412,7 @@ The following left-shifter expressions are currently
handled:
3. assignment/return statement with
- table constructor block, {}
- function call arguments block, () or {} block
- - function expression a.k.a. lambda, begin-end block.")
+ - function expression a.k.a. lambda, begin-end block."))
(defun lua-point-is-after-left-shifter-p ()
- [nongnu] elpa/lua-mode ced5226 161/468: lua-with-silent-modifications: fix old style backquotes in fallback implementation, (continued)
- [nongnu] elpa/lua-mode ced5226 161/468: lua-with-silent-modifications: fix old style backquotes in fallback implementation, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode bba7fc0 163/468: Fix byte-compilation, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode d128a74 170/468: Add initial version of test/indentation/README.md, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 4399254 177/468: Merge pull request #39, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 08ff6ea 183/468: Merge remote-tracking branch 'origin/master', Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 8aa98ae 185/468: Non-functional refactoring, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 7605d2c 186/468: lua-font-lock-keywords: rewrite poorly written regexp (issue #47), Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode c24f16e 188/468: Put Lua reference resources into TODO file, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 5d81110 196/468: Wrap symbols required during compilation into (eval-when compile ...), Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 040bc8f 213/468: Bump NEWS, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 1d8dc55 214/468: Rename lua--function-name-rx, use it in font-lock keywords init,
Philip Kaludercic <=
- [nongnu] elpa/lua-mode d552910 218/468: Add a test for defun font-locking; add make check target to run it, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 4141c85 222/468: Make builtin font-locking more stable; enable it after ".." operator, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 1716660 223/468: Fix interaction with electric-pair-mode (issue #54), Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 4217513 230/468: Remove highlighting of numbers for consistency with other major-modes, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 248bea3 233/468: Remove syntax hacks for '.' & '_' characters, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode c5e9620 238/468: Fix stacktrace parsing in inferior process buffer, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode f834c21 105/468: lua-mark-all-multiline-literals: fix missed rename, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode aec4eea 117/468: lua-mark/-unmark-all-multiline-literals: fix error occurring on empty buffer (fixes #4 ?), Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 535ca1b 128/468: lua-mark-char-multiline-delim, lua-unmark-multiline-literals: inhibit after-change-functions to avoid running automarking twice on the same text, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode bb9330f 132/468: Fix string contents indentation (issue #6), Philip Kaludercic, 2021/08/05