summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2017-12-12 18:22:05 +1100
committerMaxime Coste <mawww@kakoune.org>2017-12-12 18:22:05 +1100
commit4b06c09c684b633a9cb746c7dbe3d715cf5c6777 (patch)
tree7a99a8d1ad1342e41cbf346cc71575246b50d34c /src
parentce2c0e54f4608483480ee22109b95f318cbea12a (diff)
Make `edit` command work fine when running from an empty context
This way, the kind of context we get from a piped command allows for opening a buffer and working with it directly.
Diffstat (limited to 'src')
-rw-r--r--src/commands.cc6
-rw-r--r--src/context.cc4
2 files changed, 6 insertions, 4 deletions
diff --git a/src/commands.cc b/src/commands.cc
index 8ee19c49..cbb21cb7 100644
--- a/src/commands.cc
+++ b/src/commands.cc
@@ -249,11 +249,13 @@ void edit(const ParametersParser& parser, Context& context, const ShellContext&)
buffer->flags() &= ~Buffer::Flags::NoHooks;
}
+ Buffer* current_buffer = context.has_buffer() ? &context.buffer() : nullptr;
+
const size_t param_count = parser.positional_count();
- if (buffer != &context.buffer() or param_count > 1)
+ if (current_buffer and (buffer != current_buffer or param_count > 1))
context.push_jump();
- if (buffer != &context.buffer())
+ if (buffer != current_buffer)
context.change_buffer(*buffer);
if (param_count > 1 and not parser[1].empty())
diff --git a/src/context.cc b/src/context.cc
index ef2a999f..da23aac1 100644
--- a/src/context.cc
+++ b/src/context.cc
@@ -159,10 +159,10 @@ void JumpList::forget_buffer(Buffer& buffer)
void Context::change_buffer(Buffer& buffer)
{
- if (&buffer == &this->buffer())
+ if (has_buffer() and &buffer == &this->buffer())
return;
- if (m_edition_level > 0)
+ if (has_buffer() and m_edition_level > 0)
this->buffer().commit_undo_group();
m_window.reset();