[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/evil-matchit 90c8367856 027/244: add sdk v1.2.0
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/evil-matchit 90c8367856 027/244: add sdk v1.2.0 |
Date: |
Thu, 6 Jan 2022 02:58:46 -0500 (EST) |
branch: elpa/evil-matchit
commit 90c8367856208b952a2d69a0d38c8bade05a0562
Author: Chen Bin <chenbin.sh@gmail.com>
Commit: Chen Bin <chenbin.sh@gmail.com>
add sdk v1.2.0
---
evil-matchit-latex.el | 2 -
evil-matchit-script.el | 186 ++------------------------
evil-matchit-script.el => evil-matchit-sdk.el | 117 ++++++++--------
evil-matchit.el | 21 +--
4 files changed, 69 insertions(+), 257 deletions(-)
diff --git a/evil-matchit-latex.el b/evil-matchit-latex.el
index 89a775fbc4..0fa555fa24 100644
--- a/evil-matchit-latex.el
+++ b/evil-matchit-latex.el
@@ -26,8 +26,6 @@
;;; Code:
-(require 'evil-matchit)
-
(autoload 'LaTeX-find-matching-begin "latex-mode" nil t)
(autoload 'LaTeX-find-matching-end "latex-mode" nil t)
diff --git a/evil-matchit-script.el b/evil-matchit-script.el
index b1618bed90..f0fbee8bb0 100644
--- a/evil-matchit-script.el
+++ b/evil-matchit-script.el
@@ -26,7 +26,10 @@
;;; Code:
-(require 'evil-matchit)
+;; 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)
;; ruby/bash/lua/vimrc
(defvar evilmi--script-match-tags
@@ -36,186 +39,21 @@
(("fun!" "function!" "class" "def" "while" "function" "do") () ("end"
"endfun" "endfunction"))
("repeat" () "until")
)
- "the table we look up matched tags"
- )
-
-(defun evilmi--script-get-tag-info (tag)
- "return (row column)"
- (let (rlt elems elem tag-type
- found i j)
-
- (setq i 0)
- (while (and (< i (length evilmi--script-match-tags)) (not found))
- (setq elems (nth i evilmi--script-match-tags))
- (setq j 0)
- (while (and (not found) (< j (length elems)))
- (setq elem (nth j elems))
- (cond
- ((stringp elem)
- (if (string= tag elem)
- (setq found t)
- ))
- ((listp elem)
- (if (member tag elem)
- (setq found t)
- ))
- )
- (if (not found) (setq j (1+ j)))
- )
- (if (not found) (setq i (1+ i)))
- )
- (if found
- (setq rlt (list i j))
- )
- rlt
- )
- )
-
-(defun evilmi--script-extract-keyword (cur-line)
- "extract keyword from cur-line"
- (let (keyword
- (regexp "^[ \t]*\\([a-z]+\!?\\)\\( .*\\| *\\)$")
- (regexp-do "^.* \\(do\\) |[a-z0-9A-Z,|]+|$")
- )
- (if (string-match regexp cur-line)
- (setq keyword (match-string 1 cur-line))
- )
-
- (if (evilmi--member keyword evilmi--script-match-tags) keyword
- (when (string-match regexp-do cur-line)
- (setq keyword (match-string 1 cur-line))
- (if (evilmi--member keyword evilmi--script-match-tags) keyword)
- )
- )
- )
+ "The table we look up match tags. This is a three column table.
+The first column contains the open tag(s).
+The second column contains the middle tag(s).
+The third column contains the closed tags(s).
+"
)
;;;###autoload
(defun evilmi-script-get-tag ()
- (let (rlt
- keyword
- (cur-line (buffer-substring-no-properties
- (line-beginning-position)
- (line-end-position)))
- tag-info)
- (when (setq keyword (evilmi--script-extract-keyword cur-line))
- ;; since we mixed ruby and lua mode here
- ;; maybe we should be strict at the keyword
- (if (setq tag-info (evilmi--script-get-tag-info keyword))
- ;; 0 - open tag; 1 - middle tag; 2 - close tag;
- (setq rlt (list
- (if (= 2 (nth 1 tag-info))
- (line-end-position)
- (line-beginning-position))
- tag-info))
- )
- )
- rlt
- ))
+ (evilmi-sdk-get-tag evilmi--script-match-tags
evilmi-sdk-extract-keyword-howtos)
+ )
;;;###autoload
(defun evilmi-script-jump (rlt NUM)
- (let ((orig-tag-type (nth 1 (nth 1 rlt)))
- cur-tag-type
- (level 1)
- (cur-line (buffer-substring-no-properties
- (line-beginning-position)
- (line-end-position)))
- keyword
- found
- where-to-jump-in-theory
- )
-
- (while (not found)
- (forward-line (if (= orig-tag-type 2) -1 1))
- (setq cur-line (buffer-substring-no-properties
- (line-beginning-position)
- (line-end-position))
- )
-
- (setq keyword (evilmi--script-extract-keyword cur-line))
- (when keyword
- (setq cur-tag-type (nth 1 (evilmi--script-get-tag-info keyword)))
-
- ;; key algorithm
- (cond
- ;; handle open tag
- ;; open (0) -> mid (1) found when level is one else ignore
- ((and (= orig-tag-type 0) (= cur-tag-type 1))
- (when (= 1 level)
- (back-to-indentation)
- (setq where-to-jump-in-theory (1- (line-beginning-position)))
- (setq found t)
- )
- )
- ;; open (0) -> closed (2) found when level is zero, level--
- ((and (= orig-tag-type 0) (= cur-tag-type 2))
- (setq level (1- level))
- (when (= 0 level)
- (goto-char (line-end-position))
- (setq where-to-jump-in-theory (line-end-position))
- (setq found t)
- )
- )
- ;; open (0) -> open (0) level++
- ((and (= orig-tag-type 0) (= cur-tag-type 0))
- (setq level (1+ level))
- )
-
- ;; now handle mid tag
- ;; mid (1) -> mid (1) found when level is zero else ignore
- ((and (= orig-tag-type 1) (= cur-tag-type 1))
- (when (= 1 level)
- (back-to-indentation)
- (setq where-to-jump-in-theory (1- (line-beginning-position)))
- (setq found t)
- )
- )
- ;; mid (1) -> closed (2) found when level is zero, level --
- ((and (= orig-tag-type 1) (= cur-tag-type 2))
- (setq level (1- level))
- (when (= 0 level)
- (goto-char (line-end-position))
- (setq where-to-jump-in-theory (line-end-position))
- (setq found t)
- )
- )
- ;; mid (1) -> open (0) level++
- ((and (= orig-tag-type 1) (= cur-tag-type 0))
- (setq level (1+ level))
- )
-
- ;; now handle closed tag
- ;; closed (2) -> mid (1) ignore,impossible
- ((and (= orig-tag-type 2) (= cur-tag-type 1))
- (message "impossible to be here")
- )
- ;; closed (2) -> closed (2) level++
- ((and (= orig-tag-type 2) (= cur-tag-type 2))
- (setq level (1+ level))
- )
- ;; closed (2) -> open (0) found when level is zero, level--
- ((and (= orig-tag-type 2) (= cur-tag-type 0))
- (setq level (1- level))
- (when (= 0 level)
- (setq where-to-jump-in-theory (line-beginning-position))
- (back-to-indentation)
- (setq found t)
- )
- )
- (t (message "why here?"))
- )
- )
-
- ;; we will stop at end or beginning of buffer anyway
- (if (or (= (line-end-position) (point-max))
- (= (line-beginning-position) (point-min))
- )
- (setq found t)
- )
- )
- where-to-jump-in-theory
- )
+ (evilmi-sdk-jump rlt NUM evilmi--script-match-tags
evilmi-sdk-extract-keyword-howtos)
)
(provide 'evil-matchit-script)
\ No newline at end of file
diff --git a/evil-matchit-script.el b/evil-matchit-sdk.el
similarity index 65%
copy from evil-matchit-script.el
copy to evil-matchit-sdk.el
index b1618bed90..6ad2bb582e 100644
--- a/evil-matchit-script.el
+++ b/evil-matchit-sdk.el
@@ -1,52 +1,45 @@
-;;; evil-matchit-script.el ---script (ruby/lua) plugin of evil-matchit
-
-;; Copyright (C) 2013 Chen Bin <chenbin.sh@gmail.com>
-
-;; Author: Chen Bin <chenbin.sh@gmail.com>
-
-;; This file is not part of GNU Emacs.
-
-;;; License:
-
-;; This file is part of evil-matchit
-;;
-;; evil-matchit is free software: you can redistribute it and/or
-;; modify it under the terms of the GNU General Public License as published
-;; by the Free Software Foundation, either version 3 of the License, or
-;; (at your option) any later version.
-;;
-;; evil-matchit is distributed in the hope that it will be useful,
-;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-;; GNU General Public License for more details.
-;;
-;; You should have received a copy of the GNU General Public License
-;; along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-
-;;; Code:
-
-(require 'evil-matchit)
+(defvar evilmi-sdk-extract-keyword-howtos
+ '(("^[ \t]*\\([a-z]+\!?\\)\\( .*\\| *\\)$" 1)
+ ("^.* \\(do\\) |[a-z0-9A-Z,|]+|$" 1)
+ )
+ "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
+between '\\(' and '\\)' in regular expression.
+"
+ )
-;; 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"))
- (("fun!" "function!" "class" "def" "while" "function" "do") () ("end"
"endfun" "endfunction"))
- ("repeat" () "until")
+(defun evilmi--sdk-member (KEYWORD LIST)
+ "check if KEYWORD exist in LIST"
+ (let (rlt)
+ (cond
+ ((not LIST) nil)
+ ((stringp (car LIST))
+ (if (string= KEYWORD (car LIST)) t
+ (evilmi--sdk-member KEYWORD (cdr LIST))
+ )
+ )
+ ((listp (car LIST))
+ (setq rlt (evilmi--sdk-member KEYWORD (car LIST)))
+ (if rlt rlt (evilmi--sdk-member KEYWORD (cdr LIST)))
+ )
+ (t
+ ;; just ignore first element
+ (evilmi--sdk-member KEYWORD (cdr LIST))
+ )
+ )
)
- "the table we look up matched tags"
)
-(defun evilmi--script-get-tag-info (tag)
+(defun evilmi--sdk-get-tag-info (tag match-tags)
"return (row column)"
(let (rlt elems elem tag-type
found i j)
(setq i 0)
- (while (and (< i (length evilmi--script-match-tags)) (not found))
- (setq elems (nth i evilmi--script-match-tags))
+ (while (and (< i (length match-tags)) (not found))
+ (setq elems (nth i match-tags))
(setq j 0)
(while (and (not found) (< j (length elems)))
(setq elem (nth j elems))
@@ -71,37 +64,37 @@
)
)
-(defun evilmi--script-extract-keyword (cur-line)
- "extract keyword from cur-line"
- (let (keyword
- (regexp "^[ \t]*\\([a-z]+\!?\\)\\( .*\\| *\\)$")
- (regexp-do "^.* \\(do\\) |[a-z0-9A-Z,|]+|$")
- )
- (if (string-match regexp cur-line)
- (setq keyword (match-string 1 cur-line))
- )
+(defun evilmi--sdk-extract-keyword (cur-line match-tags howtos)
+ "extract keyword from cur-line. keyword should be defined in match-tags"
+ (let (keyword howto i)
+ (setq i 0)
+ (while (and (not keyword) (< i (length howtos)))
+ (setq howto (nth i howtos))
+
+ (when (string-match (nth 0 howto) cur-line)
+ (setq keyword (match-string (nth 1 howto) cur-line))
- (if (evilmi--member keyword evilmi--script-match-tags) keyword
- (when (string-match regexp-do cur-line)
- (setq keyword (match-string 1 cur-line))
- (if (evilmi--member keyword evilmi--script-match-tags) keyword)
+ ;; keep search keyword by using next howto (regex and match-string
index)
+ (if (not (evilmi--sdk-member keyword match-tags)) (setq keyword nil))
)
+ (setq i (1+ i))
)
+ keyword
)
)
;;;###autoload
-(defun evilmi-script-get-tag ()
+(defun evilmi-sdk-get-tag (match-tags howtos)
(let (rlt
keyword
(cur-line (buffer-substring-no-properties
(line-beginning-position)
(line-end-position)))
tag-info)
- (when (setq keyword (evilmi--script-extract-keyword cur-line))
+ (when (setq keyword (evilmi--sdk-extract-keyword cur-line match-tags
howtos))
;; since we mixed ruby and lua mode here
;; maybe we should be strict at the keyword
- (if (setq tag-info (evilmi--script-get-tag-info keyword))
+ (if (setq tag-info (evilmi--sdk-get-tag-info keyword match-tags))
;; 0 - open tag; 1 - middle tag; 2 - close tag;
(setq rlt (list
(if (= 2 (nth 1 tag-info))
@@ -111,10 +104,12 @@
)
)
rlt
- ))
+ )
+ )
+
;;;###autoload
-(defun evilmi-script-jump (rlt NUM)
+(defun evilmi-sdk-jump (rlt NUM match-tags howtos)
(let ((orig-tag-type (nth 1 (nth 1 rlt)))
cur-tag-type
(level 1)
@@ -133,9 +128,9 @@
(line-end-position))
)
- (setq keyword (evilmi--script-extract-keyword cur-line))
+ (setq keyword (evilmi--sdk-extract-keyword cur-line match-tags howtos))
(when keyword
- (setq cur-tag-type (nth 1 (evilmi--script-get-tag-info keyword)))
+ (setq cur-tag-type (nth 1 (evilmi--sdk-get-tag-info keyword
match-tags)))
;; key algorithm
(cond
@@ -218,4 +213,4 @@
)
)
-(provide 'evil-matchit-script)
\ No newline at end of file
+(provide 'evil-matchit-sdk)
\ No newline at end of file
diff --git a/evil-matchit.el b/evil-matchit.el
index eeaeee6e25..fed417c979 100644
--- a/evil-matchit.el
+++ b/evil-matchit.el
@@ -43,26 +43,7 @@
((evilmi-simple-get-tag evilmi-simple-jump))
))
-(defun evilmi--member (k l)
- (let (rlt)
- (cond
- ((not l) nil)
- ((stringp (car l))
- (if (string= k (car l)) t
- (evilmi--member k (cdr l))
- )
- )
- ((listp (car l))
- (setq rlt (evilmi--member k (car l)))
- (if rlt rlt (evilmi--member k (cdr l)))
- )
- (t
- ;; just ignore first element
- (evilmi--member k (cdr l))
- )
- )
- )
- )
+
(defun evilmi--operate-on-item (NUM &optional FUNC)
(let (plugin
- [nongnu] elpa/evil-matchit 13b95b675d 003/244: evil-jump-item parameter is wierd, v0.0.3, (continued)
- [nongnu] elpa/evil-matchit 13b95b675d 003/244: evil-jump-item parameter is wierd, v0.0.3, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit a837c1897e 006/244: tweak README, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 05f80aacf2 004/244: Declare package dependency on evil, improve package description, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 808f226b2e 002/244: updated doc, v0.0.2, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 9ed81c8b78 014/244: fixed typo in README, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 03f46e4006 001/244: first import, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit fc1731e8b2 013/244: updated doc, hotkey set up, v0.0.5, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit eb5e0bedc6 021/244: select/delete matching tags in C v1.0.2, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 748647d518 017/244: dependent on sgml-mode, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit cfcf0d083c 022/244: weak README, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 90c8367856 027/244: add sdk v1.2.0,
ELPA Syncer <=
- [nongnu] elpa/evil-matchit 65b474bb02 031/244: Better C/C++, v1.2.2, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 3b64df7610 005/244: Merge pull request #3 from purcell/patch-1, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 363b6683ab 033/244: ignore elisp flymake file, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 4f993303e1 044/244: delete leading spaces AND matched tags v1.2.9, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit dd3d90bf95 010/244: Fix malformed header line, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 285f5c2413 024/244: udpated doc and screencast, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit c65da39f49 016/244: autoload sgml-mode, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit b75893af9e 028/244: minor bug in latex-mode, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit acc7efbd8d 034/244: minor bugs fixed v1.2.3, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 78cc0335de 035/244: support latex mode, v1.2.4, ELPA Syncer, 2022/01/06