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

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

[nongnu] elpa/evil-matchit de6ce21e1e 106/244: jump in comment


From: ELPA Syncer
Subject: [nongnu] elpa/evil-matchit de6ce21e1e 106/244: jump in comment
Date: Thu, 6 Jan 2022 02:58:53 -0500 (EST)

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

    jump in comment
---
 README.org             | 19 +++++-------
 evil-matchit-pkg.el    |  2 +-
 evil-matchit-simple.el | 62 ++++++++++++++++---------------------
 evil-matchit.el        | 83 ++++++++++++++++++++++++++++++++++++--------------
 pkg.sh                 |  2 +-
 5 files changed, 97 insertions(+), 71 deletions(-)

diff --git a/README.org b/README.org
index 81fadb6999..e18014dd44 100644
--- a/README.org
+++ b/README.org
@@ -1,4 +1,4 @@
-* evil-matchit (v2.1.3)
+* evil-matchit (v2.1.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]]
 
@@ -150,11 +150,6 @@ Here is the setup to jump between the two ends of the C 
comment:
 #+begin_src elisp
 (setq evilmi-quote-chars (string-to-list "'\"/"))
 #+end_src
-** Don't ignore the comments when jumping
-#+begin_src elisp
-(setq evilmi-ignore-comments nil)
-#+end_src
-
 ** Match case sensitive tags?
 It's decided by the Emacs global variable "case-fold-search". You need not 
care about it because the major mode will set this flag automatically.
 * Developer guide
@@ -227,13 +222,15 @@ The forth *optional* column defines the relationship 
between open and close tags
 
 ;;;###autoload
 (defun evilmi-script-get-tag ()
-  (evilmi-sdk-get-tag evilmi-script-match-tags 
evilmi-sdk-extract-keyword-howtos)
-  )
+  (evilmi-sdk-get-tag evilmi-script-match-tags
+                      evilmi-sdk-extract-keyword-howtos))
 
 ;;;###autoload
-(defun evilmi-script-jump (rlt NUM)
-  (evilmi-sdk-jump rlt NUM evilmi-script-match-tags 
evilmi-sdk-extract-keyword-howtos)
-  )
+(defun evilmi-script-jump (rlt num)
+  (evilmi-sdk-jump rlt
+                   num
+                   evilmi-script-match-tags
+                   evilmi-sdk-extract-keyword-howtos))
 
 (provide 'evil-matchit-script)
 #+END_SRC
diff --git a/evil-matchit-pkg.el b/evil-matchit-pkg.el
index 85b8084606..8f1268badd 100644
--- a/evil-matchit-pkg.el
+++ b/evil-matchit-pkg.el
@@ -1,2 +1,2 @@
-(define-package "evil-matchit" "2.1.3"
+(define-package "evil-matchit" "2.1.4"
                 "Vim matchit ported into Emacs (requires EVIL)")
diff --git a/evil-matchit-simple.el b/evil-matchit-simple.el
index 10df0db350..4b42b52eae 100644
--- a/evil-matchit-simple.el
+++ b/evil-matchit-simple.el
@@ -47,29 +47,24 @@
 
 ;;;###autoload
 (defun evilmi-simple-get-tag ()
-  (let* (p
-         tmp
-         ch
-         forward-line-num
-         rlt
-         (cur-line (evilmi-sdk-curline)))
-
-    ;; Only handle open tag
-    (setq tmp (evilmi--get-char-under-cursor))
-    (if tmp (setq ch (car tmp)))
+  (let* (forward-line-num
+         ;; Only handle open tag
+         (tmp (evilmi--get-char-under-cursor))
+         (ch (if tmp (car tmp)))
+         rlt)
+
     (if evilmi-debug (message "evilmi-simple-get-tag called => %s" ch))
 
     (cond
      ;; In evil-visual-state, the (preceding-char) is actually the character 
under cursor
      ((not (evilmi--char-is-simple ch))
-      (if (setq forward-line-num (evilmi--simple-find-open-brace cur-line))
-          (when forward-line-num
-            (setq p (line-beginning-position))
-            (forward-line (1- forward-line-num))
-            (search-forward "{" nil nil)
-            (backward-char)
-            (setq rlt (list p))
-            )))
+      (when (setq forward-line-num (evilmi--simple-find-open-brace 
(evilmi-sdk-curline)))
+        (setq rlt (list (line-beginning-position)))
+        ;; need handle case "if () \n { ... }".
+        ;; move cursor over "{", prepare for `evil-jump-item'
+        (forward-line (1- forward-line-num))
+        (search-forward "{" nil nil)
+        (backward-char)))
      (t
       ;; use evil's own evilmi--simple-jump
       (setq rlt (list (point)))))
@@ -79,22 +74,19 @@
 
 ;;;###autoload
 (defun evilmi-simple-jump (rlt NUM)
-  (let (cur-line)
-    (when rlt
-      (if evilmi-debug (message "evilmi-simple-jump called"))
-
-      ;; 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))
-
-      (setq cur-line (evilmi-sdk-curline))
-      ;; hack for javascript
-      (if (string-match "^[ \t]*})(.*)\; *$" cur-line)
-          (line-end-position)
-        (1+ (point)))
-      )
-    ))
+  (when rlt
+    (if evilmi-debug (message "evilmi-simple-jump called"))
+
+    ;; 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))
+
+    ;; hack for javascript
+    (if (string-match "^[ \t]*})(.*)\; *$"
+                      (evilmi-sdk-curline))
+        (line-end-position)
+      (1+ (point)))))
 
 (provide 'evil-matchit-simple)
diff --git a/evil-matchit.el b/evil-matchit.el
index a4f1e2a152..b0513bd40e 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.1.3
+;; Version: 2.1.4
 ;; Keywords: matchit vim evil
 ;; Package-Requires: ((evil "1.0.7"))
 ;;
@@ -45,11 +45,9 @@
   "The table to define which algorithm to use and when to jump items")
 
 (defvar evilmi-may-jump-by-percentage t
-  "Simulate evil-jump-item behaviour. For example, press 50% to jump to 50 
percentage in buffer.
-If this flag is nil, then 50 means jump 50 times.")
-
-
-(defvar evilmi-ignore-comments t "Ignore comments when mathing")
+  "Simulate evil-jump-item behaviour.
+For example,press 50% to jump to 50 percentage in buffer.
+If nil, presing '50 %' means jump 50 times.")
 
 (defvar evilmi-forward-chars (string-to-list "[{("))
 (defvar evilmi-backward-chars (string-to-list "]})"))
@@ -108,12 +106,61 @@ If font-face-under-cursor is NOT nil, the quoted string 
is being processed"
     (if evilmi-debug (message "evilmi--is-jump-forward return (%s %s %s)" rlt 
ff (string ch)))
     (list rlt ff ch)))
 
+(defun evilmi--in-comment-p (pos)
+  "Check the code at POS is comment by comparing font face."
+  (let* ((fontfaces (get-text-property pos 'face)))
+    (when (not (listp fontfaces))
+      (setf fontfaces (list fontfaces)))
+    (delq nil
+          (mapcar #'(lambda (f)
+                      ;; learn this trick from flyspell
+                      (or (eq f 'font-lock-comment-face)
+                          (eq f 'font-lock-comment-delimiter-face)))
+                  fontfaces))))
+
 (defun evilmi--scan-sexps (is-forward)
   (let* ((start-pos (if is-forward (point) (+ 1 (point))))
          (arg (if is-forward 1 -1))
-         (rlt (scan-sexps start-pos arg)))
-    ;; normal state and other state
-    (if evilmi-debug (message "evilmi--scan-sexps called. Return: %s" rlt))
+         (limit (if is-forward (point-max) (point-min)))
+         (lvl 1)
+         (b (following-char))
+         (e (cond
+             ;; {}
+             ((= b 123) 125)
+             ((= b 125) 123)
+             ;; ()
+             ((= b 40) 41)
+             ((= b 41) 40)
+             ;; []
+             ((= b 91) 93)
+             ((= b 93) 91)))
+         (rlt start-pos))
+    (cond
+     ((evilmi--in-comment-p (point))
+      ;; Matching tag in comment.
+      ;; Use own algorithm instead of `scan-sexps'
+      ;; because `scan-sexps' not work in some major-mode
+      (save-excursion
+        (setq start-pos (point))
+        (while (and (not (= start-pos limit))
+                    (> lvl 0))
+          (setq start-pos (+ start-pos arg))
+          (goto-char start-pos)
+          (if (evilmi--in-comment-p start-pos)
+              (cond
+               ((= (following-char) b)
+                (setq lvl (1+ lvl)))
+               ((= (following-char) e)
+                (setq lvl (1- lvl))))))
+        (if (= lvl 0)
+            (setq rlt (+ start-pos (if is-forward 1 0))))))
+     (t
+      ;; not comment
+      ;; search but ignore comments
+      (let* ((parse-sexp-ignore-comments t))
+        (setq rlt (scan-sexps start-pos arg)))))
+
+    (if evilmi-debug (message "evilmi--scan-sexps called => rlt=%s lvl=%s" rlt 
lvl))
     rlt))
 
 (defun evilmi--adjust-quote-jumpto (is-forward pos)
@@ -157,7 +204,7 @@ If font-face-under-cursor is NOT nil, the quoted string is 
being processed"
     (if evilmi-debug (message "evilmi--find-position-to-jump return %s" 
(evilmi--adjust-jumpto is-forward rlt)))
     (evilmi--adjust-jumpto is-forward rlt)))
 
-(defun evilmi--tweak-selected-region-finally (ff jump-forward)
+(defun evilmi--tweak-selected-region (ff jump-forward)
   ;; visual-state hack!
   (if (and jump-forward (eq evil-state 'visual) (not ff))
       ;; if ff is non-nil, I control the jump flow from character level,
@@ -166,25 +213,15 @@ If font-face-under-cursor is NOT nil, the quoted string 
is being processed"
 
 (defun evilmi--simple-jump ()
   "Alternative for evil-jump-item."
-  ;; parse-sexp-ignore-comments is used
   (interactive)
-  (let* ((old-flag parse-sexp-ignore-comments)
-         (tmp (evilmi--is-jump-forward))
+  (let* ((tmp (evilmi--is-jump-forward))
          (jump-forward (car tmp))
          ;; if ff is not nil, it's jump between quotes
          ;; so we should not use (scan-sexps)
          (ff (nth 1 tmp))
          (ch (nth 2 tmp)))
-
-    (unless evilmi-ignore-comments
-      (setq parse-sexp-ignore-comments nil))
-
-    ;; need pass the char
     (goto-char (evilmi--find-position-to-jump ff jump-forward ch))
-    (evilmi--tweak-selected-region-finally ff jump-forward)
-
-    (unless evilmi-ignore-comments
-      (setq parse-sexp-ignore-comments old-flag))))
+    (evilmi--tweak-selected-region ff jump-forward)))
 
 (defun evilmi--operate-on-item (NUM &optional FUNC)
   (let ((plugin (plist-get evilmi-plugins major-mode))
@@ -412,7 +449,7 @@ If font-face-under-cursor is NOT nil, the quoted string is 
being processed"
     (evilmi--operate-on-item NUM))))
 
 ;;;###autoload
-(defun evilmi-version() (interactive) (message "2.1.3"))
+(defun evilmi-version() (interactive) (message "2.1.4"))
 
 ;;;###autoload
 (define-minor-mode evil-matchit-mode
diff --git a/pkg.sh b/pkg.sh
index 31f38467a7..bd59e0d30c 100755
--- a/pkg.sh
+++ b/pkg.sh
@@ -1,5 +1,5 @@
 #!/bin/bash
-pkg=evil-matchit-2.1.3
+pkg=evil-matchit-2.1.4
 mkdir $pkg
 cp README.org $pkg
 cp *.el $pkg



reply via email to

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