Sublime Forum

Sublime Text not recognizing curly braces

#1

Hi,

I’m trying to make a post on my website using django. I’m trying to use curly braces but it seems that sublime text is not recognizing them - I get red in the column telling me that I’m doing something wrong but I don’t know what it is. At first I thought it was because I had it set to use python so I changed it to automatic but that did not help.

Thanks in advance.

0 Likes

#2

The color of text is controlled by a combination of your color scheme and the syntax (type) of the file. In the bottom right of the window, the status bar tells you what it thinks the type of the current file is. For example, a newly created tab will have the type Plain Text displayed there.

Your situation sounds like the type of file that you’re working with is not set/inferred correctly.

0 Likes

#3

I don’t really understand what you mean by that, could you explain further? This is my code that has the curly braces:

from django.shortcuts import render

posts = [
    {
        'author': 'CoreyMS',
        'title': 'Blog Post 1',
        'content': 'first post content',
        'date_posted': 'August 27, 2018'
    },
    {
        'author': 'Jane Doe',
        'title': 'Blog Post 2',
        'content': 'Second post content',
        'date_posted': 'August 28, 2018'

    }


]
0 Likes

#4

There are many types of files that you can edit, but they don’t all have the same rules for what is valid and what is not. So it’s vital that you tell Sublime what kind of file that you think you’re editing so that it knows what to expect. There are many ways to do that but the most common way is to name the file appropriately.

Here’s what your content looks like in my Sublime; note the type of file that it thinks it is:

image

So first off, the way the content of the file is interpreted is, here, specific to Python. The result is different if Sublime thinks this is supposed to be Ruby code, for example.

Secondarily, the colors you see here may not mimic what you actually see, which would be because we use different color schemes. The syntax definition (here Python) tells Sublime how to interpret the contents of the file, and the color scheme (here Mariana) tells Sublime what color to use for each part of the file.

Seeing Red somewhere is usually an indication of two things:

  1. You happen to have a color scheme that someone has created to think parts of your file are supposed to be red (just as here parts of this are green). If that’s the case, then there’s not an issue and changing the color scheme would change the color

  2. The syntax definition knows that the content of the file is, based on the rules of the language as it understands them, not correct. In such a case, depending on your color scheme you could see red or some other color as an indication to you that thinks don’t appear correct:

image

Here the file is visibly broken; there’s a missing ' so the string is not terminated. The syntax definition thinks that is wrong and the color scheme thinks it should display that as this red background color, so it does as a hint to you to that it’s broken.

So, what if the color is displaying like this but the file content doesn’t seem to actually be wrong? If the file type is wrong, the rules being applied are wrong and all bets are off. Or, perhaps the file content is correct but the syntax rules don’t know it or are somehow broken. In that case it’s displaing as wrong but actually isn’t, so everything is fine and in that case you would report the error to the author to fix.

At the end of the day, Sublime is just an editor for text with a bunch of smart bells and whistles, but all it’s doing is editing the text; if the content is correct, regardless of what it looks like, it will still work.

This is the same sort of situation as your car; it’s for taking you from one place to another, but it cares not where you are going or what you’re going to do when you get there. It just transports you along.

0 Likes