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.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

View File

@ -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'''