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

    clean code&do
---
 README.org           | 28 ++++++++----------
 evil-matchit-html.el | 84 +++++++++++++++++++++++-----------------------------
 evil-matchit-ruby.el | 15 +++++-----
 evil-matchit-sdk.el  | 24 +++++++--------
 4 files changed, 70 insertions(+), 81 deletions(-)

diff --git a/README.org b/README.org
index 540dc53162..f407e88026 100644
--- a/README.org
+++ b/README.org
@@ -2,7 +2,7 @@
 
 
[[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]]
 
-Vim [[http://www.vim.org/scripts/script.php?script_id=39][matchit.vim]] by 
Benji Fisher ported into Emacs.
+Vim [[http://www.vim.org/scripts/script.php?script_id=39][matchit.vim]] by 
Benji Fisher is ported into Emacs.
 
 Press "%" to jump between matched tags in Emacs. For example, in HTML "<div>" 
and "</div>" are a pair of tags.
 
@@ -44,7 +44,6 @@ Tested on Emacs 24.3, 24.4, 24.5, 25.1
 - Support any modern languages (html/java/c/c++/python/latex/javascript ...)
 - Powerful. If you mix jsp, freemarker, html, jquery template or any weird 
syntax into one file, it still works!
 - Extendable. Write a plugin for it takes only 5 minutes
-- Long term support
 
 Screen cast for python:
 [[file:screencast.gif]]
@@ -53,13 +52,13 @@ Screen cast for python:
 It's already uploaded to [[http://melpa.org/]].
 
 * Set up
-Insert below code into your ~/.emacs:
+Insert below code into =~/.emacs=:
 #+BEGIN_SRC lisp
 (require 'evil-matchit)
 (global-evil-matchit-mode 1)
 #+END_SRC
 
-Alternatively, you can enable evil-matchit-mode along a major mode by adding 
=turn-on-evil-matchit-mode= to the mode hook.
+Alternatively, you can enable =evil-matchit-mode= along a major mode by adding 
=turn-on-evil-matchit-mode= to the mode hook.
 
 * Usage
 Press "%" to jump inside between tag pair in normal mode or visual mode (you 
press "v" to switch to visual mode). Please note evil-matchit is smart enough 
to *detect the tag automatically*.
@@ -68,17 +67,17 @@ Tag pair could be open/closed html tag, or character pair 
like "{}" "[]" "()", o
 
 Inner/outer text object "%" is also created. It roughly equals the region when 
you press "%" from evil-matchit.
 
-Press "va%" to select line(s) wrapped by tags including tags themselves. `M-x 
evilmi-select-items` does the same thing.
+Press "va%" to select line(s) wrapped by tags including tags themselves. =M-x 
evilmi-select-items= does the same thing.
 
-Press "da%" to delete line(s) wrapped by tags including tags themselves. `M-x 
evilmi-delete-items` does the same thing.
+Press "da%" to delete line(s) wrapped by tags including tags themselves. =M-x 
evilmi-delete-items= does the same thing.
 
 All commands support numeric argument like "3%", "5va%" or "9da%"
 
-Pressing "3%" jumps to a line 3 percentage down the file. It's the default 
behavior in original =evil-mode=. You can `(setq evilmi-may-jump-by-percentage 
nil)` to turn off this feature. Then "3%" will jump 3 times.
+Pressing "3%" jumps to a line 3 percentage down the file. It's the default 
behavior in original =evil-mode=. You can =(setq evilmi-may-jump-by-percentage 
nil)= to turn off this feature. Then "3%" will jump 3 times.
 
-Please note *only "evil-visual-state" and "evil-normal-state" are officially 
supported*.
+Please note *only =evil-visual-state= and =evil-normal-state= are supported*.
 
-If you need visually select lines, I strongly recommend *using 
"evilmi-select-items" instead*.
+If you need visually select lines, I *strongly recommend* using 
=evilmi-select-items= instead.
 
 This is actually an advantage of Emacs, you can tweak the select region 
without go into visual state at all.
 
@@ -89,9 +88,9 @@ In order to apply three matching rules =evilmi-template=, 
=evilmi-simple=, and =
 (evilmi-load-plugin-rules '(mhtml-mode) '(template simple html))
 #+end_src
 ** Use evilmi-select-items instead press "%" in evil-visual-state
-evilmi-select-items is more robust and provides more functionality. It works 
even when =evil-mode= is not loaded.
+=evilmi-select-items= is more robust and provides more functionality. It works 
even when =evil-mode= is not loaded.
 
-So you'd better stick to evilmi-select-items if possible.
+So you'd better stick to =evilmi-select-item= if possible.
 ** Add new tags into existing languages
 Use ruby as an example.
 
@@ -111,9 +110,8 @@ So you setup in ~/.emacs is as below:
 #+begin_src elisp
 (eval-after-load 'evil-matchit-ruby
   '(progn
-     (add-to-list 'evilmi-ruby-extract-keyword-howtos '("^[ 
\t]*\\([a-z]+\\)\\( .*\\| *\\)$" 1))
-     (add-to-list 'evilmi-ruby-match-tags '(("unless" "if") ("elsif" "else") 
"end"))
-     ))
+     (push '("^[ \t]*\\([a-z]+\\)\\( .*\\| *\\)$" 1) 
evilmi-ruby-extract-keyword-howtos)
+     (push '(("unless" "if") ("elsif" "else") "end"))) evilmi-ruby-match-tags)
 #+end_src
 
 ** Re-define keybinding
@@ -187,7 +185,7 @@ A complete setup:
   888)
 
 ;; Notify evil-matchit how to use above functions
-(evilmi-load-plugin-rules '(mylang-mode) '(mylan))
+(evilmi-load-plugin-rules '(mylang-mode) '(mylang))
 #+END_SRC
 
 Place above code into your =~/.emacs=, after the line 
"(global-evil-matchit-mode 1)"
diff --git a/evil-matchit-html.el b/evil-matchit-html.el
index ec3ef3da5d..19ce80a31c 100644
--- a/evil-matchit-html.el
+++ b/evil-matchit-html.el
@@ -1,6 +1,6 @@
 ;;; evil-matchit-html.el ---html plugin of evil-matchit
 
-;; Copyright (C) 2014-2017 Chen Bin <[email protected]>
+;; Copyright (C) 2014-2019 Chen Bin <[email protected]>
 
 ;; Author: Chen Bin <[email protected]>
 
@@ -33,69 +33,59 @@
 
 ;;;###autoload
 (defun evilmi-html-get-tag ()
-  (let ((b (line-beginning-position))
-        (e (line-end-position))
-        (looping t)
-        (html-tag-char (string-to-char "<"))
-        (char (following-char))
-        (p (point))
-        (found_tag -1)
-        (rlt nil))
+  (let* ((b (line-beginning-position))
+         (e (line-end-position))
+         (looping t)
+         (char (following-char))
+         (p (point))
+         (found_tag -1)
+         rlt)
 
     (save-excursion
       ;; search backward
-      (unless (= char html-tag-char)
-        (while (and looping (<= b (point)) (not (= char 60)))
+      (unless (eq char ?<)
+        (while (and looping (<= b (point)) (not (eq char ?<)))
           (setq char (following-char))
           (setq p (point))
-          (if (= p (point-min))
+          (if (eq p (point-min))
               ;; need get out of loop anyway
               (setq looping nil)
-            (backward-char))
-          ))
+            (backward-char))))
 
       ;; search forward
-      (if (not (= char html-tag-char))
-          (save-excursion
-            (while (and (>= e (point)) (not (= char 60)))
-              (setq char (following-char))
-              (setq p (point))
-              (forward-char)
-              )
-            )
-        )
+      (unless (eq char ?<)
+        (save-excursion
+          (while (and (>= e (point)) (not (eq char ?<)))
+            (setq char (following-char))
+            (setq p (point))
+            (forward-char))))
 
       ;; is end tag?
-      (when (and (= char html-tag-char) (< p e))
+      (when (and (eq char ?<) (< p e))
         (goto-char p)
         (forward-char)
-        (if (= (following-char) 47)
-            (progn
-              ;; </
-              (skip-chars-forward "^>")
-              (forward-char)
-              (setq p (point))
-              (setq found_tag 1)
-              )
-          (progn
-            ;; < , looks fine
-            (backward-char)
-            (setq found_tag 0)
-            )
-          )
-        )
-      )
+        (cond
+         ((eq (following-char) ?/)
+          ;; </
+          (skip-chars-forward "^>")
+          (forward-char)
+          (setq p (point))
+          (setq found_tag 1))
+         (t
+          ;; < , looks fine
+          (backward-char)
+          (setq found_tag 0)))))
     (setq rlt (list p found_tag ""))
     rlt))
 
 ;;;###autoload
-(defun evilmi-html-jump (rlt NUM)
-  (let ((tag-type (nth 1 rlt))
-        ;; web-mode-forward-sexp is assigned to forward-sexp-function
-        ;; it's buggy in web-mode v11, here is the workaround
-        (forward-sexp-function nil))
-    (if (=  1 tag-type) (sgml-skip-tag-backward NUM))
-    (if (=  0 tag-type) (sgml-skip-tag-forward NUM))
+(defun evilmi-html-jump (rlt num)
+  (let* ((tag-type (nth 1 rlt))
+         ;; `web-mode-forward-sexp' is assigned to `forward-sexp-function'
+         ;; it's buggy in web-mode v11, here is the workaround
+         (forward-sexp-function nil))
+    (if (eq 1 tag-type) (sgml-skip-tag-backward num))
+    (if (eq 0 tag-type) (sgml-skip-tag-forward num))
     (point)))
 
 (provide 'evil-matchit-html)
diff --git a/evil-matchit-ruby.el b/evil-matchit-ruby.el
index f5045220a3..ae78677a6c 100644
--- a/evil-matchit-ruby.el
+++ b/evil-matchit-ruby.el
@@ -1,6 +1,6 @@
 ;;; evil-matchit-ruby.el ---ruby plugin of evil-matchit
 
-;; Copyright (C) 2014-2017 Chen Bin <[email protected]>
+;; Copyright (C) 2014-2019 Chen Bin <[email protected]>
 
 ;; Author: Chen Bin <[email protected]>
 
@@ -24,11 +24,14 @@
 ;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 
-;;; Code:
+;;; Commentary:
 
 ;; OPTIONAL, you don't need SDK to write a plugin for evil-matchit
 ;; but SDK do make you write less code, isn't it?
 ;; All you need to do is just define the match-tags for SDK algorithm to 
lookup.
+
+;;; Code:
+
 (require 'evil-matchit-sdk)
 
 (defvar evilmi-ruby-extract-keyword-howtos
@@ -47,12 +50,10 @@
 
 ;;;###autoload
 (defun evilmi-ruby-get-tag ()
-  (let (rlt)
-    (setq rlt (evilmi-sdk-get-tag evilmi-ruby-match-tags 
evilmi-ruby-extract-keyword-howtos))
-    rlt))
+  (evilmi-sdk-get-tag evilmi-ruby-match-tags 
evilmi-ruby-extract-keyword-howtos))
 
 ;;;###autoload
-(defun evilmi-ruby-jump (rlt NUM)
-  (evilmi-sdk-jump rlt NUM evilmi-ruby-match-tags 
evilmi-ruby-extract-keyword-howtos))
+(defun evilmi-ruby-jump (rlt num)
+  (evilmi-sdk-jump rlt num evilmi-ruby-match-tags 
evilmi-ruby-extract-keyword-howtos))
 
 (provide 'evil-matchit-ruby)
diff --git a/evil-matchit-sdk.el b/evil-matchit-sdk.el
index a3ca76a2c6..8b4cea425f 100644
--- a/evil-matchit-sdk.el
+++ b/evil-matchit-sdk.el
@@ -5,7 +5,7 @@
   '(font-lock-string-face
     font-lock-doc-face
     font-lock-comment-face)
-  "Text with ingored fonts has no string keyword.")
+  "Text with ignored fonts has no string keyword.")
 
 (defvar evilmi-sdk-extract-keyword-howtos
   '(("^[ \t]*\\([a-z]+\!?\\)\\( .*\\| *\\)$" 1)
@@ -89,22 +89,22 @@ between '\\(' and '\\)' in regular expression.")
 ;;;###autoload
 (defun evilmi-sdk-get-tag-info (keyword match-tags)
   "Return (row column is-function-exit-point keyword).
-The row and column marked position in evilmi-mylang-match-tags
+The row and column mark the position in evilmi-mylang-match-tags
 is-function-exit-point could be unknown status"
   (let* (rlt
-         elems
-         elem
+         items
+         item
          found
          (i 0)
          j)
 
     (while (and (< i (length match-tags)) (not found))
-      (setq elems (nth i match-tags))
+      (setq items (nth i match-tags))
       (setq j 0)
-      (while (and (not found) (< j (length elems)))
-        (setq elem (nth j elems))
-        (setq found (and (or (stringp elem) (listp elem))
-                         (evilmi-sdk-member keyword elem)))
+      (while (and (not found) (< j (length items)))
+        (setq item (nth j items))
+        (setq found (and (or (stringp item) (listp item))
+                         (evilmi-sdk-member keyword item)))
         (if (not found)
             (setq j (1+ j))))
       (if (not found) (setq i (1+ i))))
@@ -193,7 +193,7 @@ after calling this function."
          keyword
          found
          where-to-jump-in-theory)
-    (if evilmi-debug (message "evilmi-sdk-jump called => rlt=%s (piont)=%s" 
rlt (point)))
+    (if evilmi-debug (message "evilmi-sdk-jump called => rlt=%s (point)=%s" 
rlt (point)))
 
     (while (not found)
       (forward-line (if (= orig-tag-type 2) -1 1))
@@ -316,8 +316,8 @@ after calling this function."
     rlt))
 
 ;;;###autoload
-(defun evilmi-evenp (num)
-  (= (% num 2) 0))
+(defmacro evilmi-evenp (num)
+  `(= (% ,num 2) 0))
 
 (defun evilmi-count-matches (regexp str)
   (let* ((count 0)

Reply via email to