parent
b60b619d5b
commit
95f2e23822
|
@ -27,12 +27,6 @@ class Application(object):
|
|||
self.need_draw = True
|
||||
self.input = keyinput.Handler()
|
||||
|
||||
# some constants
|
||||
self.error_timeout = -1
|
||||
self.max_error_len = 192
|
||||
self.max_num_kills = 64
|
||||
self.def_word_letters = string.letters + string.digits
|
||||
|
||||
# let's prepopulate some default token colors
|
||||
self.token_colors = {
|
||||
'comment': ('red', 'default', 'bold'),
|
||||
|
@ -62,7 +56,7 @@ class Application(object):
|
|||
}
|
||||
self.default_color = ('default', 'default',)
|
||||
|
||||
# xyz
|
||||
# initialize configuration defaults
|
||||
self._load_config_defaults()
|
||||
|
||||
# initialize our colors
|
||||
|
@ -188,7 +182,12 @@ class Application(object):
|
|||
curses.def_prog_mode()
|
||||
|
||||
def _load_config_defaults(self):
|
||||
self.config['ignore-suffix'] = ['~', '-']
|
||||
self.config['ignore_suffix'] = ['~', '-']
|
||||
self.config['error_timeout'] = -1
|
||||
self.config['max_error_len'] = 192
|
||||
self.config['max_num_kills'] = 64
|
||||
self.config['word_letters'] = string.letters + string.digits
|
||||
self.config['default_color'] = ('default', 'default',)
|
||||
|
||||
def completion_window_is_open(self):
|
||||
n = self.complete_slot
|
||||
|
@ -267,13 +266,13 @@ class Application(object):
|
|||
|
||||
# this sets up a mode, as well as optionally adding information on when to
|
||||
# auto-load the mode
|
||||
def setmode(self, name, cls, paths=[], basenames=[], extensions=[], detection=[]):
|
||||
def setmode(self, name, cls, paths=[], bases=[], exts=[], detection=[]):
|
||||
self.modes[name] = cls
|
||||
for p in paths:
|
||||
self.mode_paths[p] = name
|
||||
for b in basenames:
|
||||
for b in bases:
|
||||
self.mode_basenames[b] = name
|
||||
for e in extensions:
|
||||
for e in exts:
|
||||
self.mode_extensions[e] = name
|
||||
for d in detection:
|
||||
self.mode_detection[d] = name
|
||||
|
@ -310,15 +309,16 @@ class Application(object):
|
|||
|
||||
# files and stuff
|
||||
def close_buffer(self, b):
|
||||
self.bufferlist.remove_buffer(b)
|
||||
blist = self.bufferlist
|
||||
blist.remove_buffer(b)
|
||||
b.close()
|
||||
active_slot = self.bufferlist.slots[self.active_slot]
|
||||
for i in range(0, len(self.bufferlist.slots)):
|
||||
if self.bufferlist.slots[i].is_empty():
|
||||
if self.bufferlist.hidden_buffers:
|
||||
self.bufferlist.set_slot(i, self.bufferlist.hidden_buffers[0])
|
||||
active_slot = blist.slots[self.active_slot]
|
||||
for i in range(0, len(blist.slots)):
|
||||
if blist.slots[i].is_empty():
|
||||
if blist.hidden_buffers:
|
||||
blist.set_slot(i, blist.hidden_buffers[0])
|
||||
else:
|
||||
self.bufferlist.set_slot(i, active_slot.window.buffer)
|
||||
blist.set_slot(i, active_slot.window.buffer)
|
||||
|
||||
def open_path(self, path, binary=False, cipher=None, password=None):
|
||||
path = os.path.abspath(os.path.realpath(util.expand_tilde(path)))
|
||||
|
@ -372,12 +372,12 @@ class Application(object):
|
|||
return self.mini_buffer
|
||||
def mini_buffer_is_open(self):
|
||||
return self.mini_buffer is not None
|
||||
def open_mini_buffer(self, prompt, callback, method=None, tabber=None,
|
||||
def open_mini_buffer(self, prompt, cb, method=None, tabber=None,
|
||||
modename=None, startvalue=None):
|
||||
if self.mini_buffer_is_open():
|
||||
self.close_mini_buffer()
|
||||
self.mini_prompt = prompt
|
||||
self.mini_buffer = minibuffer.MiniBuffer(callback, method, tabber, modename)
|
||||
self.mini_buffer = minibuffer.MiniBuffer(cb, method, tabber, modename)
|
||||
try:
|
||||
w = self.x - 1 - len(self.mini_prompt) - 1
|
||||
window.Window(self.mini_buffer, self, height=1, width=w)
|
||||
|
@ -404,26 +404,30 @@ class Application(object):
|
|||
|
||||
# window handling
|
||||
def toggle_window(self):
|
||||
assert 0 <= self.active_slot and self.active_slot < len(self.bufferlist.slots)
|
||||
self.active_slot = (self.active_slot + 1) % len(self.bufferlist.slots) #XYZ
|
||||
blist = self.bufferlist
|
||||
assert 0 <= self.active_slot and self.active_slot < len(blist.slots)
|
||||
self.active_slot = (self.active_slot + 1) % len(blist.slots)
|
||||
def window(self):
|
||||
return self.bufferlist.slots[self.active_slot].window
|
||||
def active_window(self):
|
||||
if self.mini_active:
|
||||
return self.mini_buffer.windows[0]
|
||||
else:
|
||||
assert 0 <= self.active_slot and self.active_slot < len(self.bufferlist.slots), \
|
||||
"0 <= %d < %d" % (self.active_slot, len(self.bufferlist.slots))
|
||||
slot = self.active_slot
|
||||
assert 0 <= slot and slot < len(self.bufferlist.slots), \
|
||||
"0 <= %d < %d" % (slot, len(self.bufferlist.slots))
|
||||
i = self.active_slot
|
||||
return self.bufferlist.slots[i].window
|
||||
|
||||
# buffer handling
|
||||
def file_buffer(self, path, data, switch_to=True):
|
||||
assert not self.has_buffer_name(path), 'oh no! %r is already open' % path
|
||||
assert not os.path.exists(path), 'oh no! %r already exists in fs' % path
|
||||
def new_file_buffer(self, path, data, switch_to=True):
|
||||
assert not self.has_buffer_name(path), '%r is already open' % path
|
||||
assert not os.path.exists(path), '%r already exists' % path
|
||||
# touch the file
|
||||
f = open(path, 'w')
|
||||
f.write(data)
|
||||
f.close()
|
||||
# create the buffer
|
||||
b = buffer.FileBuffer(path)
|
||||
try:
|
||||
b.open()
|
||||
|
@ -469,7 +473,6 @@ class Application(object):
|
|||
def add_buffer(self, b):
|
||||
self.bufferlist.add_buffer(b)
|
||||
def remove_buffer(self, b):
|
||||
assert b.name() is not "*Scratch*", "can't kill the scratch"
|
||||
assert self.bufferlist.has_buffer(b), "can't kill what's not there"
|
||||
assert len(self.bufferlist.buffers) > 1, "can't kill with no other buffers"
|
||||
self.bufferlist.remove_buffer(b)
|
||||
|
@ -519,7 +522,8 @@ class Application(object):
|
|||
else:
|
||||
self.kill_ring.append(s)
|
||||
#if KILL_RING_LIMIT and len(self.kill_ring) > KILL_RING_LIMIT:
|
||||
if self.max_num_kills and len(self.kill_ring) > self.max_num_kills:
|
||||
maxnum = self.config['max_num_kills']
|
||||
if maxnum and len(self.kill_ring) > maxnum:
|
||||
self.kill_ring.pop(0)
|
||||
def pop_kill(self):
|
||||
return self.kill_ring.pop(-1)
|
||||
|
@ -648,8 +652,9 @@ class Application(object):
|
|||
self.resize_event()
|
||||
if err:
|
||||
self.set_error(err)
|
||||
if self.error_timestamp is not None and self.error_timeout > 0 and \
|
||||
time.time() - self.error_timestamp > self.error_timeout:
|
||||
if (self.error_timestamp is not None and
|
||||
self.config['error_timeout'] > 0 and
|
||||
time.time() - self.error_timestamp > self.config['error_timeout']):
|
||||
self.clear_error()
|
||||
(y, x) = self.stdscr.getmaxyx()
|
||||
if y != self.y or x != self.x:
|
||||
|
@ -733,9 +738,6 @@ class Application(object):
|
|||
if x + slot.width > len(w.buffer.lines[y]):
|
||||
x = 0
|
||||
y += 1
|
||||
#XYZ
|
||||
#while w.ishidden(y) and y < len(w.buffer.lines):
|
||||
# y += 1
|
||||
else:
|
||||
x += slot.width
|
||||
count += 1
|
||||
|
@ -771,9 +773,6 @@ class Application(object):
|
|||
if x + slot.width > len(w.buffer.lines[y]):
|
||||
x = 0
|
||||
y += 1
|
||||
#XYZ
|
||||
#while w.ishidden(y) and y < len(w.buffer.lines):
|
||||
# y += 1
|
||||
else:
|
||||
x += slot.width - 1
|
||||
count += 1
|
||||
|
@ -842,10 +841,11 @@ class Application(object):
|
|||
def get_minibuffer_lines(self):
|
||||
lines, lines2 = [], []
|
||||
if self.error_string:
|
||||
if len(self.error_string) < self.max_error_len:
|
||||
maxlen = self.config['max_error_len']
|
||||
if len(self.error_string) < maxlen:
|
||||
s = self.error_string
|
||||
else:
|
||||
s = self.error_string[:self.max_error_len] + '...'
|
||||
s = self.error_string[:maxlen] + '...'
|
||||
elif self.mini_buffer_is_open():
|
||||
s = self.mini_prompt + self.mini_buffer.lines[0]
|
||||
lines2 = self.mini_buffer.lines[1:]
|
||||
|
|
|
@ -62,7 +62,7 @@ class FileCompleter(Completer):
|
|||
candidates2 = []
|
||||
for c in candidates:
|
||||
ok = True
|
||||
for suffix in self.application.config['ignore-suffix']:
|
||||
for suffix in self.application.config['ignore_suffix']:
|
||||
if c.endswith(suffix):
|
||||
ok = False
|
||||
break
|
||||
|
|
7
lex.py
7
lex.py
|
@ -501,12 +501,9 @@ class Lexer(object):
|
|||
else:
|
||||
mode = self.mode
|
||||
app = mode.window.application
|
||||
v = list(app.default_color)
|
||||
for j in range(0, len(fqlist)):
|
||||
name = '.'.join(fqlist[j:])
|
||||
if name in app.token_colors:
|
||||
assert type(app.token_colors[name]) == type(()), repr(mode)
|
||||
v = list(app.token_colors[name])
|
||||
break
|
||||
|
||||
return v
|
||||
return app.token_colors[name]
|
||||
return app.config['default_color']
|
||||
|
|
|
@ -59,7 +59,6 @@ class KillBuffer(Method):
|
|||
name = vargs['buffername']
|
||||
a = w.application
|
||||
assert name in a.bufferlist.buffer_names, "Buffer %r does not exist" % name
|
||||
assert name != '*Scratch*', "Can't kill scratch buffer"
|
||||
self._to_kill = a.bufferlist.buffer_names[name]
|
||||
self._old_window = w
|
||||
if self.force or not self._to_kill.changed():
|
||||
|
@ -107,11 +106,8 @@ class SaveBufferAs(Method):
|
|||
if w.application.has_buffer_name(path):
|
||||
w.set_error("buffer for %r is already open" % path)
|
||||
return
|
||||
w.application.file_buffer(path, data, switch_to=True)
|
||||
if curr_buffer_name != '*Scratch*':
|
||||
w.application.methods['kill-buffer'].execute(w, buffername=curr_buffer_name)
|
||||
else:
|
||||
curr_buffer.set_data('')
|
||||
w.application.new_file_buffer(path, data, switch_to=True)
|
||||
w.application.methods['kill-buffer'].execute(w, buffername=curr_buffer_name)
|
||||
w.set_error('Wrote %r' % path)
|
||||
class SaveBuffer(Method):
|
||||
'''Save the contents of a buffer'''
|
||||
|
|
|
@ -107,7 +107,7 @@ class Fundamental(Handler):
|
|||
|
||||
def install(cls, app):
|
||||
app.setmode(cls.modename.lower(), cls, paths=cls.paths,
|
||||
basenames=cls.basenames, extensions=cls.extensions,
|
||||
bases=cls.basenames, exts=cls.extensions,
|
||||
detection=cls.detection)
|
||||
for (key, val) in cls.colors.iteritems():
|
||||
if key in app.token_colors:
|
||||
|
@ -117,9 +117,9 @@ class Fundamental(Handler):
|
|||
app.token_colors[key] = val
|
||||
|
||||
# install configuration stuff
|
||||
for (key, val) in cls.config.iteritems():
|
||||
assert key not in app.config, "uh oh: %r" % key
|
||||
app.config[key] = val
|
||||
for (name, val) in cls.config.iteritems():
|
||||
assert name not in app.config, "config conflict: %r" % name
|
||||
app.config[name] = val
|
||||
for (key, val) in cls.lconfig.iteritems():
|
||||
app.config.setdefault(key, [])
|
||||
for val2 in val:
|
||||
|
@ -234,7 +234,7 @@ class Fundamental(Handler):
|
|||
|
||||
# used for all word operations
|
||||
if not self.word_letters:
|
||||
self.word_letters = w.application.def_word_letters
|
||||
self.word_letters = w.application.config['word_letters']
|
||||
|
||||
# create all the insert actions for the basic text input
|
||||
for c in string.letters + string.digits + string.punctuation:
|
||||
|
|
Loading…
Reference in New Issue