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

    develop raw algorithm to match between forward and backward characters
---
 evil-matchit-sdk.el | 75 ++++++++++++++++++++++++++++++++++++-----------------
 evil-matchit.el     |  4 +--
 pkg.sh              |  2 +-
 3 files changed, 54 insertions(+), 27 deletions(-)

diff --git a/evil-matchit-sdk.el b/evil-matchit-sdk.el
index d244c5cdef..e779349f16 100644
--- a/evil-matchit-sdk.el
+++ b/evil-matchit-sdk.el
@@ -34,6 +34,10 @@
 
 (defvar evilmi-debug nil "Debug flag.")
 
+(defvar evilmi-raw-scan-sexps-major-modes
+  '(lisp-interaction-mode)
+  "Major modes which using raw algorithm for forward&backward characters.")
+
 (defvar evilmi-forward-chars (string-to-list "[{("))
 (defvar evilmi-backward-chars (string-to-list "]})"))
 (defvar evilmi-quote-chars (string-to-list "'\"/"))
@@ -150,6 +154,45 @@ If font-face-under-cursor is NOT nil, the quoted string is 
being processed."
         (forward-word)))
     defun-p))
 
+(defun evilmi-sdk-raw-scan-sexps (is-forward character comment-p)
+  "Get the position of matching tag with CHARACTER at point.
+If IS-FORWARD is t, jump forward; or else jump backward.
+Raw algorithm is implemented, no use of native api.
+If COMMENT-P is t, non-comment is ignored.
+If COMMENT-P is nil, comment is ignored."
+  (when evilmi-debug
+    (message "evilmi-sdk-raw-scan-sexps called => %s %s %s"
+             is-forward character comment-p))
+
+  (let* ((start-pos (point))
+         (lvl 1)
+         (limit (if is-forward (point-max) (point-min)))
+         (dest-ch (cond
+                   ;; {}
+                   ((= character 123) 125)
+                   ((= character 125) 123)
+                   ;; ()
+                   ((= character 40) 41)
+                   ((= character 41) 40)
+                   ;; []
+                   ((= character 91) 93)
+                   ((= character 93) 91)))
+         (arg (if is-forward 1 -1))
+         rlt)
+    (save-excursion
+      (while (and dest-ch (not (= start-pos limit)) (> lvl 0))
+        (goto-char (setq start-pos (+ start-pos arg)))
+        (when (or (and comment-p (evilmi-sdk-comment-p start-pos))
+                  (and (not comment-p) (not (evilmi-sdk-comment-p start-pos))))
+          (cond
+           ((= (following-char) character)
+            (setq lvl (1+ lvl)))
+           ((= (following-char) dest-ch)
+            (setq lvl (1- lvl))))))
+      (when (= lvl 0)
+        (setq rlt (+ start-pos (if is-forward 1 0)))))
+    rlt))
+
 (defun evilmi-sdk-scan-sexps (is-forward character)
   "Get the position of matching tag with CHARACTER at point.
 If IS-FORWARD is t, jump forward; or else jump backward."
@@ -158,17 +201,6 @@ If IS-FORWARD is t, jump forward; or else jump backward."
   (let* ((start-pos (if is-forward (point) (+ 1 (point))))
          (arg (if is-forward 1 -1))
          (limit (if is-forward (point-max) (point-min)))
-         (lvl 1)
-         (dest-ch (cond
-                     ;; {}
-                     ((= character 123) 125)
-                     ((= character 125) 123)
-                     ;; ()
-                     ((= character 40) 41)
-                     ((= character 41) 40)
-                     ;; []
-                     ((= character 91) 93)
-                     ((= character 93) 91)))
          (rlt start-pos))
 
     (cond
@@ -187,18 +219,13 @@ If IS-FORWARD is t, jump forward; or else jump backward."
       ;; Matching tag in comment.
       ;; Use own algorithm instead of `scan-sexps'
       ;; because `scan-sexps' does not work in some major modes
-      (save-excursion
-        (setq start-pos (point))
-        (while (and dest-ch (not (= start-pos limit)) (> lvl 0))
-          (goto-char (setq start-pos (+ start-pos arg)))
-          (when (evilmi-sdk-comment-p start-pos)
-            (cond
-             ((= (following-char) character)
-              (setq lvl (1+ lvl)))
-             ((= (following-char) dest-ch)
-              (setq lvl (1- lvl))))))
-        (when (= lvl 0)
-          (setq rlt (+ start-pos (if is-forward 1 0))))))
+      (setq rlt (evilmi-sdk-raw-scan-sexps is-forward character t)))
+
+     ;; just use raw algorithm to match characters
+     ((and (memq major-mode evilmi-raw-scan-sexps-major-modes)
+           (or (memq character evilmi-forward-chars)
+               (memq character evilmi-backward-chars)))
+      (setq rlt (evilmi-sdk-raw-scan-sexps is-forward character nil)))
 
      (t
       ;; jump inside code and ignore comments
@@ -206,7 +233,7 @@ If IS-FORWARD is t, jump forward; or else jump backward."
         (setq rlt (scan-sexps start-pos arg)))))
 
     (when evilmi-debug
-      (message "evilmi-sdk-scan-sexps => rlt=%s lvl=%s is-forward=%s" rlt lvl 
is-forward))
+      (message "evilmi-sdk-scan-sexps => rlt=%s is-forward=%s" rlt is-forward))
     rlt))
 
 (defmacro evilmi-sdk-visual-state-p ()
diff --git a/evil-matchit.el b/evil-matchit.el
index d0d45e4c51..e07552e678 100644
--- a/evil-matchit.el
+++ b/evil-matchit.el
@@ -4,7 +4,7 @@
 
 ;; Author: Chen Bin <chenbin...@gmail.com>
 ;; URL: http://github.com/redguardtoo/evil-matchit
-;; Version: 3.0.2
+;; Version: 3.0.3
 ;; Keywords: matchit vim evil
 ;; Package-Requires: ((emacs "25.1"))
 ;;
@@ -325,7 +325,7 @@ If IS-INNER is t, the region is inner text object."
 (defun evilmi-version()
   "Print version."
   (interactive)
-  (message "3.0.2"))
+  (message "3.0.3"))
 
 ;; initialize evilmi-plugins only once
 (evilmi-init-plugins)
diff --git a/pkg.sh b/pkg.sh
index db239f4b30..35eb0ec4e9 100755
--- a/pkg.sh
+++ b/pkg.sh
@@ -1,6 +1,6 @@
 #!/bin/bash
 name=evil-matchit
-version=3.0.2
+version=3.0.3
 pkg=$name-$version
 mkdir $pkg
 cp README.org $pkg

Reply via email to