Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
Use different syntax table for JSX text #24
Comments
vidjuheffex
commented
Jul 26, 2017
|
Any workarounds for this? I noticed my JSX block lost highlighting capabilities with rainbow-delimeters. (it was a single quote). Not the end of the world by any means. |
|
Here's some advice you could play around with. I haven't looked into the correct syntax table to use, but if this works for you feel free to send a PR or leave a note and I'll incorporate this into master. (defun rjsx-advice-text-syntax-table (orig-fn &rest args)
(let ((token-type (apply orig-fn args)))
(when (eq token-type rjsx-JSX-TEXT)
(let* ((token (js2-current-token))
(beg (js2-token-beg token))
(end (js2-token-end token)))
(js2-record-text-property beg end 'syntax-table (standard-syntax-table))))
token-type))
(advice-add 'rjsx-get-next-xml-token :around 'rjsx-advice-text-syntax-table)
;; (advice-remove 'rjsx-get-next-xml-token 'rjsx-advice-text-syntax-table) |
vidjuheffex
commented
Jul 27, 2017
|
Hmm didnt seem to make a change. I switched the above code snippet to be text-mode-syntax-table, but rjsx mode wouldn't come on when I did that. |
|
Can you turn on debug-on-error and paste the stack trace in here? |
vidjuheffex
commented
Jul 28, 2017
|
Not these errors don't happen with your code. I was just switching it to other modes to see if any gave the right result. The code I'm viewing in JSX is:
Which stops highlighting at the div with contraction. Here the output, trying the different text-mode-syntax-table: The full stack trace is: |
|
I think you have text-mode-syntax-table in the parenthesis (called as a function). Try unwrapping it to use it as a variable and see what that gives |
|
Maybe the problem is |
vidjuheffex
commented
Aug 2, 2017
|
Yes, I can try that this afternoon, thanks for the feedback |
vidjuheffex
commented
Aug 6, 2017
|
I'm getting the same result. |
|
That screenshot was with rainbow delimiters. What if you try running emacs with -Q and just installing those two packages? |
vidjuheffex
commented
Aug 8, 2017
•
|
@felipeochoa well what do you know... working highlighting. Thanks. I guess I have to pinpoint the problem package now. Edit: maybe I was seeing things. But I can no longer recreate this working situation. |
vidjuheffex
commented
Aug 8, 2017
|
Now here's a stranger thing. (Or maybe not, I'm kind of new to emacs) I know -Q and commenting out aren't the same (for one, .jsx files still opened in rjsx-mode) but I was wondering if you (or any other experiences emacs users) had some knowledge onhow to best troubleshoot this. |
|
I'm not sure -- you may have better luck on Stack Exchange or Reddit for debugging this. I don't use customize, so don't really know how those interact, but I would suggest you simply try adding packages back one at a time until it breaks. Then you'll have a strong clue |
|
Ah just saw you'd already posted on reddit |
vidjuheffex
commented
Aug 8, 2017
•
|
EDIT: ignore the following message. Highlighting doesnt work on either. I've managed to see it right once on each machine. I think I'm just going to turn off rainbow delimeter. Yeah, I'll get to the bottom of it eventually. I have two windows boxes, both with the same version of emacs from the same source, the same packages installed with use-package :ensure t, and on my Surface everything is fine, on my desktop highlighting breaks. It's the strangest thing. |
felipeochoa
closed this
in
4db1fc0
Aug 8, 2017
vidjuheffex
commented
Aug 8, 2017
|
@felipeochoa I spoke too soon! It's a combination of things! Okay, I have to use the first snippet you posted here. BUT. I have to toggle rainbow delimiters on and off as per the response here: https://www.reddit.com/r/emacs/comments/6sa6jt/troubleshooting_conflicting_packages/ Thanks so much and I apologize for such a long back and forth. |
|
Glad you got it fixed. Sounds like an issue of colliding font-lock handling |

felipeochoa commentedDec 27, 2016
We should use
put-text-propertyto set a different syntax table on stretches of JSX text. Not sure which syntax table is best, it should be more text-like. One issue in particular is single quotes messing up the syntax parser when they're unmatched (e.g., in a contraction). Probably should use an SGML syntax table, but maybe just fundamental itself?