[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/evil-matchit 78cc0335de 035/244: support latex mode, v1.2.
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/evil-matchit 78cc0335de 035/244: support latex mode, v1.2.4 |
Date: |
Thu, 6 Jan 2022 02:58:47 -0500 (EST) |
branch: elpa/evil-matchit
commit 78cc0335de17b20070f3af65ac4a590324dadc76
Author: Chen Bin <chenbin.sh@gmail.com>
Commit: Chen Bin <chenbin.sh@gmail.com>
support latex mode, v1.2.4
- if[x] else fi
- begin{x} end{x}
- begingroup endgroup
- {} [] ()
---
README.org | 2 +-
evil-matchit-latex.el | 164 +++++++++++++++++++++++++++++++++++++++-----------
evil-matchit-pkg.el | 2 +-
evil-matchit-sdk.el | 46 +++++++-------
evil-matchit.el | 4 +-
pkg.sh | 2 +-
6 files changed, 158 insertions(+), 62 deletions(-)
diff --git a/README.org b/README.org
index bbd2047d12..99e5a33554 100644
--- a/README.org
+++ b/README.org
@@ -1,4 +1,4 @@
-* evil-matchit (current version 1.2.3)
+* evil-matchit (current version 1.2.4)
Vim [[http://www.vim.org/scripts/script.php?script_id=39][matchit.vim]] by
Benji Fisher ported into Emacs.
diff --git a/evil-matchit-latex.el b/evil-matchit-latex.el
index fdfc6b496f..399c345a31 100644
--- a/evil-matchit-latex.el
+++ b/evil-matchit-latex.el
@@ -25,53 +25,147 @@
;;; Code:
+(require 'evil-matchit-sdk)
+
+(defvar evilmi-latex-regexp "\\\\\\([a-zA-Z]+\\(\{[a-zA-Z]+\}\\)?\\)")
+
+(defvar evilmi-latex-match-tags
+ '((("if[a-zA-Z]+" "if") "else" "fi")
+ ("left" nil "right")
+ ("begin[a-z]+" nil "end[a-z]+")
+ ("begin\{[a-z]+\}" nil "end\{[a-z]+\}"))
+ "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 'LaTeX-find-matching-begin "latex-mode" nil t)
-(autoload 'LaTeX-find-matching-end "latex-mode" nil t)
;;;###autoload
(defun evilmi-latex-get-tag ()
(let (rlt
- (regexp (concat (regexp-quote "\\") "\\(begin\\|end\\)\\b"))
keyword
+ tag-info
+ cursor-pos)
+
+ (save-excursion
+ (skip-chars-backward "a-zA-Z \t{}")
+ ;; move cursor to the beginning of tag
+ (unless (bolp)
+ (
+ backward-char 1)
)
- (skip-chars-backward "a-zA-Z \t{}")
- ;; move cursor to the beginning of tag
- (unless (bolp)
- (backward-char 1)
- )
- (re-search-forward regexp (line-end-position) t)
- (setq keyword (match-string 1))
- (if keyword
- (cond
- ((string= keyword "begin")
- (setq rlt (list (line-beginning-position) 0))
- )
- ((string= keyword "end")
- (setq rlt (list (line-end-position) 2))
- )
- ))
+ ;; extract keyword, several keyword could be in one line
+ (re-search-forward evilmi-latex-regexp (line-end-position) t)
+ (setq keyword (match-string 1))
+
+ (when (evilmi-sdk-member keyword evilmi-latex-match-tags)
+ (setq cursor-pos (point))
+ (setq tag-info (evilmi-sdk-get-tag-info keyword
evilmi-latex-match-tags))
+ (setq rlt (list
+ (if (= 2 (nth 1 tag-info))
+ (point)
+ (save-excursion
+ (backward-char (1+ (length keyword)))
+ (point)
+ )
+ )
+ tag-info
+ ))))
+ (if rlt (goto-char cursor-pos))
rlt
- )
- )
+ ))
;;;###autoload
(defun evilmi-latex-jump (rlt NUM)
- (let ((p (nth 0 rlt))
- (tag-type (nth 1 rlt))
+ (let ((orig-tag-type (nth 1 (nth 1 rlt)))
+ (orig-tag-info (nth 1 rlt))
+ cur-tag-type
+ cur-tag-info
+ level
+ keyword
+ found
where-to-jump-in-theory
+ fn-reg-search
)
- (cond
- ((= 2 tag-type)
- (LaTeX-find-matching-begin)
- (setq where-to-jump-in-theory (line-beginning-position))
- )
- ((= 0 tag-type)
- (LaTeX-find-matching-end)
- (setq where-to-jump-in-theory (line-end-position))
- )
- )
- )
- )
+
+ (setq level (if (= orig-tag-type 2) 0 1))
+ (setq fn-reg-search (if (= orig-tag-type 2) 're-search-backward
're-search-forward))
+ (while (not found)
+ (if (not (funcall fn-reg-search evilmi-latex-regexp
+ (if (= orig-tag-type 2) (point-min) (point-max))
+ t))
+ (setq found t)
+ ;; nothing found
+ (progn
+ (setq keyword (match-string 1))
+ (when (evilmi-sdk-member keyword evilmi-latex-match-tags)
+ (setq cur-tag-info (evilmi-sdk-get-tag-info keyword
evilmi-latex-match-tags))
+ (setq cur-tag-type (nth 1 cur-tag-info))
+ ;; we need more strict tag match strategy because tex is really
wierd
+ (when (= (car cur-tag-info) (car orig-tag-info))
+ ;; (message "orig-tag-type=%d cur-tag-type=%d keyword=%s"
orig-tag-type cur-tag-type keyword)
+ (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)
+ (setq where-to-jump-in-theory (point))
+ (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)
+ (setq where-to-jump-in-theory (point))
+ (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)
+ (setq where-to-jump-in-theory (point))
+ (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)
+ (setq where-to-jump-in-theory (point))
+ (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 (point))
+ (setq found t)
+ )
+ )
+ (t (message "why here?"))
+ )
+ )))))))
(provide 'evil-matchit-latex)
\ No newline at end of file
diff --git a/evil-matchit-pkg.el b/evil-matchit-pkg.el
index 6e3fa62522..b8d75a25f3 100644
--- a/evil-matchit-pkg.el
+++ b/evil-matchit-pkg.el
@@ -1,2 +1,2 @@
-(define-package "evil-matchit" "1.2.3"
+(define-package "evil-matchit" "1.2.4"
"Vim matchit ported into Emacs (requires EVIL)")
diff --git a/evil-matchit-sdk.el b/evil-matchit-sdk.el
index 6ad2bb582e..6d0d1971c0 100644
--- a/evil-matchit-sdk.el
+++ b/evil-matchit-sdk.el
@@ -10,29 +10,28 @@ between '\\(' and '\\)' in regular expression.
"
)
-(defun evilmi--sdk-member (KEYWORD LIST)
+
+;;;###autoload
+(defun evilmi-sdk-member (KEYWORD LIST)
"check if KEYWORD exist in LIST"
(let (rlt)
(cond
+ ((not KEYWORD) nil)
((not LIST) nil)
((stringp (car LIST))
- (if (string= KEYWORD (car LIST)) t
- (evilmi--sdk-member KEYWORD (cdr LIST))
- )
+ (if (string-match (concat "^" (car LIST) "$") KEYWORD) 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)))
- )
+ (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))
- )
- )
- )
- )
+ (evilmi-sdk-member KEYWORD (cdr LIST))))))
-(defun evilmi--sdk-get-tag-info (tag match-tags)
+
+;;;###autoload
+(defun evilmi-sdk-get-tag-info (tag match-tags)
"return (row column)"
(let (rlt elems elem tag-type
found i j)
@@ -45,11 +44,11 @@ between '\\(' and '\\)' in regular expression.
(setq elem (nth j elems))
(cond
((stringp elem)
- (if (string= tag elem)
+ (if (string-match (concat "^" elem "$") tag)
(setq found t)
))
((listp elem)
- (if (member tag elem)
+ (if (evilmi-sdk-member tag elem)
(setq found t)
))
)
@@ -57,9 +56,7 @@ between '\\(' and '\\)' in regular expression.
)
(if (not found) (setq i (1+ i)))
)
- (if found
- (setq rlt (list i j))
- )
+ (if found (setq rlt (list i j)))
rlt
)
)
@@ -75,7 +72,7 @@ between '\\(' and '\\)' in regular expression.
(setq keyword (match-string (nth 1 howto) cur-line))
;; keep search keyword by using next howto (regex and match-string
index)
- (if (not (evilmi--sdk-member keyword match-tags)) (setq keyword nil))
+ (if (not (evilmi-sdk-member keyword match-tags)) (setq keyword nil))
)
(setq i (1+ i))
)
@@ -94,7 +91,7 @@ between '\\(' and '\\)' in regular expression.
(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--sdk-get-tag-info keyword match-tags))
+ (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,7 +108,9 @@ between '\\(' and '\\)' in regular expression.
;;;###autoload
(defun evilmi-sdk-jump (rlt NUM match-tags howtos)
(let ((orig-tag-type (nth 1 (nth 1 rlt)))
+ (orig-tag-info (nth 1 rlt))
cur-tag-type
+ cur-tag-info
(level 1)
(cur-line (buffer-substring-no-properties
(line-beginning-position)
@@ -130,7 +129,10 @@ between '\\(' and '\\)' in regular expression.
(setq keyword (evilmi--sdk-extract-keyword cur-line match-tags howtos))
(when keyword
- (setq cur-tag-type (nth 1 (evilmi--sdk-get-tag-info keyword
match-tags)))
+ (setq cur-tag-info (evilmi-sdk-get-tag-info keyword match-tags))
+ (setq cur-tag-type (nth 1 cur-tag-info))
+
+ ;; (message "cur-tag-info=%s orig-tag-info=%s keyword=%s" cur-tag-info
orig-tag-info keyword)
;; key algorithm
(cond
@@ -146,6 +148,7 @@ between '\\(' and '\\)' in regular expression.
;; 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))
@@ -200,6 +203,7 @@ between '\\(' and '\\)' in regular expression.
)
(t (message "why here?"))
)
+
)
;; we will stop at end or beginning of buffer anyway
diff --git a/evil-matchit.el b/evil-matchit.el
index a75613a932..742dcf0f29 100644
--- a/evil-matchit.el
+++ b/evil-matchit.el
@@ -4,7 +4,7 @@
;; Author: Chen Bin <chenbin.sh@gmail.com>
;; URL: http://github.com/redguardtoo/evil-matchit
-;; Version: 1.2.3
+;; Version: 1.2.4
;; Keywords: matchit vim evil
;; Package-Requires: ((evil "1.0.7"))
;;
@@ -43,8 +43,6 @@
((evilmi-simple-get-tag evilmi-simple-jump))
))
-
-
(defun evilmi--operate-on-item (NUM &optional FUNC)
(let (plugin
rlt
diff --git a/pkg.sh b/pkg.sh
index 0074865039..074e742c30 100755
--- a/pkg.sh
+++ b/pkg.sh
@@ -1,5 +1,5 @@
#!/bin/bash
-pkg=evil-matchit-1.2.3
+pkg=evil-matchit-1.2.4
mkdir $pkg
cp README.org $pkg
cp *.el $pkg
- [nongnu] elpa/evil-matchit 90c8367856 027/244: add sdk v1.2.0, (continued)
- [nongnu] elpa/evil-matchit 90c8367856 027/244: add sdk v1.2.0, ELPA Syncer, 2022/01/06
- [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 <=
- [nongnu] elpa/evil-matchit e81d779541 046/244: support Emacs email (message-mode), ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit f7bced4500 047/244: updated README, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 313498e6ec 043/244: #26 jump to percentage, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit bd4feb7884 036/244: support cmake v1.2.5, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 6fabc1b8e7 048/244: support funtional javascript syntax v1.3.1, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 575e1e652a 037/244: support go-mode v1.2.6, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit d7f45fd142 039/244: updated doc v1.2.7, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 4d8d55e7f4 052/244: typo, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 0b2c287826 053/244: perfect support for ruby-mode v1.3.3 #29, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit b4ae58d214 040/244: some ad on stable, ELPA Syncer, 2022/01/06