parent
b83e0049e0
commit
bbe7bee4c5
15
buffer.py
15
buffer.py
|
@ -55,6 +55,7 @@ class Buffer(object):
|
|||
self.modified = False
|
||||
self.highlights = {}
|
||||
self.indentlvl = 4
|
||||
self.writetabs = False
|
||||
|
||||
def _detect_nl_type(self, data):
|
||||
mac_c = len(self.mac_re.findall(data))
|
||||
|
@ -192,7 +193,17 @@ class Buffer(object):
|
|||
def num_lines(self):
|
||||
return len(self.lines)
|
||||
def make_string(self):
|
||||
return self.nl.join(self.lines)
|
||||
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(('\t' * j) + (' ' * k) + line[i:])
|
||||
return self.nl.join(lines)
|
||||
else:
|
||||
return self.nl.join(self.lines)
|
||||
|
||||
# methods to be overridden by subclasses
|
||||
def name(self):
|
||||
|
@ -575,6 +586,8 @@ class FileBuffer(Buffer):
|
|||
if self.path_exists():
|
||||
f = self._open_file_r()
|
||||
data = f.read()
|
||||
if '\t' in data:
|
||||
self.writetabs = True
|
||||
f.close()
|
||||
self.store_checksum(data)
|
||||
else:
|
||||
|
|
|
@ -121,3 +121,13 @@ class SaveBuffer(Method):
|
|||
w.set_error("Wrote %s" % (w.buffer.path))
|
||||
else:
|
||||
w.set_error("(No changes need to be saved)")
|
||||
|
||||
class ToggleTabs(Method):
|
||||
'''Toggle whether to write tabs out or not (defaults to false)'''
|
||||
def _execute(self, w, **vargs):
|
||||
b = w.buffer
|
||||
b.writetabs = not b.writetabs
|
||||
if b.writetabs:
|
||||
w.set_error("Buffer will translate %d spaces to a tab" % b.indentlvl)
|
||||
else:
|
||||
w.set_error("Buffer will not write tabs")
|
||||
|
|
|
@ -91,7 +91,7 @@ class Fundamental(Handler):
|
|||
config = {}
|
||||
actions = []
|
||||
completers = {}
|
||||
format = "%(flag)s %(bname)-18s (%(mname)s) %(cursor)s/%(mark)s %(perc)s"
|
||||
format = "%(flag)s %(bname)-18s (%(mname)s) %(indent)s %(cursor)s/%(mark)s %(perc)s"
|
||||
|
||||
# margin/line numbering
|
||||
show_line_numbers = False
|
||||
|
@ -276,6 +276,13 @@ class Fundamental(Handler):
|
|||
return "Bot"
|
||||
else:
|
||||
return "%2d%%" % (w.first.y*100 / len(w.buffer.lines))
|
||||
def _get_indent(self):
|
||||
b = self.window.buffer
|
||||
if b.writetabs:
|
||||
t = '[t]'
|
||||
else:
|
||||
t = '[ ]'
|
||||
return '%d%s' % (b.indentlvl, t)
|
||||
def _get_mark(self):
|
||||
w = self.window
|
||||
if w.mark:
|
||||
|
@ -285,14 +292,16 @@ class Fundamental(Handler):
|
|||
def get_status_names(self):
|
||||
w = self.window
|
||||
c = w.logical_cursor()
|
||||
return {
|
||||
d = {
|
||||
'bname': w.buffer.name(),
|
||||
'mname': self.name(),
|
||||
'flag': self._get_flag(),
|
||||
'perc': self._get_perc(),
|
||||
'indent': self._get_indent(),
|
||||
'cursor': '(%d,%d)' % (c.y + 1, c.x + 1),
|
||||
'mark': self._get_mark(),
|
||||
}
|
||||
return d
|
||||
def get_status_bar(self):
|
||||
names = self.get_status_names()
|
||||
return self.format % names
|
||||
|
|
Loading…
Reference in New Issue