[wingide-users] script to read in editor, modify, and write back

brian downing brian.downing at yakkadesign.com
Wed Jun 18 21:44:05 EDT 2014


I want to write a script that reads the line(s) that are selected, make 
a modification, and then write them back.  Even if there is only a 
partial selection, I want all the lines selected.  For example if the 
cursor is at line 2 column I'd want the entire line read.  Another 
example if the section starts at line 4 column 8 and finishes at line 5 
column 2, I'd want both line 4 and 5 read.

Here is what I've got so far:
def addTxt(editor):
     assert isinstance(editor, wingapi.CAPIEditor)

     document = editor.GetDocument()

     #select every line that is part of selection
     wingapi.gApplication.ExecuteCommand('select-lines')

     document.BeginUndoAction()

     lineTxt = ???get all text on current line or selected lines???

     lenTxt += 'extra info'

     ???write lenTxt line back to editor???

     document.EndUndoAction()

Here are my questions:
1. Is 'select-lines' the correct command to select the entire line for 
where the cursor is at or any lines partial selected?
2. What is the wing command for lineTxt = ???get all text on current 
line or selected lines???
3. What is the command for ???write line back to editor???
4. Is there anything I'm missing?

I can find the doc on commands like document.EndUndoAction().  I found 
this in a snippet on the web.

Brian





More information about the wingide-users mailing list