[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/lua-mode c3b103d 290/468: lua-beginning-of-proc: improve d
From: |
Philip Kaludercic |
Subject: |
[nongnu] elpa/lua-mode c3b103d 290/468: lua-beginning-of-proc: improve defun header regex |
Date: |
Thu, 5 Aug 2021 04:58:55 -0400 (EDT) |
branch: elpa/lua-mode
commit c3b103dc4c7ca9881c40eb8f7477c85b6ea6bf7f
Author: immerrr <immerrr+lua@gmail.com>
Commit: immerrr <immerrr+lua@gmail.com>
lua-beginning-of-proc: improve defun header regex
Now it matches all common Lua function headers, including:
- local function XXX(...)
- XXX = function(...)
- XXX = local function(...)
---
lua-mode.el | 9 +++++++--
test/generic-test.el | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 57 insertions(+), 2 deletions(-)
diff --git a/lua-mode.el b/lua-mode.el
index 6640468..122a51e 100644
--- a/lua-mode.el
+++ b/lua-mode.el
@@ -1537,6 +1537,11 @@ If not, return nil."
;; 4. if there's no previous line, indentation is 0
0))))
+(defvar lua--beginning-of-defun-re
+ (lua-rx-to-string '(: bol (? (symbol "local") ws+) lua-funcheader))
+ "Lua top level (matches only at the beginning of line) function header
regex.")
+
+
(defun lua-beginning-of-proc (&optional arg)
"Move backward to the beginning of a lua proc (or similar).
@@ -1548,11 +1553,11 @@ Returns t unless search stops due to beginning or end
of buffer."
(or arg (setq arg 1))
(while (and (> arg 0)
- (re-search-backward "^function[ \t]" nil t))
+ (re-search-backward lua--beginning-of-defun-re nil t))
(setq arg (1- arg)))
(while (and (< arg 0)
- (re-search-forward "^function[ \t]" nil t))
+ (re-search-forward lua--beginning-of-defun-re nil t))
(beginning-of-line)
(setq arg (1+ arg)))
diff --git a/test/generic-test.el b/test/generic-test.el
index 0090674..f9d6d47 100644
--- a/test/generic-test.el
+++ b/test/generic-test.el
@@ -19,3 +19,53 @@
"--[[end here]] end"))
(lua-forward-sexp)
(should (looking-back (rx "--[[end here]] end")))))
+
+(ert-deftest lua-beginning-of-defun-different-headers ()
+ (with-lua-buffer
+ (lua-insert-goto-<>
+ '("function foobar()"
+ "<>"
+ "end"))
+ (beginning-of-defun)
+ (should (looking-at "function foobar()")))
+
+ (with-lua-buffer
+ (lua-insert-goto-<>
+ '("local function foobar()"
+ "<>"
+ "end"))
+ (beginning-of-defun)
+ (should (looking-at "local function foobar()")))
+
+ (with-lua-buffer
+ (lua-insert-goto-<>
+ '("local foobar = function()"
+ "<>"
+ "end"))
+ (beginning-of-defun)
+ (should (looking-at "local foobar = function()")))
+
+ (with-lua-buffer
+ (lua-insert-goto-<>
+ '("foobar = function()"
+ "<>"
+ "end"))
+ (beginning-of-defun)
+ (should (looking-at "foobar = function()"))))
+
+(ert-deftest lua-beginning-of-defun-accepts-dots-and-colons ()
+ (with-lua-buffer
+ (lua-insert-goto-<>
+ '("foo.bar = function (x,y,z)"
+ "<>"
+ "end"))
+ (beginning-of-defun)
+ (should (looking-at "foo\\.bar = function (x,y,z)")))
+
+ (with-lua-buffer
+ (lua-insert-goto-<>
+ '("function foo.bar:baz (x,y,z)"
+ "<>"
+ "end"))
+ (beginning-of-defun)
+ (should (looking-at "function foo.bar:baz (x,y,z)"))))
- [nongnu] elpa/lua-mode d4ee03e 278/468: Use syntax-propertize-function if it is available, (continued)
- [nongnu] elpa/lua-mode d4ee03e 278/468: Use syntax-propertize-function if it is available, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode fd0f6ba 280/468: Merge pull request #69 from atomontage/master, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 694421c 274/468: Add lua-remove-syntax-table-property to syntactic keywords, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode b73794f 276/468: Merge pull request #79 from j-fu/master, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 13f6ffa 277/468: Provide lua--setq-local fallback macro for pre-24.3, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode ce0a813 282/468: Mention xristos in AUTHORS, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 6d66aee 284/468: Redo handling of "stdin:N" in tracebacks, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode d7855bc 285/468: remove function lua-comment-p, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 5995697 286/468: Merge pull request #81 from v2e4lisp/remove-lua-comment-p, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 8a37fce 288/468: Merge pull request #82 from holomorph/browse-url, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode c3b103d 290/468: lua-beginning-of-proc: improve defun header regex,
Philip Kaludercic <=
- [nongnu] elpa/lua-mode 522edaf 289/468: with-lua-buffer: mark as debuggable, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode a57e25e 293/468: Update documentation, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode ceb74ae 296/468: Add file test/.nosearch, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode a7780dc 304/468: silence 25.1 byte-compiler, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 37f3c42 306/468: Silence compilation warning about referencing a variable from compile.el, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 148858c 309/468: Migrate tests to buttercup, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 0ce2b96 314/468: Allow to set lua-indent-level as file local variable, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 8b9d895 311/468: Fix comments being spilled into the code (issue #25), Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode cadc1ea 312/468: to-be-fontified-as: improve error messages, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 444ac2f 320/468: Merge 'stable' back into 'master', Philip Kaludercic, 2021/08/05