Repository: spyder-ide/spyder

Issue:
Problem when closing a project
## Description

### What steps will reproduce the problem?

<!--- You can use Markdown here --->

I have create a project using an existing folder. I worked with the project a while and then decided to switch over to another project. So used Projects|Close. The Issue reporter popped up immediately after that operation.

### Traceback
```python-traceback
  File "C:\ProgramData\Anaconda37\lib\site-packages\spyder\plugins\projects\plugin.py", line 171, in <lambda>
    lambda v: self.main.editor.setup_open_files())
  File "C:\ProgramData\Anaconda37\lib\site-packages\spyder\plugins\editor\plugin.py", line 2810, in setup_open_files
    self.load(filenames[index], goto=clines[index], set_focus=True)
IndexError: list index out of range
```

## Versions

* Spyder version: 4.0.1 
* Python version: 3.7.4
* Qt version: 5.9.6
* PyQt5 version: 5.9.2
* Operating System: Windows 10

### Dependencies

```
atomicwrites >=1.2.0         :  1.3.0 (OK)
chardet >=2.0.0              :  3.0.4 (OK)
cloudpickle >=0.5.0          :  1.2.2 (OK)
diff_match_patch >=20181111  :  20181111 (OK)
intervaltree                 :  None (OK)
IPython >=4.0                :  7.8.0 (OK)
jedi =0.14.1                 :  0.14.1 (OK)
nbconvert >=4.0              :  5.6.0 (OK)
numpydoc >=0.6.0             :  0.9.1 (OK)
pexpect >=4.4.0              :  4.8.0 (OK)
pickleshare >=0.4            :  0.7.5 (OK)
psutil >=0.3                 :  5.6.3 (OK)
pygments >=2.0               :  2.4.2 (OK)
pylint >=0.25                :  2.4.2 (OK)
pyls >=0.31.2;<0.32.0        :  0.31.9 (OK)
zmq >=17                     :  18.1.0 (OK)
qdarkstyle >=2.7             :  2.8 (OK)
qtawesome >=0.5.7            :  0.6.0 (OK)
qtconsole >=4.6.0            :  4.7.2 (OK)
qtpy >=1.5.0                 :  1.9.0 (OK)
rtree >=0.8.3                :  0.9.3 (OK)
sphinx >=0.6.6               :  2.2.0 (OK)
spyder_kernels >=1.8.1;<2.0.0:  1.8.1 (OK)
watchdog                     :  None (OK)
cython >=0.21                :  0.29.13 (OK)
matplotlib >=2.0.0           :  3.1.1 (OK)
numpy >=1.7                  :  1.16.5 (OK)
pandas >=0.13.1              :  0.25.1 (OK)
scipy >=0.17.0               :  1.3.1 (OK)
sympy >=0.7.3                :  1.4 (OK)
```



Discussion:
Thanks for reporting @StephanSchwebel!

@dalthviz, I think this can happen when the last focused file of a project is not part of the project anymore. So when trying to load it, we get this error.

Resolving patch:
diff --git a/spyder/plugins/editor/plugin.py b/spyder/plugins/editor/plugin.py
--- a/spyder/plugins/editor/plugin.py
+++ b/spyder/plugins/editor/plugin.py
@@ -2872,7 +2872,9 @@ def setup_open_files(self):
             # spyder-ide/spyder#8458.
             if layout:
                 is_vertical, cfname, clines = layout.get('splitsettings')[0]
-                if cfname in filenames:
+                # Check that a value for current line exist for each filename
+                # in the available settings. See spyder-ide/spyder#12201
+                if cfname in filenames and len(filenames) == len(clines):
                     index = filenames.index(cfname)
                     # First we load the last focused file.
                     self.load(filenames[index], goto=clines[index], set_focus=True)


Test patch: