codemirror string coloring multiple lines - codemirror

I'm using codemirror for javascript code coloring, and when I put a string in quotes "like this" it is colored just fine.
But when I put a string with a line break "like
this" the color is messed up on the second line.
Is there any way to make sure the color starts with the first quote and ends with the second quote, even if there is a line break?

JavaScript doesn't allow multi-line strings. You can use a backslash before the newline, or use template literals (backtick-quoted strings), but if you don't, you aren't writing valid JavaScript, and that is the reason why the CodeMirror mode doesn't highlight your code as you expected.

Related

How to convert embedded CRLF codes to their REAL newlines in Vscode?

I searched everywhere for this, the problem is that the search criteria is very similar to other questions.
The issue I have is that file (script actually) is embedded in another file. So when I open the parent file I can see the script as massive string with several \n and \r\n codes. I need a way to convert these codes to what they should be so that it formats the code correctly then I can read said code and work on it.
Quick snippet:
\n\n\n\n\nlocal scriptingFunctions\n\n\n\n\nlocal measuringCircles = {}\r\nlocal isCurrentlyCheckingCoherency
Should covert to:
local scriptingFunctions
local measuringCircles = {}
local isCurrentlyCheckingCoherency
perform a Regex Find-Replace
Find: (\\r)?\\n
Replace: \n
If you don't need to reconvert from newlines to \n after you're done working on the code, you can accomplish the trick by simply pressing ctrl-f and substituting every occurrence of \n with a new line (you can type enter in the replace box by pressing ctrl-enter or shift-enter).
See an example ctrl-f to do this:
If after you're done working on the code you need to reconvert to \n, you can add an invisible char to the replace string (typing it like ctrl-enter invisibleChar), and after you're done you can re-replace it with \n.
There's plenty of invisible chars, but I'd personally suggest [U+200b] (you can copy it from here); another good one is [U+2800] (⠀), as it renders as a normal whitespace, and thus is noticeable.
A thing to notice is that recent versions of vscode will show a highlight around invisible chars, but you can easily disable it by clicking on Adjust settings and then selecting Exclude from being highlighted.
If you need to reenable highlighting in the future, you'll have to look for "editor.unicodeHighlight.allowedCharacters" in the settings.

IN vs code the double quotes and single quotes are being flags as errors why?

Why is it that the double quotes are being picked up as an error and I can't even use contractions words either because they are getting flagged as a issue? This has never been a issue before so why is it starting now?
It may be that your language is not recognizing the fancy quotes as allowable string delimiters and so the red underlining under the strings mat be fixed by changing those fancy quotes to normal quotes.
As of vscode v1.63: Just to know what those orange borders around the quote marks are, the fancy quotes are unexpected unicode characters. Those orange borders are warnings that there are unexpected or ambiguous unicode characters.
If you add those fancy quote characters to this setting:
Editor > Unicode Highlight: Allowed Characters
Just copy and paste your varioucs characters, like ” into the Add Item input.
Or you can disable this setting:
Editor > Unicode Highlight: Non Basic ASCII
and those warning borders will go away.
Unicode Highlighting of certain features was added to vscode recently.

Remove here-doc syntax coloring on emacs

Hi is there a way to remove the here-doc syntax highlighting in emacs useing cperl-mode
It is highlighting the entire thing as a "String" which is technically correct but I do not want it to do that. When i program in pico/nano I make my own regular expressions to do syntax highlighting and it works great because it colors the here-docs like it colors the rest. It would be nice to learn how to create or where to insert my existing syntax highlighting regex's.
For example
print <<EOF;
This is not colored but "this is colored liek a string"
EOF
In emacs the entire thing is colored like a string which I dislike. How can i either turn here-doc syntax coloring off or edit the regular expressions directly like i do with pico?

Org-Mode Inline Code with Equals Signs

In org-mode, I want to give inline code with equals signs and quotation marks:
<div class="foo">
The way I would normally do this in org-mode is
=<div class="foo">=
When I export this to HTML, it gets rendered like this:
<div class"foo">=
What is the right way to do this inline (rather than just creating a source block)?
You could use verbatim markers, ~, instead:
~<div class="foo">~
The problem is that the equals sign after 'class' is interpreted as the closing code section delimiter. You can prevent this by inserting a space before the equals sign, like this:
=<div class = "foo">=
I wanted org-mode's source code to appear correctly in Github's parser. But, just as =:echo "hello"= would not appear correctly in Emacs, it also did not appear correctly in Github. However, I tried other characters with C-x 8 RET, and the LEFT DOUBLE QUOTATION MARK and RIGHT DOUBLE QUOTATION MARK work. That is,
=:echo “hello“=
appear successfully as
:echo “hello“
Unfortunately, I don't think they will actually work if copy-and-pasted into all environments. Vim gives E15: Invalid expression: “hello“. But then, how often do we paste commands into Vim's command line. Well, okay, there is :#".
After almost a decade, here's the correct answer:
Org's escape character is zero width space. When this character is inserted, Emacs will not interpret = as the end of the verbatim. Emacs can correctly interpret =<div class​="foo">=. Note that this string has an invisible zero width space character.
However, I think due to a bug, exports from org to other formats, will have this character and need to be removed manually. For example, the export of the string above to markdown will be `<div class​="foo">` which is what we want, except that it has an additional zero width space character.
It is not very hard to fix this. Removing all these additional characters can be easily done with replace-string command.
Tip: You can use C-x 8 RET (or insert-char command) and choose 200B to insert zero width space character inside Emacs.

Show trailing whitespace on emacs only on non-empty lines

Right now I'm using:
(setq show-trailing-whitespace t)
In my .emacs to show trailing whitespace for my CC mode. I can't seem to figure out how to have it not show the whitespace font for whitespace only lines.
Empty lines separating indenting code are sometimes indented at the code level and sometimes not indented at all, and I don't want to draw my attention to a line I don't care to change.
I'd like to stick to built-in emacs modules, but I'm willing to use whitespace.el but it's not clear how to configure it to do this.
Since you want to use built-in modules, I'd advise using the whitespace.el link you specified - as it is shipped with Emacs 23. This answer works when using that whitespace.
As long as you have 'trailing in your 'whitespace-style variable (which it is by default), the following change to the regular expression for what indicates "trailing" whitespace should give you what you want:
(setq whitespace-trailing-regexp
"\\b\\(\\(\t\\| \\|\xA0\\|\x8A0\\|\x920\\|\xE20\\|\xF20\\)+\\)$")
Note: It is just the default value, with the \b prepended, indicating that the whitespace should follow a word.
With
"\\b.*\\(\\(\t\\| \\|\xA0\\|\x8A0\\|\x920\\|\xE20\\|\xF20\\)+\\)$"
the word does not need to be directly in front of the trailing whitespaces but there can be e.g. punctuation characters between them (i.e. this also highlights trailing whitespaces behind non-word characters).
Edit:
Using
"\\b.*?\\(\\(\t\\| \\|\xA0\\|\x8A0\\|\x920\\|\xE20\\|\xF20\\)+\\)$")
highlights all the trailing whitespaces and thus eliminates the drawback mentioned in comment #1.