branch: elpa/evil-matchit
commit 7cd10d332dd19536812f9cf7d9fa72ed1c9ce472
Author: Chen Bin <[email protected]>
Commit: Chen Bin <[email protected]>
extra logic to find html open tag
---
evil-matchit-html.el | 35 ++++++++++++++++++++++++++++-------
evil-matchit.el | 2 +-
2 files changed, 29 insertions(+), 8 deletions(-)
diff --git a/evil-matchit-html.el b/evil-matchit-html.el
index e27bc0852d..9c6bdc351c 100644
--- a/evil-matchit-html.el
+++ b/evil-matchit-html.el
@@ -1,6 +1,6 @@
;;; evil-matchit-html.el ---html plugin of evil-matchit
-;; Copyright (C) 2014-2019 Chen Bin <[email protected]>
+;; Copyright (C) 2014-2020 Chen Bin <[email protected]>
;; Author: Chen Bin <[email protected]>
@@ -31,8 +31,17 @@
(autoload 'sgml-skip-tag-backward "sgml-mode" nil t)
(autoload 'sgml-skip-tag-forward "sgml-mode" nil t)
+(defun evilmi-html--open-tag-candidate (position)
+ "Get html open tag candidate.
+It starts from POSITION and possibly ends at line end."
+ (let* ((partial-line (save-excursion
+ (goto-char position)
+ (buffer-substring position (line-end-position)))))
+ (car (split-string partial-line "[ \t]+"))))
+
;;;###autoload
(defun evilmi-html-get-tag ()
+ "Get current tag."
(let* ((b (line-beginning-position))
(e (line-end-position))
(looping t)
@@ -40,8 +49,9 @@
(p (point))
(found_tag -1))
+ (if evilmi-debug (message "evilmi-html-get-tag called. p=%s" p))
(save-excursion
- ;; search backward
+ ;; search backward for "<"
(unless (eq char ?<)
(while (and looping (<= b (point)) (not (eq char ?<)))
(setq char (following-char))
@@ -51,7 +61,7 @@
(setq looping nil)
(backward-char))))
- ;; search forward
+ ;; search forward for "<"
(unless (eq char ?<)
(save-excursion
(while (and (>= e (point)) (not (eq char ?<)))
@@ -59,6 +69,12 @@
(setq p (point))
(forward-char))))
+ ;; a valid html tag should be like <[^;]
+ (unless (and (eq char ?<)
+ ;; html tags should not contain " ,;"
+ (string-match "^<[^ ;,]+$" (evilmi-html--open-tag-candidate
p)))
+ (setq char nil))
+
;; is end tag?
(when (and (eq char ?<) (< p e))
(goto-char p)
@@ -93,13 +109,18 @@
(list p found_tag "")))
;;;###autoload
-(defun evilmi-html-jump (rlt num)
- (let* ((tag-type (nth 1 rlt))
+(defun evilmi-html-jump (info num)
+ "Use INFO from current tag to jump NUM times."
+ (let* ((tag-type (nth 1 info))
;; `web-mode-forward-sexp' is assigned to `forward-sexp-function'
;; it's buggy in web-mode v11, here is the workaround
(forward-sexp-function nil))
- (if (eq 1 tag-type) (sgml-skip-tag-backward num))
- (if (eq 0 tag-type) (sgml-skip-tag-forward num))
+ (if evilmi-debug (message "evilmi-html-jump called. tag-type=%s" tag-type))
+ (cond
+ ((eq 1 tag-type)
+ (sgml-skip-tag-backward num))
+ ((eq 0 tag-type)
+ (sgml-skip-tag-forward num)))
(point)))
(provide 'evil-matchit-html)
diff --git a/evil-matchit.el b/evil-matchit.el
index 8e05b4b485..d953d7f9fc 100644
--- a/evil-matchit.el
+++ b/evil-matchit.el
@@ -268,7 +268,7 @@ If IS-FORWARD is t, jump forward; or else jump backward."
;; jump only once if the jump is successful
(setq jumped t))
(when evilmi-debug
- (message "rule=%s ideal-dest=%s (point)=%s" rule ideal-dest
(point)))))
+ (message "rlt=%s rule=%s p=%s jumped=%s" rlt rule (point) jumped))))
;; give `evilmi--simple-jump' a second chance
(unless jumped