[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/lua-mode 4342dd1 372/468: Fix compatibility with new rx pa
From: |
Philip Kaludercic |
Subject: |
[nongnu] elpa/lua-mode 4342dd1 372/468: Fix compatibility with new rx package from Emacs 27 |
Date: |
Thu, 5 Aug 2021 04:59:11 -0400 (EDT) |
branch: elpa/lua-mode
commit 4342dd1b7fa505a030e6a6871a3c4f053dbf6ad2
Author: immerrr <immerrr+lua@gmail.com>
Commit: immerrr <immerrr+lua@gmail.com>
Fix compatibility with new rx package from Emacs 27
---
lua-mode.el | 164 +++++++++++++++++++++++++++++++++++++-----------------------
1 file changed, 102 insertions(+), 62 deletions(-)
diff --git a/lua-mode.el b/lua-mode.el
index 5fdcb6d..0323250 100644
--- a/lua-mode.el
+++ b/lua-mode.el
@@ -101,80 +101,120 @@
(require 'compile))
(eval-and-compile
- (defvar lua-rx-constituents)
- (defvar rx-parent)
-
- (defun lua-rx-to-string (form &optional no-group)
- "Lua-specific replacement for `rx-to-string'.
+ (if (fboundp #'rx-let)
+ (progn
+ ;; Emacs 27+ way of customizing rx
+ (defvar lua--rx-bindings)
+
+ (setq
+ lua--rx-bindings
+ '((symbol (&rest x) (seq symbol-start (or x) symbol-end))
+ (ws (* (any " \t")))
+ (ws+ (+ (any " \t")))
+
+ (lua-name (symbol (seq (+ (any alpha "_")) (* (any alnum "_")))))
+ (lua-funcname (seq lua-name (* ws "." ws lua-name)
+ (opt ws ":" ws lua-name)))
+ (lua-funcheader
+ ;; Outer (seq ...) is here to shy-group the definition
+ (seq (or (seq (symbol "function") ws (group-n 1 lua-funcname))
+ (seq (group-n 1 lua-funcname) ws "=" ws
+ (symbol "function")))))
+ (lua-number
+ (seq (or (seq (+ digit) (opt ".") (* digit))
+ (seq (* digit) (opt ".") (+ digit)))
+ (opt (regexp "[eE][+-]?[0-9]+"))))
+ (lua-assignment-op (seq "=" (or buffer-end (not (any "=")))))
+ (lua-token (or "+" "-" "*" "/" "%" "^" "#" "==" "~=" "<=" ">=" "<"
+ ">" "=" ";" ":" "," "." ".." "..."))
+ (lua-keyword
+ (symbol "and" "break" "do" "else" "elseif" "end" "for" "function"
+ "goto" "if" "in" "local" "not" "or" "repeat" "return"
+ "then" "until" "while"))))
+
+ (defmacro lua-rx (&rest regexps)
+ (eval `(rx-let ,lua--rx-bindings
+ (rx ,@regexps))))
+
+ (defun lua-rx-to-string (form &optional no-group)
+ (rx-let-eval lua--rx-bindings
+ (rx-to-string form no-group))))
+ (progn
+ ;; Pre-Emacs 27 way of customizing rx
+ (defvar lua-rx-constituents)
+ (defvar rx-parent)
+
+ (defun lua-rx-to-string (form &optional no-group)
+ "Lua-specific replacement for `rx-to-string'.
See `rx-to-string' documentation for more information FORM and
NO-GROUP arguments."
- (let ((rx-constituents lua-rx-constituents))
- (rx-to-string form no-group)))
+ (let ((rx-constituents lua-rx-constituents))
+ (rx-to-string form no-group)))
- (defmacro lua-rx (&rest regexps)
- "Lua-specific replacement for `rx'.
+ (defmacro lua-rx (&rest regexps)
+ "Lua-specific replacement for `rx'.
See `rx' documentation for more information about REGEXPS param."
- (cond ((null regexps)
- (error "No regexp"))
- ((cdr regexps)
- (lua-rx-to-string `(and ,@regexps) t))
- (t
- (lua-rx-to-string (car regexps) t))))
+ (cond ((null regexps)
+ (error "No regexp"))
+ ((cdr regexps)
+ (lua-rx-to-string `(and ,@regexps) t))
+ (t
+ (lua-rx-to-string (car regexps) t))))
- (defun lua--new-rx-form (form)
- "Add FORM definition to `lua-rx' macro.
+ (defun lua--new-rx-form (form)
+ "Add FORM definition to `lua-rx' macro.
FORM is a cons (NAME . DEFN), see more in `rx-constituents' doc.
This function enables specifying new definitions using old ones:
if DEFN is a list that starts with `:rx' symbol its second
element is itself expanded with `lua-rx-to-string'. "
- (let ((name (car form))
- (form-definition (cdr form)))
- (when (and (listp form-definition) (eq ':rx (car form-definition)))
- (setcdr form (lua-rx-to-string (cadr form-definition) 'nogroup)))
- (push form lua-rx-constituents)))
-
- (defun lua--rx-symbol (form)
- ;; form is a list (symbol XXX ...)
- ;; Skip initial 'symbol
- (setq form (cdr form))
- ;; If there's only one element, take it from the list, otherwise wrap the
- ;; whole list into `(or XXX ...)' form.
- (setq form (if (eq 1 (length form))
- (car form)
- (append '(or) form)))
- (rx-form `(seq symbol-start ,form symbol-end) rx-parent))
-
- (setq lua-rx-constituents (copy-sequence rx-constituents))
-
- (mapc #'lua--new-rx-form
- `((symbol lua--rx-symbol 1 nil)
- (ws . "[ \t]*") (ws+ . "[ \t]+")
- (lua-name :rx (symbol (regexp "[[:alpha:]_]+[[:alnum:]_]*")))
- (lua-funcname
- :rx (seq lua-name (* ws "." ws lua-name)
- (opt ws ":" ws lua-name)))
- (lua-funcheader
- ;; Outer (seq ...) is here to shy-group the definition
- :rx (seq (or (seq (symbol "function") ws (group-n 1 lua-funcname))
- (seq (group-n 1 lua-funcname) ws "=" ws
- (symbol "function")))))
- (lua-number
- :rx (seq (or (seq (+ digit) (opt ".") (* digit))
- (seq (* digit) (opt ".") (+ digit)))
- (opt (regexp "[eE][+-]?[0-9]+"))))
- (lua-assignment-op
- :rx (seq "=" (or buffer-end (not (any "=")))))
- (lua-token
- :rx (or "+" "-" "*" "/" "%" "^" "#" "==" "~=" "<=" ">=" "<"
- ">" "=" ";" ":" "," "." ".." "..."))
- (lua-keyword
- :rx (symbol "and" "break" "do" "else" "elseif" "end" "for"
"function"
- "goto" "if" "in" "local" "not" "or" "repeat" "return"
- "then" "until" "while")))
- ))
+ (let ((name (car form))
+ (form-definition (cdr form)))
+ (when (and (listp form-definition) (eq ':rx (car form-definition)))
+ (setcdr form (lua-rx-to-string (cadr form-definition) 'nogroup)))
+ (push form lua-rx-constituents)))
+
+ (defun lua--rx-symbol (form)
+ ;; form is a list (symbol XXX ...)
+ ;; Skip initial 'symbol
+ (setq form (cdr form))
+ ;; If there's only one element, take it from the list, otherwise wrap
the
+ ;; whole list into `(or XXX ...)' form.
+ (setq form (if (eq 1 (length form))
+ (car form)
+ (append '(or) form)))
+ (rx-form `(seq symbol-start ,form symbol-end) rx-parent))
+
+ (setq lua-rx-constituents (copy-sequence rx-constituents))
+
+ (mapc #'lua--new-rx-form
+ `((symbol lua--rx-symbol 1 nil)
+ (ws . "[ \t]*") (ws+ . "[ \t]+")
+ (lua-name :rx (symbol (regexp "[[:alpha:]_]+[[:alnum:]_]*")))
+ (lua-funcname
+ :rx (seq lua-name (* ws "." ws lua-name)
+ (opt ws ":" ws lua-name)))
+ (lua-funcheader
+ ;; Outer (seq ...) is here to shy-group the definition
+ :rx (seq (or (seq (symbol "function") ws (group-n 1
lua-funcname))
+ (seq (group-n 1 lua-funcname) ws "=" ws
+ (symbol "function")))))
+ (lua-number
+ :rx (seq (or (seq (+ digit) (opt ".") (* digit))
+ (seq (* digit) (opt ".") (+ digit)))
+ (opt (regexp "[eE][+-]?[0-9]+"))))
+ (lua-assignment-op
+ :rx (seq "=" (or buffer-end (not (any "=")))))
+ (lua-token
+ :rx (or "+" "-" "*" "/" "%" "^" "#" "==" "~=" "<=" ">=" "<"
+ ">" "=" ";" ":" "," "." ".." "..."))
+ (lua-keyword
+ :rx (symbol "and" "break" "do" "else" "elseif" "end" "for"
"function"
+ "goto" "if" "in" "local" "not" "or" "repeat"
"return"
+ "then" "until" "while")))
+ ))))
;; Local variables
- [nongnu] elpa/lua-mode 04a2772 310/468: Fix goto label fontification, (continued)
- [nongnu] elpa/lua-mode 04a2772 310/468: Fix goto label fontification, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode fbad628 316/468: Add travis.yml, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 6b32777 413/468: assignment statements: unindent closing parenthesis on right hand side, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 6638de0 437/468: Merge pull request #182 from immerrr/enable-ci-via-github-actions, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode a4f49d3 438/468: Consider point as inside comment if it is inside "--" opener, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 3a0fb4b 431/468: `lua-funcname-at-point': add tests, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 430679c 433/468: `lua-funcname-at-point': handle identifiers before, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 432d9a0 333/468: lua-try-match-multiline-begin: reword the comment, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode ecfe465 352/468: Remove testing for Emacs < 24.3, and add 25.2 and 25.3, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 99312b8 365/468: Merge pull request #134 from velkyel/master, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 4342dd1 372/468: Fix compatibility with new rx package from Emacs 27,
Philip Kaludercic <=
- [nongnu] elpa/lua-mode 50d94a4 373/468: tests: silence "Indenting region..." messages, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode d746b7e 381/468: Fix typos, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode dc30240 384/468: Merge pull request #160 from tarsiiformes/typo, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 4db05e8 389/468: Use cl-lib instead of cl, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 3f67365 394/468: Renamed word “Result” to “Actual” in matcher's message, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 658bf8f 397/468: Merge pull request #166 from veprbl/patch-1, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 6436a45 398/468: Index "require" as imenu items, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 0e6813a 405/468: Refactor indentation tests to use test cases defined in *.lua files, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode acbcdc9 407/468: Don't prevent "block starter" tokens from starting continuation lines, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 4a45c6d 410/468: lua-make-indentation-info-pair: optimize "same-line" checks, Philip Kaludercic, 2021/08/05