<type>documentation</type>
<domain>intro</domain>
<id>tutorial-editor</id>
<title>Tutorial: Introduction to the Editor</title>
<date>$Date$</date>
<product>per+</product>

Now that you have set up your project, Wing will have found and analyzed the tutorial
examples, and all the modules that are imported and used by them. This analysis process
runs in the background and is used to provide auto-completion, call tips, goto-definition,
code warnings, and other editing and navigation features. With larger code bases, you may
notice the CPU load from this process, and Wing will indicate that processing is active by
displaying ``Analyzing Files`` in the status area at the bottom left of the main IDE
window:

.. image:: analysis-status.png
  :width: 406
  :height: 26

However, with this tutorial analysis will have happened instantaneously after the project
was configured.

**Editing with Wing**

~~~if WINGPRO:
Let's start by trying out a subset of Wing's editor features, focusing on the
auto-completer, ``Source Assistant``, and some of Wing's auto-editing operations.
~~~
~~~if not WINGPRO:
Let's start by trying out a subset of Wing's editor features, focusing on the
auto-completer and ``Source Assistant``.
~~~

Open the file ``example1.py`` from the ``Project`` tool. Then bring up the `Source
Assistant <script:show_panel#panel_type="source-assistant">`__ from the Tools menu or
by clicking on its tab. This is where Wing shows documentation, call signature, and other
information as you move around in your source code or work with other tools.

Scroll down to the bottom of ``example1.py`` and enter the following code by typing (not
pasting) it into the file:

.. python::
  
  news = Rea
  
Wing displays a context-sensitive auto-completer as you type. You can scroll around in the
list with the arrow keys, type ``Esc`` or ``Ctrl-G`` to abort completion, or ``Tab`` to
enter the currently selected completion.

If you are used to using the ``Enter`` key for auto-completion, add it to the `Editor >
Auto-Completion > Completion Keys
<script:show_preferences_gui#prefname="edit.autocomplete-keys">`__ preference now.

When you first typed "news" this completer wasn't helpful because you had not yet defined
``news`` as a symbol in your source. However, once you move on to type ``= Re``, Wing
displays another completion list with ``ReadPythonNews`` highlighted. Notice that the
``Source Assistant`` updates to show call information for that function, or for whatever
symbol is selected in the auto-completer:

.. image:: autoc-sassist.png
  :width: 715
  :height: 527

~~~if WINGPRO: 
Next, press ``Tab`` to enter the completion of ``ReadPythonNews`` and type ``(`` (left
parenthesis). In Wing Pro, you should now see the following code in your editor because
Wing auto-enters the argument list and closing parenthesis:

.. image:: auto-arg-entry.png
  :width: 335
  :height: 23
  
Notice that when Wing Pro auto-enters arguments, it starts with all arguments selected so
you have the option of simply typing over them. Alternatively, the ``Tab`` key can be used
to move between and replace arguments or just the default value in keyword arguments (like
``force`` in this example). When argument entry is completed by pressing ``)`` at the end
of the list or by moving the caret out of the list, Wing automatically removes any keyword
arguments with unaltered defaults.

Try this a few times now to get a feel for how the tab order works. ``Undo`` can be used
to easily undo all changes made during argument entry. If you prefer not to use this
feature, it can be turned off with the `Editor > Auto-Editing > Auto-Enter Invocation Args
<script:show_preferences_gui#prefname="edit.auto-edit-invoke">`__ preference. The same
preferences page can be used to disable auto-editing entirely or to enable and disable
other operations. The default set of enabled auto-editing operations are those that should
not interfere significantly with finger memory. The other operations will be described
later.

Now edit the code you have entered so it reads as follows and the caret is inside the
``()``:

.. python::

  news = ReadPythonNews()  
~~~

~~~if WINGPER:
Next, press the ``Tab`` key to enter the completion of ``ReadPythonNews`` and enter ``(``.
You should now have the following code in the editor:

.. python::

  news = ReadPythonNews(
  
If you are used to using the ``Enter`` key for auto-completion, add it to the `Editor >
Auto-completion > Completion Keys
<script:show_preferences_gui#prefname="edit.autocomplete-keys">`__ preference now.
~~~

Then type ``Get`` to start entering arguments for your invocation of ``ReadPythonNews``.
You will see the ``Source Assistant`` alter its display to highlight the first argument in
the call signature for ``ReadPythonNews`` and add information on the argument's completion
value:

.. image:: call-tips.png
  :width: 715
  :height: 527

The docstring for ``ReadPythonNews`` is temporarily hidden to conserve screen space. This
behavior can be toggled with the ``Show docstring during completion`` option in the
``Source Assistant``'s right-click context menu.

Now continue entering the rest of the line so you have the following complete line of
source code:

.. python::

  news = ReadPythonNews(GetItemCount())

~~~if WINGPRO: 
Notice that typing a close parenthesis at the end of the invocation in Wing Pro skips over
the close parenthesis that was previously auto-entered.
~~~

To play around with the editor a bit more, enter the following additional
lines of code:

.. python::

  PrintAsText(news)
  PromptToContinue()
  PrintAsHTML(news)

At this point you have a complete program that can be run in the debugger. Don't try it
yet, however. It contains some deliberate bugs and first we should take a look at some of
Wing's code navigation features.

