Auto-Editing in Wing IDE Pro

May 05, 2014
One way in which an IDE speeds up software development is through auto-editing operations. A common example found in almost every text editor is auto-entering ')' after the caret when '(' is pressed.

Wing IDE Professional takes this quite a bit further with a suite of operations that speed up the process of editing Python code. Some of these are disabled by default because they can be disconcerting to new users, but they are well worth exploring. This article explains how to use some of the more advanced auto-editing operations that Wing IDE Pro provides for Python.

If you want to try out each auto-editing operation while reading this, install Wing IDE Pro and Python and go into the Edit > Keyboard Personality menu and Configure Auto-Editing to turn on all the auto-editing operations.

Auto-Enter Invocation Args

This operation causes Wing to automatically insert function or method arguments when an invocation is started, so that you can more easily enter your invocation. For example, when you type getattr( Wing looks up the type of getattr and automatically places the arguments for it.  You would end up with getattr(object, name, default=None) in the editor, with the arguments selected.

At this point you can either over-type the selected arguments or tab through them to enter each one. For keyword arguments, tab order visits first the whole argument and then just the value. When you exit the invocation, Wing automatically removes any unaltered default values.

This operation also works if you are entering a def for a method that overrides an inherited method, so that the same arguments that exist in the inherited method are placed automatically.

If you tend to use uniform local variable and function/method argument names then the auto-entered arguments are often all you need. For example, typing self.MyMethod( might get you an invocation like self.MyMethod(path, filename, extend) that works as-is if the locals path, filename, and extend are defined. This can save a lot on typing and reduces opportunities for mistakes.

Here is an example of this feature in action:

Manage Blocks with Repeated Colon Presses

This auto-editing operation is disabled by default, but well worth trying out. It makes it easier to add new blocks (conditionals, loops, and so forth) and optionally applies them to existing code blocks.

When this operation is enabled, placing the caret above a block of existing code and typing if x: causes Wing to automatically place a newline and indent to prepare for input of a new line of code.

Pressing ':' a second time in this context, reformats the code so that the first line of code following the new block is placed under the conditional.

Pressing ':' a third time instead places the whole following block of contiguous lines under the conditional.  Reformatting stops at any blank line or indentation decrease.

Here is an example of this in action:

This auto-editing operation also works with for, try, except, else, while, with, and so forth -- anything that starts a new block.

Applying Keys to Selections

Another way to create new blocks of code is to select a range of lines and press the ':' key. This indents the existing lines and starts a new block. Now you can type if, for, or whatever other block type you want to create. Wing auto-inserts except when try is typed and selects except so it can be edited easily.  You can press Tab to move into the except (or finally) block.

You can also apply other keys to selections, such as '(', '[', or '[' to surround text with '()', '[]', or '[]', press quotes to create strings, or '#' to toggle whether something is commented out. These can be enable or disabled independently from the Editor > Auto-Editing preferences group.

Here this an example of this:


Auto-Enter Spaces

This auto-editing operation is also off by default since it can take some getting used to. When enabled with the Editor > Auto-Editing > Auto-Enter Spaces preference, Wing automatically inserts spacing in a way that conforms to PEP8 style spacing. For example, if you type x=1, Wing will enter x = 1.

With the Enforce PEP8 Style Spacing sub-option enabled, Wing protects against adding extra spaces when you press the space bar.

The Spaces in Argument Lists sub-option lets you override whether to use PEP8 style spaces for arguments. That's probably the most contentious part of PEP8, so we provided an separate option for it.

Notice that the auto-completer also places spacing when this auto-editing operation is enabled.  Together with Wing's auto-indent feature and the fact that Wing matches indentation style in existing files, the user is freed most of the time from having to worry about spacing.

Here is an example of this feature in action:


Correct Out-of-Order Typing

When this auto-editing operation is enabled, Wing recognizes some types of out-of-order typing and adjusts them automatically.  For example, typing def x(a,b:) enters def x(a, b): plus a new line and indentation.  Similarly x(,) is converted to x(),

Here is an example of these operations:

That's it for now.  Next time we'll take a detailed look at Wing's autocompleter and Source Assistant.

We're continuously adding to Wing's auto-editing capabilities.  If you have auto-editing features you would like to see, or have any questions about the existing features, please email us at support@wingware.com.

Share this article:

Auto-Editing in Wing IDE Pro