Merge branch 'master' into remove-buffer-change-listener

This commit is contained in:
Maxime Coste 2014-05-25 20:01:55 +01:00
commit 0a060b62a2
10 changed files with 65 additions and 19 deletions

View File

@ -60,7 +60,7 @@ Buffer* open_fifo(const String& name , const String& filename, bool scroll)
const PerArgumentCommandCompleter filename_completer({ const PerArgumentCommandCompleter filename_completer({
[](const Context& context, CompletionFlags flags, const String& prefix, ByteCount cursor_pos) [](const Context& context, CompletionFlags flags, const String& prefix, ByteCount cursor_pos)
{ return Completions{ 0_byte, prefix.length(), { return Completions{ 0_byte, cursor_pos,
complete_filename(prefix, complete_filename(prefix,
context.options()["ignored_files"].get<Regex>(), context.options()["ignored_files"].get<Regex>(),
cursor_pos) }; } cursor_pos) }; }
@ -68,7 +68,7 @@ const PerArgumentCommandCompleter filename_completer({
const PerArgumentCommandCompleter buffer_completer({ const PerArgumentCommandCompleter buffer_completer({
[](const Context& context, CompletionFlags flags, const String& prefix, ByteCount cursor_pos) [](const Context& context, CompletionFlags flags, const String& prefix, ByteCount cursor_pos)
{ return Completions{ 0_byte, prefix.length(), { return Completions{ 0_byte, cursor_pos,
BufferManager::instance().complete_buffer_name(prefix, cursor_pos) }; } BufferManager::instance().complete_buffer_name(prefix, cursor_pos) }; }
}); });
@ -956,6 +956,22 @@ void context_wrap(const ParametersParser& parser, Context& context, Func func)
GlobalHooks::instance().enable_hooks(); GlobalHooks::instance().enable_hooks();
}); });
struct DisableOption {
DisableOption(Context& context, const char* name)
: m_option(context.options()[name]),
m_prev_value(m_option.get<bool>())
{ m_option.set(false); }
~DisableOption() { m_option.set(m_prev_value); }
Option& m_option;
bool m_prev_value;
};
DisableOption disable_autoinfo(context, "autoinfo");
DisableOption disable_autoshowcompl(context, "autoshowcompl");
DisableOption disable_incsearch(context, "incsearch");
ClientManager& cm = ClientManager::instance(); ClientManager& cm = ClientManager::instance();
if (parser.has_option("buffer")) if (parser.has_option("buffer"))
{ {
@ -1211,7 +1227,7 @@ const CommandDesc try_catch_cmd = {
static Completions complete_colalias(const Context&, CompletionFlags flags, static Completions complete_colalias(const Context&, CompletionFlags flags,
const String& prefix, ByteCount cursor_pos) const String& prefix, ByteCount cursor_pos)
{ {
return {0_byte, prefix.length(), return {0_byte, cursor_pos,
ColorRegistry::instance().complete_alias_name(prefix, cursor_pos)}; ColorRegistry::instance().complete_alias_name(prefix, cursor_pos)};
} }

View File

@ -537,24 +537,25 @@ void expand_unprintable(const Context& context, HighlightFlags flags, DisplayBuf
{ {
if (atom_it->type() == DisplayAtom::BufferRange) if (atom_it->type() == DisplayAtom::BufferRange)
{ {
using Utf8It = utf8::utf8_iterator<BufferIterator, utf8::InvalidBytePolicy::Pass>; for (auto it = buffer.iterator_at(atom_it->begin()),
for (Utf8It it = buffer.iterator_at(atom_it->begin()), end = buffer.iterator_at(atom_it->end()); it < end;)
end = buffer.iterator_at(atom_it->end()); it != end; ++it)
{ {
Codepoint cp = *it; Codepoint cp = utf8::codepoint<utf8::InvalidBytePolicy::Pass>(it);
auto next = utf8::next(it);
if (cp != '\n' and not iswprint(cp)) if (cp != '\n' and not iswprint(cp))
{ {
std::ostringstream oss; std::ostringstream oss;
oss << "U+" << std::hex << cp; oss << "U+" << std::hex << cp;
String str = oss.str(); String str = oss.str();
if (it.base().coord() != atom_it->begin()) if (it.coord() != atom_it->begin())
atom_it = ++line.split(atom_it, it.base().coord()); atom_it = ++line.split(atom_it, it.coord());
if ((it+1).base().coord() != atom_it->end()) if (next.coord() < atom_it->end())
atom_it = line.split(atom_it, (it+1).base().coord()); atom_it = line.split(atom_it, next.coord());
atom_it->replace(str); atom_it->replace(str);
atom_it->colors = { Colors::Red, Colors::Black }; atom_it->colors = { Colors::Red, Colors::Black };
break; break;
} }
it = next;
} }
} }
} }

View File

@ -84,6 +84,8 @@ public:
{ {
if (key.modifiers == Key::Modifiers::None and isdigit(key.key)) if (key.modifiers == Key::Modifiers::None and isdigit(key.key))
m_count = m_count * 10 + key.key - '0'; m_count = m_count * 10 + key.key - '0';
else if (key == Key::Backspace)
m_count /= 10;
else else
{ {
auto it = keymap.find(key); auto it = keymap.find(key);
@ -138,7 +140,7 @@ public:
--m_cursor_pos; --m_cursor_pos;
} }
} }
else if (key == Key::Erase) else if (key == Key::Delete)
{ {
if (m_cursor_pos != m_line.char_length()) if (m_cursor_pos != m_line.char_length())
m_line = m_line.substr(0, m_cursor_pos) m_line = m_line.substr(0, m_cursor_pos)
@ -675,7 +677,7 @@ public:
buffer.erase(utf8::previous(pos), pos); buffer.erase(utf8::previous(pos), pos);
} }
} }
else if (key == Key::Erase) else if (key == Key::Delete)
{ {
for (auto& sel : reversed(context().selections())) for (auto& sel : reversed(context().selections()))
{ {

View File

@ -34,6 +34,7 @@ static const KeyAndName keynamemap[] = {
{ "home", Key::Home }, { "home", Key::Home },
{ "end", Key::End }, { "end", Key::End },
{ "backtab", Key::BackTab }, { "backtab", Key::BackTab },
{ "del", Key::Delete },
}; };
KeyList parse_keys(StringView str) KeyList parse_keys(StringView str)

View File

@ -22,7 +22,7 @@ struct Key
{ {
// use UTF-16 surrogate pairs range // use UTF-16 surrogate pairs range
Backspace = 0xD800, Backspace = 0xD800,
Erase, Delete,
Escape, Escape,
Up, Up,
Down, Down,

View File

@ -137,8 +137,23 @@ void register_env_vars()
[](StringView name, const Context& context) [](StringView name, const Context& context)
{ auto& sel = context.selections().main(); { auto& sel = context.selections().main();
auto beg = sel.min(); auto beg = sel.min();
return to_string(beg.line + 1) + ':' + to_string(beg.column + 1) + '+' + return to_string(beg.line + 1) + '.' + to_string(beg.column + 1) + '+' +
to_string((int)context.buffer().distance(beg, sel.max())+1); } to_string((int)context.buffer().distance(beg, sel.max())+1); }
}, {
"selections_desc",
[](StringView name, const Context& context)
{
String res;
for (auto& sel : context.selections())
{
auto beg = sel.min();
if (not res.empty())
res += ':';
res += to_string(beg.line + 1) + '.' + to_string(beg.column + 1) + '+' +
to_string((int)context.buffer().distance(beg, sel.max())+1);
}
return res;
}
}, { }, {
"window_width", "window_width",
[](StringView name, const Context& context) [](StringView name, const Context& context)
@ -163,7 +178,12 @@ void register_registers()
} dyn_regs[] = { } dyn_regs[] = {
{ '%', [](const Context& context) { return StringList{{context.buffer().display_name()}}; } }, { '%', [](const Context& context) { return StringList{{context.buffer().display_name()}}; } },
{ '.', [](const Context& context) { return context.selections_content(); } }, { '.', [](const Context& context) { return context.selections_content(); } },
{ '#', [](const Context& context) { return StringList{{to_string((int)context.selections().size())}}; } }, { '#', [](const Context& context) {
StringList res;
for (size_t i = 1; i < context.selections().size(); ++i)
res.push_back(to_string((int)i));
return res;
} }
}; };
RegisterManager& register_manager = RegisterManager::instance(); RegisterManager& register_manager = RegisterManager::instance();

View File

@ -359,7 +359,7 @@ Key NCursesUI::get_key()
else switch (c) else switch (c)
{ {
case KEY_BACKSPACE: case 127: return Key::Backspace; case KEY_BACKSPACE: case 127: return Key::Backspace;
case KEY_DC: return Key::Erase; case KEY_DC: return Key::Delete;
case KEY_UP: return Key::Up; case KEY_UP: return Key::Up;
case KEY_DOWN: return Key::Down; case KEY_DOWN: return Key::Down;
case KEY_LEFT: return Key::Left; case KEY_LEFT: return Key::Left;

View File

@ -56,7 +56,7 @@ Option& OptionManager::get_local_option(const String& name)
} }
const Option& OptionManager::operator[](const String& name) const Option& OptionManager::operator[](const String& name)
{ {
auto it = find_option(m_options, name); auto it = find_option(m_options, name);
if (it != m_options.end()) if (it != m_options.end())
@ -67,6 +67,11 @@ const Option& OptionManager::operator[](const String& name) const
throw option_not_found(name); throw option_not_found(name);
} }
const Option& OptionManager::operator[](const String& name) const
{
return const_cast<OptionManager&>(*this)[name];
}
template<typename MatchingFunc> template<typename MatchingFunc>
CandidateList OptionManager::get_matching_names(MatchingFunc func) CandidateList OptionManager::get_matching_names(MatchingFunc func)
{ {

View File

@ -88,6 +88,7 @@ public:
OptionManager(OptionManager& parent); OptionManager(OptionManager& parent);
~OptionManager(); ~OptionManager();
Option& operator[] (const String& name);
const Option& operator[] (const String& name) const; const Option& operator[] (const String& name) const;
Option& get_local_option(const String& name); Option& get_local_option(const String& name);

View File

@ -104,7 +104,7 @@ public:
check_invariant(); check_invariant();
other.check_invariant(); other.check_invariant();
CharCount dist = 0; CharCount dist = 0;
while (other.m_it != m_it) while (other.m_it < m_it)
{ {
++dist; ++dist;
++other; ++other;