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

Wingware Support support at wingware.com
Thu Jun 19 09:53:05 EDT 2014


brian downing via wingide-users wrote:
> 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?

Yes, select-lines will select the current line or lines so whole lines 
are selected.  The following shows how to get and set the text, and also 
to set the selection in case you want to retain or restore that in some 
fashion.  It also wraps the changes in a single undo action using a 
try/finally which avoids confused/broken undo if something fails:

   doc = editor.GetDocument()
   start, end = editor.GetSelection()
   doc.BeginUndoAction()
   try:
     lenTxt = doc.GetCharRange(start, end)   # Implements your step 2.
     lenTxt += 'extra info'
     doc.DeleteChars(start, end-1)           # Implements your step 3.
     doc.InsertChars(start, lenTxt)         # Implements your step 3.
   finally:
     doc.EndUndoAction()
   editor.SetSelection(start, start+len(lenTxt))

You may want to look at or just use _transform_selection in 
scripts/editor-extensions.py in your Wing installation.  That file also 
has other examples that may be relevant for you.

I hope this is useful.

-- 

Stephan Deibel
Wingware | Python IDE

The Intelligent Development Environment for Python Programmers

wingware.com



More information about the wingide-users mailing list