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

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

[nongnu] elpa/evil-matchit 0b0e6d61a6 119/244: clean code


From: ELPA Syncer
Subject: [nongnu] elpa/evil-matchit 0b0e6d61a6 119/244: clean code
Date: Thu, 6 Jan 2022 02:58:55 -0500 (EST)

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

    clean code
    
    - support text-object and other evlimi commands
    - use namespace evilmi-ocaml
    - remove trailing spaces
---
 README.org            |  7 +++----
 evil-matchit-ocaml.el | 48 ++++++++++++++++++++++++++----------------------
 evil-matchit.el       |  8 ++++----
 pkg.sh                |  2 +-
 4 files changed, 34 insertions(+), 31 deletions(-)

diff --git a/README.org b/README.org
index 386281b74f..fe6395ad41 100644
--- a/README.org
+++ b/README.org
@@ -1,4 +1,4 @@
-* evil-matchit (v2.2.1)
+* evil-matchit (v2.2.2)
 
 
[[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]]
 
@@ -14,6 +14,7 @@ Many modern languages are supported:
 - Javascript
 - React JSX (rjsx-mode)
 - JSON
+- OCaml
 - Perl
 - Latex
 - CMake
@@ -175,9 +176,7 @@ Here is a complete sample:
 ;;         we use it to select/delete tag. The other elements of the list could
 ;;         be any data type
 (defun evilmi-mylang-find-tag ()
-  (let (rlt)
-    (setq rlt '(position-of-open-end "anything-you-like" "anything-you-like")
-    rlt))
+  (list position-of-open-end "anything-you-like" "anything-you-like"))
 
 ;; @parama rlt result from evilmi-mylang-find-tag
 ;; @param NUM numeric argument when user press "%" to match tag
diff --git a/evil-matchit-ocaml.el b/evil-matchit-ocaml.el
index 00e1c2e00e..1ec48b39b7 100644
--- a/evil-matchit-ocaml.el
+++ b/evil-matchit-ocaml.el
@@ -1,28 +1,29 @@
-(setq evilmi-ocaml-keywords
-      '((("struct" "begin" "object") ("end"))
-        (("if") ("then"))
-        (("match") ("with"))
-        (("match" "try") ("with"))
-        (("while" "for") ("done"))
-        (("let") ("in"))
-        ()))
+(defvar evilmi-ocaml-keywords
+  '((("struct" "begin" "object") ("end"))
+    (("if") ("then"))
+    (("match") ("with"))
+    (("match" "try") ("with"))
+    (("while" "for") ("done"))
+    (("let") ("in"))
+    ())
+  "Ocaml keywords.")
 
-;; regexp to find next/previous keyword
-(setq keywords-regex
+(defvar evilmi-ocaml-keywords-regex
   (let ((all-keywords (apply 'append (apply 'append evilmi-ocaml-keywords))))
-    (format "\\<\\(%s\\)\\>" (mapconcat 'identity all-keywords "\\|"))))
+    (format "\\<\\(%s\\)\\>" (mapconcat 'identity all-keywords "\\|")))
+  "Regexp to find next/previous keyword.")
 
 ;; jumps to next keyword. Returs nil if there's no next word
 (defun evilmi-ocaml-next-word (direction)
   (if (= direction 0)
       (let ((new-point (save-excursion
           (forward-char)
-          (if (search-forward-regexp keywords-regex nil t)
-              (search-backward-regexp keywords-regex)
+          (if (search-forward-regexp evilmi-ocaml-keywords-regex nil t)
+              (search-backward-regexp evilmi-ocaml-keywords-regex)
             nil)
         )))
         (if new-point (goto-char new-point)))
-    (search-backward-regexp keywords-regex nil t)))
+    (search-backward-regexp evilmi-ocaml-keywords-regex nil t)))
 
 (defun evilmi-ocaml-end-word ()
   (save-excursion
@@ -33,11 +34,11 @@
   (buffer-substring-no-properties (point) (evilmi-ocaml-end-word)))
 
 (defun evilmi-ocaml-is-keyword (l keyword)
-  "Checks if the keyword belongs to a row"
+  "Checks if the keyword belongs to a row."
   (find-if (lambda (w) (string-equal w keyword)) (apply 'append l)))
 
 (defun evilmi-ocaml-get-tag-info (keyword)
-  "Find the row in the evilmi-ocaml-keywords"
+  "Find the row in the evilmi-ocaml-keywords."
   (find-if (lambda (l) (evilmi-ocaml-is-keyword l keyword)) 
evilmi-ocaml-keywords))
 
 ;; 0 - forward
@@ -46,7 +47,7 @@
   (if (= level 0)
       (point)
     (if (evilmi-ocaml-next-word direction)
-        (progn 
+        (progn
           (setq keyword (evilmi-ocaml-get-word))
 
           (if (evilmi-ocaml-is-keyword tag-info keyword)
@@ -66,17 +67,20 @@
 
 ;;;###autoload
 (defun evilmi-ocaml-get-tag ()
-  (save-excursion 
+  "Return information of current tag: (list position-of-word word)."
+  (save-excursion
     (evilmi-ocaml-goto-word-beginning)
-    (evilmi-ocaml-get-word)))
+    (list (car (bounds-of-thing-at-point 'word))
+          (evilmi-ocaml-get-word))))
 
 ;;;###autoload
 (defun evilmi-ocaml-jump (rlt num)
-  (let* ((tag-info (evilmi-ocaml-get-tag-info rlt))
-         (direction (if (member rlt (car tag-info)) 0 1)))
+  (let* ((keyword (cadr rlt))
+         (tag-info (evilmi-ocaml-get-tag-info keyword))
+         (direction (if (member keyword (car tag-info)) 0 1)))
     (let ((new-point (save-excursion
                        (evilmi-ocaml-goto-word-beginning)
                        (evilmi-ocaml-go tag-info 1 direction))))
       (if new-point (goto-char new-point)))))
 
-(provide 'evil-matchit-ocaml)
+(provide 'evil-matchit-ocaml)
\ No newline at end of file
diff --git a/evil-matchit.el b/evil-matchit.el
index ab489f1c6f..1c1899261d 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.1
+;; Version: 2.2.2
 ;; Keywords: matchit vim evil
 ;; Package-Requires: ((evil "1.0.7"))
 ;;
@@ -312,8 +312,8 @@ If font-face-under-cursor is NOT nil, the quoted string is 
being processed."
   ;; ocaml
   (autoload 'evilmi-ocaml-get-tag "evil-matchit-ocaml" nil)
   (autoload 'evilmi-ocaml-jump "evil-matchit-ocaml" nil t)
-  (plist-put evilmi-plugins 'tuareg-mode '((evilmi-ocaml-get-tag 
evilmi-ocaml-jump)
-                                          (evilmi-simple-get-tag 
evilmi-simple-jump)))
+  (plist-put evilmi-plugins 'tuareg-mode '((evilmi-simple-get-tag 
evilmi-simple-jump)
+                                           (evilmi-ocaml-get-tag 
evilmi-ocaml-jump)))
 
   ;; Python
   (autoload 'evilmi-python-get-tag "evil-matchit-python" nil)
@@ -479,7 +479,7 @@ If font-face-under-cursor is NOT nil, the quoted string is 
being processed."
 ;;;###autoload
 (defun evilmi-version()
   (interactive)
-  (message "2.2.1"))
+  (message "2.2.2"))
 
 ;;;###autoload
 (define-minor-mode evil-matchit-mode
diff --git a/pkg.sh b/pkg.sh
index 386c0168c0..7120125b4a 100755
--- a/pkg.sh
+++ b/pkg.sh
@@ -1,6 +1,6 @@
 #!/bin/bash
 name=evil-matchit
-version=2.2.1
+version=2.2.2
 pkg=$name-$version
 mkdir $pkg
 cp README.org $pkg



reply via email to

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