From a0b42323ed4de19ca38d24c25134f7c86c47bba2 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 8 Mar 2017 19:33:25 +0000 Subject: [PATCH] Add a -debug flag to :edit to set the buffer as debug data As for the *debug* buffer, buffers with the debug flag wont get used for cycling through buffer, or word completion. --- rc/base/lint.kak | 2 +- rc/extra/clang.kak | 2 +- src/buffer_utils.cc | 8 ++++---- src/buffer_utils.hh | 2 +- src/commands.cc | 12 +++++++----- src/main.cc | 2 +- 6 files changed, 15 insertions(+), 13 deletions(-) diff --git a/rc/base/lint.kak b/rc/base/lint.kak index 223f46fb..14dba497 100644 --- a/rc/base/lint.kak +++ b/rc/base/lint.kak @@ -12,7 +12,7 @@ def lint -docstring 'Parse the current buffer with a linter' %{ printf '%s\n' "eval -no-hooks write $dir/buf" printf '%s\n' "eval -draft %{ - edit! -fifo $dir/fifo *lint-output* + edit! -fifo $dir/fifo -debug *lint-output* set buffer filetype make set buffer make_current_error_line 0 hook -group fifo buffer BufCloseFifo .* %{ diff --git a/rc/extra/clang.kak b/rc/extra/clang.kak index f75445f7..fb51ebe3 100644 --- a/rc/extra/clang.kak +++ b/rc/extra/clang.kak @@ -20,7 +20,7 @@ The syntaxic errors detected during parsing are shown when auto-diagnostics are %sh{ dir=${kak_opt_clang_tmp_dir} printf %s\\n "eval -draft %{ - edit! -fifo ${dir}/fifo *clang-output* + edit! -fifo ${dir}/fifo -debug *clang-output* set buffer filetype make set buffer make_current_error_line 0 hook -group fifo buffer BufCloseFifo .* %{ diff --git a/src/buffer_utils.cc b/src/buffer_utils.cc index f808400c..fa21eca8 100644 --- a/src/buffer_utils.cc +++ b/src/buffer_utils.cc @@ -87,7 +87,7 @@ void reload_file_buffer(Buffer& buffer) buffer.reload(file_data, file_data.st.st_mtim); } -Buffer* create_fifo_buffer(String name, int fd, bool scroll) +Buffer* create_fifo_buffer(String name, int fd, Buffer::Flags flags, bool scroll) { static ValueId s_fifo_watcher_id = get_free_value_id(); @@ -95,12 +95,12 @@ Buffer* create_fifo_buffer(String name, int fd, bool scroll) Buffer* buffer = buffer_manager.get_buffer_ifp(name); if (buffer) { - buffer->flags() |= Buffer::Flags::NoUndo; + buffer->flags() |= Buffer::Flags::NoUndo | flags; buffer->reload({}, InvalidTime); } else buffer = buffer_manager.create_buffer( - std::move(name), Buffer::Flags::Fifo | Buffer::Flags::NoUndo); + std::move(name), flags | Buffer::Flags::Fifo | Buffer::Flags::NoUndo); auto watcher_deleter = [buffer](FDWatcher* watcher) { kak_assert(buffer->flags() & Buffer::Flags::Fifo); @@ -159,7 +159,7 @@ Buffer* create_fifo_buffer(String name, int fd, bool scroll) }), std::move(watcher_deleter)); buffer->values()[fifo_watcher_id] = Value(std::move(watcher)); - buffer->flags() = Buffer::Flags::Fifo | Buffer::Flags::NoUndo; + buffer->flags() = flags | Buffer::Flags::Fifo | Buffer::Flags::NoUndo; buffer->run_hook_in_own_context("BufOpenFifo", buffer->name()); return buffer; diff --git a/src/buffer_utils.hh b/src/buffer_utils.hh index 58443062..92cc52cf 100644 --- a/src/buffer_utils.hh +++ b/src/buffer_utils.hh @@ -75,7 +75,7 @@ ColumnCount get_column(const Buffer& buffer, ByteCount get_byte_to_column(const Buffer& buffer, ColumnCount tabstop, DisplayCoord coord); -Buffer* create_fifo_buffer(String name, int fd, bool scroll = false); +Buffer* create_fifo_buffer(String name, int fd, Buffer::Flags flags, bool scroll = false); Buffer* open_file_buffer(StringView filename, Buffer::Flags flags = Buffer::Flags::None); Buffer* open_or_create_file_buffer(StringView filename, diff --git a/src/commands.cc b/src/commands.cc index 9753714c..7ffc0c0e 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -58,14 +58,14 @@ struct option_type_name> namespace { -Buffer* open_fifo(StringView name, StringView filename, bool scroll) +Buffer* open_fifo(StringView name, StringView filename, Buffer::Flags flags, bool scroll) { int fd = open(parse_filename(filename).c_str(), O_RDONLY | O_NONBLOCK); fcntl(fd, F_SETFD, FD_CLOEXEC); if (fd < 0) throw runtime_error(format("unable to open '{}'", filename)); - return create_fifo_buffer(name.str(), fd, scroll); + return create_fifo_buffer(name.str(), fd, flags, scroll); } template struct PerArgumentCommandCompleter; @@ -228,7 +228,8 @@ void edit(const ParametersParser& parser, Context& context, const ShellContext&) Buffer* buffer = buffer_manager.get_buffer_ifp(name); const bool no_hooks = context.hooks_disabled(); - const auto flags = no_hooks ? Buffer::Flags::NoHooks : Buffer::Flags::None; + const auto flags = (no_hooks ? Buffer::Flags::NoHooks : Buffer::Flags::None) | + (parser.get_switch("debug") ? Buffer::Flags::Debug : Buffer::Flags::None); if (force_reload and buffer and buffer->flags() & Buffer::Flags::File) reload_file_buffer(*buffer); @@ -246,7 +247,7 @@ void edit(const ParametersParser& parser, Context& context, const ShellContext&) buffer = buffer_manager.create_buffer(name, flags); } else if (auto fifo = parser.get_switch("fifo")) - buffer = open_fifo(name, *fifo, (bool)parser.get_switch("scroll")); + buffer = open_fifo(name, *fifo, flags, (bool)parser.get_switch("scroll")); else if (not buffer) { buffer = parser.get_switch("existing") ? open_file_buffer(name, flags) @@ -282,6 +283,7 @@ void edit(const ParametersParser& parser, Context& context, const ShellContext&) ParameterDesc edit_params{ { { "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" } }, + { "debug", { false, "treate buffer as debug output" } }, { "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 @@ -543,7 +545,7 @@ void cycle_buffer(const ParametersParser& parser, Context& context, const ShellC newbuf = it->get(); }; cycle(); - if (newbuf->flags() & Buffer::Flags::Debug) + while (newbuf != oldbuf and newbuf->flags() & Buffer::Flags::Debug) cycle(); if (newbuf != oldbuf) diff --git a/src/main.cc b/src/main.cc index 0f8f3e4b..c4e54dac 100644 --- a/src/main.cc +++ b/src/main.cc @@ -449,7 +449,7 @@ std::unique_ptr create_local_ui(UIType ui_type) int tty = open("/dev/tty", O_RDONLY); dup2(tty, 0); close(tty); - create_fifo_buffer("*stdin*", fd); + create_fifo_buffer("*stdin*", fd, Buffer::Flags::None); } return make_unique();