improve handling of indenting/whitespace in tab-using buffers
--HG-- branch : pmacs2
This commit is contained in:
parent
3bcf14bbb0
commit
6fd32c02df
|
@ -950,7 +950,8 @@ class Application(object):
|
|||
for j in xrange(0, w.mode.header):
|
||||
k = 0
|
||||
for rstr in rstrs[j]:
|
||||
rstr.draw(self.win, slot.y_offset + j, slot.x_offset + k, slot.width)
|
||||
#rstr.draw(self.win, slot.y_offset + j, slot.x_offset + k, slot.width)
|
||||
rstr.draw(self.win, slot.y_offset + j, slot.x_offset + k)
|
||||
#k += len(rstr.string)
|
||||
k += rstr.width(w)
|
||||
|
||||
|
|
|
@ -282,7 +282,7 @@ class DeleteLeftWhitespace(Method):
|
|||
l = w.point_left(p)
|
||||
if l is None:
|
||||
return
|
||||
while l is not None and w.point_char(l) in (' ', '\n'):
|
||||
while l is not None and w.point_char(l) in (' ', '\t', '\n'):
|
||||
p = l
|
||||
l = w.point_left(p)
|
||||
if p < c:
|
||||
|
@ -292,7 +292,7 @@ class DeleteRightWhitespace(Method):
|
|||
def _execute(self, w, **vargs):
|
||||
c = w.logical_cursor()
|
||||
p = c
|
||||
while w.point_char(p) in (' ', '\n'):
|
||||
while w.point_char(p) in (' ', '\t', '\n'):
|
||||
r = w.point_right(p)
|
||||
if r is None:
|
||||
break
|
||||
|
@ -307,7 +307,7 @@ class DeleteLeftSpace(Method):
|
|||
l = w.point_left(p)
|
||||
if l is None:
|
||||
return
|
||||
while l is not None and w.point_char(l) == ' ':
|
||||
while l is not None and w.point_char(l) in (' ', '\t'):
|
||||
p = l
|
||||
l = w.point_left(p)
|
||||
if p < c:
|
||||
|
@ -317,7 +317,7 @@ class DeleteRightSpace(Method):
|
|||
def _execute(self, w, **vargs):
|
||||
c = w.logical_cursor()
|
||||
p = c
|
||||
while w.point_char(p) == ' ':
|
||||
while w.point_char(p) in (' ', '\t'):
|
||||
r = w.point_right(p)
|
||||
if r is None:
|
||||
break
|
||||
|
@ -490,7 +490,6 @@ class InsertTab(Method):
|
|||
|
||||
# if no lvl, insert a literal tab
|
||||
if lvl is None:
|
||||
#w.insert_string_at_cursor(' ' * w.mode.tabwidth)
|
||||
if w.buffer.usetabs:
|
||||
# see HACK in buffer
|
||||
w.insert_string_at_cursor('\t \t')
|
||||
|
@ -839,7 +838,14 @@ class Redo(Method):
|
|||
class UnindentBlock(Method):
|
||||
'''Prepend a tab of space to each line in region'''
|
||||
def _execute(self, w, **vargs):
|
||||
if w.buffer.usetabs:
|
||||
# see HACK in buffer
|
||||
lvl = 4
|
||||
tstr = '\t \t'
|
||||
else:
|
||||
lvl = w.mode.tabwidth
|
||||
tstr = ' ' * lvl
|
||||
|
||||
cursor = w.logical_cursor()
|
||||
if cursor < w.mark:
|
||||
p1 = cursor
|
||||
|
@ -850,9 +856,11 @@ class UnindentBlock(Method):
|
|||
else:
|
||||
w.input_line = "Empty kill region"
|
||||
return
|
||||
|
||||
lines = w.buffer.lines[p1.y:p2.y]
|
||||
|
||||
for i in xrange(0, len(lines)):
|
||||
if lines[i].startswith(' '):
|
||||
if lines[i].startswith(tstr):
|
||||
lines[i] = lines[i][lvl:]
|
||||
w.buffer.delete(Point(0, p1.y), Point(0, p2.y))
|
||||
w.buffer.insert_string(Point(0, p1.y), '\n'.join(lines) + '\n')
|
||||
|
@ -870,7 +878,13 @@ class IndentBlock(Method):
|
|||
w.input_line = "Empty kill region"
|
||||
return
|
||||
lines = w.buffer.lines[p1.y:p2.y]
|
||||
|
||||
if w.buffer.usetabs:
|
||||
# see HACK in buffer
|
||||
tstr = '\t \t'
|
||||
else:
|
||||
tstr = ' ' * w.mode.tabwidth
|
||||
|
||||
for i in xrange(0, len(lines)):
|
||||
lines[i] = tstr + lines[i]
|
||||
w.buffer.delete(Point(0, p1.y), Point(0, p2.y))
|
||||
|
|
Loading…
Reference in New Issue