[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/lua-mode d7ff9c0 444/468: Fix lua-goto-matching-block for
From: |
Philip Kaludercic |
Subject: |
[nongnu] elpa/lua-mode d7ff9c0 444/468: Fix lua-goto-matching-block for when point is at the beginning of keyword |
Date: |
Thu, 5 Aug 2021 04:59:26 -0400 (EDT) |
branch: elpa/lua-mode
commit d7ff9c09e903b0c9f18888b99b9f15e4bf5442ce
Author: immerrr <immerrr+lua@gmail.com>
Commit: immerrr <immerrr+lua@gmail.com>
Fix lua-goto-matching-block for when point is at the beginning of keyword
---
lua-mode.el | 5 +++--
test/test-generic.el | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++
test/utils.el | 7 +++++++
3 files changed, 69 insertions(+), 2 deletions(-)
diff --git a/lua-mode.el b/lua-mode.el
index ccdb1be..42ccf31 100644
--- a/lua-mode.el
+++ b/lua-mode.el
@@ -1148,8 +1148,9 @@ 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)
- (re-search-backward "\\_<" nil t))
+ (when (and (eq (char-syntax (following-char)) ?w)
+ (not (looking-at "\\_<")))
+ (re-search-backward "\\_<" nil t))
(let ((position (lua-goto-matching-block-token)))
(if (and (not position)
(not noreport))
diff --git a/test/test-generic.el b/test/test-generic.el
index 1afcadc..796db3b 100644
--- a/test/test-generic.el
+++ b/test/test-generic.el
@@ -195,3 +195,62 @@ local foo = <2>{
:with-point-at "<1>"
:after-executing (lua-backward-up-list)
:to-end-up-at "<2>")))
+
+
+(describe "lua-goto-matching-block"
+ (it "works for do...end block"
+ (expect (lua-goto-matching-block) :to-move-point-from-1-to-2
+ "<2>do if true then print(123) end <1>end")
+
+ (expect (lua-goto-matching-block) :to-move-point-from-1-to-2
+ "<2>do if true then print(123) end e<1>nd")
+
+ (expect (lua-goto-matching-block) :to-move-point-from-1-to-2
+ "<2>do if true then print(123) end en<1>d")
+
+ (expect (lua-goto-matching-block) :to-move-point-from-1-to-2
+ "<1>do if true then print(123) end <2>end")
+
+ (expect (lua-goto-matching-block) :to-move-point-from-1-to-2
+ "d<1>o if true then print(123) end <2>end"))
+
+ (it "works for repeat...until block"
+ (expect (lua-goto-matching-block) :to-move-point-from-1-to-2
+ "<1>repeat if true then print(123) end <2>until true")
+
+ (expect (lua-goto-matching-block) :to-move-point-from-1-to-2
+ "<2>repeat if true then print(123) end <1>until true"))
+
+ (it "works for while...do...end block"
+ (expect (lua-goto-matching-block) :to-move-point-from-1-to-2
+ "<1>while foo() do if true then print(123) end <2>end")
+ (expect (lua-goto-matching-block) :to-move-point-from-1-to-2
+ "<2>while foo() do if true then print(123) end <1>end")
+ (expect (lua-goto-matching-block) :to-move-point-from-1-to-2
+ "while foo() <1>do if true then print(123) end <2>end")
+ ;; The next line is a valid statement that ensures
+ ;; "lua-goto-matching-block" can distinguish between "while..do" and
+ ;; "do..end"
+ (expect (lua-goto-matching-block) :to-move-point-from-1-to-2
+ "<1>while false do print(123) <2>end do print(123) end")
+ (expect (lua-goto-matching-block) :to-move-point-from-1-to-2
+ "while false do print(123) end <1>do print(123) <2>end"))
+
+ (it "works for if..elseif..else..end block"
+ (expect (lua-goto-matching-block) :to-move-point-from-1-to-2
+ "<1>if true then foo() elseif false then bar() else baz() <2>end")
+
+ (expect (lua-goto-matching-block) :to-move-point-from-1-to-2
+ "<2>if true then foo() elseif false then bar() else baz() <1>end")
+
+ (expect (lua-goto-matching-block) :to-move-point-from-1-to-2
+ "<2>if true then foo() elseif false then bar() <1>else baz() end")
+
+ (expect (lua-goto-matching-block) :to-move-point-from-1-to-2
+ "<2>if true then foo() elseif false <1>then bar() else baz() end")
+
+ (expect (lua-goto-matching-block) :to-move-point-from-1-to-2
+ "<2>if true then foo() <1>elseif false then bar() else baz() end")
+
+ (expect (lua-goto-matching-block) :to-move-point-from-1-to-2
+ "<2>if true <1>then foo() elseif false then bar() else baz()
end")))
diff --git a/test/utils.el b/test/utils.el
index fb588ad..6fc7912 100644
--- a/test/utils.el
+++ b/test/utils.el
@@ -231,6 +231,13 @@ This is a mere typing/reading aid for lua-mode's font-lock
tests."
(buttercup-define-matcher :with-point-at (&rest args)
(apply #'with-point-at-matcher `(:lua-code ,(car args) :with-point-at ,@(cdr
args))))
+;;; Shortcut for with-point-at with <1> and <2> placeholders
+(buttercup-define-matcher :to-move-point-from-1-to-2 (code-block lua-code)
+ (with-point-at-matcher
+ :lua-code lua-code
+ :with-point-at (lambda () "<1>")
+ :after-executing code-block
+ :to-end-up-at (lambda () "<2>")))
(defun lua--string-trim (string &optional trim-left trim-right)
;; Backport of string-trim for Emacs 24 that doesn't have subr-x lib.
- [nongnu] elpa/lua-mode 5bfdea5 420/468: Merge pull request #177 from immerrr/refactor-variable-list-fontification, (continued)
- [nongnu] elpa/lua-mode 5bfdea5 420/468: Merge pull request #177 from immerrr/refactor-variable-list-fontification, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 0546418 423/468: Extend lua-default-application doc a bit, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 9d46ad3 424/468: Update readme, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 345ebfc 425/468: Merge pull request #174 from immerrr/assorted-fixes, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 85d01e9 429/468: `lua-funcname-at-point': fix regexes, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode b647537 428/468: `lua-start-proces': don't hang if already running, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 853b040 432/468: `lua-start-process': start a new process sometimes, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode fbdbf05 439/468: Merge pull request #181 from immerrr/treat-comment-delimiters-as-comments-too, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode d63f2af 441/468: Merge pull request #183 from immerrr/add-lua-skip-ws-comment-functions, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode e81d0f2 442/468: Merge pull request #179 from nbfalcon/code-cleanup/fix-fixmes, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode d7ff9c0 444/468: Fix lua-goto-matching-block for when point is at the beginning of keyword,
Philip Kaludercic <=
- [nongnu] elpa/lua-mode 1f74cd5 453/468: Remove backward-up-list for "for" continuation lines, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 4e346d4 457/468: Add COPYING file, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode cf076a6 460/468: Replace funcall-interactively -> call-interactively (for Emacs-24.3), Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 9454aee 461/468: Merge pull request #187 from immerrr/re-enable-emacs-24, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 2d9a468 463/468: Merge pull request #189 from jcs-PR/badge, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode a57b1b1 462/468: Add badges to README, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode bc77051 464/468: Fix indentation, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 7ee3feb 468/468: Bump version tag for v20210802 release, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 4dc4cba 421/468: Remove stray tabs, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 2fc3251 426/468: `lua-funcname-at-point': don't modify the syntax, Philip Kaludercic, 2021/08/05