Thursday, April 11, 2019

Wingware Blog: Auto-Editing in Wing Pro (Part 3 of 3)

Wing Pro implements a suite of auto-editing operations that take care of common low-level editing tasks. In the previous installments of this 3-part Wing Tips series on Wing Pro's auto-editing features we looked at managing Python code blocks and auto-invocation.

To finish up this series, let's take a look at PEP 8 compliant auto-spacing and a few less frequently needed but useful operations.

Note: If you have Wing Personal, you don't have the features described here. We'll return to features that are also present in Wing Personal next time. Or try Wing Pro on a free trial.

Auto-Entering Spaces and PEP 8

Wing Pro can auto-enter spacing as you type, but this operation is off by default since it may take some getting used to. Once enabled with the Editor > Auto-Editing > Auto-Enter Spaces preference, you can type x=1 to get x = 1 or i=range(x=0,10) to enter i = range(x=0, 10). Spacing is entered in a PEP 8 compliant way.

/images/blog/wingpro-auto-editing/auto-spacing.gif

Shown above: Type "t([1,2,3],y=f)" without any spaces; PEP 8 compliant spacing is auto-entered as needed.

Some options for auto-spacing are available on the Editor > Auto-Editing preferences page, to control whether spaces are auto-entered after unambiguous keyword names are entered, whether to prevent insertion of spacing that is not PEP 8 compliant, and how to place spaces in type annotations.

PEP 8 Reformatting: If you're interested in maintaining strict PEP 8 compliance, you can enable automatic PEP 8 reformatting in the Editor > PEP 8 preferences group. Reformatting takes place either after leaving an edited line or for the whole file when it is saved to disk. Or, trigger reformatting manually from the Source > PEP 8 menu group.

Correcting Out-of-Order Typing

Wing recognizes some types of out-of-order typing and adjusts them automatically, as a way to save on keystrokes. Some of the transformations include:

Keys Pressed Keys Entered
if x(:) if x(): followed by a new line and indentation
def x(-) def x() -> for entering a type annotation
x()t x().t
x(.y) x().y
x(,) x(),
/images/blog/wingpro-auto-editing/out-of-order.gif

Shown above: Type "def x(:)" to start the first def, "def y(a,b-)" for the second, and finally "c=a,x(,)b"

Changing Type of Quotes on a String

When the caret is just after a string and a quote character is pressed, the quotes around the string are changed to that type of quote. This works with regular and triple-quoted strings, although it's most useful for regular strings when the string needs to be edited to contain a quote character.

/images/blog/wingpro-auto-editing/change-quote.gif

Shown above: Type 'x = "test"', move caret to right, and then press ' to change to single quotes so the string can contain a double quote



That's it for our three-part Wing Tips series on auto-editing in Wing Pro. For details on all the available auto-editing operations, see Auto-Editing in the Wing Pro manual.

Auto-editing is just one way in which Wing helps with writing, testing, and debugging Python code. Next week we'll move on to some of the others.



from Planet Python
via read more

No comments:

Post a Comment

TestDriven.io: Working with Static and Media Files in Django

This article looks at how to work with static and media files in a Django project, locally and in production. from Planet Python via read...