Sublime Forum

How to show UTF-8 line separator character, which is currently not displayed

#1

Update:

How can I display UTF-8 “unprintable” characters like the Line Separator character when viewing files in Sublime, so that I know the characters are there. Currently, it just does not display them.


Original:

When Sublime Text v3.2.1 Build 3207 on Mac displays code containing a string with an embedded newline, it does not show the newline or wrap the string at the newline’s position. For example, in basic TextView on Mac, I see the following, where the embedded newlines actually cause a line break in the “text” element of this label:

            <label opaque="NO" userInteractionEnabled="NO" tag="1001" contentMode="left" 
horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Your device is currently OFF.
Turn your device back on to
prevent loss of relief. " textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" 
baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" 
translatesAutoresizingMaskIntoConstraints="NO" id="2ic-aD-F5p">

But in Sublime it is hiding the newlines (which are actually pretty important):

How do I get it to either wrap the string at the newline onscreen or else show a special character there.

Note: I do NOT want to see every newline in the file, just the ones inside strings. All my searches on this topic end up at answers to questions about newlines in general, and not those within strings.

0 Likes

#2

Isn’t all text in the screenshot 34th line? What is the “hidden newline” or “embedded newline” in the screenshot?

0 Likes

#3

There is no indication at all that there are newlines within the text inside the quotes.

There is no line break, and there is no character indicator like \n or ↵

There is just no way to tell there are newlines there.

0 Likes

#4

It’s a single line, the 34th line. If there is 35th line, then 34th has an EOL.

True.

0 Likes

#5

The issue is that it is hiding file content for no reason. It’s true it is a single line, but the string has characters in it that Sublime Text is choosing not to show, which is not useful. For reference, in C/C++, the string would be:

"Your device is currently OFF.\nTurn your device back on to\nprevent loss of relief. "

There are embedded newlines. These are correctly seen in other editors like TextView and in XCode.

I agree the line should only have one line number but it should either display it as something like:

34    text="Your device is currently OFF.↵Turn your device back on to↵prevent loss of relief. "

or

34    text="Your device is currently OFF.
Turn your device back on to
prevent loss of relief. "

To actually show the newline characters that are not at the end of the line.

Why is it hiding the inline characters?

0 Likes

#6

I cannot get your point.

34    text="Your device is currently OFF.↵Turn your device back on to↵prevent loss of relief. "

What is this? You call this one line? Or two lines?

  • If one line, what’s ? Isn’t it a newline char according to your definition? What’s the difference between and \n?
  • If two lines, why they are all in line 34?

Is there a misunderstanding among raw string \n, newline (printed) and ?

What’s the definition of the “line counts”? In the text editor? In the execution result?
I feel they are mixed in the above discussion.

1 Like

#7

It’s a string containing a literal newline character within it. Since it is within the string, it does not cause a logical new line for the language that interprets it, which is probably why Sublime is not creating a new line, but it is a problem that it’s hiding the character.

and \n are just different ways of visually showing the same thing; some editors show literal newlines using the C-like “\n” two character sequence, but some show a single character like “↵”.

0 Likes

#8

I don’t think ST is hiding anything. Are you sure they are copied as-is? Can you paste them in a text editor which you think the result is correct and save it into a file and then make it public available on somewhere like github?

I think you are mixing concepts between execution result and raw source code.

The string is printed as two lines if you execute the compiled binary. But in the code in editor is in the same line as you write it in one line. Isn’t it?

Take your C-like as an example,

1 #include <iostream>
2
3 using namespace std;
4
5 int main (int argc, char *argv[]) {
6     cout << "hello\nworld!" << endl;
7     return 0;
8 }

It prints two lines after execution.

hello
world!

But in the text editor, it’s one line just because you write it in one line.

6   cout << "hello\nworld!" << endl;
0 Likes

#9

Can you share a sample file with this so-called newline character? I suspect it’s not a line feed but something like a line separator or a similar non-ascii character, which ST does not handle.

0 Likes

#10

I dumped the bytes with a C program, and you’re correct; it’s actually the UTF-8 Line Separator /0xE2 80 A8/

Sorry for the confusion.

(Still wish it displayed it instead of hiding it.)

1 Like

#11

I think it can be visualized by writing a plugin using inline phantom. Although I am do not know how st decides to render a char or not.

I just copied a Line Separator from https://unicode-table.com/en/2028/.

And it’s shown as a block in my ST
image
Maybe related to ST’s font rendering mechanism. I am not sure…

0 Likes

#12

The Gremlins package will show these

3 Likes

#13

Gremlins will show a helpful mark in the gutter, but not a character in the text itself. This is better than no indication, so thank you for pointing out this package! There are also commands added to ‘Find’ the next invisible character, which are helpful, but if quickly scanning the text then it is still easy to miss these characters.

image

0 Likes

#14

Yes, seeing a representation of a new line in a string is really important in debugging C++ text handlers such as ISRs. The symbol used is not so important as the fact that something shows you that it’s there. Wish there was something in ST 3.2.1
In fact there’s a lot more than just line feeds to account for(CR,HT,VT,etc.). It would be good to show a white space that when moused over reveals the hex or decimal character present. It should also be possible to insert a non-printing character by hex/dec value.

1 Like

#15

I may make a plugin to visualize them with phantoms with data from https://github.com/redoPop/SublimeGremlins/blob/master/Gremlins.py#L12-L32 when I am available.

2 Likes

#16

So, a working version is here.

It works like the following screenshot. It adds a phantom at the position of an invisible char.
When your cursor is put on an invisible char, its information will be shown in a popup.
image


Due to the long period of code reviewing for publishing it on Package Control, you may use a custom repository to install it which is mentioned in the readme.

4 Likes

#17

Amazing! Works great! Thank you very much for creating this!

1 Like

#18

Just a FYI, https://packagecontrol.io/packages/Highlight%20Dodgy%20Chars may work simpler for you if you are writing in Latin more.

Source from https://www.reddit.com/r/SublimeText/comments/d03456/a_package_i_wish_id_known_about_earlier/.

0 Likes

#19

This will be addressed in the next release.

0 Likes