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

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

[nongnu] elpa/evil-matchit 5e92e374e6 179/244: better algorithm to match


From: ELPA Syncer
Subject: [nongnu] elpa/evil-matchit 5e92e374e6 179/244: better algorithm to match keyword
Date: Thu, 6 Jan 2022 02:58:59 -0500 (EST)

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

    better algorithm to match keyword
---
 README.org            |  5 +---
 evil-matchit-ocaml.el |  9 ++++---
 evil-matchit-org.el   | 75 ++++++++++++++++++++++++---------------------------
 evil-matchit-sdk.el   | 37 +++++++++++--------------
 evil-matchit.el       | 16 +++++++++--
 pkg.sh                |  2 +-
 6 files changed, 72 insertions(+), 72 deletions(-)

diff --git a/README.org b/README.org
index 5dd87c97c2..540dc53162 100644
--- a/README.org
+++ b/README.org
@@ -1,4 +1,4 @@
-* evil-matchit (v2.3.3)
+* evil-matchit (v2.3.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]]
 
@@ -235,8 +235,5 @@ Step 3, add below code to =~/.emacs.=,
 #+END_SRC
 ** APIs
 - evilmi-load-plugin-rules
-- evilmi-current-font-among-fonts-p
-- evilmi-in-comment-p
-- evilmi-in-string-or-doc-p
 * Contact me
 Report bugs at [[https://github.com/redguardtoo/evil-matchit]].
diff --git a/evil-matchit-ocaml.el b/evil-matchit-ocaml.el
index 3c1801fbbb..56630594a1 100644
--- a/evil-matchit-ocaml.el
+++ b/evil-matchit-ocaml.el
@@ -57,10 +57,11 @@
 
 (defun evilmi-ocaml-in-keyword-p (pos)
   "Check character at POS is keyword by comparing font face."
-  (evilmi-current-font-among-fonts-p pos '(tuareg-font-lock-governing-face
-                                           tuareg-font-lock-operator-face  ;; 
for parentheses
-                                           tuareg-font-double-colon-face   ;; 
for double semicolon
-                                           font-lock-keyword-face)))
+  (evilmi-among-fonts-p pos
+                        '(tuareg-font-lock-governing-face
+                          tuareg-font-lock-operator-face  ; for parentheses
+                          tuareg-font-double-colon-face   ; for double 
semicolon
+                          font-lock-keyword-face)))
 
 ;; jumps to next keyword. Returs nil if there's no next word
 (defun evilmi-ocaml-next-possible-keyword (direction keywords-regex)
diff --git a/evil-matchit-org.el b/evil-matchit-org.el
index 0372e64dd5..38253d05ec 100644
--- a/evil-matchit-org.el
+++ b/evil-matchit-org.el
@@ -34,22 +34,19 @@
 
 (defvar evilmi-org-extract-keyword-howtos
   '(("^[ \t]*#\\+\\([a-zA-Z_]+\\).*$" 1)
-    ("^[ \t]*\\:\\([a-zA-Z_]+\\)\\:$" 1)
-    )
+    ("^[ \t]*\\:\\([a-zA-Z_]+\\)\\:$" 1))
   "The list of HOWTO on extracting keyword from current line.
 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.")
+
 ;; ruby/bash/lua/vimrc
 (defvar evilmi-org-match-tags
   '((("begin_src") () ( "end_src") "MONOGAMY")
     (("begin_example") () ( "end_example") "MONOGAMY")
     (("begin_html") () ( "end_html") "MONOGAMY")
-    (("results") () ( "end") "MONOGAMY")
-    ))
+    (("results") () ( "end") "MONOGAMY")))
 
 (defun evilmi--element-property (property element)
   "Extract the value from the PROPERTY of an ELEMENT."
@@ -60,7 +57,7 @@ between '\\(' and '\\)' in regular expression.
 
 (defun evilmi--get-embedded-language-major-mode ()
   ;; org-element-at-point is available only at org7+
-  (let ((lang (evilmi--element-property :language (org-element-at-point))))
+  (let* ((lang (evilmi--element-property :language (org-element-at-point))))
     (when lang
       (if (string= lang "elisp")
           'emacs-lisp-mode
@@ -68,39 +65,37 @@ between '\\(' and '\\)' in regular expression.
 
 ;;;###autoload
 (defun evilmi-org-get-tag ()
-  (let (rlt)
-    (setq rlt (evilmi-sdk-get-tag evilmi-org-match-tags 
evilmi-org-extract-keyword-howtos))
-    (if (not rlt)
-        (setq rlt '(-1)) ;; evilmi-org-jump knows what -1 means
-      )
-    rlt
-    ))
+  "Get current tag in org file."
+  (let* ((rlt (evilmi-sdk-get-tag evilmi-org-match-tags
+                                  evilmi-org-extract-keyword-howtos)))
+    (unless rlt
+        ;; evilmi-org-jump knows what -1 means
+        (setq rlt '(-1)))
+    rlt))
 
 ;;;###autoload
-(defun evilmi-org-jump (rlt NUM)
-  (if (< (car rlt) 0)
-      (let (where-to-jump-in-theory
-            jumped
-            plugin
-            info
-            (lang-f (evilmi--get-embedded-language-major-mode)))
-        (when lang-f
-          (setq plugin (plist-get evilmi-plugins lang-f))
-          (when plugin
-              (mapc
-               (lambda (elem)
-                 (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))
-                   ;; jump only once if the jump is successful
-                   (setq jumped t)
-                   ))
-               plugin
-               ))
-          )
-        )
-      (evilmi-sdk-jump rlt NUM evilmi-org-match-tags 
evilmi-org-extract-keyword-howtos)
-      ))
+(defun evilmi-org-jump (rlt num)
+  (cond
+   ((< (car rlt) 0)
+    (let* (where-to-jump-in-theory
+           jumped
+           info
+           (lang-f (evilmi--get-embedded-language-major-mode))
+           (plugin (and lang-f (plist-get evilmi-plugins lang-f))))
+      (when plugin
+        (mapc
+         (lambda (elem)
+           (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))
+             ;; jump only once if the jump is successful
+             (setq jumped t)))
+         plugin))))
+   (t
+    (evilmi-sdk-jump rlt
+                     num
+                     evilmi-org-match-tags
+                     evilmi-org-extract-keyword-howtos))))
 
 (provide 'evil-matchit-org)
diff --git a/evil-matchit-sdk.el b/evil-matchit-sdk.el
index 135ff8ee75..a3ca76a2c6 100644
--- a/evil-matchit-sdk.el
+++ b/evil-matchit-sdk.el
@@ -1,6 +1,12 @@
 (defvar evilmi-debug nil
   "Debug flag.")
 
+(defvar evilmi-ignored-fonts
+  '(font-lock-string-face
+    font-lock-doc-face
+    font-lock-comment-face)
+  "Text with ingored fonts has no string keyword.")
+
 (defvar evilmi-sdk-extract-keyword-howtos
   '(("^[ \t]*\\([a-z]+\!?\\)\\( .*\\| *\\)$" 1)
     ("^.* \\(do\\) |[a-z0-9A-Z,|]+|$" 1))
@@ -126,6 +132,15 @@ is-function-exit-point could be unknown 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)))
+
+    (when keyword
+      ;; ignore text with specific font
+      (save-excursion
+        (goto-char (line-beginning-position))
+        (when (and (search-forward keyword (line-end-position) t)
+                   (evilmi-among-fonts-p (point)
+                                         evilmi-ignored-fonts))
+          (setq keyword nil))))
     keyword))
 
 (defun evilmi--is-monogamy (tag-info)
@@ -265,7 +280,7 @@ after calling this function."
 
 
 ;;;###autoload
-(defun evilmi-current-font-among-fonts-p (pos fonts)
+(defun evilmi-among-fonts-p (pos fonts)
   "If current font at POS is among FONTS."
   (let* ((fontfaces (get-text-property pos 'face)))
     (when (not (listp fontfaces))
@@ -300,26 +315,6 @@ after calling this function."
           (setq rlt line)))))
     rlt))
 
-;;;###autoload
-(defun evilmi-in-comment-p (pos)
-  "Check character at POS is comment by comparing font face."
-  (cond
-   ;; @see https://github.com/redguardtoo/evil-matchit/issues/92
-   ((eq major-mode 'tuareg-mode)
-    (evilmi-current-font-among-fonts-p pos '(font-lock-comment-face
-                                             font-lock-comment-delimiter-face
-                                             font-lock-doc-face)))
-   (t
-    (evilmi-current-font-among-fonts-p pos '(font-lock-comment-face
-                                             
font-lock-comment-delimiter-face)))))
-
-
-;;;###autoload
-(defun evilmi-in-string-or-doc-p (pos)
-  "Check character at POS is string or document by comparing font face."
-  (evilmi-current-font-among-fonts-p pos '(font-lock-string-face
-                                           font-lock-doc-face)))
-
 ;;;###autoload
 (defun evilmi-evenp (num)
   (= (% num 2) 0))
diff --git a/evil-matchit.el b/evil-matchit.el
index 2841bac7ed..ad07b59bd0 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.3.3
+;; Version: 2.3.4
 ;; Keywords: matchit vim evil
 ;; Package-Requires: ((evil "1.2.0") (emacs "24.4"))
 ;;
@@ -127,6 +127,18 @@ 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 character at POS is comment by comparing font face."
+  (cond
+   ;; @see https://github.com/redguardtoo/evil-matchit/issues/92
+   ((eq major-mode 'tuareg-mode)
+    (evilmi-among-fonts-p pos '(font-lock-comment-face
+                                             font-lock-comment-delimiter-face
+                                             font-lock-doc-face)))
+   (t
+    (evilmi-among-fonts-p pos '(font-lock-comment-face
+                                             
font-lock-comment-delimiter-face)))))
+
 (defun evilmi--scan-sexps (is-forward)
   "Get the position of matching tag.
 If IS-FORWARD is t, jump forward; or else jump backward."
@@ -455,7 +467,7 @@ If IS-FORWARD is t, jump forward; or else jump backward."
 ;;;###autoload
 (defun evilmi-version()
   (interactive)
-  (message "2.3.3"))
+  (message "2.3.4"))
 
 ;;;###autoload
 (define-minor-mode evil-matchit-mode
diff --git a/pkg.sh b/pkg.sh
index 26de8a61d8..1eb61b94d7 100755
--- a/pkg.sh
+++ b/pkg.sh
@@ -1,6 +1,6 @@
 #!/bin/bash
 name=evil-matchit
-version=2.3.3
+version=2.3.4
 pkg=$name-$version
 mkdir $pkg
 cp README.org $pkg



reply via email to

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