(using a hack) improve support for buffers with tabs
--HG-- branch : pmacs2
This commit is contained in:
parent
215a53dbee
commit
102dc8787e
|
@ -74,6 +74,7 @@ class Buffer(object):
|
|||
self.highlights = {}
|
||||
self.settings = {}
|
||||
self.indentlvl = 4
|
||||
self.usetabs = False
|
||||
self.writetabs = False
|
||||
self.metadata = {}
|
||||
|
||||
|
@ -226,15 +227,11 @@ class Buffer(object):
|
|||
return len(self.lines)
|
||||
def make_string(self):
|
||||
if self.writetabs:
|
||||
lines = []
|
||||
for line in self.lines:
|
||||
i = 0
|
||||
while i < len(line) and line[i] == ' ':
|
||||
i += 1
|
||||
j, k = i // self.indentlvl, i % self.indentlvl
|
||||
lines.append((u'\t' * j) + (u' ' * k) + line[i:])
|
||||
return self.nl.join(lines)
|
||||
# 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)
|
||||
|
||||
# methods to be overridden by subclasses
|
||||
|
@ -625,14 +622,6 @@ class FileBuffer(Buffer):
|
|||
def store_checksum(self, data):
|
||||
self.checksum = hasher(data)
|
||||
|
||||
def decode(self, data, codec):
|
||||
try:
|
||||
data2 = data.decode(codec).replace("\t", " ")
|
||||
self.codec = codec
|
||||
return data2
|
||||
except UnicodeDecodeError:
|
||||
return None
|
||||
|
||||
def read(self):
|
||||
if self.path_exists():
|
||||
f = self._open_file_r()
|
||||
|
@ -653,7 +642,17 @@ class FileBuffer(Buffer):
|
|||
|
||||
data = data.decode(self.codec)
|
||||
|
||||
if '\t' in data: self.writetabs = True
|
||||
if '\t' in data:
|
||||
self.writetabs = True
|
||||
self.usetabs = True
|
||||
|
||||
# OK, this is a horrible, horrible hack. because the "one unicode
|
||||
# char occupies one screen position" assumption is built into the
|
||||
# syntax highlighting and render strings at a pretty low level, we
|
||||
# have to "pad out" the tab to make it take up enough physical
|
||||
# space.
|
||||
data = data.replace('\t', '\t \t')
|
||||
|
||||
self.nl = self._detect_nl_type(data)
|
||||
|
||||
if '\x00' in data[:8192]:
|
||||
|
@ -693,15 +692,10 @@ class FileBuffer(Buffer):
|
|||
|
||||
|
||||
try:
|
||||
data = self.make_string()
|
||||
if self.windows[0].mode.savetabs:
|
||||
data = data.replace(" ", "\t")
|
||||
data = self.write_filter(data.encode(self.codec))
|
||||
|
||||
data = self.write_filter(self.make_string().encode(self.codec))
|
||||
f2 = self._open_file_w(self.path, preserve=False)
|
||||
f2.write(data)
|
||||
f2.close()
|
||||
#except Exception, e:
|
||||
except NameError, e:
|
||||
if exists: shutil.copyfile(temp_path, self.path)
|
||||
raise e
|
||||
|
@ -713,17 +707,6 @@ class FileBuffer(Buffer):
|
|||
self.path = path
|
||||
self.save()
|
||||
|
||||
#class AesBuffer(FileBuffer):
|
||||
# btype = 'aesfile'
|
||||
# def __init__(self, path, password, name=None):
|
||||
# '''fb = FileBuffer(path)'''
|
||||
# FileBuffer.__init__(self, path, name)
|
||||
# self.password = password
|
||||
# def read_filter(self, data):
|
||||
# return aes.decrypt_data(data, self.password)
|
||||
# def write_filter(self, data):
|
||||
# return aes.encrypt_data(data, self.password)
|
||||
|
||||
class Binary32Buffer(FileBuffer):
|
||||
btype = 'bin32file'
|
||||
grouppad = 2
|
||||
|
|
Loading…
Reference in New Issue