Repository: spyder-ide/spyder

Issue:
Missing "magic" key for custom color schemes
<!--- **PLEASE READ:** When submitting here, please ensure you've completed the following checklist and checked the boxes to confirm. Issue reports without it may be closed. Thanks! --->

### Issue Report Checklist

* [x] Searched the [issues page](https://github.com/spyder-ide/spyder/issues?q=is%3Aissue) for similar reports
* [ ] Read the relevant sections of the [Spyder Troubleshooting Guide](https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ) and followed its advice
* [ ] Reproduced the issue after updating with ``conda update spyder`` (or ``pip``, if not using Anaconda)
* [ ] Could not reproduce inside ``jupyter qtconsole`` (if console-related)
* [ ] Tried basic troubleshooting (if a bug/error)
    * [x] Restarted Spyder
    * [ ] Reset preferences with ``spyder --reset``
    * [ ] Reinstalled the latest version of [Anaconda](https://www.anaconda.com/download/)
    * [ ] Tried the other applicable steps from the Troubleshooting Guide
* [x] Completed the **Problem Description**, **Steps to Reproduce** and **Version** sections below


## Problem Description
After PR #11101, Spyder refuses to launch because of custom color schemes created before that PR have not the `magic` key (as specified [here](https://github.com/spyder-ide/spyder/blob/4ee7fb3dc8e5794dd5bc88070f6b5195a0e07fa1/spyder/utils/syntaxhighlighters.py#L75)) in their configs. So, when `get_color_scheme` is iterating over scheme keys, it will fail when reaching the `magic` key as it does not exist.
This issue can be workaround by adding the missing field manually in `spyder.ini`.

### What steps reproduce the problem?

1. Create a custom scheme before #11101 and check it is selected
2. Pull changes with #11101
3. Open Spyder

### What is the expected output? What do you see instead?
Spyder refuses to launch with the following traceback.

### Paste Traceback/Error Below (if applicable)
<!--- Copy from error dialog or View > Panes > Internal Console --->

```python-traceback

Traceback (most recent call last):
  File "bootstrap.py", line 239, in <module>
    start.main()
  File "/home/Public/spyder/spyder/app/start.py", line 227, in main
    mainwindow.main(options, args)
  File "/home/Public/spyder/spyder/app/mainwindow.py", line 4073, in main
    mainwindow = create_window(app, splash, options, args)
  File "/home/Public/spyder/spyder/app/mainwindow.py", line 3930, in create_window
    main.setup()
  File "/home/Public/spyder/spyder/app/mainwindow.py", line 1212, in setup
    self.editor = Editor(self)
  File "/home/Public/spyder/spyder/plugins/editor/plugin.py", line 227, in __init__
    self.editorsplitter = EditorSplitter(self, self,
  File "/home/Public/spyder/spyder/plugins/editor/widgets/editor.py", line 3133, in __init__
    self.register_editorstack_cb(self.editorstack)
  File "/home/Public/spyder/spyder/plugins/editor/plugin.py", line 1378, in register_editorstack
    color_scheme = self.get_color_scheme()
  File "/home/Public/spyder/spyder/api/plugins.py", line 380, in get_color_scheme
    return super(BasePluginWidget, self)._get_color_scheme()
  File "/home/Public/spyder/spyder/plugins/base.py", line 446, in _get_color_scheme
    return get_color_scheme(CONF.get('appearance', 'selected'))
  File "/home/Public/spyder/spyder/config/gui.py", line 114, in get_color_scheme
    color_scheme[key] = CONF.get("appearance", "%s/%s" % (name, key))
  File "/home/Public/spyder/spyder/config/manager.py", line 228, in get
    return config.get(section=section, option=option, default=default)
  File "/home/Public/spyder/spyder/config/user.py", line 976, in get
    return config.get(section=section, option=option, default=default)
  File "/home/Public/spyder/spyder/config/user.py", line 513, in get
    raise cp.NoOptionError(option, section)
configparser.NoOptionError: No option 'custom-0/magic' in section: 'appearance'
```

## Versions
<!--- You can get this information from Help > About Spyder...
or (if Spyder won't launch) the "conda list" command
from the Anaconda Prompt/Terminal/command line. --->

* Spyder version: 4.3.0dev0
* Python version: 3.8.5
* Qt version: 5.15.2
* PyQt version: 5.14.1
* Operating System name/version: Linux 5.4.0-58-generic


Discussion:
Hi @trollodel thank you for the feedback! Probably we need to add a default value in the case the new config key doesn't exits. We will checking this for a future release. Also, if you have an idea of how to fix this let us know :)

Resolving patch:
diff --git a/spyder/config/gui.py b/spyder/config/gui.py
--- a/spyder/config/gui.py
+++ b/spyder/config/gui.py
@@ -111,7 +111,10 @@ def get_color_scheme(name):
     """Get syntax color scheme"""
     color_scheme = {}
     for key in sh.COLOR_SCHEME_KEYS:
-        color_scheme[key] = CONF.get("appearance", "%s/%s" % (name, key))
+        color_scheme[key] = CONF.get(
+            "appearance",
+            "%s/%s" % (name, key),
+            default=sh.COLOR_SCHEME_DEFAULT_VALUES[key])
     return color_scheme
 
 
diff --git a/spyder/utils/syntaxhighlighters.py b/spyder/utils/syntaxhighlighters.py
--- a/spyder/utils/syntaxhighlighters.py
+++ b/spyder/utils/syntaxhighlighters.py
@@ -75,6 +75,26 @@
     "magic":          _("Magic:"),
 }
 
+COLOR_SCHEME_DEFAULT_VALUES = {
+    "background":  "#19232D",
+    "currentline": "#3a424a",
+    "currentcell": "#292d3e",
+    "occurrence":  "#4734b3",
+    "ctrlclick":   "#179ae0",
+    "sideareas":   "#222b35",
+    "matched_p":   "#0bbe0b",
+    "unmatched_p": "#ff4340",
+    "normal":     ("#ffffff", False, False),
+    "keyword":    ("#c670e0", False, False),
+    "builtin":    ("#fab16c", False, False),
+    "definition": ("#57d6e4", True, False),
+    "comment":    ("#999999", False, False),
+    "string":     ("#b0e686", False, True),
+    "number":     ("#faed5c", False, False),
+    "instance":   ("#ee6772", False, True),
+    "magic":      ("#c670e0", False, False),
+}
+
 COLOR_SCHEME_NAMES = CONF.get('appearance', 'names')
 
 # Mapping for file extensions that use Pygments highlighting but should use


Test patch: