branch: elpa/evil-matchit commit e44de538b95a86e9f14b67b54fefc22db1c76a52 Author: Chen Bin <chenbin...@gmail.com> Commit: Chen Bin <chenbin...@gmail.com>
clean code & doc --- README.org | 4 ++-- evil-matchit-sdk.el | 44 +++++++++++++++++++++++--------------------- evil-matchit.el | 16 +++++++++++----- 3 files changed, 36 insertions(+), 28 deletions(-) diff --git a/README.org b/README.org index b66d0b4d5c..9b9878fef4 100644 --- a/README.org +++ b/README.org @@ -106,7 +106,7 @@ Open evil-matchit-ruby.el whole structure is like, (provide 'evil-matchit-ruby) #+end_src -So you setup in ~/.emacs is as below: +So you configuration in =~/.emacs= is as below: #+begin_src elisp (with-eval-after-load "evil-matchit-ruby" (push '("^[ \t]*\\([a-z]+\\)\\( .*\\| *\\)$" 1) evilmi-ruby-extract-keyword-howtos) @@ -114,7 +114,7 @@ So you setup in ~/.emacs is as below: #+end_src ** Re-define keybinding -All you need to do is to define function evilmi-customize-keybinding before turning on evil-match-mode: +All you need to do is to define function =evilmi-customize-keybinding= before turning on =evil-matchit-mode=: The shortcut =%= is defined in =evilmi-shortcut=. It's the name of text object and shortcut of =evilmi-jump-items=. Some people prefer set it to "m". diff --git a/evil-matchit-sdk.el b/evil-matchit-sdk.el index 467639ae76..cf898366c0 100644 --- a/evil-matchit-sdk.el +++ b/evil-matchit-sdk.el @@ -20,16 +20,16 @@ "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 +to extract the keyword which starts from one. The sub-match is the match defined between '\\(' and '\\)' in regular expression.") -(defmacro evilmi-sdk-keyword (info) +(defun evilmi-sdk-keyword (info) "Get keyword from INFO." - `(nth 3 ,info)) + (nth 3 info)) -(defmacro evilmi-sdk-get-char (position) +(defun evilmi-sdk-get-char (position) "Get character at POSITION." - `(char-after ,position)) + (char-after position)) (defun evilmi-sdk-jump-forward-p () "Return: (forward-direction font-face-under-cursor character-under-cursor). @@ -161,8 +161,8 @@ If IS-FORWARD is t, jump forward; or else jump backward." (goto-char (evilmi-sdk-jumpto-where ff jump-forward ch)) (evilmi-sdk-tweak-selected-region ff jump-forward))) -(defmacro evilmi-sdk-strictly-type-p (crt orig) - `(or (evilmi-sdk-monogamy-p ,crt) (evilmi-sdk-monogamy-p ,orig))) +(defun evilmi-sdk-strictly-type-p (crt orig) + (or (evilmi-sdk-monogamy-p crt) (evilmi-sdk-monogamy-p orig))) (defun evilmi-sdk-tags-matched-p (level orig-tag-info cur-tag-info match-tags) (let* (rlt @@ -191,8 +191,9 @@ If IS-FORWARD is t, jump forward; or else jump backward." rlt)) ;;;###autoload -(defmacro evilmi-sdk-curline () - `(buffer-substring-no-properties (line-beginning-position) (line-end-position))) +(defun evilmi-sdk-curline () + (buffer-substring-no-properties (line-beginning-position) + (line-end-position))) ;;;###autoload (defun evilmi-sdk-member (keyword keyword-list) @@ -273,6 +274,7 @@ Rule is looked up in HOWTOS." (setq howto (nth i howtos)) (when (string-match (nth 0 howto) cur-line) ;; keyword should be trimmed because FORTRAN use "else if" + (unless (featurep 'subr-x) (require 'subr-x)) (setq keyword (string-trim (match-string (nth 1 howto) cur-line))) ;; keep search keyword by using next howto (regex and match-string index) (unless (evilmi-sdk-member keyword match-tags) (setq keyword nil))) @@ -283,18 +285,18 @@ Rule is looked up in HOWTOS." (line-beginning-position) (line-end-position))))) -(defmacro evilmi-sdk-monogamy-p (tag-info) - `(and (nth 2 ,tag-info) (string= (nth 2 ,tag-info) "MONOGAMY"))) +(defun evilmi-sdk-monogamy-p (tag-info) + (and (nth 2 tag-info) (string= (nth 2 tag-info) "MONOGAMY"))) -(defmacro evilmi-sdk-exactly-same-type-p (crt orig) - `(= (nth 0 ,crt) (nth 0 ,orig))) +(defun evilmi-sdk-exactly-same-type-p (crt orig) + (= (nth 0 crt) (nth 0 orig))) -(defmacro evilmi-sdk-same-type (crt orig) - `(when (and ,crt ,orig) - ;; crt and orig should be at same row if either of them is monogamy - (if (evilmi-sdk-strictly-type-p ,crt ,orig) - (evilmi-sdk-exactly-same-type-p ,crt ,orig) - t))) +(defun evilmi-sdk-same-type (crt orig) + (when (and crt orig) + ;; crt and orig should be at same row if either of them is monogamy + (if (evilmi-sdk-strictly-type-p crt orig) + (evilmi-sdk-exactly-same-type-p crt orig) + t))) ;;;###autoload (defun evilmi-sdk-get-tag (match-tags howtos) @@ -449,8 +451,8 @@ after calling this function." rlt)) ;;;###autoload -(defmacro evilmi-evenp (num) - `(= (% ,num 2) 0)) +(defun evilmi-evenp (num) + (= (% num 2) 0)) (defun evilmi-count-matches (regexp str) (let* ((count 0) diff --git a/evil-matchit.el b/evil-matchit.el index 7c11153dc9..cef81591e9 100644 --- a/evil-matchit.el +++ b/evil-matchit.el @@ -103,8 +103,9 @@ Some people prefer using \"m\" instead.") (if evilmi-debug (message "evilmi--operate-on-item called. Return: %s" ideal-dest)) ideal-dest)) -(defun evilmi--push-mark (rlt) - (push-mark (nth 0 rlt) t t)) +(defun evilmi--push-mark (position) + "Pus POSITION as marker." + (push-mark (nth 0 position) t t)) (defun evilmi--convert-rules (rules) "Convert RULES to function pairs list." @@ -210,6 +211,8 @@ Some people prefer using \"m\" instead.") (defun evilmi--region-to-select-or-delete (num &optional is-inner) + "Get NUM region(s) to select or delete. +If IS-INNER is t, the region is inner text object." (let* (ideal-dest b e) (save-excursion (setq ideal-dest (evilmi--operate-on-item num #'evilmi--push-mark)) @@ -271,7 +274,7 @@ Some people prefer using \"m\" instead.") ;;;###autoload (defun evilmi-jump-to-percentage (num) - "Like Vim %." + "Like Vim %, NUM is the percentage of location." (interactive "P") (let* (dst) (when (and num (> num 0)) @@ -306,6 +309,9 @@ Some people prefer using \"m\" instead.") (interactive) (message "2.3.5")) +(defvar evil-matchit-mode-map (make-sparse-keymap) + "Keymap used by the minor mode.") + ;;;###autoload (define-minor-mode evil-matchit-mode "Buffer-local minor mode to emulate matchit.vim." @@ -324,12 +330,12 @@ Some people prefer using \"m\" instead.") ;;;###autoload (defun turn-on-evil-matchit-mode () - "Enable `evil-matchit-mode' in the current buffer." + "Enable the minor mode in the current buffer." (evil-matchit-mode 1)) ;;;###autoload (defun turn-off-evil-matchit-mode () - "Disable `evil-matchit-mode' in the current buffer." + "Disable the minor mode in the current buffer." (evil-matchit-mode -1)) ;;;###autoload