branch: elpa/evil-matchit
commit f981f722dfad002a885d5de1a0060ae17249ca6a
Author: Chen Bin <[email protected]>
Commit: Chen Bin <[email protected]>

    avoid hang in python-mode, v2.1.1
---
 README.org             |   2 +-
 evil-matchit-pkg.el    |   2 +-
 evil-matchit-python.el | 128 +++++++++++++++++--------------------------------
 evil-matchit-simple.el |   2 +-
 evil-matchit.el        |   4 +-
 pkg.sh                 |   2 +-
 6 files changed, 51 insertions(+), 89 deletions(-)

diff --git a/README.org b/README.org
index 90b71dd613..9ef3032d4b 100644
--- a/README.org
+++ b/README.org
@@ -1,4 +1,4 @@
-* evil-matchit (v2.1)
+* evil-matchit (v2.1.1)
 
 Vim [[http://www.vim.org/scripts/script.php?script_id=39][matchit.vim]] by 
Benji Fisher ported into Emacs.
 
diff --git a/evil-matchit-pkg.el b/evil-matchit-pkg.el
index 014b95979a..8ea0d00a1e 100644
--- a/evil-matchit-pkg.el
+++ b/evil-matchit-pkg.el
@@ -1,2 +1,2 @@
-(define-package "evil-matchit" "2.1"
+(define-package "evil-matchit" "2.1.1"
                 "Vim matchit ported into Emacs (requires EVIL)")
diff --git a/evil-matchit-python.el b/evil-matchit-python.el
index 36a6991d5f..daddfcb818 100644
--- a/evil-matchit-python.el
+++ b/evil-matchit-python.el
@@ -154,58 +154,26 @@
                    (line-beginning-position)
                    (line-end-position)))
         cur-indent
-        (tag-type 0)
+        tag-type
         keyword
         p
-        cur-indent
-        )
+        cur-indent)
+
+    (if evilmi-debug (message "evilmi-python-get-tag called"))
 
     (setq cur-indent (evilmi--python-calculate-indent cur-line))
-    ;; move cursor to the beginning of line
-    (if (string-match regexp cur-line)
-        ;; open tag
-        (progn
-          (setq keyword (match-string 1 cur-line))
-          (setq p (line-beginning-position))
-          (setq tag-type 0)
-          )
-      ;; closed tag
-      (progn
-        (setq keyword "")
-        (setq tag-type 1)
-        (setq p (line-end-position))
-        (save-excursion
-          ;; find the limit end from current line
-          (while (and (>= (evilmi--python-calculate-indent
-                           (buffer-substring-no-properties
-                            (line-beginning-position) (line-end-position))) 
cur-indent)
-                      (not (= p (point-max)))
-                      )
-            (forward-line 1)
-            (setq p (line-end-position))
-            )
-          ;; scroll back, skip all the empty lines
-          (let ((scrolling-back t)
-                my-indent
-                )
-            (while scrolling-back
-              (setq my-indent (evilmi--python-calculate-indent
-                               (buffer-substring-no-properties
-                                (line-beginning-position) 
(line-end-position))))
-
-              (if (or (= my-indent 999)
-                      (< my-indent cur-indent)
-                      (= (line-beginning-position) (point-min))
-                      )
-                  (forward-line -1)
-                (setq scrolling-back nil)
-                )
-              )
-            )
-          (setq p (line-end-position))
-          )
-        )
-      )
+    (cond
+     ((string-match regexp cur-line)
+      ;; we are at open tag now, and will jump forward
+      (setq keyword (match-string 1 cur-line))
+      (setq p (line-beginning-position))
+      (setq tag-type 0))
+     (t
+      ;; we are at closed tag now, will jump backward
+      (setq keyword "")
+      (setq tag-type 1)
+      (setq p (line-end-position))
+      ))
 
     (setq rlt (list p tag-type keyword))
     (if (and evilmi-debug rlt) (message "evilmi-python-get-tag called. rlt=%s" 
rlt))
@@ -221,36 +189,34 @@
                    (line-end-position)))
         cur-indent
         dendent
-        where-to-jump-in-theory)
+        rlt)
 
     (setq cur-indent (evilmi--python-calculate-indent cur-line))
 
     (if evilmi-debug (message "evilmi-python-jump called. tag-type=%d p=%d" 
tag-type p))
-    ;; start from closed tag
     (cond
+     ;; start from closed tag
      ((=  1 tag-type)
-      (goto-char p)
-      ;; jump to open tag
-      (while (not dendent)
-        (forward-line -1)
-        ;; first line
-        (setq cur-line (buffer-substring-no-properties
-                        (line-beginning-position)
-                        (line-end-position)))
+      ;; jump to back to open tag when current indentation is NOT zero
+      (unless (= cur-indent 0)
+        (goto-char p)
+        (while (not dendent)
+          (forward-line -1)
+          ;; first line
+          (setq cur-line (buffer-substring-no-properties
+                          (line-beginning-position)
+                          (line-end-position)))
 
-        ;; skip empty lines
-        (when (not (string-match "^[ \t]*$" cur-line))
-          (if (< (evilmi--python-calculate-indent cur-line) cur-indent)
-              (progn
-                (setq dendent t)
-                (skip-chars-forward " \t")
-                (setq dendent t)
-                (evilmi--python-move-to-first-open-tag (1- cur-indent))
-                (setq where-to-jump-in-theory (point))
-                )
-            ))
-        )
-      )
+          (if evilmi-debug (message "cur-line=%s" cur-line))
+
+          ;; skip empty lines
+          (when (and (not (string-match "^[ \t]*$" cur-line))
+                     (< (evilmi--python-calculate-indent cur-line) cur-indent))
+            (setq dendent t)
+            (skip-chars-forward " \t")
+            (evilmi--python-move-to-first-open-tag (1- cur-indent))
+            (setq rlt (point)))
+          )))
 
      ;; start from open tag
      ((=  0 tag-type)
@@ -262,24 +228,20 @@
                         (line-end-position)))
 
         ;; just skip empty line
-        (when (not (string-match "^[ \t]*$" cur-line))
+        (if (not (string-match "^[ \t]*$" cur-line))
           (if (<= (evilmi--python-calculate-indent cur-line) cur-indent)
-              (progn
-                (setq dendent t)
-                )
-            (progn
-              ;; record the latest indented line info
-              (setq where-to-jump-in-theory (line-end-position))
-              )
+              (setq dendent t)
+            ;; record the latest indented line info
+            (setq rlt (line-end-position))
             ))
         ;; last line
-        (if (= (point-max) (line-end-position)) (setq dendent t))
-        )
+        (if (= (point-max) (line-end-position)) (setq dendent t)))
 
-      (if where-to-jump-in-theory (goto-char where-to-jump-in-theory))
+      (if rlt (goto-char rlt))
 
       (evilmi--python-move-to-next-open-tag keyword cur-indent)
+
       ))
-    where-to-jump-in-theory))
+    rlt))
 
 (provide 'evil-matchit-python)
diff --git a/evil-matchit-simple.el b/evil-matchit-simple.el
index d21118e740..930985cf90 100644
--- a/evil-matchit-simple.el
+++ b/evil-matchit-simple.el
@@ -58,8 +58,8 @@
     ;; Only handle open tag
     (setq tmp (evilmi--get-char-under-cursor))
     (if tmp (setq ch (car tmp)))
+    (if evilmi-debug (message "evilmi-simple-get-tag called => %s" ch))
 
-    (if evilmi-debug (message "ch=%d tag-chars=%s" ch tag-chars))
     (cond
      ;; In evil-visual-state, the (preceding-char) is actually the character 
under cursor
      ((not (evilmi--char-is-simple ch))
diff --git a/evil-matchit.el b/evil-matchit.el
index 3d32a41519..edaba36e95 100644
--- a/evil-matchit.el
+++ b/evil-matchit.el
@@ -4,7 +4,7 @@
 
 ;; Author: Chen Bin <[email protected]>
 ;; URL: http://github.com/redguardtoo/evil-matchit
-;; Version: 2.1
+;; Version: 2.1.1
 ;; Keywords: matchit vim evil
 ;; Package-Requires: ((evil "1.0.7"))
 ;;
@@ -434,7 +434,7 @@ If font-face-under-cursor is NOT nil, the quoted string is 
being processed"
    ))
 
 ;;;###autoload
-(defun evilmi-version() (interactive) (message "2.1"))
+(defun evilmi-version() (interactive) (message "2.1.1"))
 
 ;;;###autoload
 (define-minor-mode evil-matchit-mode
diff --git a/pkg.sh b/pkg.sh
index d89bba376e..91c07c779f 100755
--- a/pkg.sh
+++ b/pkg.sh
@@ -1,5 +1,5 @@
 #!/bin/bash
-pkg=evil-matchit-2.1
+pkg=evil-matchit-2.1.1
 mkdir $pkg
 cp README.org $pkg
 cp *.el $pkg

Reply via email to