-
Notifications
You must be signed in to change notification settings - Fork 32
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
Embedded languages #71
Comments
|
|
mooz/js2-mode#288 It could solve the jsx indentation issue , since it has "start", "end" character wise location and even "line" and "column" [3] "type": "JSXIdentifier",
"start": 277,
"end": 280,
"loc": {
"start": {
"line": 16,
"column": 11
},
"end": {
"line": 16,
"column": 14
}
},
"name": "div" ^ also useful for coloring tokens/keywords IMHO using external tools ie node shouldn't be a problem since we are already developing jsx and most likely already using the babel transpiler directly or indirectly, else we wouldn't be using rjsx-mode. css ast [4] @Wesitos [9] Connecting emacs to a node process is already done: [1] https://github.com/babel/babel/blob/master/packages/babel-parser/ast/spec.md |
Support for styled-components 👍 |
Here's a quick hack for editing in another buffer like org-mode does, using fence-edit and rx (modify-syntax-entry ?` "\"" js-mode-syntax-table)
(setq
styled-component-start
(rx-to-string '(: (1+ (and (+ word) (0+ "\.") (0+ "(" (+ alpha) ")"))) "`" eol)))
(setq
styled-component-end
(rx-to-string '(: "`;" eol)))
(setq
fence-edit-blocks `((,styled-component-start ,styled-component-end)))
(setq fence-edit-default-mode 'css-mode) with cursor inside string template call fence-edit-code-at-point minor-mode maybe? EDIT: Catches; export const Container = styled.div`
`;
Container.Settings = Container.Row.extend`
`;
export const Scrollbar = styled(Scrollbars)`
`;
export const Scrollbar = aaaa.styled(Scrollbars)`
`; |
I was trying to implement this with polymode. Indentation works, but syntax highlighting does not. |
+1 for I'm currently using fence-edit like this: (add-to-list 'fence-edit-blocks '("graphql[ \t\n]*(?`" "`" graphql))
(bind-key "C-c '" #'fence-edit-dwim) My full config: https://gitlab.com/mnewt/dotemacs/blob/master/.emacs.d/init.el#L2777 |
Polymode works for me, despite its documentation claims otherwise. I just have to make sure polymode is loaded after rjsx-mode, otherwise the graphql block will still be using rjsx-mode's string face. This is my config: (use-package polymode
:after rjsx-mode
:config
(define-hostmode poly-rjsx-hostmode nil
"RJSX hostmode."
:mode 'rjsx-mode)
(define-innermode poly-rjsx-graphql-innermode nil
:mode 'graphql-mode
:head-matcher "graphql\`"
:tail-matcher "\`"
:head-mode 'host
:tail-mode 'host)
(define-polymode poly-rjsx-mode
:hostmode 'poly-rjsx-hostmode
:innermodes '(poly-rjsx-graphql-innermode))
(add-to-list 'auto-mode-alist '("\\.jsx?\\'" . poly-rjsx-mode)))
(use-package rjsx-mode
:mode ("\\.jsx?\\'" "\\.mjs\\'")) |
Based on wyuenho's answer styled-components or emotion.js css-in-js can be done via
|
I might have spoken too soon. While that's the correct way to set up a poly mode, it doesn't work very well since every time rjsx reparses, the font lock will be wiped out |
I opted to use |
@rangeoshun, I was taking a look at your snippet, any idea of how this could work with something like |
@deviantfero, I think it just works as far as I can tell:
Also by adding an Hope I answered your question :) |
Thank you so much, I'll have a look, I've been looking into improving
performance when editing JSX and this seems to be the appropriate answer
…On Wed, 4 Dec 2019 at 06:02, rangeoshun ***@***.***> wrote:
@deviantfero <https://github.com/deviantfero>, I think it just works as
far as I can tell:
[image: Screenshot 2019-12-04 at 12 55 52]
<https://user-images.githubusercontent.com/1267842/70140799-cf2d1d80-1695-11ea-8003-544c62ddfb73.png>
[image: Screenshot 2019-12-04 at 12 56 16]
<https://user-images.githubusercontent.com/1267842/70140801-d0f6e100-1695-11ea-9c6a-35a67cbd66cd.png>
Also tide-fix works with one little caveat. When applied, mmm does not
repaint the block right away. But it starts working again when you edit the
block. This could be fixed by forcing mmm to reapply the modes if tide
has a hook for this. I did not have the time to look into this tho.
My complete doom config is here, if you're interested:
https://github.com/rangeoshun/dot-doom-d/blob/master/config.el
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#71?email_source=notifications&email_token=ACVCGSO27LA6OA7MNF43IK3QW6L5VA5CNFSM4E47FAOKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEF4Y3XY#issuecomment-561614303>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACVCGSOW6UTE3OW3KDPGZULQW6L5VANCNFSM4E47FAOA>
.
|
I'm using @rangeoshun's solution for function foo() {
return (
<MyComponent>
{() => (
<div> {/* <- indentation fails here */}
<div></div>
</div>
)()}
</MyComponent>
)
} Is it possible to modify the RegExp to use web mode for the entire return block? Web-mode is quite unperformant when using it on the whole file for some reason. EDIT: @deviantfero did you ever manage so solve your performance issues? |
@JacksonGariety I see now what you mean! To be honest, I had issues with I have tried to create multiple |
@JacksonGariety Also, we use |
@rangeoshun how do you get |
@JacksonGariety I simply turned on (add-hook 'typescript-mode-hook 'prettier-js-mode) |
@rangeoshun how does it fare with string interpolation inside template literals? |
If I understand your question correctly, you'll lose some company-mode features. But generally, I like to define my functions outside the literal, and interpolate the function by reference. Please tell me if I got your question wrong 😄 |
Also anyone checking this topic, it might worth to try this repo here: |
There have been a several requests for this before (#70, #69, #63), and I've closed them because I felt them to be out of scope for
rjsx
. However, given this is a recurring issue, I'm now thinking it might make sense to add this torjsx
.This wouldn't be an easy task, and is not something I use, so there would need be significant community support for getting this done. There are a few things that would help move this along without having to sit and code the entire thing start to finish, so please weigh in with information/opinions on these topics:
The text was updated successfully, but these errors were encountered: