diff --git a/buffer/__init__.py b/buffer/__init__.py index eb03ea6..2d2ff50 100644 --- a/buffer/__init__.py +++ b/buffer/__init__.py @@ -74,6 +74,7 @@ class Buffer(object): self.highlights = {} self.settings = {} self.indentlvl = 4 + self.hastabs = False self.usetabs = False self.writetabs = False self.metadata = {} @@ -226,13 +227,15 @@ class Buffer(object): def num_lines(self): return len(self.lines) def make_string(self): - if self.writetabs: + if not self.hastabs: + lines2 = self.lines + elif self.writetabs: # reverse the "horrible hack" mentioned below when writing # out the string. lines2 = [s.replace('\t \t', '\t') for s in self.lines] else: - lines2 = self.lines - return self.nl.join(self.lines) + lines2 = [s.replace('\t \t', ' ') for s in self.lines] + return self.nl.join(lines2) # methods to be overridden by subclasses def name(self): @@ -643,6 +646,7 @@ class FileBuffer(Buffer): data = data.decode(self.codec) if '\t' in data: + self.hastabs = True self.writetabs = True self.usetabs = True diff --git a/method/buffers.py b/method/buffers.py index 1c63e48..d163980 100644 --- a/method/buffers.py +++ b/method/buffers.py @@ -169,9 +169,9 @@ class ToggleTabs(Method): b = w.buffer b.writetabs = not b.writetabs if b.writetabs: - w.set_error("Buffer will translate %d spaces to a tab" % b.indentlvl) + w.set_error("Buffer will save tabs") else: - w.set_error("Buffer will not write tabs") + w.set_error("Buffer will not save tabs") class Pwd(Method): '''Print the buffer's current working directory'''