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

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

Closed
iambumblehead opened this issue Jul 26, 2022 · 13 comments
Closed

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

iambumblehead opened this issue Jul 26, 2022 · 13 comments

Comments

@iambumblehead
Copy link

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
Copy link
Owner

dgutov commented Jul 26, 2022

(setq mmm-parse-when-idle t)

should help.

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

@iambumblehead
Copy link
Author

@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
Copy link
Author

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

@dgutov
Copy link
Owner

dgutov commented Jul 26, 2022

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
Copy link
Owner

dgutov commented Jul 26, 2022

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
Copy link
Author

@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
Copy link
Author

iambumblehead commented Jul 26, 2022

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
Copy link
Author

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
Copy link
Owner

dgutov commented Jul 26, 2022

Here's the relevant issue: mooz/js2-mode#124

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

@iambumblehead
Copy link
Author

'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
Copy link
Author

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
Copy link
Author

and a little gif screenshot for fun
emacs-vuejs

@dgutov
Copy link
Owner

dgutov commented Jul 26, 2022

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.

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