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

Select wrong formatter when file is mhtml-mode #302

Closed
eki3z opened this issue May 5, 2024 · 4 comments
Closed

Select wrong formatter when file is mhtml-mode #302

eki3z opened this issue May 5, 2024 · 4 comments

Comments

@eki3z
Copy link

eki3z commented May 5, 2024

In mhtml-mode, the var major-mode is changed when your point moved into different position:

  1. if point at <style>... </style>, major-mode is identidied as css-mode;
  2. if point at <script>... </script>, major-mode is identidied as js-mode;
  3. at other place, major-mode is mhtml-mode.

so when I point at <style></style> section, apheleia select prettier-css which is wrong, to fix the problem we need to
always get mhtml-mode as major-mode .

;; NOTE if current point is at mhtml submode, then
;; return `mhtml-mode' instead.
(or (and (get-text-property
          (if (and (eobp) (not (bobp)))
              (1- (point))
            (point))
          'mhtml-submode)
         'mhtml-mode)
    major-mode)

@raxod502 I guess need to fix function apheleia--get-formatters, does issue #29 is related to this either ?

@raxod502
Copy link
Member

One option would be to add to mhtml-mode-hook a function that sets apheleia-formatter to whatever you desire it to be. The buffer-local variable overrides automatic formatter detection.

But, since mhtml-mode is built in, I guess we should make this work by default. I'd like to do it in a way that does not special-case one particular mode in the internal code. Let me add something generic for that, one moment.

@raxod502
Copy link
Member

How do you feel about the approach in #303? I'm not sure if it's the best, but it seems not unreasonable to me.

@eki3z
Copy link
Author

eki3z commented May 11, 2024

LGTM. mhtml-mode is the only mode which can fontify css/js code correctly in html file so far, thanks for your great package !

@eki3z eki3z closed this as completed May 11, 2024
@raxod502
Copy link
Member

I use web-mode, personally, but that has its own problems.

raxod502 added a commit that referenced this issue May 17, 2024
For #302. Not tested
yet. Going to add unit tests before merging.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants