From 6fd32c02df6e6174bccb2c4f56c8dcabd8265450 Mon Sep 17 00:00:00 2001 From: Erik Osheim Date: Tue, 27 Jul 2010 15:26:42 -0400 Subject: [PATCH] improve handling of indenting/whitespace in tab-using buffers --HG-- branch : pmacs2 --- application.py | 3 ++- method/__init__.py | 30 ++++++++++++++++++++++-------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/application.py b/application.py index 8837970..c5a2e1d 100755 --- a/application.py +++ b/application.py @@ -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) diff --git a/method/__init__.py b/method/__init__.py index 5cf7153..b120da6 100644 --- a/method/__init__.py +++ b/method/__init__.py @@ -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): - lvl = w.mode.tabwidth + 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] - tstr = ' ' * w.mode.tabwidth + + 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))