branch: elpa/evil-matchit
commit 86daa28dbd200c9a9b016380431f47522fd3c921
Author: Chen Bin <[email protected]>
Commit: Chen Bin <[email protected]>
doc, minor regex issue, tdd for lua
---
Makefile | 3 ++-
evil-matchit-c.el | 7 ++----
evil-matchit-cmake.el | 9 +++++++-
evil-matchit-elixir.el | 11 +++++-----
evil-matchit-fortran.el | 15 +++++++------
evil-matchit-latex.el | 24 ++++++++++----------
evil-matchit-org.el | 1 -
evil-matchit-python.el | 53 +++++++++++++++++++++++++--------------------
evil-matchit-ruby.el | 7 ++++--
evil-matchit-script.el | 27 +++++++++++++----------
evil-matchit-sh.el | 9 ++++----
evil-matchit-sql.el | 28 ++++++++++++------------
evil-matchit-verilog.el | 31 ++++++++++++++------------
tests/evil-matchit-tests.el | 49 ++++++++++++++++++++++++++++++++++++++++-
14 files changed, 170 insertions(+), 104 deletions(-)
diff --git a/Makefile b/Makefile
index a6ed2b7173..c5e5e0675e 100644
--- a/Makefile
+++ b/Makefile
@@ -11,7 +11,8 @@ clean:
deps:
@mkdir -p deps;
@if [ ! -f deps/evil-1.14.0/evil.el ]; then curl -L
https://stable.melpa.org/packages/evil-1.14.0.tar | tar x -C deps/; fi;
+ @if [ ! -f deps/lua-mode.el ]; then curl -L
https://raw.githubusercontent.com/immerrr/lua-mode/master/lua-mode.el >
deps/lua-mode.el; fi;
.PHONY: test
test: deps clean
- @$(EMACS) -batch -Q -L . -L deps/evil-1.14.0 -l evil-matchit.el -l
tests/evil-matchit-tests.el
\ No newline at end of file
+ @$(EMACS) -batch -Q -L . -L deps/evil-1.14.0 -l deps/lua-mode.el -l
evil-matchit.el -l tests/evil-matchit-tests.el
\ No newline at end of file
diff --git a/evil-matchit-c.el b/evil-matchit-c.el
index 6bd20124d1..cbaa44d234 100644
--- a/evil-matchit-c.el
+++ b/evil-matchit-c.el
@@ -27,16 +27,13 @@
;;; Code:
(require 'evil-matchit-sdk)
-;; ruby/bash/lua/vimrc
(defvar evilmi-c-match-tags
'((("# *ifdef" "# *ifndef" "# *if") ("# *elif" "# *else") "# *endif"
"MONOGAMY")
- ("switch" "case" "default" "MONOGAMY")
- ))
+ ("switch" "case" "default" "MONOGAMY")))
(defvar evilmi-c-extract-keyword-howtos
'(("^[ \t]*\\(# *[a-z]+\\)" 1)
- ("^[ \t]*\\([a-z]+\\)\\([ (:].*\\| *\\)$" 1)
- ))
+ ("^[ \t]*\\([a-z]+\\)\\([ (:].*\\| *\\)$" 1)))
;;;###autoload
(defun evilmi-c-get-tag ()
diff --git a/evil-matchit-cmake.el b/evil-matchit-cmake.el
index 59a1ac3e49..bbf98ed83a 100644
--- a/evil-matchit-cmake.el
+++ b/evil-matchit-cmake.el
@@ -1,4 +1,4 @@
-;;; evil-matchit-cmake.el ---cmake (ruby/lua) plugin of evil-matchit
+;;; evil-matchit-cmake.el --- cmake plugin of evil-matchit
;; Copyright (C) 2014-2020 Chen Bin <chenbin DOT sh AT gmail DOT com>
@@ -24,6 +24,10 @@
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+;;
+
;;; Code:
;; OPTIONAL, you don't need SDK to write a plugin for evil-matchit
@@ -57,3 +61,6 @@
evilmi-cmake-extract-keyword-howtos))
(provide 'evil-matchit-cmake)
+
+(provide 'evil-matchit-cmake)
+;;; evil-matchit-cmake.el ends here
diff --git a/evil-matchit-elixir.el b/evil-matchit-elixir.el
index e42b9a4ee7..a0ff995604 100644
--- a/evil-matchit-elixir.el
+++ b/evil-matchit-elixir.el
@@ -1,4 +1,4 @@
-;;; evil-matchit-elixir.el ---elixir plugin of evil-matchit
+;;; evil-matchit-elixir.el --- elixir plugin of evil-matchit
;; Copyright (C) 2018-2020 Chen Bin <chenbin DOT sh AT gmail DOT com>
@@ -22,8 +22,9 @@
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-
+;;
+;;; Commentary:
+;;
;;; Code:
;; OPTIONAL, you don't need SDK to write a plugin for evil-matchit
@@ -64,13 +65,13 @@
rlt))
;;;###autoload
-(defun evilmi-elixir-jump (rlt NUM)
+(defun evilmi-elixir-jump (rlt num)
(cond
((integerp rlt)
(goto-char rlt))
(t
(evilmi-sdk-jump rlt
- NUM
+ num
evilmi-elixir-match-tags
evilmi-elixir-extract-keyword-howtos))))
diff --git a/evil-matchit-fortran.el b/evil-matchit-fortran.el
index f5f45dece3..74e4d1e8f8 100644
--- a/evil-matchit-fortran.el
+++ b/evil-matchit-fortran.el
@@ -1,4 +1,4 @@
-;;; evil-matchit-fortran.el ---fortran (ruby/lua) plugin of evil-matchit
+;;; evil-matchit-fortran.el --- fortran plugin of evil-matchit
;; Copyright (C) 2014-2020 Chen Bin <chenbin DOT sh AT gmail DOT com>
@@ -22,8 +22,10 @@
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-
+;;
+;;; Commentary:
+;;
+;;
;;; Code:
;; OPTIONAL, you don't need SDK to write a plugin for evil-matchit
@@ -56,12 +58,11 @@
;;;###autoload
(defun evilmi-fortran-get-tag ()
- (evilmi-sdk-get-tag evilmi-fortran-match-tags
evilmi-fortran-extract-keyword-howtos)
- )
+ (evilmi-sdk-get-tag evilmi-fortran-match-tags
evilmi-fortran-extract-keyword-howtos))
;;;###autoload
(defun evilmi-fortran-jump (rlt NUM)
- (evilmi-sdk-jump rlt NUM evilmi-fortran-match-tags
evilmi-fortran-extract-keyword-howtos)
- )
+ (evilmi-sdk-jump rlt NUM evilmi-fortran-match-tags
evilmi-fortran-extract-keyword-howtos))
(provide 'evil-matchit-fortran)
+;;; evil-matchit-fortran.el ends here
diff --git a/evil-matchit-latex.el b/evil-matchit-latex.el
index 1a5aa556e9..6eec68f1c8 100644
--- a/evil-matchit-latex.el
+++ b/evil-matchit-latex.el
@@ -1,4 +1,4 @@
-;;; evil-matchit-latex.el ---latex plugin of evil-matchit
+;;; evil-matchit-latex.el --- latex plugin of evil-matchit
;; Copyright (C) 2014-2020 Chen Bin <chenbin DOT sh AT gmail DOT com>
@@ -22,31 +22,29 @@
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-
+;;
+;;; Commentary:
+;;
;;; Code:
+
(require 'evil-matchit-sdk)
(defvar evilmi-latex-extract-keyword-howtos
- '(("\\\\\\([a-zA-Z]+\\(\{[a-zA-Z0-9+*_-]+\}\\)?\\)" 1)
- ))
-;; (defvar evilmi-latex-regexp
"\\\\\\([a-zA-Z]+\\(\{[a-zA-Z0-9+*_-]+\}\\)?\\)")
+ '(("\\\\\\([a-zA-Z]+\\(\{[a-zA-Z0-9+*_-]+\}\\)?\\)" 1)))
(defvar evilmi-latex-match-tags
'((("if[a-zA-Z]+" "if") "else" "fi" "MONOGAMY")
("left" nil "right" "MONOGAMY")
("begin[a-z]+" nil "end[a-z]+")
- ("begin\{[a-zA-Z0-9+*_-]+\}" nil "end\{[a-zA-Z0-9+*_-]+\}")
- ))
+ ("begin\{[a-zA-Z0-9+*_-]+\}" nil "end\{[a-zA-Z0-9+*_-]+\}")))
;;;###autoload
(defun evilmi-latex-get-tag ()
- (let (rlt)
- (setq rlt (evilmi-sdk-get-tag evilmi-latex-match-tags
evilmi-latex-extract-keyword-howtos))
- rlt))
+ (evilmi-sdk-get-tag evilmi-latex-match-tags
evilmi-latex-extract-keyword-howtos))
;;;###autoload
-(defun evilmi-latex-jump (rlt NUM)
- (evilmi-sdk-jump rlt NUM evilmi-latex-match-tags
evilmi-latex-extract-keyword-howtos))
+(defun evilmi-latex-jump (rlt num)
+ (evilmi-sdk-jump rlt num evilmi-latex-match-tags
evilmi-latex-extract-keyword-howtos))
(provide 'evil-matchit-latex)
+;;; evil-matchit-latex.el ends here
diff --git a/evil-matchit-org.el b/evil-matchit-org.el
index 89aa268359..be716a9f61 100644
--- a/evil-matchit-org.el
+++ b/evil-matchit-org.el
@@ -41,7 +41,6 @@ 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.")
-;; ruby/bash/lua/vimrc
(defvar evilmi-org-match-tags
'((("begin_src") () ( "end_src") "MONOGAMY")
(("begin_example") () ( "end_example") "MONOGAMY")
diff --git a/evil-matchit-python.el b/evil-matchit-python.el
index 7135f75321..4368e0f764 100644
--- a/evil-matchit-python.el
+++ b/evil-matchit-python.el
@@ -1,4 +1,4 @@
-;;; evil-matchit-python.el ---python plugin of evil-matchit
+;;; evil-matchit-python.el --- python plugin of evil-matchit
;; Copyright (C) 2014-2020 Chen Bin <chenbin DOT sh AT gmail DOT com>
@@ -24,12 +24,16 @@
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+;;
+
;;; Code:
(require 'evil-matchit-sdk)
-;; @return number of indent
(defun evilmi--python-calculate-indent (line)
+ "Return number of indent of LINE."
(let* (prefix)
(cond
((string-match "^[ \t]*$" line)
@@ -47,9 +51,10 @@
;; line begin at the first column
0))))
-;; jump from else to if, jump from finally to try
-;; only python need this hack, a weird language
(defun evilmi--python-move-to-first-open-tag (cur-indent)
+ "Jump to the open tag based on CUR-INDENT.
+For example, jump from the tag \"finally\" to \"try\".
+Only python need this hack."
(let* (out-of-loop
keyword
where-to-go
@@ -57,15 +62,15 @@
(cur-line (evilmi-sdk-curline)))
;; extract keyword from current line
- (if (string-match "^[ \t]*\\([a-z]+\\) *.*:\s*\\(#.*\\)?$" cur-line)
+ (if (string-match "^[ \t]*\\([a-z]+\\) *.*:[ \t]*\\(#.*\\)?$" cur-line)
(setq keyword (match-string 1 cur-line)))
(cond
((string= keyword "else")
- (setq regexp "^[ \t]*\\(if\\) *.*:\s*\\(#.*\\)?$"))
+ (setq regexp "^[ \t]*\\(if\\) *.*:[ \t]*\\(#.*\\)?$"))
((or (string= keyword "finally") (string= keyword "except"))
- (setq regexp "^[ \t]*\\(try\\) *.*:\s*\\(#.*\\)?$")))
+ (setq regexp "^[ \t]*\\(try\\) *.*:[ \t]*\\(#.*\\)?$")))
(when regexp
(save-excursion
@@ -86,6 +91,7 @@
(skip-chars-forward " \t")))))
(defun evilmi--python-move-to-next-open-tag (keyword cur-indent)
+ "Move to next open tag using KEYWORD and CUR-INDENT."
(let* (out-of-loop
where-to-go
regexp
@@ -93,13 +99,13 @@
(cond
((string= keyword "try")
- (setq regexp "^[ \t]*\\(except\\) *.*:\s*\\(#.*\\)?$"))
+ (setq regexp "^[ \t]*\\(except\\) *.*:[ \t]*\\(#.*\\)?$"))
((string= keyword "except")
- (setq regexp "^[ \t]*\\(except\\|finally\\) *.*:\s*\\(#.*\\)?$"))
+ (setq regexp "^[ \t]*\\(except\\|finally\\) *.*:[ \t]*\\(#.*\\)?$"))
((or (string= keyword "elif") (string= keyword "if"))
- (setq regexp "^[ \t]*\\(elif\\|else\\) *.*:\s*\\(#.*\\)?$")))
+ (setq regexp "^[ \t]*\\(elif\\|else\\) *.*:[ \t]*\\(#.*\\)?$")))
(save-excursion
(while (not out-of-loop)
@@ -111,8 +117,8 @@
(setq where-to-go (line-beginning-position)))
(setq out-of-loop t))
;; if it's last line, we need get out of loop
- (if (= (point-max) (line-end-position))
- (setq out-of-loop t))))
+ (when (= (point-max) (line-end-position))
+ (setq out-of-loop t))))
(when where-to-go
(goto-char where-to-go)
@@ -120,9 +126,9 @@
;;;###autoload
(defun evilmi-python-get-tag ()
- "Reutrn '(start-position tag-type keyword)."
+ "Return '(start-position tag-type keyword)."
(let* (rlt
- (regexp "^[ \t]*\\([a-z]+\\) *.*:\s*\\(#.*\\)?$")
+ (regexp "^[ \t]*\\([a-z]+\\) *.*:[ \t]*\\(#.*\\)?$")
(cur-line (evilmi-sdk-curline))
next-line)
@@ -141,9 +147,7 @@
;; double check next line to make sure current line is close tag
;; if next line indention is less than current line or next line is
empty line
;; we are at closed tag now, will jump backward
- (setq rlt (list (line-end-position)
- 1
- "")))
+ (setq rlt (list (line-end-position) 1 "")))
(t
(setq rlt nil)))
@@ -153,17 +157,17 @@
rlt))
;;;###autoload
-(defun evilmi-python-jump (rlt NUM)
- (let* ((p (nth 0 rlt))
- (tag-type (nth 1 rlt))
- (keyword (nth 2 rlt))
+(defun evilmi-python-jump (info num)
+ "Use INFO returned by `evilmi-python-get-tag' and NUM to jump to matched
tag."
+ (ignore num)
+ (let* ((p (nth 0 info))
+ (tag-type (nth 1 info))
+ (keyword (nth 2 info))
(cur-line (evilmi-sdk-curline))
- cur-indent
+ (cur-indent (evilmi--python-calculate-indent cur-line))
dendent
rlt)
- (setq cur-indent (evilmi--python-calculate-indent cur-line))
-
(if evilmi-debug (message "evilmi-python-jump called. tag-type=%d p=%d"
tag-type p))
(cond
;; start from closed tag
@@ -208,3 +212,4 @@
rlt))
(provide 'evil-matchit-python)
+;;; evil-matchit-python.el ends here
diff --git a/evil-matchit-ruby.el b/evil-matchit-ruby.el
index 19672a709f..75061a0c2f 100644
--- a/evil-matchit-ruby.el
+++ b/evil-matchit-ruby.el
@@ -1,4 +1,4 @@
-;;; evil-matchit-ruby.el ---ruby plugin of evil-matchit
+;;; evil-matchit-ruby.el --- ruby plugin of evil-matchit
;; Copyright (C) 2014-2020 Chen Bin <chenbin DOT sh AT gmail DOT com>
@@ -29,7 +29,9 @@
;; 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.
-
+;;
+;;; Commentary:
+;;
;;; Code:
(require 'evil-matchit-sdk)
@@ -57,3 +59,4 @@
(evilmi-sdk-jump rlt num evilmi-ruby-match-tags
evilmi-ruby-extract-keyword-howtos))
(provide 'evil-matchit-ruby)
+;;; evil-matchit-ruby.el ends here
diff --git a/evil-matchit-script.el b/evil-matchit-script.el
index 4d2a847303..7bc7c4b7fd 100644
--- a/evil-matchit-script.el
+++ b/evil-matchit-script.el
@@ -1,4 +1,4 @@
-;;; evil-matchit-script.el ---script (ruby/lua) plugin of evil-matchit
+;;; evil-matchit-script.el --- script (vimrc/lua) plugin of evil-matchit
;; Copyright (C) 2014-2020 Chen Bin <chenbin DOT sh AT gmail DOT com>
@@ -23,6 +23,8 @@
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+;;; Commentary:
+;;
;;; Code:
@@ -31,29 +33,30 @@
;; All you need to do is just define the match-tags for SDK algorithm to
lookup.
(require 'evil-matchit-sdk)
-;; ruby/bash/lua/vimrc
(defvar evilmi-script-match-tags
'((("unless" "if") ("elif" "elsif" "elseif" "else") ("end" "fi" "endif"))
("begin" ("rescue" "ensure") "end")
("case" ("when" "else") ("esac" "end"))
("for" () "end")
(("fun!" "function!" "class" "def" "while" "function" "do") () ("end"
"endfun" "endfunction"))
- ("repeat" () "until")
- ))
+ ("repeat" () "until")))
(defvar evilmi-script-extract-keyword-howtos
- '(("^.*\\(=\\|local\s\\)\s*\\(function\\)\s*.*$" 2)
- ("^\s*\\([a-z]+\!?\\)\\(\s.*\\| *\\)$" 1)
- ("^.*\s\\(do\\)\s|[a-z0-9A-Z,|]+|$" 1)))
+ '(("^.*\\(=\\|local[ \t]\\)[ \t]*\\(function\\)[ \t]*.*$" 2)
+ ;; lua code: "local thread = coroutine.create(function() ... )"
+ ("\\(function\\)([^()]*)[ \t]*$" 1)
+ ("^[ \t]*\\([a-z]+!?\\)[)]?\\([ \t].*\\| *\\)$" 1)
+ ("^.*[ \t]\\(do\\)[ \t]|[a-z0-9A-Z,|]+|$" 1)))
;;;###autoload
(defun evilmi-script-get-tag ()
- (evilmi-sdk-get-tag evilmi-script-match-tags
evilmi-script-extract-keyword-howtos)
- )
+ "Get tag at point."
+ (evilmi-sdk-get-tag evilmi-script-match-tags
evilmi-script-extract-keyword-howtos))
;;;###autoload
-(defun evilmi-script-jump (rlt NUM)
- (evilmi-sdk-jump rlt NUM evilmi-script-match-tags
evilmi-script-extract-keyword-howtos)
- )
+(defun evilmi-script-jump (info num)
+ "Use INFO returned by `evilmi-script-get-tag' and NUM to jump to matched
tag."
+ (evilmi-sdk-jump info num evilmi-script-match-tags
evilmi-script-extract-keyword-howtos))
(provide 'evil-matchit-script)
+;;; evil-matchit-script.el ends here
\ No newline at end of file
diff --git a/evil-matchit-sh.el b/evil-matchit-sh.el
index 1015a27429..932ed0fb4a 100644
--- a/evil-matchit-sh.el
+++ b/evil-matchit-sh.el
@@ -1,4 +1,4 @@
-;;; evil-matchit-sh.el ---sh (bash/zsh) plugin of evil-matchit
+;;; evil-matchit-sh.el --- sh (bash/zsh) plugin of evil-matchit
;; Copyright (C) 2014-2020 Chen Bin <chenbin DOT sh AT gmail DOT com>
@@ -22,8 +22,9 @@
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-
+;;
+;;; Commentary:
+;;
;;; Code:
;; OPTIONAL, you don't need SDK to write a plugin for evil-matchit
@@ -31,7 +32,6 @@
;; All you need to do is just define the match-tags for SDK algorithm to
lookup.
(require 'evil-matchit-sdk)
-;; ruby/bash/lua/vimrc
(defvar evilmi-sh-match-tags
'((("if") ("elif" "else") ("fi") "MONOGAMY")
("case" (";;") ("esac") "MONOGAMY")
@@ -51,3 +51,4 @@
(evilmi-sdk-jump rlt NUM evilmi-sh-match-tags
evilmi-sh-extract-keyword-howtos))
(provide 'evil-matchit-sh)
+;;; evil-matchit-sh.el ends here
diff --git a/evil-matchit-sql.el b/evil-matchit-sql.el
index 4a3382118c..01c485a4e5 100644
--- a/evil-matchit-sql.el
+++ b/evil-matchit-sql.el
@@ -1,4 +1,4 @@
-;;; evil-matchit-sql.el ---sql plugin of evil-matchit
+;;; evil-matchit-sql.el --- sql plugin of evil-matchit
;; Copyright (C) 2014-2020 Chen Bin <chenbin DOT sh AT gmail DOT com>
@@ -22,8 +22,9 @@
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-
+;;
+;;; Commentary:
+;;
;;; Code:
;; OPTIONAL, you don't need SDK to write a plugin for evil-matchit
@@ -71,31 +72,30 @@
;; WHEN OTHERS THEN
;;
;; create[ or replace] procedure|function|event
- ;; '^\s*\<\%(do\|for\|while\|loop\)\>.*:'.
+ ;; '^[ \t]*\<\%(do\|for\|while\|loop\)\>.*:'.
;; TODO for one howto, if it cannot match any keyword,
;; should try next howto, the purpose is avoid missing any howto
(defvar evilmi-sql-extract-keyword-howtos
- '(("^[ \t]*\\([a-zA-Z]+ [a-zA-Z]+\\)" 1)
+ '(("^[ \t]*\\([a-zA-Z]+[ \t][a-zA-Z]+\\)" 1)
("^[ \t]*\\([a-zA-Z]+\\)" 1)
- ("^.* \\(loop\\)[;]? *$" 1)
- ))
+ ("^.*[ \t]\\(loop\\)[;]?[ \t]*$" 1)))
(defvar evilmi-sql-match-tags
'(("if" ("elsif" "else" "elseif" "else *if") ("end" "end *if"))
(("loop") ("leave" "break" "continue" "exit") ("end loop"))
("begin" () "end")
("case" ("when *others") ("end *case" "end"))
- (("do") () "do *end")
- ))
+ (("do") () "do *end")))
;;;###autoload
(defun evilmi-sql-get-tag ()
- (let (rlt)
- (setq rlt (evilmi-sdk-get-tag evilmi-sql-match-tags
evilmi-sql-extract-keyword-howtos))
- rlt))
+ "Get tag at point."
+ (evilmi-sdk-get-tag evilmi-sql-match-tags evilmi-sql-extract-keyword-howtos))
;;;###autoload
-(defun evilmi-sql-jump (rlt NUM)
- (evilmi-sdk-jump rlt NUM evilmi-sql-match-tags
evilmi-sql-extract-keyword-howtos))
+(defun evilmi-sql-jump (info num)
+ "Use INFO returned by `evilmi-sql-get-tag' and NUM to jump to matched tag."
+ (evilmi-sdk-jump info num evilmi-sql-match-tags
evilmi-sql-extract-keyword-howtos))
(provide 'evil-matchit-sql)
+;;; evil-matchit-sql.el ends here
diff --git a/evil-matchit-verilog.el b/evil-matchit-verilog.el
index eed25fa911..2f5c8a61db 100644
--- a/evil-matchit-verilog.el
+++ b/evil-matchit-verilog.el
@@ -1,4 +1,4 @@
-;;; evil-matchit-verilog.el ---verilog plugin of evil-matchit
+;;; evil-matchit-verilog.el --- verilog plugin of evil-matchit
;; Copyright (C) 2014-2020 Chen Bin <chenbin DOT sh AT gmail DOT com>
@@ -22,8 +22,9 @@
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-
+;;
+;;; Commentary:
+;;
;;; Code:
;; OPTIONAL, you don't need SDK to write a plugin for evil-matchit
@@ -93,11 +94,12 @@
;;;###autoload
(defun evilmi-verilog-get-tag ()
- (let* ((orig-info (evilmi-sdk-get-tag evilmi-verilog-match-tags
+ "Get tag at point."
+ (let* ((info (evilmi-sdk-get-tag evilmi-verilog-match-tags
evilmi-verilog-extract-keyword-howtos)))
- (if evilmi-debug (message "evilmi-verilog-get-tag called => %s" orig-info))
+ (if evilmi-debug (message "evilmi-verilog-get-tag called => %s" info))
;; hack if current line is `if' or `else if'
- (unless orig-info
+ (unless info
(let* ((cur-line (evilmi-sdk-curline))
next-line
(pos (line-beginning-position)))
@@ -105,19 +107,20 @@
;; second chance for if else statement
(save-excursion
(forward-line 1)
- (setq orig-info (evilmi-sdk-get-tag evilmi-verilog-match-tags
+ (setq info (evilmi-sdk-get-tag evilmi-verilog-match-tags
evilmi-verilog-extract-keyword-howtos)))
;; move to the next line now. maybe there exist end statement
- (when orig-info
+ (when info
(forward-line 1)
- (setq orig-info (cons pos (cdr orig-info)))))))
- orig-info))
+ (setq info (cons pos (cdr info)))))))
+ info))
;;;###autoload
-(defun evilmi-verilog-jump (orig-info num)
- (let* ((orig-keyword (evilmi-sdk-keyword (cadr orig-info))))
- (if evilmi-debug (message "evilmi-verilog-jump called => %s" orig-info))
- (evilmi-sdk-jump orig-info
+(defun evilmi-verilog-jump (info num)
+ "Use INFO returned by `evilmi-verlog-get-tag' and NUM to jump to matched
tag."
+ (let* ((orig-keyword (evilmi-sdk-keyword (cadr info))))
+ (if evilmi-debug (message "evilmi-verilog-jump called => %s" info))
+ (evilmi-sdk-jump info
num
evilmi-verilog-match-tags
evilmi-verilog-extract-keyword-howtos)))
diff --git a/tests/evil-matchit-tests.el b/tests/evil-matchit-tests.el
index bddc0eebb7..1768c2319e 100644
--- a/tests/evil-matchit-tests.el
+++ b/tests/evil-matchit-tests.el
@@ -173,8 +173,55 @@
; jump back
(evilmi-jump-items)
(should (eq (following-char) ?{))
- (should (string-match "switch(c)" (evilmi-sdk-curline) ))
+ (should (string-match "switch(c)" (evilmi-sdk-curline)))
(should (eq major-mode 'c-mode))))
+
+(ert-deftest evilmi-test-lua ()
+ (with-temp-buffer
+ (insert "if configTable:FindFirstChild(configName) then\n"
+ " configs[configName] =
configTable:FindFirstChild(configName).Value\n"
+ "else\n"
+ " configs[configName] = defaultValue\n"
+ "end\n"
+ "\n"
+ "local thread = coroutine.create(function()\n"
+ " while true do\n"
+ " wait()\n"
+ " if state then\n"
+ " display.Text = state.Name\n"
+ " end\n"
+ " end\n"
+ "end)\n")
+ (lua-mode)
+
+ ;; jump from start
+ (goto-char (point-min))
+
+ ;; test if else end
+ (evilmi-jump-items)
+ (should (string= "else" (thing-at-point 'symbol)))
+ (evilmi-jump-items)
+ (should (string= "end" (thing-at-point 'symbol)))
+ (evilmi-jump-items)
+ ;; no back to the beginning
+ (should (string= "if" (thing-at-point 'symbol)))
+ (should (eq (point) (point-min)))
+
+ ;; test function
+ (search-forward "local thread = coroutine.create")
+ (evilmi-jump-items)
+ (should (string= "end)" (evilmi-sdk-curline)))
+ (evilmi-jump-items)
+ (should (string= "local thread = coroutine.create(function()" (string-trim
(evilmi-sdk-curline))))
+ ;; test while embedded in function
+ (search-forward "while true do")
+ (evilmi-jump-items)
+ (should (string= "end" (thing-at-point 'symbol)))
+ (evilmi-jump-items)
+ (should (string= "while true do" (string-trim (evilmi-sdk-curline))))
+
+ (should (eq major-mode 'lua-mode))))
+
(ert-run-tests-batch-and-exit)
;;; evil-matchit-tests.el ends here