better commenting

--HG--
branch : pmacs2
This commit is contained in:
moculus 2009-02-13 20:46:05 +00:00
parent a5bb43c14a
commit be3990d7d7
1 changed files with 17 additions and 4 deletions

View File

@ -492,6 +492,7 @@ class GetIndentionLevel(Method):
w.set_error('Indention level: %r' % i)
# commenting
# commenting in python
class CommentRegion(Method):
'''Prepend a comment to every line in the current buffer'''
commentc = '#'
@ -506,11 +507,17 @@ class CommentRegion(Method):
else:
w.input_line = "Empty kill region"
return
x = w.buffer.detect_indent_level(p1.y, p2.y) or 0
for y in range(p1.y, p2.y):
w.buffer.insert_string(Point(0, y), self.commentc)
c = self.commentc
if len(w.buffer.lines[y]) < x:
c += ' ' * (x - len(w.buffer.lines[y]))
w.buffer.insert_string(Point(x, y), c)
class UncommentRegion(Method):
'''Remove a comment from every line in the current buffer'''
commentc = '#'
commentre = re.compile('^( *)(#+)')
def _execute(self, w, **vargs):
cursor = w.logical_cursor()
if cursor < w.mark:
@ -522,9 +529,15 @@ class UncommentRegion(Method):
else:
w.input_line = "Empty kill region"
return
for y in range(p1.y, p2.y):
if w.buffer.lines[y].startswith(self.commentc):
w.buffer.delete(Point(0, y), Point(1, y))
line = w.buffer.lines[y]
m = self.commentre.match(line)
if not m:
continue
s1, s2 = m.groups()
x1, x2 = len(s1), len(s1) + len(s2)
w.buffer.delete(Point(x1, y), Point(x2, y))
# wrapping/justifying/etc
class WrapLine(Method):