[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/lua-mode 770a83d 376/468: Merge pull request #152 from imm
From: |
Philip Kaludercic |
Subject: |
[nongnu] elpa/lua-mode 770a83d 376/468: Merge pull request #152 from immerrr/fix-compat-with-new-rx-package |
Date: |
Thu, 5 Aug 2021 04:59:12 -0400 (EDT) |
branch: elpa/lua-mode
commit 770a83d8e3df68fb93df72456007f721e94d10e9
Merge: 95c64bb 99c7431
Author: immerrr again <immerrr+lua@gmail.com>
Commit: GitHub <noreply@github.com>
Merge pull request #152 from immerrr/fix-compat-with-new-rx-package
Fix compatibility with new rx package from Emacs 27
---
.travis.yml | 12 ++-
lua-mode.el | 207 ++++++++++++++++++++++++++++++-------------------
test/test-font-lock.el | 15 +++-
test/utils.el | 11 +--
4 files changed, 158 insertions(+), 87 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index bdf11ca..0479a5c 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,20 +1,28 @@
-language: emacs-lisp
+dist: xenial
+language: minimal
sudo: no
addons:
apt:
packages:
- lua5.2
env:
+ - EVM_EMACS=emacs-26.1-travis-linux-xenial
+ - EVM_EMACS=emacs-26.2-travis-linux-xenial
+ - EVM_EMACS=emacs-git-snapshot-travis-linux-xenial
- EVM_EMACS=emacs-24.3-travis
- EVM_EMACS=emacs-24.4-travis
- EVM_EMACS=emacs-24.5-travis
- EVM_EMACS=emacs-25.1-travis
- EVM_EMACS=emacs-25.2-travis
- EVM_EMACS=emacs-25.3-travis
-# - EVM_EMACS=emacs-git-snapshot-travis
+matrix:
+ allow_failures:
+ - env: EVM_EMACS=emacs-git-snapshot-travis-linux-xenial
+ fast_finish: true
before_install:
- curl -fsSkL https://gist.github.com/rejeep/ebcd57c3af83b049833b/raw >
travis.sh && source ./travis.sh
- evm install "$EVM_EMACS" --use --skip
+ - emacs --version
install:
- cask install
script:
diff --git a/lua-mode.el b/lua-mode.el
index af94a13..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
@@ -1101,8 +1141,11 @@ DIRECTION has to be either 'forward or 'backward."
(defun lua-goto-matching-block-token (&optional parse-start direction)
"Find block begion/end token matching the one at the point.
This function moves the point to the token that matches the one
-at the current point. Returns the point position of the first character of
-the matching token if successful, nil otherwise."
+at the current point. Returns the point position of the first character of
+the matching token if successful, nil otherwise.
+
+Optional PARSE-START is a position to which the point should be moved first.
+DIRECTION has to be 'forward or 'backward ('forward by default)."
(if parse-start (goto-char parse-start))
(let ((case-fold-search nil))
(if (looking-at lua-indentation-modifier-regexp)
@@ -1114,7 +1157,10 @@ the matching token if successful, nil otherwise."
(defun lua-goto-matching-block (&optional noreport)
"Go to the keyword balancing the one under the point.
If the point is on a keyword/brace that starts a block, go to the
-matching keyword that ends the block, and vice versa."
+matching keyword that ends the block, and vice versa.
+
+If optional NOREPORT is non-nil, it won't flag an error if there
+is no block open/close open."
(interactive)
;; search backward to the beginning of the keyword if necessary
(if (eq (char-syntax (following-char)) ?w)
@@ -1129,7 +1175,7 @@ matching keyword that ends the block, and vice versa."
"Move 1 line forward (back if BACK is non-nil) skipping blank lines.
Moves point 1 line forward (or backward) skipping lines that contain
-no Lua code besides comments. The point is put to the beginning of
+no Lua code besides comments. The point is put to the beginning of
the line.
Returns final value of point as integer or nil if operation failed."
@@ -1160,7 +1206,7 @@ Returns final value of point as integer or nil if
operation failed."
t)
"\\)"
"\\s *\\="))
- "Regexp that matches the ending of a line that needs continuation
+ "Regexp that matches the ending of a line that needs continuation.
This regexp starts from eol and looks for a binary operator or an unclosed
block intro (i.e. 'for' without 'do' or 'if' without 'then') followed by
@@ -1179,15 +1225,15 @@ an optional whitespace till the end of the line.")
t)
"\\($\\|[^" lua-operator-class "]\\)"
"\\)"))
- "Regexp that matches a line that continues previous one
+ "Regexp that matches a line that continues previous one.
This regexp means, starting from point there is an optional whitespace followed
-by Lua binary operator. Lua is very liberal when it comes to continuation line,
+by Lua binary operator. Lua is very liberal when it comes to continuation
line,
so we're safe to assume that every line that starts with a binop continues
previous one even though it looked like an end-of-statement.")
(defun lua-last-token-continues-p ()
- "Returns true if the last token on this line is a continuation token."
+ "Return non-nil if the last token on this line is a continuation token."
(let ((line-begin (line-beginning-position))
(line-end (line-end-position)))
(save-excursion
@@ -1201,7 +1247,7 @@ previous one even though it looked like an
end-of-statement.")
(re-search-backward lua-cont-eol-regexp line-begin t))))
(defun lua-first-token-continues-p ()
- "Returns true if the first token on this line is a continuation token."
+ "Return non-nil if the first token on this line is a continuation token."
(let ((line-end (line-end-position)))
(save-excursion
(beginning-of-line)
@@ -1219,14 +1265,15 @@ previous one even though it looked like an
end-of-statement.")
"\\_>\\)")))
(defun lua-first-token-starts-block-p ()
- "Returns true if the first token on this line is a block starter token."
+ "Return non-nil if the first token on this line is a block starter token."
(let ((line-end (line-end-position)))
(save-excursion
(beginning-of-line)
(re-search-forward (concat "\\s *" lua-block-starter-regexp) line-end
t))))
(defun lua-is-continuing-statement-p (&optional parse-start)
- "Return non-nil if the line continues a statement.
+ "Return non-nil if the line at PARSE-START continues a statement.
+
More specifically, return the point in the line that is continued.
The criteria for a continuing statement are:
@@ -1246,8 +1293,10 @@ The criteria for a continuing statement are:
(lua-last-token-continues-p)))))))
(defun lua-make-indentation-info-pair (found-token found-pos)
- "This is a helper function to lua-calculate-indentation-info. Don't
-use standalone."
+ "Create a pair from FOUND-TOKEN and FOUND-POS for indentation calculation.
+
+This is a helper function to lua-calculate-indentation-info.
+Don't use standalone."
(cond
;; function is a bit tricky to indent right. They can appear in a lot ot
;; different contexts. Until I find a shortcut, I'll leave it with a simple
@@ -1321,17 +1370,17 @@ use standalone."
(- lua-indent-level))))))
(defun lua-add-indentation-info-pair (pair info)
- "Add the given indentation info pair to the list of indentation information.
+ "Add the given indentation info PAIR to the list of indentation INFO.
This function has special case handling for two tokens: remove-matching,
-and replace-matching. These two tokens are cleanup tokens that remove or
+and replace-matching. These two tokens are cleanup tokens that remove or
alter the effect of a previously recorded indentation info.
When a remove-matching token is encountered, the last recorded info, i.e.
-the car of the list is removed. This is used to roll-back an indentation of a
+the car of the list is removed. This is used to roll-back an indentation of a
block opening statement when it is closed.
When a replace-matching token is seen, the last recorded info is removed,
-and the cdr of the replace-matching info is added in its place. This is used
+and the cdr of the replace-matching info is added in its place. This is used
when a middle-of the block (the only case is 'else') is seen on the same line
the block is opened."
(cond
diff --git a/test/test-font-lock.el b/test/test-font-lock.el
index b89037d..f30b1fc 100644
--- a/test/test-font-lock.el
+++ b/test/test-font-lock.el
@@ -81,7 +81,20 @@ _table.sort(foobar)
(describe "Fontification of function headers"
- (it "fontifies simple headers"
+ (it "fontifies function <name>(...) headers"
+ (expect "function bar() end"
+ :to-be-fontified-as '(("function" keyword "bar" function-name
"end" keyword))))
+ (it "fontifies local function <name>(...) headers"
+ (expect "local function baz() end"
+ :to-be-fontified-as '(("local" keyword "function" keyword "baz"
function-name "end" keyword))))
+ (it "fontifies <name> = function (...) headers"
+ (expect "qux = function() end"
+ :to-be-fontified-as '(("qux" function-name "function" keyword
"end" keyword))))
+ (it "fontifies local <name> = function (...) headers"
+ (expect "local quux = function() end"
+ :to-be-fontified-as '(("local" keyword "quux" function-name
"function" keyword "end" keyword))))
+
+ (it "fontifies different variations of headers altogether"
(expect
;; Check all defun variants, check embedded defuns
"\
diff --git a/test/utils.el b/test/utils.el
index 63d77be..3b95c63 100644
--- a/test/utils.el
+++ b/test/utils.el
@@ -139,11 +139,12 @@ This is a mere typing/reading aid for lua-mode's
font-lock tests."
(butlast
(split-string
(with-lua-buffer
- (insert (replace-regexp-in-string "^\\s *" "" (lua-join-lines strs)))
- (font-lock-fontify-buffer)
- (indent-region (point-min) (point-max))
- (buffer-substring-no-properties
- (point-min) (point-max)))
+ (let ((inhibit-message t))
+ (insert (replace-regexp-in-string "^\\s *" "" (lua-join-lines strs)))
+ (font-lock-fontify-buffer)
+ (indent-region (point-min) (point-max))
+ (buffer-substring-no-properties
+ (point-min) (point-max))))
"\n" nil)))
(defun lua-insert-goto-<> (strs)
- [nongnu] elpa/lua-mode eacf137 349/468: Spell “Lua” consistently and its “process” (not “subprocess”), (continued)
- [nongnu] elpa/lua-mode eacf137 349/468: Spell “Lua” consistently and its “process” (not “subprocess”), Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode acd0c55 354/468: Revert to using group-n in lua--left-shifter-regexp, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 3ba5ecc 360/468: Minor simplification of lua-get-create-process, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode c6e053e 361/468: Spell “Lua” consistently and its “process” (not “subprocess”), Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 7909513 363/468: Merge pull request #141 from rrthomas/master, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode a260cf9 368/468: Travis: enable testing on 26.1, 26.2 and git snapshot, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode c9635fb 369/468: travis.yml: print emacs version, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 494a5de 371/468: Fix some linter complaints about docstrings, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode ceb575b 374/468: tests: break down function header tests into separate cases, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 99c7431 375/468: travis: mark "git-snapshot" as allowed failure, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 770a83d 376/468: Merge pull request #152 from immerrr/fix-compat-with-new-rx-package,
Philip Kaludercic <=
- [nongnu] elpa/lua-mode 171b99c 382/468: Merge pull request #159 from tarsiiformes/typos, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode a1f6d28 385/468: added lua-indent-close-paren-align var, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 3c9ec08 391/468: Depend on Emacs 24.3, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 478da4a 393/468: Fixed order of expected & actual in matcher's message, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode d15bdb1 395/468: Merge pull request #164 from sergeyklay/fix/buttercup-matcher-message, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode c1b6019 396/468: Fix reproducibility issue caused by %d pattern in export-subst, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode c9b9d47 401/468: Fix typo, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode d7eaa8e 403/468: Add lua-backward-up-list command, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode db8d474 408/468: Fix indentation of multiline while/for+do and if/elseif+then, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 099c130 240/468: Bump NEWS, Philip Kaludercic, 2021/08/05