[wingide-users] deleting spaces; Wing API

Mitchell L Model MLMConsulting at Comcast.net
Fri Mar 19 10:49:35 MDT 2010


Please critique this code from the standpoint of appropriate use of  
scripting mechanisms?

def just_one_space(count=wingapi.kArgNumericModifier(4),  
app=wingapi.kArgApplication):
     """[from Emacs] Delete all spaces and tabs around point, leaving  
one space (or n spaces)"""
     editor = app.GetActiveEditor()
     doc = editor.GetDocument()
     start, end = editor.GetSelection()
     while doc.GetCharRange(start-1, start) in (' ', '\t'):
         start -= 1
     while doc.GetCharRange(end, end+1) in (' ', '\t'):
         end += 1
     doc.BeginUndoAction()
     doc.DeleteChars(start, end-1)
     doc.InsertChars(start, ' ' * max(1, count))
     doc.EndUndoAction()
     editor.ExecuteCommand("forward_char")

Also, providing a count argument by typing Escape and a number doesn't  
change its behavior even though the InsertChars is supposed to insert  
that many characters. What did I do wrong?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/wingide-users/attachments/20100319/fb916975/attachment.html


More information about the wingide-users mailing list