edit command switch to the given buffer if it is already opened

use edit! (or e!) to force reloading of the buffer
This commit is contained in:
Maxime Coste 2012-02-13 21:48:16 +00:00
parent 38d921f3d2
commit 3019ce3d3c

View File

@ -529,13 +529,21 @@ Buffer* open_or_create(const std::string& filename)
return buffer;
}
template<bool force_reload>
void edit(const CommandParameters& params, const Context& context)
{
if (params.size() != 1)
throw wrong_argument_count();
std::string filename = params[0];
main_context = Context(*open_or_create(filename)->get_or_create_window());
Buffer* buffer = nullptr;
if (not force_reload)
buffer = BufferManager::instance().get_buffer(filename);
if (not buffer)
buffer = open_or_create(filename);
main_context = Context(*buffer->get_or_create_window());
}
void write_buffer(const CommandParameters& params, const Context& context)
@ -1145,7 +1153,10 @@ int main(int argc, char* argv[])
FilterRegistry filter_registry;
GlobalHooksManager hooks_manager;
command_manager.register_commands({ "e", "edit" }, edit,
command_manager.register_commands({ "e", "edit" }, edit<false>,
CommandManager::None,
PerArgumentCommandCompleter({ complete_filename }));
command_manager.register_commands({ "e!", "edit!" }, edit<true>,
CommandManager::None,
PerArgumentCommandCompleter({ complete_filename }));
command_manager.register_commands({ "q", "quit" }, quit<false>);