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

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

[nongnu] elpa/evil-matchit 25ad66d397 190/244: clean code


From: ELPA Syncer
Subject: [nongnu] elpa/evil-matchit 25ad66d397 190/244: clean code
Date: Thu, 6 Jan 2022 02:59:00 -0500 (EST)

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

    clean code
---
 evil-matchit-org.el    |  4 ++--
 evil-matchit-sdk.el    | 14 ++++++------
 evil-matchit-simple.el | 30 ++++++++++++++++---------
 evil-matchit.el        | 60 +++++++++++++++++++++++++++-----------------------
 4 files changed, 61 insertions(+), 47 deletions(-)

diff --git a/evil-matchit-org.el b/evil-matchit-org.el
index 38253d05ec..61357a3077 100644
--- a/evil-matchit-org.el
+++ b/evil-matchit-org.el
@@ -77,7 +77,7 @@ between '\\(' and '\\)' in regular expression.")
 (defun evilmi-org-jump (rlt num)
   (cond
    ((< (car rlt) 0)
-    (let* (where-to-jump-in-theory
+    (let* (ideal-dest
            jumped
            info
            (lang-f (evilmi--get-embedded-language-major-mode))
@@ -88,7 +88,7 @@ between '\\(' and '\\)' in regular expression.")
            (setq info (funcall (nth 0 elem)))
            (when (and info (not jumped))
              ;; before jump, we may need some operation
-             (setq where-to-jump-in-theory (funcall (nth 1 elem) info num))
+             (setq ideal-dest (funcall (nth 1 elem) info num))
              ;; jump only once if the jump is successful
              (setq jumped t)))
          plugin))))
diff --git a/evil-matchit-sdk.el b/evil-matchit-sdk.el
index 34ecd2698d..1526cc3627 100644
--- a/evil-matchit-sdk.el
+++ b/evil-matchit-sdk.el
@@ -195,7 +195,7 @@ after calling this function."
          (cur-line (evilmi-sdk-curline))
          keyword
          found
-         where-to-jump-in-theory)
+         ideal-dest)
     (if evilmi-debug (message "evilmi-sdk-jump called => rlt=%s (point)=%s" 
rlt (point)))
 
     (while (not found)
@@ -216,14 +216,14 @@ after calling this function."
            ((and (= orig-tag-type 0) (= cur-tag-type 1))
             (when (evilmi-sdk-tags-is-matched level orig-tag-info cur-tag-info 
match-tags)
               (back-to-indentation)
-              (setq where-to-jump-in-theory (1- (line-beginning-position)))
+              (setq ideal-dest (1- (line-beginning-position)))
               (setq found t)))
 
            ;; open (0) -> closed (2) found when level is zero, level--
            ((and (= orig-tag-type 0) (= cur-tag-type 2))
             (when (evilmi-sdk-tags-is-matched level orig-tag-info cur-tag-info 
match-tags)
               (goto-char (line-end-position))
-              (setq where-to-jump-in-theory (line-end-position))
+              (setq ideal-dest (line-end-position))
               (setq found t))
             (setq level (1- level)))
 
@@ -241,14 +241,14 @@ after calling this function."
 
             (when (evilmi-sdk-tags-is-matched level orig-tag-info cur-tag-info 
match-tags)
               (back-to-indentation)
-              (setq where-to-jump-in-theory (1- (line-beginning-position)))
+              (setq ideal-dest (1- (line-beginning-position)))
               (setq found t)))
 
            ;; mid (1) -> closed (2) found when level is zero, level --
            ((and (= orig-tag-type 1) (= cur-tag-type 2))
             (when (evilmi-sdk-tags-is-matched level orig-tag-info cur-tag-info 
match-tags)
               (goto-char (line-end-position))
-              (setq where-to-jump-in-theory (line-end-position))
+              (setq ideal-dest (line-end-position))
               (setq found t))
             (setq level (1- level)))
 
@@ -267,7 +267,7 @@ after calling this function."
            ;; closed (2) -> open (0) found when level is zero, level--
            ((and (= orig-tag-type 2) (= cur-tag-type 0))
             (when (evilmi-sdk-tags-is-matched level orig-tag-info cur-tag-info 
match-tags)
-              (setq where-to-jump-in-theory (line-beginning-position))
+              (setq ideal-dest (line-beginning-position))
               (back-to-indentation)
               (setq found t))
             (setq level (1- level)))
@@ -279,7 +279,7 @@ after calling this function."
               (= (line-beginning-position) (point-min)))
           (setq found t)))
 
-    where-to-jump-in-theory))
+    ideal-dest))
 
 
 ;;;###autoload
diff --git a/evil-matchit-simple.el b/evil-matchit-simple.el
index cbaf04e479..0dfd4c8864 100644
--- a/evil-matchit-simple.el
+++ b/evil-matchit-simple.el
@@ -1,6 +1,6 @@
 ;;; evil-matchit-simple.el --- simple match plugin of evil-matchit
 
-;; Copyright (C) 2014-2019 Chen Bin <chenbin.sh@gmail.com>
+;; Copyright (C) 2014-2020 Chen Bin <chenbin.sh@gmail.com>
 
 
 ;; Author: Chen Bin <chenbin.sh@gmail.com>
@@ -25,6 +25,9 @@
 ;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 
+
+;;; Commentary:
+
 ;;; Code:
 
 (require 'evil-matchit-sdk)
@@ -87,21 +90,26 @@
     rlt))
 
 ;;;###autoload
-(defun evilmi-simple-jump (rlt NUM)
-  "Jump from current tag to matching tag in simple language."
-  (when rlt
+(defun evilmi-simple-jump (info num)
+  "Use INFO of current tag ot jump to matching tag.  NUM is ignored."
+  (when info
     (if evilmi-debug (message "evilmi-simple-jump called (point)=%d" (point)))
 
     ;; In latex-mode `scan-sexps' does NOT work properly between "[]"
     ;; so we have to fallback to evil's API.
-    (if (memq major-mode '(latex-mode))
-        (evil-jump-item)
-      (evilmi--simple-jump))
+    (cond
+     ((memq major-mode '(latex-mode))
+      (evil-jump-item))
+     (t
+      (evilmi--simple-jump)))
 
     ;; hack for javascript
-    (if (string-match-p "^[ \t]*})\\((.*)\\)?\; *$"
-                      (evilmi-sdk-curline))
-        (line-end-position)
-      (1+ (point)))))
+    (cond
+     ((string-match "^[ \t]*})\\((.*)\\)?\; *$"
+                    (evilmi-sdk-curline))
+      (line-end-position))
+     (t
+      (1+ (point))))))
 
 (provide 'evil-matchit-simple)
+;;; evil-matchit-simple.el ends here
diff --git a/evil-matchit.el b/evil-matchit.el
index e40db14a79..8e05b4b485 100644
--- a/evil-matchit.el
+++ b/evil-matchit.el
@@ -241,37 +241,43 @@ If IS-FORWARD is t, jump forward; or else jump backward."
     (goto-char (evilmi--find-position-to-jump ff jump-forward ch))
     (evilmi--tweak-selected-region ff jump-forward)))
 
-(defun evilmi--operate-on-item (num &optional FUNC)
-  (if evilmi-debug (message "evilmi--operate-on-item called => %s (point)=%d" 
num (point)))
-  (let* ((plugin (plist-get evilmi-plugins major-mode))
+(defun evilmi--operate-on-item (num &optional func)
+  "Jump NUM times and apply function FUNC."
+  (when evilmi-debug
+    (message "evilmi--operate-on-item called => %s (point)=%d" num (point)))
+  (let* ((jump-rules (plist-get evilmi-plugins major-mode))
          rlt
+         (i 0)
+         rule
          jumped
-         where-to-jump-in-theory)
+         ideal-dest)
 
     (unless num (setq num 1))
 
-    (if plugin
-        (mapc
-         (lambda (elem)
-           ;; execute evilmi-xxxx-get-tag
-           (setq rlt (funcall (nth 0 elem)))
-           (when (and rlt (not jumped))
-             ;; before jump, we may need some operation
-             (if FUNC (funcall FUNC rlt))
-             ;; jump now, execute evilmi-xxxx-jump
-             (setq where-to-jump-in-theory (funcall (nth 1 elem) rlt num))
-             ;; jump only once if the jump is successful
-             (setq jumped t)))
-         plugin))
-
-    ;; give `evilmi--simple-jump' a chance
-    (when (not jumped)
-      (if FUNC (funcall FUNC (list (point))))
+    (when jump-rules
+      (dolist (rule jump-rules)
+        ;; execute evilmi-xxxx-get-tag
+        ;; every rule should be executed.
+        ;; the simple rule might just forward a word
+        (setq rlt (funcall (nth 0 rule)))
+        (when (and rlt (not jumped))
+          ;; before jump, we may need some operation
+          (if func (funcall func rlt))
+          ;; jump now, execute evilmi-xxxx-jump
+          (setq ideal-dest (funcall (nth 1 rule) rlt num))
+          ;; jump only once if the jump is successful
+          (setq jumped t))
+        (when evilmi-debug
+          (message "rule=%s ideal-dest=%s (point)=%s" rule ideal-dest 
(point)))))
+
+    ;; give `evilmi--simple-jump' a second chance
+    (unless jumped
+      (if func (funcall func (list (point))))
       (evilmi--simple-jump)
-      (setq where-to-jump-in-theory (point)))
+      (setq ideal-dest (point)))
 
-    (if evilmi-debug (message "evilmi--operate-on-item called. Return: %s" 
where-to-jump-in-theory))
-    where-to-jump-in-theory))
+    (if evilmi-debug (message "evilmi--operate-on-item called. Return: %s" 
ideal-dest))
+    ideal-dest))
 
 (defun evilmi--push-mark (rlt)
     (push-mark (nth 0 rlt) t t))
@@ -376,10 +382,10 @@ If IS-FORWARD is t, jump forward; or else jump backward."
 
 
 (defun evilmi--region-to-select-or-delete (num &optional is-inner)
-  (let* (where-to-jump-in-theory b e)
+  (let* (ideal-dest b e)
     (save-excursion
-      (setq where-to-jump-in-theory (evilmi--operate-on-item num 
'evilmi--push-mark))
-      (if where-to-jump-in-theory (goto-char where-to-jump-in-theory))
+      (setq ideal-dest (evilmi--operate-on-item num 'evilmi--push-mark))
+      (if ideal-dest (goto-char ideal-dest))
       (setq b (region-beginning))
       (setq e (region-end))
       (goto-char b)



reply via email to

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