parent
f747b06318
commit
b3c6d6d717
|
@ -220,7 +220,7 @@ class Buffer(object):
|
|||
while i < len(line) and line[i] == ' ':
|
||||
i += 1
|
||||
j, k = i // self.indentlvl, i % self.indentlvl
|
||||
lines.append(('\t' * j) + (' ' * k) + line[i:])
|
||||
lines.append((u'\t' * j) + (u' ' * k) + line[i:])
|
||||
return self.nl.join(lines)
|
||||
else:
|
||||
return self.nl.join(self.lines)
|
||||
|
@ -562,9 +562,10 @@ class FileBuffer(Buffer):
|
|||
def __init__(self, path, name=None):
|
||||
'''fb = FileBuffer(path)'''
|
||||
Buffer.__init__(self)
|
||||
self.path = os.path.realpath(path)
|
||||
self.path = os.path.realpath(path)
|
||||
self.checksum = None
|
||||
self.bytemark = ''
|
||||
self.codec = 'utf-8'
|
||||
if name is None:
|
||||
self._name = os.path.basename(self.path)
|
||||
else:
|
||||
|
@ -612,6 +613,15 @@ class FileBuffer(Buffer):
|
|||
return os.path.exists(self.path)
|
||||
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()
|
||||
|
@ -631,12 +641,16 @@ class FileBuffer(Buffer):
|
|||
|
||||
self.nl = self._detect_nl_type(data)
|
||||
data = self.read_filter(data)
|
||||
try:
|
||||
data = data.decode('utf-8')
|
||||
data = data.replace("\t", " ")
|
||||
return data
|
||||
except UnicodeDecodeError:
|
||||
|
||||
if '\x00' in data[:8192]:
|
||||
raise BinaryDataException("binary files are not supported")
|
||||
|
||||
for codec in ('utf-8', 'latin-1'):
|
||||
data2 = self.decode(data, codec)
|
||||
if data2 is not None: return data2
|
||||
|
||||
raise BinaryDataException("binary files are not supported")
|
||||
|
||||
def open(self):
|
||||
data = self.read()
|
||||
self.lines = data.split(self.nl)
|
||||
|
@ -671,7 +685,8 @@ class FileBuffer(Buffer):
|
|||
try:
|
||||
data = self.make_string()
|
||||
if self.windows[0].mode.savetabs:
|
||||
data = data.replace(" ", "\t")
|
||||
data = data.replace(" ", "\t").encode(self.codec)
|
||||
|
||||
data = self.write_filter(data)
|
||||
|
||||
f2 = self._open_file_w(self.path, preserve=False)
|
||||
|
|
|
@ -95,8 +95,8 @@ class ArchiveBuffer(DirBuffer):
|
|||
['.tar.bz2', 'tar xfj %(archive)r -C %(dir)r'],
|
||||
#['.gz', 'gunzip %(archive)r'],
|
||||
#['.bz2', 'bunzip2 %(archive)r'],
|
||||
#['.zip', 'unzip %(archive)r'],
|
||||
#['.jar', 'unzip %(archive)r'],
|
||||
['.zip', 'unzip -qq %(archive)r -d %(dir)r'],
|
||||
['.jar', 'unzip -qq %(archive)r -d %(dir)r'],
|
||||
]
|
||||
def __init__(self, path, name=None):
|
||||
self.archive = os.path.realpath(path)
|
||||
|
|
|
@ -71,13 +71,15 @@ class OpenArchive(Method):
|
|||
b.open()
|
||||
Window(b, a, height=0, width=0, mode_name='dir')
|
||||
a.add_buffer(b)
|
||||
|
||||
a.methods['switch-buffer'].execute(w, buffername=b.name())
|
||||
if b.btype != 'archive':
|
||||
return
|
||||
if b.btype != 'archive': return
|
||||
|
||||
names = [x for x in b.get_names() if x != '.' and x != '..']
|
||||
if len(names) == 1:
|
||||
path2 = os.path.join(b.path, names[0])
|
||||
a.methods['open-file'].execute(w, filename=path2)
|
||||
if os.path.isdir(path2):
|
||||
a.methods['open-file'].execute(w, filename=path2)
|
||||
|
||||
class DirRefresh(Method):
|
||||
def _execute(self, w, **vargs):
|
||||
|
|
Loading…
Reference in New Issue