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

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

[nongnu] elpa/evil-matchit 2ea15db747 185/244: improve ruby matching alg


From: ELPA Syncer
Subject: [nongnu] elpa/evil-matchit 2ea15db747 185/244: improve ruby matching algorithm (fixed item 1 of #114)
Date: Thu, 6 Jan 2022 02:59:00 -0500 (EST)

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

    improve ruby matching algorithm (fixed item 1 of #114)
---
 evil-matchit-sdk.el | 52 +++++++++++++++++++++++++++-------------------------
 1 file changed, 27 insertions(+), 25 deletions(-)

diff --git a/evil-matchit-sdk.el b/evil-matchit-sdk.el
index f81de4c9b8..34ecd2698d 100644
--- a/evil-matchit-sdk.el
+++ b/evil-matchit-sdk.el
@@ -106,9 +106,8 @@ is-function-exit-point could be unknown status"
         (setq item (nth j items))
         (setq found (and (or (stringp item) (listp item))
                          (evilmi-sdk-member keyword item)))
-        (if (not found)
-            (setq j (1+ j))))
-      (if (not found) (setq i (1+ i))))
+        (unless found (setq j (1+ j))))
+      (unless found (setq i (1+ i))))
     (when found
       ;; function exit point maybe?
       (if (nth 3 (nth i match-tags))
@@ -120,6 +119,17 @@ is-function-exit-point could be unknown status"
   (if evilmi-debug (message "evilmi-sdk-get-tag-info called => %s %s. rlt=%s" 
keyword match-tags rlt))
     rlt))
 
+(defun evilmi--sdk-check-keyword (keyword begin end)
+  "KEYWORD has valid keyword font space between BEGIN and END."
+  (let* (rlt)
+    (save-excursion
+      (goto-char begin)
+      (while (search-forward keyword end t)
+        (when (not (evilmi-among-fonts-p (point)
+                                         evilmi-ignored-fonts))
+          (setq rlt keyword))))
+    rlt))
+
 (defun evilmi--sdk-extract-keyword (cur-line match-tags howtos)
   "Extract keyword from CUR-LINE.  Keyword is defined in MATCH-TAGS."
   (let* (keyword howto (i 0))
@@ -127,22 +137,16 @@ is-function-exit-point could be unknown status"
       (setq howto (nth i howtos))
       (when (string-match (nth 0 howto) cur-line)
         ;; keyword should be trimmed because FORTRAN use "else if"
-        (setq keyword (evilmi-sdk-trim-string (match-string (nth 1 howto) 
cur-line) ))
-        ;; (message "keyword=%s" keyword)
-
+        (setq keyword (evilmi-sdk-trim-string (match-string (nth 1 howto)
+                                                            cur-line)))
         ;; keep search keyword by using next howto (regex and match-string 
index)
-        (if (not (evilmi-sdk-member keyword match-tags)) (setq keyword nil)))
+        (unless (evilmi-sdk-member keyword match-tags) (setq keyword nil)))
       (setq i (1+ i)))
 
-    (when keyword
-      ;; ignore text with specific font
-      (save-excursion
-        (goto-char (line-beginning-position))
-        (when (and (search-forward keyword (line-end-position) t)
-                   (evilmi-among-fonts-p (point)
-                                         evilmi-ignored-fonts))
-          (setq keyword nil))))
-    keyword))
+    (and keyword
+         (evilmi--sdk-check-keyword keyword
+                                    (line-beginning-position)
+                                    (line-end-position)))))
 
 (defun evilmi--is-monogamy (tag-info)
   (and (nth 2 tag-info) (string= (nth 2 tag-info) "MONOGAMY")))
@@ -165,20 +169,18 @@ is-function-exit-point could be unknown status"
 ;;;###autoload
 (defun evilmi-sdk-get-tag (match-tags howtos)
   "Return '(start-point ((row column is-function-exit-point keyword))."
-  (let* (rlt
-         (cur-line (evilmi-sdk-curline))
+  (let* ((cur-line (evilmi-sdk-curline))
          (keyword (evilmi--sdk-extract-keyword cur-line match-tags howtos))
          (tag-info (if keyword (evilmi-sdk-get-tag-info keyword match-tags))))
 
     ;; since we mixed ruby and lua mode here
     ;; maybe we should be strict at the keyword
-    (if tag-info
-        ;; 0 - open tag; 1 - middle tag; 2 - close tag;
-        (setq rlt (list (if (= 2 (nth 1 tag-info))
-                            (line-end-position)
-                          (line-beginning-position))
-                        tag-info)))
-    rlt))
+    (and tag-info
+      ;; 0 - open tag; 1 - middle tag; 2 - close tag;
+         (list (if (= 2 (nth 1 tag-info))
+                   (line-end-position)
+                 (line-beginning-position))
+               tag-info))))
 
 ;;;###autoload
 (defun evilmi-sdk-jump (rlt num match-tags howtos)



reply via email to

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