Σάββατο, 6 Αυγούστου 2011

Code completion improvements

With the help of Mohammad, a number of new code completion features have now been implemented.

  • Code completion with Unicode function and class names e.g.

    def моя_функция(): #Russian.
        pass
    моя  # Press Ctrl + Space
  • Automatic completion if there is only one entry in the completion list e.g.

    ge <- Press Ctrl + Space and you get
    getattr
  • New IDE option "Case Sensitive Code Completion" (default True)
    This controls the way the completion list is filtered when you type characters.  If you set it to False, then when, say, you type “a” in the editor you see entries starting with either small or capital A.
  • New IDE option "Complete Python keywords" (default True)
    So you now can get completion of Python keywords such as “import”
  • New IDE option "Complete as you type" (default True)
    If set to true you get the completion pop-up as soon as you start typing without having to press Ctrl+Space.  This is similar to the way Microsoft Visual C# works and can be a real productivity booster.  Say for example you want to enter the following code.

    from keyword import kwlist

    you type the following and you get the above

    fr[space]kim[space]k

    i.e. you type just 8 characters and you get the above import statement.  This is because there is only one module starting with k which contains only one attribute starting with k.

    This feature may take some getting used to and you if you find it irritating you can turn it off.
  • New IDE option "Complete with word-break chars" (default True)
    Completing with word-break chars, in addition to pressing Tab or Enter, has always been a feature of PyScripter.  e.g.  if you press Ctrl+Space, type “ge” and then type “(“ you get “getattr()”.  Or if if you press Ctrl+Space, type “Ass” and then type space you get “AssertionError ”.

    However you may want to turn this off when you have "Complete as you type" on.  The reason is the following.  Say you want to type

    for i in range(10):

    when you type “for i” and you press space you will see “for id “ instead. This is because i is not defined and with "Complete as you type" on the completion box would show the identifier “id” instead.  What you need to do is to remember to press Esc after typing i, so that the completion list is hidden, and then press space.  If having to remember to press Esc after you introduce new variables makes "Complete as you type" too irritating, you may want to turn off  "Complete with word-break chars" so that completion occurs only when you press Tab or Enter.
  • Paremeter completion does not get hidden when you invoke code completion.

All the above apply to both editor and interpreter code completion. The next code completion feature we are working on is showing the doc string of the currently selected completion entry next to the completion list.

If you want to try the above and provide feedback, you can get the early preview of the next version.