Jun 24, 2014

Check out our new screencast, which shows some of the features of Wing IDE Professional version 5 in action:



Share this article:






May 23, 2014

In the previous blog post we talked about how auto-editing in Wing IDE Pro can be used to speed up writing and editing Python code. Now let's look at how the auto-completer works with other parts of the IDE to make coding easier.

Auto-completer Basics

By default, Wing's auto-completer uses the Tab key for completion, but this can be changed with the Editor > Auto-Completion > Completion Keys preference. The same preferences group lets you specify whether to show the completer immediately or only after a certain number of characters or time, how to place the completion, and various other options.

Here is what the completer looks like in action:



Notice that the auto-completer contains two columns of icons like keyword module inherited method and dict that indicate the origin and type of the symbol. These are described in detail in the Auto-Completer documentation.

Snippets

The completer also offers code snippets appropriate for the current context. These are indicated with the snippet icon. The default set of snippets that come with Wing IDE may be viewed and altered in the Snippets tool in the Tools menu.

Here is an example of entering snippets with the auto-completer, showing how the same snippet may enter different code, according to context:



Editing with the Debugger

Normally, Wing's auto-completer shows type information obtained through static analysis of your code and the libraries that you import. This works well in most cases, but may fail in dynamic code that resists static analysis.

A quick and easy way to get around this is to set a breakpoint in the code you are working on and start the debugger to reach that breakpoint. Once this is done, the auto-completer uses both static analysis and runtime type analysis in any code that is active on the debug process stack. The source of a symbol in the completer is indicated with the runtime icon.

Starting the debugger is usually just a question of selecting Start/Continue in the Debug menu or using the toolbar icon. In some cases you may first need to set up and configure a project.

Here is an example of this:



Working while the debugger is active also lets you try out new code right away. We'll talk more about that in the next blog post.

Turbo Completion Mode

Wing's auto-completer offers another completion mode for Python that can be incredibly productive, particularly when working with the live runtime state, as described above. It turns all non-symbol keys into completion keys in a context-appropriate way, according to where you are typing, what you are typing, and what key you have just pressed.

So, for example, pressing the = key after an argument completes the argument but pressing the = key after for x does not because you are defining a new symbol x.

Turbo-completion is illustrated in the following:



This mode is off by default because it requires some getting used to. But it is well worth learning and can be enabled with the Edit > Auto-completion > Python Turbo Mode preference.

Using the Source Assistant

The Source Assistant is where Wing shows more details about the type of a symbol, including documentation, call signature, and information about object inheritance and overridden methods. For builtin types and the standard library, this includes also links into Python documentation.

The Source Assistant is integrated with every part of Wing IDE, so it shows information for the current selection in the editor, auto-completer, Python Shell, Source Browser, Project manager, and Debug Probe (a shell for interacting with the debug process that we'll talk about next time).

Here are some examples of the Source Assistant in action:



That's it for now. Next time we'll take a detailed look at Wing's debugger.

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

Share this article:






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:




Older blog posts are available at wingware.blogspot.com.

Wingware Blog