improved (but not perfect) wrap-paragraph
--HG-- branch : pmacs2
This commit is contained in:
parent
cc4108d107
commit
2f23872896
24
dirutil.py
24
dirutil.py
|
@ -80,22 +80,14 @@ def path_fields(path, name):
|
||||||
# - regular, b block, c character, d directory, l symlink, p fifo
|
# - regular, b block, c character, d directory, l symlink, p fifo
|
||||||
# s socket, ? unknown
|
# s socket, ? unknown
|
||||||
perm = [' '] * 10
|
perm = [' '] * 10
|
||||||
if stat.S_ISREG(info.st_mode):
|
if stat.S_ISREG(info.st_mode): perm[0] = '-'
|
||||||
perm[0] = '-'
|
elif stat.S_ISBLK(info.st_mode): perm[0] = 'b'
|
||||||
elif stat.S_ISBLK(info.st_mode):
|
elif stat.S_ISCHR(info.st_mode): perm[0] = 'c'
|
||||||
perm[0] = 'b'
|
elif stat.S_ISDIR(info.st_mode): perm[0] = 'd'
|
||||||
elif stat.S_ISCHR(info.st_mode):
|
elif stat.S_ISLNK(info.st_mode): perm[0] = 'l'
|
||||||
perm[0] = 'c'
|
elif stat.S_ISFIFO(info.st_mode): perm[0] = 'p'
|
||||||
elif stat.S_ISDIR(info.st_mode):
|
elif stat.S_ISSOCK(info.st_mode): perm[0] = 's'
|
||||||
perm[0] = 'd'
|
else: perm[0] = '?'
|
||||||
elif stat.S_ISLNK(info.st_mode):
|
|
||||||
perm[0] = 'l'
|
|
||||||
elif stat.S_ISFIFO(info.st_mode):
|
|
||||||
perm[0] = 'p'
|
|
||||||
elif stat.S_ISSOCK(info.st_mode):
|
|
||||||
perm[0] = 's'
|
|
||||||
else:
|
|
||||||
perm[0] = '?'
|
|
||||||
|
|
||||||
i = 1
|
i = 1
|
||||||
symbols = ('r', 'w', 'x')
|
symbols = ('r', 'w', 'x')
|
||||||
|
|
|
@ -644,8 +644,8 @@ class WrapLine(Method):
|
||||||
class WrapParagraph(Method):
|
class WrapParagraph(Method):
|
||||||
'''Wrap contiguous lines of text based on a predefined margin'''
|
'''Wrap contiguous lines of text based on a predefined margin'''
|
||||||
limit = 80
|
limit = 80
|
||||||
valid_re = re.compile('^( *)([^ ].*)$')
|
valid_re = re.compile('^()( *)([^ ].*)$')
|
||||||
empty_re = regex.whitespace
|
empty_re = re.compile('^ ')
|
||||||
def _execute(self, w, **vargs):
|
def _execute(self, w, **vargs):
|
||||||
limit = util.get_margin_limit(w, self.limit)
|
limit = util.get_margin_limit(w, self.limit)
|
||||||
|
|
||||||
|
@ -654,11 +654,14 @@ class WrapParagraph(Method):
|
||||||
p1 = oldc = w.logical_cursor()
|
p1 = oldc = w.logical_cursor()
|
||||||
cur_offset = 0
|
cur_offset = 0
|
||||||
|
|
||||||
|
if self.empty_re.match(w.buffer.lines[p1.y]):
|
||||||
|
return
|
||||||
|
|
||||||
m = self.valid_re.match(w.buffer.lines[p1.y])
|
m = self.valid_re.match(w.buffer.lines[p1.y])
|
||||||
if not m:
|
if not m:
|
||||||
# the line was empty
|
# the line was empty
|
||||||
return
|
return
|
||||||
elif m.group(1):
|
elif not m.group(1) and m.group(2):
|
||||||
# the line had leading whitespace
|
# the line had leading whitespace
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -666,7 +669,8 @@ class WrapParagraph(Method):
|
||||||
# let's find the actual begining, and update p1 accordingly.
|
# let's find the actual begining, and update p1 accordingly.
|
||||||
i = p1.y
|
i = p1.y
|
||||||
if i > 1 and w.buffer.lines[i] and not w.buffer.lines[i].startswith(' '):
|
if i > 1 and w.buffer.lines[i] and not w.buffer.lines[i].startswith(' '):
|
||||||
while i > 1 and w.buffer.lines[i - 1] and not w.buffer.lines[i - 1].startswith(' '):
|
while (i > 1 and w.buffer.lines[i - 1] and
|
||||||
|
not self.empty_re.match(w.buffer.lines[i - 1])):
|
||||||
i -= 1
|
i -= 1
|
||||||
p1 = Point(0, i)
|
p1 = Point(0, i)
|
||||||
|
|
||||||
|
@ -679,7 +683,8 @@ class WrapParagraph(Method):
|
||||||
|
|
||||||
# ok, so now let's move forward and find the end of the paragraph.
|
# ok, so now let's move forward and find the end of the paragraph.
|
||||||
i = p1.y + 1
|
i = p1.y + 1
|
||||||
while i < len(w.buffer.lines) and w.buffer.lines[i] and not w.buffer.lines[i].startswith(' '):
|
while (i < len(w.buffer.lines) and w.buffer.lines[i] and
|
||||||
|
not self.empty_re.match(w.buffer.lines[i])):
|
||||||
s1 = w.buffer.lines[i]
|
s1 = w.buffer.lines[i]
|
||||||
s2 = s1.rstrip()
|
s2 = s1.rstrip()
|
||||||
if oldc.y == i:
|
if oldc.y == i:
|
||||||
|
@ -697,8 +702,6 @@ class WrapParagraph(Method):
|
||||||
# stringify our paragraph
|
# stringify our paragraph
|
||||||
s = " ".join(lines)
|
s = " ".join(lines)
|
||||||
|
|
||||||
#raise Exception, '%r %r' % (limit, s)
|
|
||||||
|
|
||||||
# ok, so now we need to find the line breaks
|
# ok, so now we need to find the line breaks
|
||||||
newlines = []
|
newlines = []
|
||||||
while s:
|
while s:
|
||||||
|
@ -727,8 +730,6 @@ class WrapParagraph(Method):
|
||||||
y += 1
|
y += 1
|
||||||
k += 1
|
k += 1
|
||||||
|
|
||||||
#assert len(newlines), 'fooga: %r %r' % (limit, s)
|
|
||||||
|
|
||||||
# kill the old paragraph region, insert the new, and goto the new cursor
|
# kill the old paragraph region, insert the new, and goto the new cursor
|
||||||
w.delete(p1, Point(len(w.buffer.lines[i-1]), i-1))
|
w.delete(p1, Point(len(w.buffer.lines[i-1]), i-1))
|
||||||
w.insert_lines(p1, newlines)
|
w.insert_lines(p1, newlines)
|
||||||
|
|
|
@ -24,7 +24,8 @@ class MuttGrammar(Grammar):
|
||||||
|
|
||||||
class MuttWrapParagraph(WrapParagraph):
|
class MuttWrapParagraph(WrapParagraph):
|
||||||
limit = 72
|
limit = 72
|
||||||
empty_re = re.compile('^(?: *>.*| *)$')
|
valid_re = re.compile('^((?:>[> ]*)?)( *)([^> ].*)$')
|
||||||
|
empty_re = re.compile('^[> ]*$')
|
||||||
class MuttInsertSpace(TextInsertSpace):
|
class MuttInsertSpace(TextInsertSpace):
|
||||||
wrapper = MuttWrapParagraph
|
wrapper = MuttWrapParagraph
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue