Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overhaul Editor doc with many new sections and screenshots #331

Merged
merged 30 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2391ed0
Add new content about some of the Editor main features
hyounes4560 Oct 5, 2022
7cfadb1
Add some images to the editor doc
hyounes4560 Oct 10, 2022
f379e0a
Add more images/GIF to the editor doc
hyounes4560 Oct 11, 2022
d611978
Fix a few instances of missing OSPL line breaks
CAM-Gerlach Oct 12, 2022
5b52275
Standardize heading characters and spacing
CAM-Gerlach Oct 12, 2022
0700b93
Clean up stray special characters left over from Google Docs conversion
CAM-Gerlach Oct 12, 2022
a202623
Eliminate a handful of stray double spaces
CAM-Gerlach Oct 12, 2022
ca4ce73
Apply changes suggested by Stephannie, & a few inspired by them
CAM-Gerlach Oct 12, 2022
e0636a8
Apply additional minor syntax, formatting and textual tweaks
CAM-Gerlach Oct 12, 2022
4621f58
Optimize and tweak minor border cropping of added images
CAM-Gerlach Oct 12, 2022
798c4a3
Crop new Editor images to focus more carefully on their main subjects
CAM-Gerlach Oct 12, 2022
aa0394d
Flatten run section headings to simplify structure
CAM-Gerlach Oct 12, 2022
233a0b3
Elide entirely unrelated material in Running Code introduction
CAM-Gerlach Oct 12, 2022
6038e69
Make bullet points more focused, concise, and consistent
CAM-Gerlach Oct 12, 2022
f90aac2
Describe more concisely how to run a file in the Editor
CAM-Gerlach Oct 12, 2022
b1da813
Correct 'Re-run last' to last file, move it accordingly & be more con…
CAM-Gerlach Oct 12, 2022
5e514ea
Unify the duplicated run line(s) sections and make more concise
CAM-Gerlach Oct 12, 2022
a204314
Add menu item for Run cell, fix shortcut & discuss run and advance op…
CAM-Gerlach Oct 12, 2022
a4a5c02
Describe run config more accurately, completely and concisesly
CAM-Gerlach Oct 12, 2022
106d1d7
Rename Find to Find/Replace, describe more concisely and add more det…
CAM-Gerlach Oct 12, 2022
c40af41
Describe Go to Line more concisely & with additional details
CAM-Gerlach Oct 12, 2022
f1cd0e6
Revise class/function selector text for conciseness, and add more det…
CAM-Gerlach Oct 12, 2022
2d93ac2
Make KB shortcuts section clearer, more accurate & much more concise
CAM-Gerlach Oct 12, 2022
c3dda6e
Update the editor.rst file and add gifs
hyounes4560 Nov 12, 2022
a45929c
Add reviewer feedback
hyounes4560 Nov 14, 2022
8ba0708
Apply Carlos' straightforward review suggestions on Editor doc
CAM-Gerlach Nov 15, 2022
4b33f01
Add screenshot of Editor run configuration dialog per Carlos' feedback
CAM-Gerlach Nov 15, 2022
1318c7b
Screenshot is of hover hints, not calltips per Carlos' feedback
CAM-Gerlach Nov 15, 2022
4711deb
Regenerate GIFs from source videos to larger 720 px target width
CAM-Gerlach Nov 15, 2022
0e05aa5
Perform final polish pass on Editor doc with trivial textual tweaks
CAM-Gerlach Nov 15, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/editor/editor-calltip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/editor/editor-code-completion.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/editor/editor-code-style-setting.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/editor/editor-file-switcher.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/editor/editor-file-switcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/editor/editor-find-replace-panel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/editor/editor-go-to-definition.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/editor/editor-go-to-line.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/editor/editor-linting-setting.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/editor/editor-pane-code-error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/editor/editor-split-panels.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/editor/editor-syntax-highlighting.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/editor/editor-tabs-browser.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/editor/editor-tabs-sorting.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
263 changes: 254 additions & 9 deletions doc/panes/editor.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ In addition, it integrates a number of powerful tools for an easy to use, effici
.. image:: /images/editor/editor-standard.png
:alt: Spyder's Editor panel, split horizontally and with style analysis



==============
Key components
==============
Expand All @@ -29,32 +31,275 @@ The Editor pane consists of the following areas:



===================
Defining code cells
===================
=========
Interface
=========

Tabs
~~~~

You can browse and navigate between open files in the Editor with tabs.
Click the :guilabel:`Browse tabs` button on the left of the tab bar to display a list of open files, with the active tab checked.

.. image:: /images/editor/editor-tabs-browser.png
:alt: Spyder's Editor pane, showing the tabs browser

Reorder files by dragging and dropping, or with :guilabel:`Sort tabs alphabetically` in the options menu, which also allows closing all tabs to the right of, or all tabs but the active one.

.. image:: /images/editor/editor-tabs-sorting.gif
:alt: Spyder's Editor pane, showing how to browse and sort open tabs alphabetically

File switcher
~~~~~~~~~~~~~

The Editor features a file switcher, which enables you to navigate and switch between multiple open files.
The file switcher is helpful for locating any file when there are several files opened.

.. image:: /images/editor/editor-file-switcher.png
:alt: Spyder's Editor pane, showing the file switcher

It can be accessed from the :menuselection:`File --> File Switcher` menu or :kbd:`Ctrl-P`, and includes a search function.
You can type in any part of an open file's name and—if exists—it can be switched to by pressing :kbd:`Enter`.

.. image:: /images/editor/editor-file-switcher.gif
:alt: Spyder's Editor pane, showing searching and switching to an existing file


Split panels
~~~~~~~~~~~~

The Editor can be split horizontally and vertically into as many distinct panels as desired.
This allows viewing and editing the contents of several files (or different parts of the same file) at the same time.

.. image:: /images/editor/editor-split-panels.gif
:alt: Spyder's Editor pane, showing how to split panels

Split the Editor with the :guilabel:`Split vertically` (:kbd:`Ctrl-Shift-{`) and :guilabel:`Split horizontally` (:kbd:`Ctrl-Shift--`) commands in the options menu, and use :guilabel:`Close this panel` (:kbd:`Alt-Shift-W`) to close the selected split panel.

.. note:: :menuselection:`Close this panel` closes a split panel, while :menuselection:`Close` hides the entire Editor *pane* (including all splits, which are restored when the Editor is re-opened).



================
Editing features
================

Syntax highlighting
CAM-Gerlach marked this conversation as resolved.
Show resolved Hide resolved
~~~~~~~~~~~~~~~~~~~

To improve the readability of your code, Spyder has a syntax highlighting feature that determines the color and style of text in the Editor, as well as in the :doc:`ipythonconsole`.

You can configure and preview syntax highlighting themes and fonts under :menuselection:`Preferences --> Appearance`.
The :guilabel:`Syntax highlighting theme` section allows you to change the color and style of the syntax elements and background to match your preferences.
You can switch between available themes in the drop-down menu, modify the selected theme, create a new theme, and more.
The :guilabel:`Fonts` section lets you change the text font and size.

.. image:: /images/editor/editor-syntax-highlighting.gif
:alt: Spyder's Editor panel, showing how to switch between syntax highlighting themes

.. note:: Changes made to the syntax highlighting theme and font settings are common to all source files, regardless of their language.


Code cells
~~~~~~~~~~

A "code cell" in Spyder is a block of lines, typically in a script, that can be easily executed all at once in the current :doc:`ipythonconsole`.
This is much like a "cell" in MATLAB (except without any need to enable a "cell mode", since in Spyder, cells are detected automatically).
This is similar to "cell" behavior in Jupyter Notebook and MATLAB.
You can divide your scripts into as many cells as needed, or none at all—the choice is yours.

.. image:: /images/editor/editor-cells.png
:alt: Spyder's Editor panel, showing an example of a code cell

You can separate cells by lines starting with either:

* ``#%%`` (standard cell separator)
* ``# %%`` (standard cell separator, when file has been edited with Eclipse)
* ``# %%`` (standard cell separator), or
* ``# <codecell>`` (IPython notebook cell separator)

Providing a description to the right of the separator will give that cell its own name in the :guilabel:`Outline Explorer`.
Providing a description to the right of the separator will give that cell its own name in the :doc:`outline`.
You can also create "subsections" by adding more ``%`` signs to the cell separator, e.g. ``# %%%`` to create a level 2 subsection, ``# %%%%`` for level 3, etc.
This displays multiple levels in the the :guilabel:`Outline Explorer`.
This displays multiple levels in the :doc:`outline`.
CAM-Gerlach marked this conversation as resolved.
Show resolved Hide resolved

.. image:: /images/editor/editor-subsections.png
:alt: Spyder outline panel, showing an example of sub sections

Note that this only affects how the outline is displayed; it has no impact on the functioning of the code cells.
.. note:: This only affects how the cell is displayed in the :doc:`outline`, and doesn't affect running it in the Editor.

To run the code in a cell, use :menuselection:`Run --> Run cell`, the :guilabel:`Run cell` button in the toolbar or the keyboard shortcut (:kbd:`Ctrl-Enter`/:kbd:`Cmd-Return` by default).
You can also run a cell and then jump to the next one, letting you quickly step through multiple cells, using :menuselection:`Run --> Run cell and advance` (:kbd:`Shift-Enter` by default).


Automatic formatting
~~~~~~~~~~~~~~~~~~~~

The Editor has built-in support for automatically formatting your code using several popular tools, including `Autopep8 <https://github.com/hhatto/autopep8>`_, `Yapf <https://github.com/google/yapf>`_, and `Black <https://black.readthedocs.io/en/stable/>`_.
CAM-Gerlach marked this conversation as resolved.
Show resolved Hide resolved
The :guilabel:`Format file or selection with {tool}` command in the :guilabel:`Source` or context menu will format either the selected fragment (if text is selected) or the entire active file.

.. image:: /images/editor/editor-automatic-formatting.gif
:alt: Spyder editor panel, showing an example of code selection formatting

You can have the Editor automatically autoformat a file every time you save your work.
To set this up, go to :menuselection:`Preferences --> Completion and linting --> Code style and formatting --> Code formatting` and check the :guilabel:`Autoformat files on save` option.

.. image:: /images/editor/editor-autoformat-setting.png
:alt: Spyder's preferences dialog, showing checking the autoformat files on save setting



============
Running code
============

The Editor lets you run an entire file as well as specific lines, selections or cells.

As your code is running,

* The :doc:`ipythonconsole` will display output and errors.
* The :doc:`variableexplorer` allows you to browse and interact with the objects generated.
* The :doc:`plots` pane renders the figures and images created.
* The :doc:`profiler` helps you optimize your code's run time.
CAM-Gerlach marked this conversation as resolved.
Show resolved Hide resolved


Run file
~~~~~~~~

Run an entire Editor file using the :menuselection:`Run --> Run` menu item, the :guilabel:`Run file` toolbar button or the :kbd:`F5` key.
Use :menuselection:`Run --> Re-Run last script` to re-run the most recent file executed with the above.


Run line/selection
~~~~~~~~~~~~~~~~~~

You can execute the current line—or multiple selected lines—using the :guilabel:`Run selection or current line` option from the toolbar or the :menuselection:`Run` menu, as well as with the :kbd:`F9` key.
After running the current line, the cursor automatically advances to the next, so you can step through your code line by line.
CAM-Gerlach marked this conversation as resolved.
Show resolved Hide resolved
Unlike :guilabel:`Run file`, the executed lines are shown in the :doc:`ipythonconsole`.


Code cells
~~~~~~~~~~

To run a cell, place your cursor inside it and use the :menuselection:`Run --> Run cell` menu item, the :guilabel:`Run current cell` toolbar button or the :kbd:`Ctrl-Enter` / :kbd:`Cmd-Return` keyboard shortcut.
Use :guilabel:`Run cell and advance` in the :guilabel:`Run` menu/toolbar or :kbd:`Shift-Enter` to jump to the next cell after running, useful for stepping through cells quickly.


Run configuration
~~~~~~~~~~~~~~~~~

You can use the :guilabel:`Run configuration per file` dialog to set each file's working directory, console mode (current, dedicated or external), CLI arguments, execution options (clear all variables, run in an existing/empty namespace, debug on error), and more.
CAM-Gerlach marked this conversation as resolved.
Show resolved Hide resolved
To access it, click :menuselection:`Run --> Configuration per file...` or press :kbd:`Ctrl-F6` / :kbd:`Cmd-F6`.



===============
Code navigation
===============

Find and replace
~~~~~~~~~~~~~~~~

To search for text in the current file, use :menuselection:`Search --> Find text` or :kbd:`Ctrl-F` / :kbd:`Cmd-F`, and to replace it, use :menuselection:`Search --> Replace text` or :kbd:`Ctrl-R` / :kbd:`Cmd-R`.
Typing your search string in the resulting panel below the Editor highlights each result and counts the total.
Navigate between matches with :guilabel:`Find Previous` and :guilabel:`Find Next` in the find/replace panel and the :guilabel:`Search` menu, or use the :kbd:`F2` and :kbd:`F3` keys.
CAM-Gerlach marked this conversation as resolved.
Show resolved Hide resolved
Use the :guilabel:`.*` button to process search text as a `regular expression <https://docs.python.org/3/library/re.html>`_, :guilabel:`Aa` to treat it as case-sensitive and :guilabel:`[–]` to only match whole words (e.g. for ``data``, match ``data()`` but not ``dataframe``).

.. image:: /images/editor/editor-find-replace-panel.png
:alt: Spyder's Editor pane, showing the find and replace panel


Go to line
~~~~~~~~~~

The :guilabel:`Go to line` dialog allows jumping to a specific line in the active file.
Open it with :menuselection:`Search --> Go to line` or :kbd:`Ctrl-L` / :kbd:`Cmd-L`, type the line you want and press :kbd:`Enter` (or click :guilabel:`OK`).
CAM-Gerlach marked this conversation as resolved.
Show resolved Hide resolved

.. image:: /images/editor/editor-go-to-line.gif
:alt: Spyder's Editor pane, showing the go to line feature

It also shows the current line number and total line count in the file.


Class/function selector
~~~~~~~~~~~~~~~~~~~~~~~

This panel, activated under :menuselection:`Source --> Show selector for classes and functions`, displays (as applicable) the name of the cell, function/method and class the Editor cursor is located inside.
Use its dropdowns to view and jump to the functions, methods and classes in the current file.

.. image:: /images/editor/editor-class-function-selector.gif
:alt: Spyder's Editor pane, showing the class and function selector panel


=============================
Code analysis and completions
=============================

Spyder uses the `Language Server Protocol <https://microsoft.github.io/language-server-protocol/>`_ (LSP) to provide code completion and linting for the Editor, similar to VSCode, Atom, and other popular editors/IDEs.
CAM-Gerlach marked this conversation as resolved.
Show resolved Hide resolved

.. note::

Many issues with completion and linting are outside of Spyder's control, and are either limitations with LSP or the code that is being introspected, but some can be worked around.
CAM-Gerlach marked this conversation as resolved.
Show resolved Hide resolved
See :ref:`code-completion-problems-ref` for troubleshooting steps.

Python is supported out of the box, and advanced users can add completion and linting support for other languages by setting up LSP servers for them under :menuselection:`Preferences --> Completion and Linting --> Other languages`.


Code completion
~~~~~~~~~~~~~~~

Automatic code completion as you type is enabled by default in the Editor, and can also be triggered manually with :kbd:`Ctrl-Space`/:kbd:`Cmd-Space`, showing you help, possible completions, and available code snippets.
CAM-Gerlach marked this conversation as resolved.
Show resolved Hide resolved
For example, typing ``cla`` will display the keyword ``class``, the decorator ``classmethod`` and two built-in snippets with class templates.
Select the desired completion with the arrow keys and :kbd:`Enter`, or by double clicking.

.. image:: /images/editor/editor-code-completion.png
:alt: Spyder's Editor pane, showing a code completion example

You can enable or disable on-the-fly code completion, as well as modify when it is triggered and what results are shown, under :menuselection:`Preferences --> Completion and Linting --> General --> Completions`.
Spyder also allows you to define custom completion snippets to use, in addition to the ones offered by LSP, under :menuselection:`Preferences --> Completion and Linting --> Advanced`.
CAM-Gerlach marked this conversation as resolved.
Show resolved Hide resolved


Linting and code style
~~~~~~~~~~~~~~~~~~~~~~

Spyder can optionally highlight syntax errors, style issues, and other potential problems with your code in the Editor, which can help you spot bugs quickly and make your code easier to read and understand.

.. image:: /images/editor/editor-pane-code-error.png
:alt: Spyder's Editor pane, showing an example of a highlighted code error

The Editor's basic linting, powered by `Pyflakes <https://github.com/PyCQA/pyflakes>`_, warns of syntax errors and likely bugs in your code.
It is on by default, and can be disabled or customized under :menuselection:`Preferences --> Completion and Linting --> Linting`.

.. image:: /images/editor/editor-linting-setting.png
:alt: Spyder's preferences dialog, showing linting settings

Code style analysis, powered by `Pycodestyle <https://pycodestyle.pycqa.org/en/stable/>`_, flags deviations from the style conventions in :pep:`8`.
CAM-Gerlach marked this conversation as resolved.
Show resolved Hide resolved
It is not active by default; you can enable it and customize the `pycodestyle error codes <https://pycodestyle.pycqa.org/en/stable/intro.html#error-codes>`_ shown with the options under :menuselection:`Preferences --> Completion and Linting --> Code style and formatting --> Code Style`.
CAM-Gerlach marked this conversation as resolved.
Show resolved Hide resolved

.. image:: /images/editor/editor-code-style-setting.png
:alt: Spyder's preferences dialog, showing code style and formatting settings


Introspection features
~~~~~~~~~~~~~~~~~~~~~~

If there's a function, class or variable that you want to jump to the definition of, :kbd:`Ctrl`/:kbd:`Cmd`-click its name in the Editor (or click its name and press :kbd:`Ctrl-G` / :kbd:`Cmd-G` to jump to the file and line where it is defined.
CAM-Gerlach marked this conversation as resolved.
Show resolved Hide resolved

.. image:: /images/editor/editor-go-to-definition.gif
hyounes4560 marked this conversation as resolved.
Show resolved Hide resolved
:alt: Spyder's Editor pane, showing the go to definition feature

If you type the name of a function, method or class constructor and then an open parenthesis, a calltip will pop up which shows the function's parameters as you type them, as well as a summary of its documentation.

.. image:: /images/editor/editor-calltip.png
CAM-Gerlach marked this conversation as resolved.
Show resolved Hide resolved
:alt: Spyder's Editor pane, showing an example of a calltip

Finally, you can also hover over the name of an object for pop-up help, as :ref:`described in the Help pane docs <help-hover-hints>`.
These features can be enabled and customized under :menuselection:`Preferences --> Completion and Linting --> Introspection`.



==================
Keyboard shortcuts
==================

To view the Editor's primary keyboard shortcuts, consult its section under :menuselection:`Help --> Shortcuts Summary`.
The full list can be browsed, searched and customized (on double-click) in :menuselection:`Preferences --> Keyboard shortcuts`.



Expand Down
1 change: 1 addition & 0 deletions doc/panes/help.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ The latter can be useful when docstrings are not available or insufficient to do
:alt: Spyder help pane showing different modes


.. _help-hover-hints:

========================
Getting help by hovering
Expand Down