branch: elpa/evil-matchit commit 271551560c3c8c066b29d335f781ff9b5aefe746 Author: Chen Bin <chenbin...@gmail.com> Commit: Chen Bin <chenbin...@gmail.com>
add evilmi-jump-hook --- README.org | 15 ++++++++++++++- evil-matchit-sdk.el | 8 ++++---- evil-matchit.el | 29 +++++++++++++++++++++++++++-- 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/README.org b/README.org index 65ba054464..7d3f0f737b 100644 --- a/README.org +++ b/README.org @@ -95,7 +95,20 @@ Use =evilmi-jump-items-native= to replace =evilmi-jump-items=. Evil text object But all the other commands like =evilmi-delete-items= and =evilmi-select-items= still work. -* Advanced tips +* Tips +** Toggle other modes before&after jumping to the matched tag +It's reported [[https://github.com/redguardtoo/evil-matchit/issues/138][some mode is not compatible with this package]]. + +You can use =evilmi-jump-hook= to turn off the mode before jumping to the matched tag. + +Then turn on it after the jump using the same hook. + +Here is an example to toggle =global-tree-sitter-mode=, +#+begin_src elisp +(add-hook 'evilmi-jump-hook + (lambda (before-jump-p) + (global-tree-sitter-mode (not before-jump-p)))) +#+end_src ** Support new major modes In order to apply three matching rules =evilmi-template=, =evilmi-simple=, and =evilmi-html= on =mhtml-mode=, please insert below code *after* your evil-matchit setup: #+begin_src elisp diff --git a/evil-matchit-sdk.el b/evil-matchit-sdk.el index b3e778262e..f9a4e21e93 100644 --- a/evil-matchit-sdk.el +++ b/evil-matchit-sdk.el @@ -124,11 +124,11 @@ If font-face-under-cursor is NOT nil, the quoted string is being processed." ;; @see https://github.com/redguardtoo/evil-matchit/issues/92 ((eq major-mode 'tuareg-mode) (evilmi-sdk-font-p pos '(font-lock-comment-face - font-lock-comment-delimiter-face - font-lock-doc-face))) + font-lock-comment-delimiter-face + font-lock-doc-face))) (t (evilmi-sdk-font-p pos '(font-lock-comment-face - font-lock-comment-delimiter-face))))) + font-lock-comment-delimiter-face))))) (defun evilmi-sdk-defun-p () "At the beginning of function definition." @@ -257,7 +257,7 @@ If IS-FORWARD is t, jump forward; or else jump backward." (let* ((tmp (evilmi-sdk-jump-forward-p)) (jump-forward (car tmp)) ;; if ff is not nil, it's jump between quotes - ;; so we should not use (scan-sexps) + ;; so we should not use `scan-sexps' (ff (nth 1 tmp)) (ch (nth 2 tmp)) (dst (evilmi-sdk-jumpto-where ff jump-forward ch))) diff --git a/evil-matchit.el b/evil-matchit.el index dcfa78c50a..ce8c31ae21 100644 --- a/evil-matchit.el +++ b/evil-matchit.el @@ -47,9 +47,21 @@ ;; If EVIL is NOT installed, ;; - Use `evilmi-jump-items-native' to replace `evilmi-jump-items' ;; -;; - Forget `evilmi-shortcut' and `global-evil-matchit-mode' +;; - `evilmi-shortcut' and `global-evil-matchit-mode' are not used ;; -;; See https://github.com/redguardtoo/evil-matchit/ for help. +;; Tips: +;; It's reported some mode is not compatible with this package. +;; You can use `evilmi-jump-hook' to turn off the mode before +;; jumping to the matched tag. +;; Then turn on it after the jump using the same hook. +;; +;; An example to toggle `global-tree-sitter-mode', +;; +;; (add-hook 'evilmi-jump-hook +;; (lambda (before-jump-p) +;; (global-tree-sitter-mode (not before-jump-p)))) +;; +;; See https://github.com/redguardtoo/evil-matchit/ for more information ;; ;; This program requires EVIL (https://github.com/emacs-evil/evil) ;; @@ -65,6 +77,14 @@ (require 'evil-matchit-sdk) +(defcustom evilmi-jump-hook nil + "Hook run before&after jump to the matched tag. +If the parameter of hook is t, the hook runs before jump. +Or else, the hook runs after jump. +Some modes can be toggle on/off in the hook" + :group 'evil-matchit + :type 'hook) + (defcustom evilmi-plugins '(emacs-lisp-mode ((evilmi-simple-get-tag evilmi-simple-jump))) "The Matrix of algorithms." @@ -83,6 +103,9 @@ (unless num (setq num 1)) + + (run-hook-with-args 'evilmi-jump-hook t) + (when (derived-mode-p 'prog-mode) (setq jump-rules (append (plist-get evilmi-plugins 'prog-mode) jump-rules))) @@ -115,6 +138,8 @@ (setq ideal-dest (point))) (if evilmi-debug (message "evilmi-jump-items-internal called. Return: %s" ideal-dest)) + + (run-hook-with-args 'evilmi-jump-hook nil) ideal-dest)) ;;;###autoload