This happens a lot: you start typing a complex expression something().somethingelse[2].this.that.
and then you think, wait a minute, where am I? Or something + somethingElse
provokes the question, just what is the current value of somethingElse
?
Field offers a few of places to find the answer and help you figure out what needs to be typed next — where you are and where you are going. One is auto-completion: command-period. This can be used in lots of places to tell you not just what you might want to "type next" but some things concerning the value of what you have on the left-hand side of the cursor, for example:
command-period is related to command-option-period which provides autocomplete that ignores Java's access modifiers (so you can see non-public methods and fields).
You have to be careful that you ask the completion system the right question — it's attempting to work out what you will type next, so it needs to be able to guess what you want based on what you have already typed. Typing PL
and asking for completion will offer FLine
, the line geometry object (and maybe a few other things, any variables and packages that you have that start with PL
). Typing FLine
and asking for completion will yield only the constructor for FLine
. To see 'inside' FLine
, you need to have either FLine
. (note the period), FLine()
or a variable that is a FLine
. Likewise _sel
will provoke _self
but only _self
. will give you the documentation and completion 'inside' _self
.
We've spent quite a bit of time both using this autocompletion and refining it's interface. It tries to offer as much information as it can:
You'll see the contents of fields printed as well as methods.
Note the parameter names (created by parsing the source code) and the values of simple primitives fields that are always "safe" to evaluate.
... and sometimes you just want to see everything.
The grayed out lines are protected & private variables (which Python can access, but are worth indicating in a different weight). These only appear if you are holding down option.
What isn't clear from the screenshot is that you can keep typing while you have this menu up and it will refine itself to include only results that start with what you have written. Backspace, enter (to accept the proposed completion), escape (to forget about the whole thing) and the up and down arrow keys (to choose from the menu without using the mouse) all work as expected. Tapping option shows and hides those 'private' members. Refining your search to the point where only a few options remain will focus the display on the documentation for those things (taken from parsing the JavaDocs for Java things, or from the documentation comments of Python things) and will, in the case of short Java methods, show you source for the method itself.
Thus together these two things are becoming a way of offering and navigating documentation (see the autocompletion offered for _self.
for example).
A different "series" of keyboard shortcuts starts with command/ . This print
s the expression on the left hand side of the cursor. Literally — it's like you cursor-ed back to the start of the line, added a print, executed the line and then deleted everything you wrote and put the cursor back in the old spot.
Further in this vein, command ^ / 'pretty-prints' the expression. It generally does a better job of formatting lists and showing you what they contain, for example, than Python's built in (and fixed) print
. Also, unlike print
you can add your own pretty-printers, crafted to whatever objects you are working with, in OutputInserts.addPrintHandler( ...)
Most importantly for our purposes here command ^ / evaluates and prints generators (up to a certain point, it doesn't try to print a generator that never terminates).