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