dgutov / mmm-mode

New official home for mmm-mode, fixed for Emacs >= 23
http://mmm-mode.sourceforge.net/
GNU General Public License v2.0
333 stars 32 forks source link

how does one run `mmm-parse-buffer` after the buffer is loaded? #125

Closed iambumblehead closed 2 years ago

iambumblehead commented 2 years ago

when calling mmm-parse-buffer from js2-mode-hook or from mmm-mode-hook, the buffer is left in a broke state with incorrect syntax-highlighting and indentation. How does one run this command automatically?

dgutov commented 2 years ago
(setq mmm-parse-when-idle t)

should help.

But js2-mode is incompatible with mmm-mode. Try js-mode instead, maybe.

iambumblehead commented 2 years ago

@dgutov hey thank you I'm glad to read your response. I do have (setq mmm-parse-when-idle 't) defined at the top (not inside any hook). What happens is, the file loads and the sub-region is not syntax-highlighted until I "touch" the file --eg, if I go to the template area an move or edit a tag, then the whole area gets syntax-highlighting and looks nice.

iambumblehead commented 2 years ago

should js-mode be the new "default mode" for js?

dgutov commented 2 years ago

That sounds like a bug: either inside mmm-mode's code.

Or an incompatibility between the major modes, which they might need extra help with.

If the problem is with js2-mode, then I suggest using js-mode instead.

dgutov commented 2 years ago

js2-mode is good for "regular" JS code, and has some useful stuff for it.

It's not so great, OOTB, for React-style code. There are some extensions for it which can help (e.g. rjsx-mode), you can try those. I don't recommend mixing it with mmm-mode, though.

iambumblehead commented 2 years ago

@dgutov it works with js-mode

the syntax highlighting looks a little plain compared to js2-mode but is OK. I'll upload a little screenshots js2-mode and js-mode, simply to share and no other reason

iambumblehead commented 2 years ago

js2-mode

Screen Shot 2022-07-26 at 11 51 43 AM

js-mode

Screen Shot 2022-07-26 at 11 50 50 AM
iambumblehead commented 2 years ago

this calls (mmm-parse-buffer) one time after one second and can be added to the mmm-mode hook. Its not ideal, but...

(run-at-time 1 nil (lambda() (mmm-parse-buffer)))
dgutov commented 2 years ago

Here's the relevant issue: https://github.com/mooz/js2-mode/issues/124

Not on my roadmap currently, but maybe someday. The screenshots look pretty convincing.

iambumblehead commented 2 years ago

'looping back to give a summary of what happened. The setup here uses eglot with typescript-language-server and flymake to get auto-completion and auto-linting and the result is amazing. This screenshot shows how "icons" are auto-suggested at the import expression --I did not open any files before screenshot and only opened the buffer file with emacs directly,

Screen Shot 2022-07-26 at 12 54 55 PM

this was added to an eglot hook and to the mmm-mode hook, the delay is acceptable and not overly-intrusive,

(add-hook 'eglot-server-initialized-hook (lambda (server) (run-at-time 1 nil (lambda() (mmm-parse-buffer)))))
(add-hook 'mmm-mode-hook (lambda () (run-at-time 1 nil (lambda() (mmm-parse-buffer))))

other than these mmm-mode definitions, everything else are standard

(mmm-add-classes
    '((js-vue
          :submode web-mode
          :face mmm-code-submode-face
          :front ": `"
          :front-offset (end-of-line 1)
          :back-offset (end-of-line 1)
          :back ">`")))

(mmm-add-mode-ext-class 'js2-mode nil 'js-vue)
(mmm-add-mode-ext-class 'js-mode nil 'js-vue)

eglot does not require configuration, so after installing typescript-language-server and then eglot, this was added to my .emacs file

(require 'eglot)
iambumblehead commented 2 years ago

I don't want to bother you and "@" your name dgutov, thank you for using time responding to me and my comments here. Your input is always appreciated by me.

iambumblehead commented 2 years ago

and a little gif screenshot for fun emacs-vuejs

dgutov commented 2 years ago

It's no bother.

I see that it's more or less working okay for you, and that's great. I feared the breakage might be more annoying.