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

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

[nongnu] elpa/evil-matchit 4101ee2432 130/244: handle 'switch' in C prop


From: ELPA Syncer
Subject: [nongnu] elpa/evil-matchit 4101ee2432 130/244: handle 'switch' in C properly
Date: Thu, 6 Jan 2022 02:58:56 -0500 (EST)

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

    handle 'switch' in C properly
---
 README.org          |  2 +-
 evil-matchit-c.el   | 21 ++++++++++++++++++++-
 evil-matchit-sdk.el | 49 +++++++++++++++++++++----------------------------
 evil-matchit.el     |  4 ++--
 pkg.sh              |  2 +-
 5 files changed, 45 insertions(+), 33 deletions(-)

diff --git a/README.org b/README.org
index 2f2b07a802..5add38bbdc 100644
--- a/README.org
+++ b/README.org
@@ -1,4 +1,4 @@
-* evil-matchit (v2.2.3)
+* evil-matchit (v2.2.4)
 
 
[[http://melpa.org/#/evil-matchit][file:http://melpa.org/packages/evil-matchit-badge.svg]]
 
[[http://stable.melpa.org/#/evil-matchit][file:http://stable.melpa.org/packages/evil-matchit-badge.svg]]
 
diff --git a/evil-matchit-c.el b/evil-matchit-c.el
index 442a60aa8f..eb27ecc9f0 100644
--- a/evil-matchit-c.el
+++ b/evil-matchit-c.el
@@ -44,6 +44,25 @@
 
 ;;;###autoload
 (defun evilmi-c-jump (rlt NUM)
-  (evilmi-sdk-jump rlt NUM evilmi-c-match-tags 
evilmi-c-extract-keyword-howtos))
+  (let* ((old-pos (point))
+         (pos (evilmi-sdk-jump rlt NUM evilmi-c-match-tags 
evilmi-c-extract-keyword-howtos))
+         (orig-tag (and rlt (nth 3 (cadr rlt)))))
+
+    ;; Place cursor over last case of 'switch' statement and press %:
+    ;; Should go back to beginning of switch:
+    ;;   switch(c) {
+    ;;   case 'a':
+    ;;       break;
+    ;;   case 'b':
+    ;;       break;
+    ;;   }
+    (when (and (string= orig-tag "case")
+               ;; failed to find matching tag
+               (not pos))
+      (goto-char old-pos)
+      ;; Goto outer bracket
+      (c-beginning-of-defun)
+      (setq pos (beginning-of-line)))
+    pos))
 
 (provide 'evil-matchit-c)
diff --git a/evil-matchit-sdk.el b/evil-matchit-sdk.el
index 2655f96c90..ce7e6fdd06 100644
--- a/evil-matchit-sdk.el
+++ b/evil-matchit-sdk.el
@@ -163,6 +163,9 @@ is-function-exit-point could be unknown status"
 
 ;;;###autoload
 (defun evilmi-sdk-jump (rlt num match-tags howtos)
+  "Use RLT, NUM, MATCH-TAGS and HOWTOS to jump.
+Return nil if no matching tag found.  Please note (point) is changed
+after calling this function."
   (let* ((orig-tag-type (nth 1 (nth 1 rlt)))
          (orig-tag-info (nth 1 rlt))
          cur-tag-type
@@ -172,7 +175,7 @@ is-function-exit-point could be unknown status"
          keyword
          found
          where-to-jump-in-theory)
-    (if evilmi-debug (message "evilmi-sdk-jump called => %s" rlt))
+    (if evilmi-debug (message "evilmi-sdk-jump called => rlt=%s (piont)=%s" 
rlt (point)))
 
     (while (not found)
       (forward-line (if (= orig-tag-type 2) -1 1))
@@ -183,7 +186,6 @@ is-function-exit-point could be unknown status"
       (when keyword
         (setq cur-tag-info (evilmi-sdk-get-tag-info keyword match-tags))
         (when (evilmi--same-type cur-tag-info orig-tag-info)
-
           (setq cur-tag-type (nth 1 cur-tag-info))
 
           ;; key algorithm
@@ -198,7 +200,6 @@ is-function-exit-point could be unknown status"
 
            ;; 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))
@@ -220,51 +221,43 @@ is-function-exit-point could be unknown status"
             (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 found t)
-              )
-            )
+              (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 found t)
-              )
-            (setq level (1- level))
-            )
+              (setq found t))
+            (setq level (1- level)))
+
            ;; mid (1) -> open (0) level++
            ((and (= orig-tag-type 1) (= cur-tag-type 0))
-            (setq level (1+ level))
-            )
+            (setq level (1+ level)))
 
            ;; now handle closed tag
            ;; closed (2) -> mid (1) ignore,impossible
-           ((and (= orig-tag-type 2) (= cur-tag-type 1))
-            )
+           ((and (= orig-tag-type 2) (= cur-tag-type 1)))
+
            ;; closed (2) -> closed (2) level++
            ((and (= orig-tag-type 2) (= cur-tag-type 2))
-            (setq level (1+ level))
-            )
+            (setq level (1+ level)))
+
            ;; 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))
               (back-to-indentation)
-              (setq found t)
-              )
-            (setq level (1- level))
-            )
-           (t (message "why here?"))
-           )
-          )
-        )
+              (setq found t))
+            (setq level (1- level)))
+
+           (t (message "why here?")))))
 
       ;; we will stop at end or beginning of buffer anyway
       (if (or (= (line-end-position) (point-max))
-              (= (line-beginning-position) (point-min))
-              )
-          (setq found t)
-        ))
+              (= (line-beginning-position) (point-min)))
+          (setq found t)))
+
     where-to-jump-in-theory))
 
 (defun evilmi-count-matches (regexp str)
diff --git a/evil-matchit.el b/evil-matchit.el
index 7ac63afca1..6c7c3ff485 100644
--- a/evil-matchit.el
+++ b/evil-matchit.el
@@ -4,7 +4,7 @@
 
 ;; Author: Chen Bin <chenbin.sh@gmail.com>
 ;; URL: http://github.com/redguardtoo/evil-matchit
-;; Version: 2.2.3
+;; Version: 2.2.4
 ;; Keywords: matchit vim evil
 ;; Package-Requires: ((evil "1.0.7"))
 ;;
@@ -492,7 +492,7 @@ If IS-FORWARD is t, jump forward; or else jump backward."
 ;;;###autoload
 (defun evilmi-version()
   (interactive)
-  (message "2.2.3"))
+  (message "2.2.4"))
 
 ;;;###autoload
 (define-minor-mode evil-matchit-mode
diff --git a/pkg.sh b/pkg.sh
index 60f17e0b96..0962b0fd3d 100755
--- a/pkg.sh
+++ b/pkg.sh
@@ -1,6 +1,6 @@
 #!/bin/bash
 name=evil-matchit
-version=2.2.3
+version=2.2.4
 pkg=$name-$version
 mkdir $pkg
 cp README.org $pkg



reply via email to

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