3
votes

How can I set a custom syntax highlight color for python docstrings in atom? I would like to be able to use different colors for triple-quoted '''docstrings''' and single-quoted 'string'.

Follow-up, after trying suggestions from @FedericoBau:

I've deleted all but the built-in themes, and edited the stylesheet as per Federico's instructions. Results are shown in the screenshot below. Base theme is OneDark, unmodified except by changing ~/.atom/styles.less as shown in the screenshot. The docstrings are still shown the same as ordinary strings.

enter image description here

2
@katherineLong That's awesome. I added to my answer your reference so if someone in future need it can have the full picture. One thing if my answer helped you I suggest you to mark is as accepted so that your question can be removed from the not answered queue. thanks - Federico Baù

2 Answers

1
votes

Here is what should look like the JSON for Python Docs String:

atom-text-editor::shadow .string.quoted.double.block.python {
  color: #282a2e;

  // Quotes
  .punctuation.definition {
    // color: #282a2e;
  }
}

Important note

As suggested by Katharine Long, you should use Brunel-syntax, have a look at her answer here.


You may create you own theme or update an existing one.

Press Ctrl+Shift+P or ⌘ + ⌥ + P (macOS and start typing "Generate Syntax Theme" to generate a new theme package. Select "Generate Syntax Theme," and you'll be asked for the path where your theme will be created. Let's call ours motif-syntax.

Open a file written in the language that you want to specify the colors for in Atom.

If you want to do the same thing from the menu, go choosePackages > Command Palette > Toggle, and type log cursor scope into the Command Palette, which has just appeared, and select Editor: Log Cursor Scope.

If the above did not work try this other way. Go from the menu top left corner file, then click on style-sheet.

It will open a new style-sheet called base.less. Add the JSON below and save.


Documentation & Referance##

0
votes

After more experimentation, it seems this is done successfully in the Brunel-syntax theme when using MagicPython.

Most themes don't seem to recognize any syntactical distinction between strings, docstrings, etc, in which case nothing done to styles.less will color docstrings and ordinary strings differently.

To see how it's done, see the code in ~/.atom/packages/brunel-syntax/styles/syntax/python/magicpython/python.less.

This does what I was looking for, and I can adapt it for use in my own style. Here's how it looks:

enter image description here