fix the new tab support

--HG--
branch : pmacs2
This commit is contained in:
Erik Osheim 2010-04-03 23:49:24 -04:00
parent 102dc8787e
commit 976482cda2
2 changed files with 9 additions and 5 deletions

View File

@ -74,6 +74,7 @@ class Buffer(object):
self.highlights = {} self.highlights = {}
self.settings = {} self.settings = {}
self.indentlvl = 4 self.indentlvl = 4
self.hastabs = False
self.usetabs = False self.usetabs = False
self.writetabs = False self.writetabs = False
self.metadata = {} self.metadata = {}
@ -226,13 +227,15 @@ class Buffer(object):
def num_lines(self): def num_lines(self):
return len(self.lines) return len(self.lines)
def make_string(self): 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 # reverse the "horrible hack" mentioned below when writing
# out the string. # out the string.
lines2 = [s.replace('\t \t', '\t') for s in self.lines] lines2 = [s.replace('\t \t', '\t') for s in self.lines]
else: else:
lines2 = self.lines lines2 = [s.replace('\t \t', ' ') for s in self.lines]
return self.nl.join(self.lines) return self.nl.join(lines2)
# methods to be overridden by subclasses # methods to be overridden by subclasses
def name(self): def name(self):
@ -643,6 +646,7 @@ class FileBuffer(Buffer):
data = data.decode(self.codec) data = data.decode(self.codec)
if '\t' in data: if '\t' in data:
self.hastabs = True
self.writetabs = True self.writetabs = True
self.usetabs = True self.usetabs = True

View File

@ -169,9 +169,9 @@ class ToggleTabs(Method):
b = w.buffer b = w.buffer
b.writetabs = not b.writetabs b.writetabs = not b.writetabs
if 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: else:
w.set_error("Buffer will not write tabs") w.set_error("Buffer will not save tabs")
class Pwd(Method): class Pwd(Method):
'''Print the buffer's current working directory''' '''Print the buffer's current working directory'''