Matching when on a bracket and inside it like matchit.vim
srustamo opened this issue · 18 comments
Perhaps I'm missing an existing feature, but with evil-matchit
placing a point on the first <
in this statement <head> Hello </head>
and pressing % will jump to </head>
element. matchit.vim
will jump to >
element of the opening <head>
element.
edit: matchit.vim
will jump to a closing </head>
element if the cursor (in vimspeak) is anywhere between < >
but not on them.
I think the current behavior make sense, because most time I'm jumping between tags.
But evil-matchit is totally customizable. If your use case is different from mine, you can write your own rule,
(mapc (lambda (mode)
(plist-put evilmi-plugins mode '((evilmi-template-get-tag evilmi-template-jump)
(evilmi-simple-get-tag evilmi-simple-jump)
(evilmi-your-get-tag evilmi-your-jump)
(evilmi-html-get-tag evilmi-html-jump)))
)
'(web-mode html-mode nxml-mode nxhtml-mode sgml-mode message-mode))
Could you please give me a full working config for jumping between two div
s (rather than between matching <>
) in the html below:
<div>
<link rel="stylesheet" /css/font-awesome.min.css">
</div>
(require 'evil-matchit)
(global-evil-matchit-mode 1)
Official setup works.
You major mode should be of web-mode html-mode nxml-mode nxhtml-mode sgml-mode message-mode
what's your major-mode?
I'm in sgml-mode
editing the code above. Hitting % inside the the first <div>
- point on d
letter - takes me to the very first <
. My desired behaviour is that it should take me to the closing </div>
.
evilmi-version
? I tested with sgml-mode, it's working.
2.1.4
C-h k %
in evil-normal-state?
% runs the command evil-jump-item (found in evil-motion-state-map), which is an
interactive compiled Lisp function in ‘evil-commands.el’.
It is bound to %.
(evil-jump-item &optional COUNT)
Find the next item in this line after or under the cursor
and jump to the corresponding one.
[back]
you should bind %
to evilmi-jump-items. place my setup after (evil-mode 1)
Sorry, I have confused you, because I forget that I disabled the evil-matchit
mode, because of the intended by you behaviour. My original question (please see the very first post) is to match the behaviour of matchit.vim
(described in the first post).
And my follow up post was to ask for your help to produce this behaviour through configing your package, which you seem to imply is possible.
There are many things I don't like about vim-matchit. For example, jumping between <>
.
Butevil-matchit
gives you full freedom to DIY, like Emacs. So now is the good time to learn lisp.
I wrote a prototype for your problem. Place it after your evil-matchit setup,
(defun evilmi-your-get-tag ()
(if (or (= (following-char) 60) ;<
(= (following-char) 62)) ;>
(list (point))))
(defun evilmi-your-jump (rlt num)
(if (= (following-char) 60) (search-forward ">" nil nil))
(if (= (following-char) 62) (search-backward "<" nil nil))
(point))
(plist-put evilmi-plugins 'sgml-mode '((evilmi-template-get-tag evilmi-template-jump)
(evilmi-simple-get-tag evilmi-simple-jump)
(evilmi-your-get-tag evilmi-your-jump)
(evilmi-html-get-tag evilmi-html-jump)))
Many thanks for trying to help. I tried the code starting the evilmi-your-get-tag
function. I don't see any change in the original behaviour. C-h-v
evilmi-plugins
yields this for sgml-mode
:
sgml-mode
((evilmi-template-get-tag evilmi-template-jump)
(evilmi-simple-get-tag evilmi-simple-jump)
(evilmi-html-get-tag evilmi-html-jump))
Looks like (plist-put)
does not do its job.
thanks. Looks this is a bug in evil-matchit which always reset evilmi-plugins when minor-mode enabled. Fixed.
b01763b initialize evilmi-plugins only once v2.1.5 (Chen Bin)
Thanks. I hope it will be pushed to Melpa soon.
already there http://stable.melpa.org/#/evil-matchit
Thanks. I see that evilmi-plugins
gets updated properly now. However, the plugin code for jumping between <>
still does not work.
I understand if you don't want to spend more time on this issue. If you still have a spare moment, please have a look if it works for you.
It's working in v2.1.5, make sure you are using sgml-mode, C-h v major-mode
,
Here is my evil-matchit -setup,
(require 'evil-matchit)
(global-evil-matchit-mode 1)
(defun evilmi-your-get-tag ()
(if (or (= (following-char) 60) ;<
(= (following-char) 62)) ;>
(list (point))))
(defun evilmi-your-jump (rlt num)
(if (= (following-char) 60) (search-forward ">" nil nil))
(if (= (following-char) 62) (search-backward "<" nil nil))
(point))
(plist-put evilmi-plugins 'sgml-mode '((evilmi-template-get-tag evilmi-template-jump)
(evilmi-simple-get-tag evilmi-simple-jump)
(evilmi-your-get-tag evilmi-your-jump)
(evilmi-html-get-tag evilmi-html-jump)))
If it still does NOT work for you, send me a complete html file, and tell me your exact steps to reproduce the issue
All is well. Thank you.