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

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

[nongnu] elpa/evil-matchit 38df050735 103/244: clean code


From: ELPA Syncer
Subject: [nongnu] elpa/evil-matchit 38df050735 103/244: clean code
Date: Thu, 6 Jan 2022 02:58:53 -0500 (EST)

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

    clean code
---
 evil-matchit-diff.el       | 13 +++++--------
 evil-matchit-javascript.el | 21 ++++++---------------
 evil-matchit-python.el     | 44 +++++++++++++-------------------------------
 evil-matchit-sdk.el        | 44 ++++++++++++++++++--------------------------
 evil-matchit-simple.el     | 21 +++++++++------------
 5 files changed, 51 insertions(+), 92 deletions(-)

diff --git a/evil-matchit-diff.el b/evil-matchit-diff.el
index e654d307ba..d0c978bce6 100644
--- a/evil-matchit-diff.el
+++ b/evil-matchit-diff.el
@@ -26,20 +26,17 @@
 
 ;;; Code:
 
-(defun evilmi--cur-line ()
-  (buffer-substring-no-properties
-   (line-beginning-position)
-   (line-end-position)))
+(require 'evil-matchit-sdk)
 
 (defun evilmi-diff-guess-final-pos ()
   (let* ((final-pos (point)))
     (save-excursion
       (let* (tmp-line)
         (forward-line -1)
-        (setq tmp-line (evilmi--cur-line))
+        (setq tmp-line (evilmi-sdk-curline))
         (if (string-match-p "^index [0-9a-z]+\\.+[0-9a-z]+ [0-9]+$" tmp-line)
             (forward-line -1))
-        (setq tmp-line (evilmi--cur-line))
+        (setq tmp-line (evilmi-sdk-curline))
         (if (string-match-p "^diff [^ ]" tmp-line)
             (forward-line -1))
         (setq final-pos (line-end-position))))
@@ -48,7 +45,7 @@
 ;;;###autoload
 (defun evilmi-diff-get-tag ()
   ;; do nothing
-  (let* ((cur-line (evilmi--cur-line))
+  (let* ((cur-line (evilmi-sdk-curline))
          (final-pos (point)))
     (if (string-match-p "^--- " cur-line)
         (save-excursion
@@ -57,7 +54,7 @@
 
 ;;;###autoload
 (defun evilmi-diff-jump (rlt NUM)
-  (let* ((cur-line (evilmi--cur-line))
+  (let* ((cur-line (evilmi-sdk-curline))
          (final-pos (point)))
     (cond
      ((string-match-p "^\\+\\+\\+ " cur-line)
diff --git a/evil-matchit-javascript.el b/evil-matchit-javascript.el
index 020915d449..4569d2c3d6 100644
--- a/evil-matchit-javascript.el
+++ b/evil-matchit-javascript.el
@@ -26,9 +26,9 @@
 
 ;;; Code:
 
+(require 'evil-matchit-sdk)
 (require 'evil-matchit)
 
-;; TODO, fn.then().({}, find the second (
 (defun evilmi--javascript-find-open-brace (cur-line)
   (let (rlt)
     ;; javascript code line "(function(...) { ..."
@@ -38,13 +38,9 @@
         (setq rlt 1)
       (save-excursion
         (forward-line)
-        (setq cur-line (buffer-substring-no-properties
-                        (line-beginning-position) (line-end-position)))
+        (setq cur-line (evilmi-sdk-curline))
         (if (string-match "^[ \t]*{ *$" cur-line)
-            (setq rlt 2)
-          )
-        )
-      )
+            (setq rlt 2))))
     rlt))
 
 ;;;###autoload
@@ -52,8 +48,7 @@
   (let (p
         forward-line-num
         rlt
-        (cur-line (buffer-substring-no-properties
-                   (line-beginning-position) (line-end-position)))
+        (cur-line (evilmi-sdk-curline))
         )
     ;; only handle open tag
     (if (not (memq (following-char) (string-to-list "{[(}}])")))
@@ -76,17 +71,13 @@
     (when rlt
       (evilmi--simple-jump)
 
-      (setq cur-line (buffer-substring-no-properties
-                      (line-beginning-position)
-                      (line-end-position)))
+      (setq cur-line (evilmi-sdk-curline))
       ;; hack for javascript
       (if (or (string-match "^[ \t]*}\)\(.*\)\; *$" cur-line)
               (string-match "^[ \t]*}\(.*\))\; *$" cur-line)
               (string-match "^[ \t]*}\])\; *$" cur-line))
           (line-end-position)
-        (1+ (point))
-        )
-      )
+        (1+ (point))))
     ))
 
 (provide 'evil-matchit-javascript)
diff --git a/evil-matchit-python.el b/evil-matchit-python.el
index 22375b0770..0bad0e570f 100644
--- a/evil-matchit-python.el
+++ b/evil-matchit-python.el
@@ -26,6 +26,7 @@
 
 ;;; Code:
 
+(require 'evil-matchit-sdk)
 (require 'evil-matchit)
 
 ;; @return number of indent
@@ -53,9 +54,7 @@
         keyword
         where-to-go
         regexp
-        (cur-line (buffer-substring-no-properties
-                   (line-beginning-position)
-                   (line-end-position))))
+        (cur-line (evilmi-sdk-curline)))
 
     ;; extract keyword from current line
     (if (string-match "^[ \t]*\\([a-z]+\\) *.*:\s*\\(#.*\\)?$" cur-line)
@@ -73,27 +72,20 @@
       (save-excursion
         (while (not out-of-loop)
           (forward-line -1)
-          (setq cur-line (buffer-substring-no-properties
-                          (line-beginning-position)
-                          (line-end-position)))
+          (setq cur-line (evilmi-sdk-curline))
 
           (when (and (= cur-indent (evilmi--python-calculate-indent cur-line))
-                     (string-match regexp cur-line)
-                     )
+                     (string-match regexp cur-line))
             (setq where-to-go (line-beginning-position))
-            (setq out-of-loop t)
-            )
+            (setq out-of-loop t))
 
           ;; if it's first line, we need get out of loop
           (if (= (point-min) (line-beginning-position))
-              (setq out-of-loop t)
-            )
-          )
-        )
+              (setq out-of-loop t))
+          ))
       (when where-to-go
         (goto-char where-to-go)
-        (skip-chars-forward " \t"))
-      )
+        (skip-chars-forward " \t")))
     ))
 
 (defun evilmi--python-move-to-next-open-tag (keyword cur-indent)
@@ -116,9 +108,7 @@
     (save-excursion
       (while (not out-of-loop)
         (forward-line)
-        (setq cur-line (buffer-substring-no-properties
-                        (line-beginning-position)
-                        (line-end-position)))
+        (setq cur-line (evilmi-sdk-curline))
 
         (when (= cur-indent (evilmi--python-calculate-indent cur-line))
           (if (and regexp (string-match regexp cur-line))
@@ -142,9 +132,7 @@
 (defun evilmi-python-get-tag ()
   (let (rlt
         (regexp "^[ \t]*\\([a-z]+\\) *.*:\s*\\(#.*\\)?$")
-        (cur-line (buffer-substring-no-properties
-                   (line-beginning-position)
-                   (line-end-position)))
+        (cur-line (evilmi-sdk-curline))
         cur-indent
         tag-type
         keyword
@@ -176,9 +164,7 @@
   (let ((p (nth 0 rlt))
         (tag-type (nth 1 rlt))
         (keyword (nth 2 rlt))
-        (cur-line (buffer-substring-no-properties
-                   (line-beginning-position)
-                   (line-end-position)))
+        (cur-line (evilmi-sdk-curline))
         cur-indent
         dendent
         rlt)
@@ -195,9 +181,7 @@
         (while (not dendent)
           (forward-line -1)
           ;; first line
-          (setq cur-line (buffer-substring-no-properties
-                          (line-beginning-position)
-                          (line-end-position)))
+          (setq cur-line (evilmi-sdk-curline))
 
           (if evilmi-debug (message "cur-line=%s" cur-line))
 
@@ -215,9 +199,7 @@
       ;; jump to closed tag
       (while (not dendent)
         (forward-line)
-        (setq cur-line (buffer-substring-no-properties
-                        (line-beginning-position)
-                        (line-end-position)))
+        (setq cur-line (evilmi-sdk-curline))
 
         ;; just skip empty line
         (if (not (string-match "^[ \t]*$" cur-line))
diff --git a/evil-matchit-sdk.el b/evil-matchit-sdk.el
index e3c8229e88..2335a76013 100644
--- a/evil-matchit-sdk.el
+++ b/evil-matchit-sdk.el
@@ -6,8 +6,7 @@
 Each howto is actually a pair. The first element of pair is the regular
 expression to match the current line. The second is the index of sub-matches
 to extract the keyword which starts from one. The sub-match is the match 
defined
-between '\\(' and '\\)' in regular expression.
-")
+between '\\(' and '\\)' in regular expression.")
 
 ;; slower but I don't care
 ;; @see http://ergoemacs.org/emacs/modernization_elisp_lib_problem.html
@@ -42,6 +41,12 @@ between '\\(' and '\\)' in regular expression.
            )))
     rlt))
 
+;;;###autoload
+(defun evilmi-sdk-curline ()
+  (buffer-substring-no-properties
+   (line-beginning-position)
+   (line-end-position)))
+
 ;;;###autoload
 (defun evilmi-sdk-member (KEYWORD LIST)
   "check if KEYWORD exist in LIST"
@@ -85,8 +90,8 @@ is-function-exit-point could be 'FN_EXIT' or other status"
         (setq elem (nth j elems))
         (setq found (and (or (stringp elem) (listp elem))
                          (evilmi-sdk-member KEYWORD elem)))
-        (if (not found) (setq j (1+ j)))
-        )
+        (if (not found)
+            (setq j (1+ j))))
       (if (not found) (setq i (1+ i))))
     (when found
       ;; function exit point maybe?
@@ -98,8 +103,7 @@ is-function-exit-point could be 'FN_EXIT' or other status"
                      KEYWORD))
         (setq rlt (list i j nil KEYWORD))
         ))
-    rlt
-    ))
+    rlt))
 
 (defun evilmi--sdk-extract-keyword (cur-line match-tags howtos)
   "extract keyword from cur-line. keyword should be defined in match-tags"
@@ -117,8 +121,7 @@ is-function-exit-point could be 'FN_EXIT' or other status"
         ;; keep search keyword by using next howto (regex and match-string 
index)
         (if (not (evilmi-sdk-member keyword match-tags)) (setq keyword nil))
         )
-      (setq i (1+ i))
-      )
+      (setq i (1+ i)))
     keyword))
 
 (defun evilmi--is-monogamy (tag-info)
@@ -130,8 +133,7 @@ is-function-exit-point could be 'FN_EXIT' or other status"
         ;; i1 and i2 should be at same row if either of them is monogamy
       (if (or (evilmi--is-monogamy i1) (evilmi--is-monogamy i2))
           (setq rlt (= (nth 0 i1) (nth 0 i2)))
-        (setq rlt t))
-      )
+        (setq rlt t)))
     rlt))
 
 ;;;###autoload
@@ -139,9 +141,7 @@ is-function-exit-point could be 'FN_EXIT' or other status"
   "return '(start-point tag-info)"
   (let (rlt
         keyword
-        (cur-line (buffer-substring-no-properties
-                   (line-beginning-position)
-                   (line-end-position)))
+        (cur-line (evilmi-sdk-curline))
         tag-info)
 
     (when (setq keyword (evilmi--sdk-extract-keyword cur-line match-tags 
howtos))
@@ -155,8 +155,7 @@ is-function-exit-point could be 'FN_EXIT' or other status"
                          (line-end-position)
                        (line-beginning-position))
                      tag-info))
-        )
-      )
+        ))
     rlt))
 
 ;;;###autoload
@@ -166,18 +165,14 @@ is-function-exit-point could be 'FN_EXIT' or other status"
         cur-tag-type
         cur-tag-info
         (level 1)
-        (cur-line (buffer-substring-no-properties
-                   (line-beginning-position)
-                   (line-end-position)))
+        (cur-line (evilmi-sdk-curline))
         keyword
         found
         where-to-jump-in-theory)
 
     (while (not found)
       (forward-line (if (= orig-tag-type 2) -1 1))
-      (setq cur-line (buffer-substring-no-properties
-                      (line-beginning-position)
-                      (line-end-position)))
+      (setq cur-line (evilmi-sdk-curline))
 
       (setq keyword (evilmi--sdk-extract-keyword cur-line match-tags howtos))
 
@@ -269,10 +264,7 @@ is-function-exit-point could be 'FN_EXIT' or other status"
               (= (line-beginning-position) (point-min))
               )
           (setq found t)
-        )
-      )
-    where-to-jump-in-theory
-    )
-  )
+        ))
+    where-to-jump-in-theory))
 
 (provide 'evil-matchit-sdk)
diff --git a/evil-matchit-simple.el b/evil-matchit-simple.el
index e686927ada..dc422b8208 100644
--- a/evil-matchit-simple.el
+++ b/evil-matchit-simple.el
@@ -27,6 +27,7 @@
 
 ;;; Code:
 
+(require 'evil-matchit-sdk)
 (require 'evil-matchit)
 
 (defun evilmi--simple-find-open-brace (cur-line)
@@ -38,8 +39,7 @@
         (setq rlt 1)
       (save-excursion
         (forward-line)
-        (setq cur-line (buffer-substring-no-properties
-                        (line-beginning-position) (line-end-position)))
+        (setq cur-line (evilmi-sdk-curline))
         (if (string-match "^[ \t]*{ *$" cur-line)
             (setq rlt 2))
         ))
@@ -47,13 +47,12 @@
 
 ;;;###autoload
 (defun evilmi-simple-get-tag ()
-  (let (p
-        tmp
-        ch
-        forward-line-num
-        rlt
-        (cur-line (buffer-substring-no-properties
-                   (line-beginning-position) (line-end-position))))
+  (let* (p
+         tmp
+         ch
+         forward-line-num
+         rlt
+         (cur-line (evilmi-sdk-curline)))
 
     ;; Only handle open tag
     (setq tmp (evilmi--get-char-under-cursor))
@@ -85,9 +84,7 @@
       (if evilmi-debug (message "evilmi-simple-jump called"))
 
       (evilmi--simple-jump)
-      (setq cur-line (buffer-substring-no-properties
-                      (line-beginning-position)
-                      (line-end-position)))
+      (setq cur-line (evilmi-sdk-curline))
       ;; hack for javascript
       (if (string-match "^[ \t]*})(.*)\; *$" cur-line)
           (line-end-position)



reply via email to

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