Feature Request: Infinite Nesting
Sorry for all the edits, I accidentally pressed enter while typing the title.
This is similar to issue #102, but instead of going two levels, I need to go any number of levels deep.
Here is the sample code:
As you can see the html where is cursor is is lisp-mode, while it should be html-mode.
Here is is as text:
(write-html
<html>
<head>
<link rel="stylesheet" href="/site.css" />
<title>,(progn title) - New Poll</title>
</head>
<body>
<header>
<h1 id="title">,(progn title)</h1>
</header>
<form method="POST" action="/new-poll">
,@(when (null names)
(list <input-name index="0" name="" />
<input-name index="1" name="" />
<input-name index="2" name="" />))
,@(mapcar (lambda (name i)
<input-name index=i name=name />)
names (enumerate names))
,(when (string= action "add")
<input-name index=(length names) name="" />)
,(when errors <ul class="error"> ,@errors </ul>)
<button name="action" type="submit" value="add">Add</button>
<button name="action" type="submit" value="submit">Submit</button>
</form>
<hr />
<footer>
</footer>
</body>
</html>)
Here is my MMM config:
(require 'sgml-mode)
(require 'lisp-mode)
(require 'mmm-mode)
;; add preferences for relevant modes
(mmm-add-to-major-mode-preferences 'lisp 'lisp-mode t)
(mmm-add-to-major-mode-preferences 'html 'html-mode t)
(defun html-back-matcher ()
(forward-char -2)
(with-syntax-table html-mode-syntax-table
(sgml-skip-tag-forward 1))
0)
(defun lisp-back-matcher ()
(forward-char -1)
(with-syntax-table lisp-mode-syntax-table
(forward-sexp))
0)
(mmm-add-classes
'((mmm-lisp
:submode lisp
:face mmm-declaration-submode-face
:front ",(\\|,@\\|=("
:include-front t
:back "."
:back-offset (lisp-back-matcher))))
(mmm-add-mode-ext-class 'lisp-mode nil 'mmm-lisp)
(mmm-add-classes
'((mmm-html
:submode html
:face mmm-declaration-submode-face
:front "\\(?1:<\\)[^=[:space:]]"
:front-match 1
:include-front t
:back "."
:back-offset (html-back-matcher))))
(mmm-add-mode-ext-class 'lisp-mode nil 'mmm-html)
Basically, what I would like is for the mmm-modes to be applied recursively until there isn't another one found.
Hi!
This is indeed not something currently supported.
If you have spare time to dig in and implement this, I'd review a PR. The performance hit would have to be minimal, or this would have to be preffed out by default, of course.
Do you have any idea where in the source I would start looking to implement it?
mmm-apply-classes might be the place to start.
Thanks for the tip. I have made some progress: commit. But I'm stuck on some stubborn parenthesis; I thought I could use some help.
See how the parenthesis under the cursor is in html-mode while it should be in lisp-mode? I've tried debugging html-back-matcher and lisp-back-matcher, but they appear to be stopping in the correct locations. I have also tried changing html-back-matcher and lisp-back-matcher to return -1, but it makes no difference.
Is it parsed as part of the delimiters? As you can see in mmm-make-region, delimiters are by default left in "primary" mode.
Upon further inspection, I have determined that the mode regions are being applied correctly. The red parenthesis are due to rainbow-delimiters-mode not using widen. So think this issue is solved. Should I just make a pull request with that commit?
I'm happy it's working for you, but always running the loop 10 times will result in a definite slowdown.
I'd prefer to see some smarter solution. At least one that checks whether the last iteration changed something.
BTW, have you ever tried https://github.com/polymode/polymode/? AFAIK it has a couple more advanced features. It's possible that it supports this feature out-of-the-box.
I actually did try polymode, but it is more for markup, and the documentation is more sparse than mmm. Mmm seems to be more for code and is already working better than polymode ever did for this same purpose.
About my commit, it only runs 10 times as a maximum. Line 109 will exit the loop if no more sub-modes have been applied.
I actually did try polymode, but it is more for markup, and the documentation is more sparse than mmm. Mmm seems to be more for code and is already working better than polymode ever did for this same purpose.
I wonder if it is because the documentation is lacking, or if it really lacks in features. If you had done a comparison, I'd be curious to examine it.
About my commit, it only runs 10 times as a maximum. Line 109 will exit the loop if no more sub-modes have been applied.
Ah, I see. You can open a PR, and we'll continue the discussion from there.