emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/evil-matchit ceec6a63b0 236/244: better algorithm to match


From: ELPA Syncer
Subject: [nongnu] elpa/evil-matchit ceec6a63b0 236/244: better algorithm to match bracket/brace in javascript
Date: Thu, 6 Jan 2022 02:59:05 -0500 (EST)

branch: elpa/evil-matchit
commit ceec6a63b014da874c9b6b6b0174592c93b4e12b
Author: Chen Bin <chenbin.sh@gmail.com>
Commit: Chen Bin <chenbin.sh@gmail.com>

    better algorithm to match bracket/brace in javascript
---
 evil-matchit-javascript.el  |  6 ++++--
 tests/evil-matchit-tests.el | 24 ++++++++++++++++++++++++
 tests/hello.js              | 11 ++++++++++-
 3 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/evil-matchit-javascript.el b/evil-matchit-javascript.el
index 28a965728f..901a6306cd 100644
--- a/evil-matchit-javascript.el
+++ b/evil-matchit-javascript.el
@@ -45,7 +45,8 @@
 ;; React JS code: " return ("
 ;; line could ends with C++ or C comment
 (defvar evilmi-javascript-open-brace-pattern
-  "^[ \t]*[(}]?[$_a-zA-Z0-9]+.*\\([{(]\\)[ \t]*\\(\/\/.*\\|\/\*[^/]*\*\/\\)?$")
+  "^[ \t]*[(}]?[$_a-zA-Z0-9]+.*\\([{(\[]\\)[ 
\t]*\\(\/\/.*\\|\/\*[^/]*\*\/\\)?$"
+  "Pattern to match line which ends with brace or bracket character.")
 
 (defun evilmi--javascript-find-open-brace (cur-line)
   "Find open brace from CUR-LINE."
@@ -54,6 +55,7 @@
      ((string-match evilmi-javascript-open-brace-pattern
                     cur-line)
       (setq rlt (list 1 (match-string 1 cur-line))))
+
      (t
       (save-excursion
         (forward-line)
@@ -94,7 +96,7 @@
   "Jump to the matching tag using INFO and NUM."
   (cond
    ((not info)
-    ;; don nothing
+    ;; do nothing
     )
    ((evilmi-sdk-get-tag evilmi-javascript-match-tags
                         evilmi-javascript-extract-keyword-howtos)
diff --git a/tests/evil-matchit-tests.el b/tests/evil-matchit-tests.el
index 3f02c81b93..a16abd6365 100644
--- a/tests/evil-matchit-tests.el
+++ b/tests/evil-matchit-tests.el
@@ -108,6 +108,30 @@
       (evilmi-jump-items)
       (should (eq (point) beg)))
 
+    (search-forward "test1" (point-max) t)
+    (backward-word)
+    (should (string= (evilmi-sdk-curline) "const test1 = ["))
+    (evilmi-jump-items)
+    (should (string= (evilmi-sdk-curline) "];"))
+    (evilmi-jump-items)
+    (should (string= (evilmi-sdk-curline) "const test1 = ["))
+
+    (search-forward "test2" (point-max) t)
+    (backward-word)
+    (should (string= (evilmi-sdk-curline) "const test2 = {"))
+    (evilmi-jump-items)
+    (should (string= (evilmi-sdk-curline) "};"))
+    (evilmi-jump-items)
+    (should (string= (evilmi-sdk-curline) "const test2 = {"))
+
+    (search-forward "test3" (point-max) t)
+    (backward-word)
+    (should (string= (evilmi-sdk-curline) "const test3 = hello("))
+    (evilmi-jump-items)
+    (should (string= (evilmi-sdk-curline) ");"))
+    (evilmi-jump-items)
+    (should (string= (evilmi-sdk-curline) "const test3 = hello("))
+
     (should (eq major-mode 'js-mode))))
 
 (ert-deftest evilmi-test-html ()
diff --git a/tests/hello.js b/tests/hello.js
index 73955f05bc..7eecc3ff42 100644
--- a/tests/hello.js
+++ b/tests/hello.js
@@ -1,3 +1,12 @@
 function hello() {
   console.log('hello world');
-}
\ No newline at end of file
+}
+
+const test1 = [
+];
+
+const test2 = {
+};
+
+const test3 = hello(
+);
\ No newline at end of file



reply via email to

[Prev in Thread] Current Thread [Next in Thread]