For the first part of the problem, how about having some meta syntax
to express explicit adjustment of the current indentation column?
I imagine it wouldn't be disruptive of the grammar, and i think it
would be fairly legible.
Ie, a line occupied only by a '^' carat, with the carat pointing to
the new column location to be considered the current-nesting
indentation. Then code fragments could be inserted unchanged, with
the indentation temporarily adjusted to accomodate them - rehomed.
Subsequent rehoming could be used to restore the original indentation
margin, and simple utilities could readjust indentation to strip
rehoming, for any rehomed code you wish to keep.
Eg, here's some artificial use of rehoming to illustrate, with some
gratuitous butchering of existing Python demo code. (Neat stuff, this
code, overloading the interpretation of sequentiality like that!)
Ken.
# Demo/Rev.py with some arbitrary rehoming for illustration purposes.
from string import joinfields
class Rev:
def __init__( self, seq ):
self.forw = seq
^ # Move indentation home back a tab.
self.back, unnecessary, yet, more = self, yet, more, unnecessary
^ # Restore discarded tab.
def __len__( self ):
return len( self.forw )
def __getitem__( self, j ):
return self.forw[ -( j + 1 ) ]
^ # Allow ostensibly-pasted def at left margin:
def __repr__( self ):
seq = self.forw
if type(seq) == type( [] ) :
wrap = '[]'
sep = ', '
elif type(seq) == type( () ) :
wrap = '()'
sep = ', '
elif type(seq) == type( '' ) :
wrap = ''
sep = ''
else:
wrap = '<>'
sep = ', '
outstrs = []
for item in self.back :
outstrs.append( str( item ) )
return wrap[:1] + joinfields( outstrs, sep ) + wrap[-1:]
#Probably don't need to rehome for the class to close, since this is
#the end of the file.