diff --git a/rc/grep.kak b/rc/grep.kak index 12ec6915..2fc920ae 100644 --- a/rc/grep.kak +++ b/rc/grep.kak @@ -34,7 +34,7 @@ decl str jumpclient def jump %{ exec 'xs^([^:]+):(\d+):(\d+)?' set buffer _grep_current_line %val{cursor_line} - eval -try-client %opt{jumpclient} edit %reg{1} %reg{2} %reg{3} + eval -try-client %opt{jumpclient} edit -existing %reg{1} %reg{2} %reg{3} try %{ focus %opt{jumpclient} } } diff --git a/rc/make.kak b/rc/make.kak index 8e92e22d..9d606a63 100644 --- a/rc/make.kak +++ b/rc/make.kak @@ -33,12 +33,12 @@ def errjump -docstring 'Jump to error location' %{ exec gll "Entering directory" exec s "Entering directory '([^']+)'.*\n([^:]+):(\d+):(\d+):([^\n]+)\'" l set buffer _make_current_error_line %val{cursor_line} - eval -try-client %opt{jumpclient} %rec{edit %reg{1}/%reg{2} %reg{3} %reg{4}; echo -color Information '%reg{5}'} + eval -try-client %opt{jumpclient} %rec{edit -existing %reg{1}/%reg{2} %reg{3} %reg{4}; echo -color Information '%reg{5}'} try %{ focus %opt{jumpclient} } } catch %{ exec ghgl s "([^:]+):(\d+):(\d+):([^\n]+)\'" l set buffer _make_current_error_line %val{cursor_line} - eval -try-client %opt{jumpclient} %rec{edit %reg{1} %reg{2} %reg{3}; echo -color Information '%reg{4}'} + eval -try-client %opt{jumpclient} %rec{edit -existing %reg{1} %reg{2} %reg{3}; echo -color Information '%reg{4}'} try %{ focus %opt{jumpclient} } } } diff --git a/src/commands.cc b/src/commands.cc index 2967ae1f..57e4d142 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -34,17 +34,6 @@ namespace Kakoune namespace { -Buffer* open_or_create(const String& filename, Context& context) -{ - Buffer* buffer = create_buffer_from_file(filename); - if (not buffer) - { - context.print_status({ "new file " + filename, get_face("StatusLine") }); - buffer = new Buffer(filename, Buffer::Flags::File | Buffer::Flags::New); - } - return buffer; -} - Buffer* open_fifo(const String& name , const String& filename, bool scroll) { int fd = open(parse_filename(filename).c_str(), O_RDONLY); @@ -116,7 +105,17 @@ void edit(const ParametersParser& parser, Context& context) else if (parser.has_option("fifo")) buffer = open_fifo(name, parser.option_value("fifo"), parser.has_option("scroll")); else - buffer = open_or_create(name, context); + { + buffer = create_buffer_from_file(name); + if (not buffer) + { + if (parser.has_option("existing")) + throw runtime_error("unable to open " + name); + + context.print_status({ "new file " + name, get_face("StatusLine") }); + buffer = new Buffer(name, Buffer::Flags::File | Buffer::Flags::New); + } + } } BufferManager::instance().set_last_used_buffer(*buffer); @@ -142,7 +141,8 @@ void edit(const ParametersParser& parser, Context& context) } ParameterDesc edit_params{ - SwitchMap{ { "scratch", { false, "create a scratch buffer, not linked to a file" } }, + SwitchMap{ { "existing", { false, "fail if the file does not exists, do not open a new file" } }, + { "scratch", { false, "create a scratch buffer, not linked to a file" } }, { "fifo", { true, "create a buffer reading its content from a named fifo" } }, { "scroll", { false, "place the initial cursor so that the fifo will scroll to show new data" } } }, ParameterDesc::Flags::None, 0, 3