[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/evil-matchit ae8fddea39 207/244: clean code, tdd for markd
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/evil-matchit ae8fddea39 207/244: clean code, tdd for markdown |
Date: |
Thu, 6 Jan 2022 02:59:02 -0500 (EST) |
branch: elpa/evil-matchit
commit ae8fddea392441229ed8c3038f7c0ea94dbac9dc
Author: Chen Bin <chenbin.sh@gmail.com>
Commit: Chen Bin <chenbin.sh@gmail.com>
clean code, tdd for markdown
---
Makefile | 3 ++-
evil-matchit-markdown.el | 61 +++++++++++++++++----------------------------
evil-matchit-sdk.el | 6 ++++-
tests/evil-matchit-tests.el | 31 +++++++++++++++++++++++
4 files changed, 61 insertions(+), 40 deletions(-)
diff --git a/Makefile b/Makefile
index c5e5e0675e..44320d1bcd 100644
--- a/Makefile
+++ b/Makefile
@@ -12,7 +12,8 @@ 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;
+ @if [ ! -f deps/markdown-mode.el ]; then curl -L
https://raw.githubusercontent.com/jrblevin/markdown-mode/master/markdown-mode.el
> deps/markdown-mode.el; fi;
.PHONY: test
test: deps clean
- @$(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
+ @$(EMACS) -batch -Q -L . -L deps/evil-1.14.0 -l deps/lua-mode.el -l
deps/markdown-mode.el -l evil-matchit.el -l tests/evil-matchit-tests.el
\ No newline at end of file
diff --git a/evil-matchit-markdown.el b/evil-matchit-markdown.el
index 550e0d4bb9..f4f54c828b 100644
--- a/evil-matchit-markdown.el
+++ b/evil-matchit-markdown.el
@@ -26,54 +26,39 @@
;;; Code:
-;; OPTIONAL, you don't need SDK to write a plugin for evil-matchit
-;; but SDK don make you write less code, isn't it?
-;; All you need to do is just define the match-tags for SDK algorithm to
lookup.
(require 'evil-matchit-sdk)
;;;###autoload
(defun evilmi-markdown-get-tag ()
- "Get current tag.
-Return (list start-position tag)."
- (let* ((cur-line (evilmi-sdk-curline))
- rlt
- forward-direction)
- (if (string-match "^\\(```\\)" cur-line)
- (let* ((str (match-string 1 cur-line))
- (prefix (buffer-substring-no-properties (point-min)
-
(line-beginning-position)))
- (forward-direction (eq (% (evilmi-sdk-count-matches str prefix)
2) 0)))
- (setq rlt (list (if forward-direction (line-beginning-position)
- (line-end-position))
- forward-direction
- str))))
- rlt))
+ "Get current tag. Return (list start-position tag)."
+ (when (string-match "^\\(```\\)" (evilmi-sdk-curline))
+ (let* ((str "```")
+ (text (evilmi-sdk-text-before-current-line))
+ (forward-p (eq (% (evilmi-sdk-count-matches str text) 2) 0)))
+ (list (if forward-p (line-beginning-position) (line-end-position))
+ forward-p
+ str))))
;;;###autoload
(defun evilmi-markdown-jump (info num)
- "Jump to the next tag."
- (let* ((forward-direction (nth 1 info))
+ "Jump to the next tag using INFO and NUM."
+ (ignore num)
+ (let* ((forward-p (nth 1 info))
(str (nth 2 info))
(pos (point))
(rlt pos))
- (cond
- ((string= str "```")
- (let* ((prefix (buffer-substring-no-properties (point-min)
-
(line-beginning-position))))
- (cond
- (forward-direction
- ;; jump forward
- (goto-char (+ pos (length str)))
- (search-forward str)
- (setq rlt (line-end-position)))
- (t
- ;; jump backward
- (goto-char (- pos (length str)))
- (search-backward str)
- (setq rlt (line-beginning-position))))))
- (t
- ;; do nothing
- ))
+ (when (string= str "```")
+ (cond
+ (forward-p
+ ;; jump forward
+ (goto-char (+ pos (length str)))
+ (search-forward str)
+ (setq rlt (line-end-position)))
+ (t
+ ;; jump backward
+ (goto-char (- pos (length str)))
+ (search-backward str)
+ (setq rlt (line-beginning-position)))))
rlt))
(provide 'evil-matchit-markdown)
diff --git a/evil-matchit-sdk.el b/evil-matchit-sdk.el
index 973c63b672..1ca71c2bdc 100644
--- a/evil-matchit-sdk.el
+++ b/evil-matchit-sdk.el
@@ -198,6 +198,10 @@ If IS-FORWARD is t, jump forward; or else jump backward."
(buffer-substring-no-properties (line-beginning-position)
(line-end-position))))
+(defun evilmi-sdk-text-before-current-line ()
+ "Text before current line."
+ (buffer-substring-no-properties (point-min) (line-beginning-position)))
+
;;;###autoload
(defun evilmi-sdk-member (keyword keyword-list)
"Check if KEYWORD exist in KEYWORD-LIST."
@@ -450,7 +454,7 @@ after calling this function."
rlt))
(defun evilmi-sdk-count-matches (regexp str)
- "Count matches of regexp in STR."
+ "Count match of REGEXP in STR."
(let* ((count 0)
(start 0))
(while (string-match regexp str start)
diff --git a/tests/evil-matchit-tests.el b/tests/evil-matchit-tests.el
index 12247b6761..feebc6cede 100644
--- a/tests/evil-matchit-tests.el
+++ b/tests/evil-matchit-tests.el
@@ -377,5 +377,36 @@
(should (eq major-mode 'verilog-mode))))
+(ert-deftest evilmi-test-markdown ()
+ (with-temp-buffer
+ (insert "### test1\n"
+ "```java\n"
+ "Example 1\n"
+ "```\n\n"
+ "### test2\n"
+ "```c\n"
+ "Example 2\n"
+ "```\n")
+ (markdown-mode)
+
+ (goto-char (point-min))
+ (forward-line 1)
+ (evilmi-jump-items)
+ (should (string= "```" (evilmi-sdk-curline)))
+ (forward-line -1)
+ (should (string= "Example 1" (evilmi-sdk-curline)))
+ (forward-line 1)
+ (evilmi-jump-items)
+ (should (string= "```java" (evilmi-sdk-curline)))
+
+ (goto-char (point-min))
+ (search-forward "```c")
+ (evilmi-jump-items)
+ (should (string= "```" (evilmi-sdk-curline)))
+ (evilmi-jump-items)
+ (should (string= "```c" (evilmi-sdk-curline)))
+
+ (should (eq major-mode 'markdown-mode))))
+
(ert-run-tests-batch-and-exit)
;;; evil-matchit-tests.el ends here
- [nongnu] elpa/evil-matchit 8d6bd9187d 154/244: [chen] update doc, (continued)
- [nongnu] elpa/evil-matchit 8d6bd9187d 154/244: [chen] update doc, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 2143844e2b 170/244: support js2-jsx-mode, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit e941c695f3 173/244: Add [ and { as well., ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit c04f8f480c 164/244: Match Ruby's begin also when it's not on the beginning of the line, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit d779aedaf1 195/244: clean code, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit dead63c7d0 194/244: add unit test, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 80dc731ab7 237/244: clean code, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 0be04f960f 049/244: use text objects v1.3.2, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 62cef4f91a 077/244: replace evil-jump-items v2.0, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 6390e9e06c 216/244: Silence byte-compiler, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit ae8fddea39 207/244: clean code, tdd for markdown,
ELPA Syncer <=
- [nongnu] elpa/evil-matchit 0fd65c463b 226/244: clean code&doc, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit ceec6a63b0 236/244: better algorithm to match bracket/brace in javascript, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 8c4f516265 238/244: Support matlab-mode, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 82c80786e5 240/244: jump between merge conflict markers, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 5c43939d01 212/244: Merge pull request #126 from neojski/more-ocaml-tests, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit cdb9b90381 229/244: extra json support, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit d005e0465e 223/244: Merge pull request #130 from nbfalcon/bugfix/evilmi-sdk-simple-jump-whitespace, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit ce90eae4bd 243/244: typo, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit a0c5bd1fe8 230/244: support quote and export section in org file, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 9cdaddd55d 228/244: Merge pull request #132 from aaronjensen/require-evil-macros, ELPA Syncer, 2022/01/06