quit: do not quit if modified buffer exists, add q! command

This commit is contained in:
Maxime Coste 2011-10-05 18:43:47 +00:00
parent cf162ae617
commit f9be716776

View File

@ -15,7 +15,7 @@
using namespace Kakoune; using namespace Kakoune;
using namespace std::placeholders; using namespace std::placeholders;
void set_attribute(int attribute, bool on) void set_attribute(int attribute, bool on)
{ {
if (on) if (on)
attron(attribute); attron(attribute);
@ -53,7 +53,7 @@ void set_color(Color fg_color, Color bg_color)
std::pair<Color, Color> colorpair(fg_color, bg_color); std::pair<Color, Color> colorpair(fg_color, bg_color);
auto it = colorpairs.find(colorpair); auto it = colorpairs.find(colorpair);
if (it != colorpairs.end()) if (it != colorpairs.end())
{ {
current_pair = it->second; current_pair = it->second;
attron(COLOR_PAIR(it->second)); attron(COLOR_PAIR(it->second));
@ -124,7 +124,6 @@ void draw_window(Window& window)
clrtoeol(); clrtoeol();
addch('~'); addch('~');
} }
move(max_y, 0);
set_attribute(A_UNDERLINE, 0); set_attribute(A_UNDERLINE, 0);
set_attribute(A_REVERSE, 0); set_attribute(A_REVERSE, 0);
@ -132,8 +131,10 @@ void draw_window(Window& window)
set_attribute(A_BOLD, 0); set_attribute(A_BOLD, 0);
set_color(Color::Cyan, Color::Black); set_color(Color::Cyan, Color::Black);
std::string status_line = window.status_line();
move(max_y, max_x - status_line.length());
clrtoeol(); clrtoeol();
addstr(window.status_line().c_str()); addstr(status_line.c_str());
const WindowCoord& cursor_position = window.cursor_position(); const WindowCoord& cursor_position = window.cursor_position();
move(cursor_position.line, cursor_position.column); move(cursor_position.line, cursor_position.column);
@ -389,11 +390,23 @@ void write_buffer(const CommandParameters& params)
bool quit_requested = false; bool quit_requested = false;
template<bool force>
void quit(const CommandParameters& params) void quit(const CommandParameters& params)
{ {
if (params.size() != 0) if (params.size() != 0)
throw wrong_argument_count(); throw wrong_argument_count();
if (not force)
{
for (auto& buffer : BufferManager::instance())
{
if (buffer.is_modified())
{
print_status("modified buffer remaining");
return;
}
}
}
quit_requested = true; quit_requested = true;
} }
@ -528,7 +541,8 @@ int main(int argc, char* argv[])
command_manager.register_command(std::vector<std::string>{ "e", "edit" }, edit, command_manager.register_command(std::vector<std::string>{ "e", "edit" }, edit,
PerArgumentCommandCompleter{ complete_filename }); PerArgumentCommandCompleter{ complete_filename });
command_manager.register_command(std::vector<std::string>{ "q", "quit" }, quit); command_manager.register_command(std::vector<std::string>{ "q", "quit" }, quit<false>);
command_manager.register_command(std::vector<std::string>{ "q!", "quit!" }, quit<true>);
command_manager.register_command(std::vector<std::string>{ "w", "write" }, write_buffer, command_manager.register_command(std::vector<std::string>{ "w", "write" }, write_buffer,
PerArgumentCommandCompleter{ complete_filename }); PerArgumentCommandCompleter{ complete_filename });
command_manager.register_command(std::vector<std::string>{ "b", "buffer" }, show_buffer, command_manager.register_command(std::vector<std::string>{ "b", "buffer" }, show_buffer,