0

I'm using the default setting. I'm looking for a simple legend that says 'this color means that' or 'comments are blue, functions are green', whatever. I'd think the need for this would be painfully obvious to all but I can't find it (the gedit help is useless).

Also, from looking around, it seems there is a way to set my own color scheme, but how would I know I got all the possible terms and forms colorized? Is there a list of those somewhere?

For example, I don't want to miss strings and functions and have them both end up black and thus I'm not getting the benefit of syntax highlighting - which I guess I'm not anyway since I don't know what all the colors I'm looking at now mean anyway.

Thanks.

edit/update

@ Maythux Doesn't this apply only to gedit itself, and not Python? I made a text file and saved it with a .py extension. For example:

import this:  | 'import' is purple  <br/>
var = some_variable  | both sides of the equation are black <br/>
'This is a string'  | It is pink  <br/>
for is a special word, so is in  | 'for', 'is', 'is', and 'in' are all blood red  <br/>
"""This is still a string"""   | Triple quotes are pink <br/>
# This is a comment | but this string is dark blue  <br/>  

Where are these color rules coming from, and where is the legend that explains what color means what? ps - I hate markdown

2 Answers 2

3

I realize I'm quite late to the party, but I had a similar issue and this thread was the first that popped up. So I thought I would add a thorough answer explaining what is going on.

The best documentation I found for how the highlighting works is the documentation for GTKSourceView (, which is what Gedit uses for highlighting): https://www.manpagez.com/html/gtksourceview/gtksourceview-3.12.2/ch02.php But it doesn't answer OP's question directly.

So to answer OP's question more directly. I don't know of a simple list, but you can find the information you are looking for if you know a bit about how the highlighting works.

There are two important parts to how the highlighting works:

  1. The .lang file (there is one for each supported programming language), which defines how Gedit (or rather GTKSourceView) should understand the syntax of the programming language. i.e. in python.lang it is defined, that # marks a comment, "for", "if" and "else" are keywords, '...' is a string and so on.

  2. The color scheme then tells Gedit how to color a generic comment, a generic keyword and so on, based on how comments, keywords, strings and so on are defined in the .lang file of the language you are currently using.

What language you are using is specified in the bottom of Gedit: Language selection dialog currently python (2.x)

What color scheme you are using is set under: menu -> preferences -> Font and Colors -> Color Scheme Color Scheme dialog

The .lang files are (probably) found in:

/usr/share/gtksourceview-3.0/styles/language-specs

or

/usr/share/gtksourceview-4/styles/language-specs

depending on your version of GTK.

and the The color scheme/styles are in:

/usr/share/gtksourceview-3.0/styles/

or

/usr/share/gtksourceview-4/styles/

again depending on your version of GTK.

So to answer OP's question. You would go to the .lang file for the language you are interested in e.g. python.lang or python3.lang. There at the top you will find a list of styles looking like:

    <style id="keyword"           name="Keyword"               map-to="def:keyword"/>

This says, that the coloring style for python keywords (which are defined later in the python.lang file) should be colored in the same way as "def:keyword", which is the is the default for keywords in any supported language ("def" for default, def: refers to the default styles which are found in def.lang).

The definition of what a keyword in python is can then be found later if you search for 'style-ref="keyword"' in a block like:

<context id="keywords" style-ref="keyword">
  <keyword>and</keyword>
  <keyword>assert</keyword>
  ...

Here 'id="keywords", means that the following entries are what we define as python keywords, 'style-ref="keyword" means that the things listed bellow should be colored with the python keyword coloring style, and then it lists the keywords: "and", "assert", "if", "for" and so on.

Now we know from the .lang files what the different styles are called and what is colored with which styles. Now we can specify in the color scheme which actual colors to use for all the abstract styles, that has been defined in the .lang files.

In the color theme files e.g. tango.xml you will find lines like:

  <style name="def:keyword"                 foreground="#0000ff"/>

"def:keyword" is the default keyword style which is used to color things according to the .lang files. and 'foreground="#0000ff" means, that the text will be colored with the RGB hex value 00-00-ff - i.e. pure blue.

This will color the python keywords blue, since the keyword style defined in python.lang was mapped to def:keyword which we now declared should be blue.

It should also color keywords from all other languages blue (so long as they are also mapped to def:keyword in their .lang file).

You can also specify a color for the python keywords specifically, by writing:

  <style name="python:keyword"                 foreground="#00ff00"/>

where the part part before the colon is the id of the language (written at the top of the .lang file) and the part after the colon is the name of the style in that .lang file.

The styles which are not given a color, will be decided by your default color theme for Gnome/Ubuntu in a way, that I sadly do not understand ¯_(ツ)_/¯

1
  • Never let it be said that it is too late for a good answer. Thanks. Dec 12, 2021 at 2:32
2

This is related to which color scheme you choose in Font & color prefrences of your gedit. For me I choose Classic

enter image description here

Now to see how it highlights open the xml of the color scheme

gedit /usr/share/gtksourceview-3.0/styles/classic.xml 

Here is a sample of output:

<!-- Bracket Matching -->
  <style name="bracket-match"               foreground="#white" background="#grey" bold="true"/>
  <style name="bracket-mismatch"            foreground="#white" background="#red" bold="true"/>

  <!-- Search Matching -->
  <style name="search-match"                background="yellow"/>  

  <!-- Comments -->
  <style name="def:comment"                 foreground="blue"/>
  <style name="def:shebang"                 foreground="blue" bold="true"/>
  <style name="def:doc-comment-element"     italic="true"/>

Then you can know that grey color is used for bracket matching and blue color for comments and yellow for search, etc...

You can check the other schemes from their xml files founded in the path:

/usr/share/gtksourceview-3.0/styles/

Also, as a hint you can use this xml to change the colors as you like so you can customize each scheme to your needs or likes

3
  • Thanks, but - and maybe I'm being dense here - I don't see how this answers my question. I got the xml file as you suggested, but as near as I can tell this is only telling me about the color scheme of gedit generally. It does not tell me how Python specifically is color coded. For example, I made up a little text file, saved it with a .py extention, and this is what I got: import this: var = some_variable 'This is a string' for is a special word, so is in """This is still a string""" # This is a comment Jun 12, 2015 at 17:21
  • The color schemes is applied whatever your programming language in gedit. Those are the highlighting colors. This is exactly what you asked about. If this is not the case then please edit your question and enter more details to make it understandable
    – Maythux
    Jun 13, 2015 at 5:01
  • I don't know why but we are not understanding each other. You think that xml file answers my question, but I don't see it at all. I don't know what else to say or do about this. Jun 16, 2015 at 2:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .