#!python
def setArea(ed,headerStr = 'auto'):
""" Selects the Auto Generated Area between the '+++ <headerStr>' & '+++ end of <headerStr>' markers
and clears it. leaving the cursor ready for insertion in the (now empty) area.
If area isnt found - its created
"""
sectBegin = '+++ %s' %headerStr
sectEnd = '+++ end of %s' %headerStr
endpos = ed.GetLength()
pos1 = ed.FindText(0, endpos, sectBegin, 0)
pos2 = ed.FindText(0, endpos, sectEnd, 0)
if pos1<0: #opening header not found
ed.AppendText('\n\n%s\n'%sectBegin)
ed.AppendText('\n%s\n'%sectEnd)
pos1 = ed.PositionFromLine(ed.LineFromPosition(ed.GetLength())-3)
pos2 = ed.PositionFromLine(ed.LineFromPosition(ed.GetLength())-2)
else: #opening header found, but...
if pos2<0: #closing header not found
ed.GotoPos(ed.PositionFromLine(ed.LineFromPosition(pos1)+1))
ed.AddText('\n\n%s\n'%sectEnd)
pos2 = ed.PositionFromLine(ed.LineFromPosition(pos1)+2)
else: #both found
pos2 = pos2-1
pos1 = ed.PositionFromLine(ed.LineFromPosition(pos1)+1)
ed.SetSelection(pos1, pos2)
ed.ReplaceSelection("\n\n")
ed.GotoPos(pos1)