Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mason <%perl> section identifies as HTML submode instead of (c)perl-mode #141

Closed
esabol opened this issue Mar 18, 2024 · 8 comments
Closed

Comments

@esabol
Copy link

esabol commented Mar 18, 2024

I'm probably doing something wrong (some kind of precedence thing?), but when I load up the file attached below into my Emacs using mmm-mode version 0.5.11, I'm not getting (c)perl-mode in the <%perl> section. I'm getting "HTML helper" mode instead.

Here's what I have in my .emacs:

      (require 'mmm-auto)
      (require 'mmm-mason)
      (load-library "cl-seq")
      (setq mmm-global-mode 'maybe)
      (setq mmm-submode-decoration-level 0)
      (setq mmm-parse-when-idle t)
      (setq mmm-major-mode-preferences '((perl perl-mode cperl-mode)
					 (javascript javascript-mode c++-mode)
					 (java jde-mode java-mode c++-mode)
					 (html html-helper-mode)
					 (css css-mode c++-mode)))
      (setq auto-mode-alist (cons '("\\.form\\'" . html-helper-mode)
				  auto-mode-alist))
      (mmm-add-classes '((html-style-attributes
			  :submode css
			  :front "style=\""
			  :back "\""
			  :face mmm-declaration-submode-face
			  :delimiter-mode nil)))
      (mmm-add-mode-ext-class nil "\\.mas\\'" 'mason)
      (mmm-add-mode-ext-class nil "\\(auto\\|d\\)handler\\'" 'mason)
;;      (add-to-list 'mmm-mode-ext-classes-alist '(html-helper-mode nil html-js))
;;      (add-to-list 'mmm-mode-ext-classes-alist '(html-helper-mode nil embedded-css))
;;      (add-to-list 'mmm-mode-ext-classes-alist '(html-helper-mode nil html-style-attributes))

(I've tried it with and without the last three lines commented out. Same result.)

Here is the file I'm editing (rename it to foo.mas after downloding it):
foo.mas.txt

Hmmm.... If I delete lines 18-19 from the file, then the whole <%perl> section does switch to (c)perl-mode. I guess the <script> tags in the comments on these lines are somehow overriding the submode for the whole section. Why? What can be done about this?

I've been using mmm-mode for something like 20 years, I think. I'm very appreciative of your efforts in developing and maintaining it. Thank you!

@dgutov
Copy link
Owner

dgutov commented Mar 23, 2024

Hi! Thanks for the kind words.

When you say lines 18-19, which exact lines are you referring to?

If it's about mmm-add-mode-ext-class, then some association between the .mas extension and the classes needs to be made somewhere. Without it, you'd just get the base major mode.

I'm also not seeing the auto-mode-alist setting, and which major mode it maps .mas files to.

The below config makes things work in my testing:

(setq mmm-global-mode 'maybe)

(require 'mmm-mason)

(mmm-add-mode-ext-class nil "\\.mas\\'" 'mason)

(add-to-list 'auto-mode-alist '("\\.mason\\'" . html-mode))

We should probably also change mmm-major-mode-preferences like you did, to move perl-mode before cperl-mode. The Mason readme mentions problems with the latter, and I also saw some in my testing.

@dgutov
Copy link
Owner

dgutov commented Mar 23, 2024

Maybe you're referring to this line:

(add-to-list 'mmm-mode-ext-classes-alist '(html-helper-mode nil html-js))

If this class's rules match the print "<script> lines in your file (I'm not 100% sure - the regexps are non-trivial, but they could), it might as well happen that the mason-perl class is not applied. You can try changing the order in which the classes are set up in your configuration: if mason-perl comes first during parsing, then it should be applied.

@esabol
Copy link
Author

esabol commented Mar 23, 2024

Thanks for replying.

I think you've misunderstood me? I meant lines 18-19 of the foo.mas file I uploaded in my original post. Specifically, these lines:

#       print "<script>console.log('opt_val = $opt_val')</script>\n";
#       print "<script>console.log('opt_name = $temp')</script>\n";

So, if I delete those two lines from the foo.mas file, the submode is correct (perl-mode). With those two lines in the file, the submode of the whole <%perl> section is wrong (html-helper-mode).

@esabol
Copy link
Author

esabol commented Mar 23, 2024

Oh, sorry, I was replying to your first comment. I think you figured it out. I'll try changing the order and get back to you. Thanks!

@esabol
Copy link
Author

esabol commented Mar 23, 2024

Well, I think it's working now. I think commenting out (add-to-list 'mmm-mode-ext-classes-alist '(html-helper-mode nil html-js)) did the trick. I swear I tested commenting that line out before I opened the issue, but it's working now with that change and not working with it uncommented.

I think the ideal solution is something like PR #114 though, and I'm sad to see that that hasn't been merged in 3.5 years (because of legitimate problems, I'm sure, but I wish they'd been worked through).

Anyway, thanks for the support. Cheers!

@esabol esabol closed this as completed Mar 23, 2024
@dgutov
Copy link
Owner

dgutov commented Mar 24, 2024

I think the ideal solution is something like PR 114 though

IIUC it's solving a slightly different problem: infinite nesting. But even with that patch applied, parsing would still be affected by the order of classes in the list.

To help with problem currently discussed, we'd either need to introduce class priorities (so that the order can be specified more explicitly, at least), or alter the algorithm in a way that would be able to recognize new regions even when they cross already-found ones, while retaining consistency. The latter is harder, though it doesn't seem impossible.

@esabol
Copy link
Author

esabol commented Mar 24, 2024

IIUC it's solving a slightly different problem: infinite nesting.

Oh, I thought it was adding support for nested submodes, like sub-submodes and sub-sub-submodes, etc. I misunderstood. Anyway, thanks!

@dgutov
Copy link
Owner

dgutov commented Mar 25, 2024

Just to clarify. If your file has nesting like

A
> B
>> C
> B
A
> C
A

then the list of classes has to be A B C. A C B will result in the B regions (in the example above) not being recognized.

The PR above adds the ability for the nesting to be infinite (or very deep anyway), but doesn't change the above rule.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants