diff --git a/doc/conjure.txt b/doc/conjure.txt index 21aeec0c..19d5996d 100644 --- a/doc/conjure.txt +++ b/doc/conjure.txt @@ -688,6 +688,11 @@ configure the ones you care about one at a time you can set: warnings you would normally see from your LSP setup if switched off. Default: `false` + *g:conjure#log#treesitter* +`g:conjure#log#treesitter` + Enables treesitter in the log buffer. You may want this off if you + notice large logs slowing down your editor. + Default: `true` *g:conjure#log#break_length* `g:conjure#log#break_length` diff --git a/fnl/conjure/config.fnl b/fnl/conjure/config.fnl index b5d76c81..3c3ddf71 100644 --- a/fnl/conjure/config.fnl +++ b/fnl/conjure/config.fnl @@ -94,6 +94,7 @@ :log {:wrap false :diagnostics false + :treesitter true :hud {:width 0.42 :height 0.3 :zindex 1 diff --git a/fnl/conjure/log.fnl b/fnl/conjure/log.fnl index ba4ec551..4d3ab72a 100644 --- a/fnl/conjure/log.fnl +++ b/fnl/conjure/log.fnl @@ -43,6 +43,10 @@ (when (and vim.diagnostic (= false (config.get-in [:log :diagnostics]))) (vim.diagnostic.disable buf)) + (when (and vim.treesitter (= false (config.get-in [:log :treesitter]))) + (vim.treesitter.stop buf) + (nvim.buf_set_option buf :syntax "on")) + (nvim.buf_set_lines buf 0 -1 false [(str.join [(client.get :comment-prefix) diff --git a/lua/conjure/config.lua b/lua/conjure/config.lua index fa76a3fb..32001c8f 100644 --- a/lua/conjure/config.lua +++ b/lua/conjure/config.lua @@ -68,7 +68,7 @@ local function merge(tbl, opts, ks) return nil end _2amodule_2a["merge"] = merge -merge({relative_file_root = nil, path_subs = nil, client_on_load = true, filetypes = {"clojure", "fennel", "janet", "hy", "julia", "racket", "scheme", "lua", "lisp", "python", "rust", "sql"}, filetype = {clojure = "conjure.client.clojure.nrepl", fennel = "conjure.client.fennel.aniseed", janet = "conjure.client.janet.netrepl", hy = "conjure.client.hy.stdio", julia = "conjure.client.julia.stdio", racket = "conjure.client.racket.stdio", scheme = "conjure.client.scheme.stdio", lua = "conjure.client.lua.neovim", lisp = "conjure.client.common-lisp.swank", python = "conjure.client.python.stdio", rust = "conjure.client.rust.evcxr", sql = "conjure.client.sql.stdio"}, filetype_suffixes = {racket = {"rkt"}, scheme = {"scm", "ss"}}, eval = {result_register = "c", inline_results = true, inline = {highlight = "comment", prefix = "=> "}, comment_prefix = nil, gsubs = {}}, mapping = {prefix = "", enable_ft_mappings = true, enable_defaults = true}, completion = {omnifunc = "ConjureOmnifunc", fallback = "syntaxcomplete#Complete"}, highlight = {group = "IncSearch", timeout = 500, enabled = false}, log = {hud = {width = 0.42, height = 0.3, zindex = 1, enabled = true, passive_close_delay = 0, minimum_lifetime_ms = 20, overlap_padding = 0.1, border = "single", anchor = "NE", ignore_low_priority = false}, jump_to_latest = {cursor_scroll_position = "top", enabled = false}, break_length = 80, trim = {at = 10000, to = 6000}, strip_ansi_escape_sequences_line_limit = 1000, fold = {lines = 10, marker = {start = "~~~%{", ["end"] = "}%~~~"}, enabled = false}, botright = false, wrap = false, diagnostics = false}, extract = {context_header_lines = 24, form_pairs = {{"(", ")"}, {"{", "}"}, {"[", "]", true}}, tree_sitter = {enabled = true}}, preview = {sample_limit = 0.3}, debug = false}) +merge({relative_file_root = nil, path_subs = nil, client_on_load = true, filetypes = {"clojure", "fennel", "janet", "hy", "julia", "racket", "scheme", "lua", "lisp", "python", "rust", "sql"}, filetype = {clojure = "conjure.client.clojure.nrepl", fennel = "conjure.client.fennel.aniseed", janet = "conjure.client.janet.netrepl", hy = "conjure.client.hy.stdio", julia = "conjure.client.julia.stdio", racket = "conjure.client.racket.stdio", scheme = "conjure.client.scheme.stdio", lua = "conjure.client.lua.neovim", lisp = "conjure.client.common-lisp.swank", python = "conjure.client.python.stdio", rust = "conjure.client.rust.evcxr", sql = "conjure.client.sql.stdio"}, filetype_suffixes = {racket = {"rkt"}, scheme = {"scm", "ss"}}, eval = {result_register = "c", inline_results = true, inline = {highlight = "comment", prefix = "=> "}, comment_prefix = nil, gsubs = {}}, mapping = {prefix = "", enable_ft_mappings = true, enable_defaults = true}, completion = {omnifunc = "ConjureOmnifunc", fallback = "syntaxcomplete#Complete"}, highlight = {group = "IncSearch", timeout = 500, enabled = false}, log = {treesitter = true, hud = {width = 0.42, height = 0.3, zindex = 1, enabled = true, passive_close_delay = 0, minimum_lifetime_ms = 20, overlap_padding = 0.1, border = "single", anchor = "NE", ignore_low_priority = false}, jump_to_latest = {cursor_scroll_position = "top", enabled = false}, break_length = 80, trim = {at = 10000, to = 6000}, strip_ansi_escape_sequences_line_limit = 1000, fold = {lines = 10, marker = {start = "~~~%{", ["end"] = "}%~~~"}, enabled = false}, botright = false, diagnostics = false, wrap = false}, extract = {context_header_lines = 24, form_pairs = {{"(", ")"}, {"{", "}"}, {"[", "]", true}}, tree_sitter = {enabled = true}}, preview = {sample_limit = 0.3}, debug = false}) if get_in({"mapping", "enable_defaults"}) then merge({mapping = {log_split = "ls", log_vsplit = "lv", log_tab = "lt", log_buf = "le", log_toggle = "lg", log_close_visible = "lq", log_reset_soft = "lr", log_reset_hard = "lR", log_jump_to_latest = "ll", eval_current_form = "ee", eval_comment_current_form = "ece", eval_root_form = "er", eval_comment_root_form = "ecr", eval_word = "ew", eval_comment_word = "ecw", eval_replace_form = "e!", eval_marked_form = "em", eval_file = "ef", eval_buf = "eb", eval_visual = "E", eval_motion = "E", eval_previous = "ep", def_word = "gd", doc_word = {"K"}}}) else diff --git a/lua/conjure/log.lua b/lua/conjure/log.lua index a607f3a0..ed1b3427 100644 --- a/lua/conjure/log.lua +++ b/lua/conjure/log.lua @@ -48,6 +48,11 @@ local function on_new_log_buf(buf) vim.diagnostic.disable(buf) else end + if (vim.treesitter and (false == config["get-in"]({"log", "treesitter"}))) then + vim.treesitter.stop(buf) + nvim.buf_set_option(buf, "syntax", "on") + else + end return nvim.buf_set_lines(buf, 0, -1, false, {str.join({client.get("comment-prefix"), "Sponsored by @", a.get(sponsors, a.inc(math.floor(a.rand(a.dec(a.count(sponsors)))))), " \226\157\164"})}) end _2amodule_locals_2a["on-new-log-buf"] = on_new_log_buf @@ -59,7 +64,7 @@ local function clear_close_hud_passive_timer() return a["update-in"](state, {"hud", "timer"}, timer.destroy) end _2amodule_2a["clear-close-hud-passive-timer"] = clear_close_hud_passive_timer -local function _2_() +local function _3_() if state.hud.id then pcall(nvim.win_close, state.hud.id, true) state.hud.id = nil @@ -68,7 +73,7 @@ local function _2_() return nil end end -hook.define("close-hud", _2_) +hook.define("close-hud", _3_) local function close_hud() clear_close_hud_passive_timer() return hook.exec("close-hud") @@ -98,24 +103,24 @@ end _2amodule_2a["close-hud-passive"] = close_hud_passive local function break_lines(buf) local break_str = _break() - local function _9_(_7_) - local _arg_8_ = _7_ - local n = _arg_8_[1] - local s = _arg_8_[2] + local function _10_(_8_) + local _arg_9_ = _8_ + local n = _arg_9_[1] + local s = _arg_9_[2] return (s == break_str) end - return a.map(a.first, a.filter(_9_, a["kv-pairs"](nvim.buf_get_lines(buf, 0, -1, false)))) + return a.map(a.first, a.filter(_10_, a["kv-pairs"](nvim.buf_get_lines(buf, 0, -1, false)))) end _2amodule_locals_2a["break-lines"] = break_lines local function set_win_opts_21(win) - local function _10_() + local function _11_() if config["get-in"]({"log", "wrap"}) then return true else return false end end - nvim.win_set_option(win, "wrap", _10_()) + nvim.win_set_option(win, "wrap", _11_()) nvim.win_set_option(win, "foldmethod", "marker") nvim.win_set_option(win, "foldmarker", (config["get-in"]({"log", "fold", "marker", "start"}) .. "," .. config["get-in"]({"log", "fold", "marker", "end"}))) return nvim.win_set_option(win, "foldlevel", 0) @@ -128,26 +133,26 @@ _2amodule_locals_2a["in-box?"] = in_box_3f local function flip_anchor(anchor, n) local chars = {anchor:sub(1, 1), anchor:sub(2)} local flip = {N = "S", S = "N", E = "W", W = "E"} - local function _11_(_241) + local function _12_(_241) return a.get(flip, _241) end - return str.join(a.update(chars, n, _11_)) + return str.join(a.update(chars, n, _12_)) end _2amodule_locals_2a["flip-anchor"] = flip_anchor local function pad_box(box, padding) - local function _12_(_241) + local function _13_(_241) return (_241 - padding.x) end - local function _13_(_241) + local function _14_(_241) return (_241 - padding.y) end - local function _14_(_241) + local function _15_(_241) return (_241 + padding.x) end - local function _15_(_241) + local function _16_(_241) return (_241 + padding.y) end - return a.update(a.update(a.update(a.update(box, "x1", _12_), "y1", _13_), "x2", _14_), "y2", _15_) + return a.update(a.update(a.update(a.update(box, "x1", _13_), "y1", _14_), "x2", _15_), "y2", _16_) end _2amodule_locals_2a["pad-box"] = pad_box local function hud_window_pos(anchor, size, rec_3f) @@ -157,29 +162,29 @@ local function hud_window_pos(anchor, size, rec_3f) local east = editor.width() local padding_percent = config["get-in"]({"log", "hud", "overlap_padding"}) local pos - local _16_ + local _17_ if ("NE" == anchor) then - _16_ = {row = north, col = east, box = {y1 = north, x1 = (east - size.width), y2 = (north + size.height), x2 = east}} + _17_ = {row = north, col = east, box = {y1 = north, x1 = (east - size.width), y2 = (north + size.height), x2 = east}} elseif ("SE" == anchor) then - _16_ = {row = south, col = east, box = {y1 = (south - size.height), x1 = (east - size.width), y2 = south, x2 = east}} + _17_ = {row = south, col = east, box = {y1 = (south - size.height), x1 = (east - size.width), y2 = south, x2 = east}} elseif ("SW" == anchor) then - _16_ = {row = south, col = west, box = {y1 = (south - size.height), x1 = west, y2 = south, x2 = (west + size.width)}} + _17_ = {row = south, col = west, box = {y1 = (south - size.height), x1 = west, y2 = south, x2 = (west + size.width)}} elseif ("NW" == anchor) then - _16_ = {row = north, col = west, box = {y1 = north, x1 = west, y2 = (north + size.height), x2 = (west + size.width)}} + _17_ = {row = north, col = west, box = {y1 = north, x1 = west, y2 = (north + size.height), x2 = (west + size.width)}} else nvim.err_writeln("g:conjure#log#hud#anchor must be one of: NE, SE, SW, NW") - _16_ = hud_window_pos("NE", size) + _17_ = hud_window_pos("NE", size) end - pos = a.assoc(_16_, "anchor", anchor) + pos = a.assoc(_17_, "anchor", anchor) if (not rec_3f and in_box_3f(pad_box(pos.box, {x = editor["percent-width"](padding_percent), y = editor["percent-height"](padding_percent)}), {x = editor["cursor-left"](), y = editor["cursor-top"]()})) then - local function _18_() + local function _19_() if (size.width > size.height) then return 1 else return 2 end end - return hud_window_pos(flip_anchor(anchor, _18_()), size, true) + return hud_window_pos(flip_anchor(anchor, _19_()), size, true) else return pos end @@ -212,7 +217,7 @@ local function handle_low_priority_spam_21(low_priority_3f) end end _2amodule_locals_2a["handle-low-priority-spam!"] = handle_low_priority_spam_21 -local function _23_(opts) +local function _24_(opts) local buf = upsert_buf() local last_break = a.last(break_lines(buf)) local line_count = nvim.buf_line_count(buf) @@ -239,7 +244,7 @@ local function _23_(opts) return nvim.win_set_cursor(state.hud.id, {line_count, 0}) end end -hook.define("display-hud", _23_) +hook.define("display-hud", _24_) local function display_hud(opts) if (config["get-in"]({"log", "hud", "enabled"}) and not current_window_floating_3f() and (not config["get-in"]({"log", "hud", "ignore_low_priority"}) or (config["get-in"]({"log", "hud", "ignore_low_priority"}) and not a.get(opts, "low-priority?")))) then clear_close_hud_passive_timer() @@ -254,14 +259,14 @@ local function win_visible_3f(win) end _2amodule_locals_2a["win-visible?"] = win_visible_3f local function with_buf_wins(buf, f) - local function _28_(win) + local function _29_(win) if (buf == nvim.win_get_buf(win)) then return f(win) else return nil end end - return a["run!"](_28_, nvim.list_wins()) + return a["run!"](_29_, nvim.list_wins()) end _2amodule_locals_2a["with-buf-wins"] = with_buf_wins local function win_botline(win) @@ -273,25 +278,25 @@ local function trim(buf) if (line_count > config["get-in"]({"log", "trim", "at"})) then local target_line_count = (line_count - config["get-in"]({"log", "trim", "to"})) local break_line - local function _30_(line) + local function _31_(line) if (line >= target_line_count) then return line else return nil end end - break_line = a.some(_30_, break_lines(buf)) + break_line = a.some(_31_, break_lines(buf)) if break_line then nvim.buf_set_lines(buf, 0, break_line, false, {}) local line_count0 = nvim.buf_line_count(buf) - local function _32_(win) - local _let_33_ = nvim.win_get_cursor(win) - local row = _let_33_[1] - local col = _let_33_[2] + local function _33_(win) + local _let_34_ = nvim.win_get_cursor(win) + local row = _let_34_[1] + local col = _let_34_[2] nvim.win_set_cursor(win, {1, 0}) return nvim.win_set_cursor(win, {row, col}) end - return with_buf_wins(buf, _32_) + return with_buf_wins(buf, _33_) else return nil end @@ -309,22 +314,22 @@ _2amodule_2a["cursor-scroll-position->command"] = cursor_scroll_position__3ecomm local function jump_to_latest() local buf = upsert_buf() local last_eval_start = nvim.buf_get_extmark_by_id(buf, state["jump-to-latest"].ns, state["jump-to-latest"].mark, {}) - local function _36_(win) - local function _37_() + local function _37_(win) + local function _38_() return nvim.win_set_cursor(win, last_eval_start) end - pcall(_37_) + pcall(_38_) local cmd = a.get(cursor_scroll_position__3ecommand, config["get-in"]({"log", "jump_to_latest", "cursor_scroll_position"})) if cmd then - local function _38_() + local function _39_() return nvim.command(cmd) end - return nvim.win_call(win, _38_) + return nvim.win_call(win, _39_) else return nil end end - return with_buf_wins(buf, _36_) + return with_buf_wins(buf, _37_) end _2amodule_2a["jump-to-latest"] = jump_to_latest local function append(lines, opts) @@ -334,10 +339,10 @@ local function append(lines, opts) local buf = upsert_buf() local join_first_3f = a.get(opts, "join-first?") local lines0 - local function _40_(line) + local function _41_(line) return string.gsub(tostring(line), "\n", "\226\134\181") end - lines0 = a.map(_40_, lines) + lines0 = a.map(_41_, lines) local lines1 if (line_count <= config["get-in"]({"log", "strip_ansi_escape_sequences_line_limit"})) then lines1 = a.map(text["strip-ansi-escape-sequences"], lines0) @@ -355,43 +360,43 @@ local function append(lines, opts) local last_fold_3f = (fold_marker_end == last_line(buf)) local lines3 if a.get(opts, "break?") then - local _43_ + local _44_ if client["multiple-states?"]() then - _43_ = {state_key_header()} + _44_ = {state_key_header()} else - _43_ = nil + _44_ = nil end - lines3 = a.concat({_break()}, _43_, lines2) + lines3 = a.concat({_break()}, _44_, lines2) elseif join_first_3f then - local _45_ + local _46_ if last_fold_3f then - _45_ = {(last_line(buf, -1) .. a.first(lines2)), fold_marker_end} + _46_ = {(last_line(buf, -1) .. a.first(lines2)), fold_marker_end} else - _45_ = {(last_line(buf) .. a.first(lines2))} + _46_ = {(last_line(buf) .. a.first(lines2))} end - lines3 = a.concat(_45_, a.rest(lines2)) + lines3 = a.concat(_46_, a.rest(lines2)) else lines3 = lines2 end local old_lines = nvim.buf_line_count(buf) do local ok_3f, err = nil, nil - local function _48_() - local _49_ + local function _49_() + local _50_ if buffer["empty?"](buf) then - _49_ = 0 + _50_ = 0 elseif join_first_3f then if last_fold_3f then - _49_ = -3 + _50_ = -3 else - _49_ = -2 + _50_ = -2 end else - _49_ = -1 + _50_ = -1 end - return nvim.buf_set_lines(buf, _49_, -1, false, lines3) + return nvim.buf_set_lines(buf, _50_, -1, false, lines3) end - ok_3f, err = pcall(_48_) + ok_3f, err = pcall(_49_) if not ok_3f then error(("Conjure failed to append to log: " .. err .. "\n" .. "Offending lines: " .. a["pr-str"](lines3))) else @@ -400,18 +405,18 @@ local function append(lines, opts) do local new_lines = nvim.buf_line_count(buf) local jump_to_latest_3f = config["get-in"]({"log", "jump_to_latest", "enabled"}) - local _53_ + local _54_ if join_first_3f then - _53_ = old_lines + _54_ = old_lines else - _53_ = a.inc(old_lines) + _54_ = a.inc(old_lines) end - nvim.buf_set_extmark(buf, state["jump-to-latest"].ns, _53_, 0, {id = state["jump-to-latest"].mark}) - local function _55_(win) + nvim.buf_set_extmark(buf, state["jump-to-latest"].ns, _54_, 0, {id = state["jump-to-latest"].mark}) + local function _56_(win) visible_scrolling_log_3f = ((win ~= state.hud.id) and win_visible_3f(win) and (jump_to_latest_3f or (win_botline(win) >= old_lines))) - local _let_56_ = nvim.win_get_cursor(win) - local row = _let_56_[1] - local _ = _let_56_[2] + local _let_57_ = nvim.win_get_cursor(win) + local row = _let_57_[1] + local _ = _let_57_[2] if jump_to_latest_3f then return jump_to_latest() elseif (row == old_lines) then @@ -420,7 +425,7 @@ local function append(lines, opts) return nil end end - with_buf_wins(buf, _55_) + with_buf_wins(buf, _56_) end if (not a.get(opts, "suppress-hud?") and not visible_scrolling_log_3f) then display_hud(opts) @@ -436,14 +441,14 @@ _2amodule_2a["append"] = append local function create_win(cmd) state["last-open-cmd"] = cmd local buf = upsert_buf() - local function _60_() + local function _61_() if config["get-in"]({"log", "botright"}) then return "botright " else return "" end end - nvim.command(("keepalt " .. _60_() .. cmd .. " " .. buffer.resolve(log_buf_name()))) + nvim.command(("keepalt " .. _61_() .. cmd .. " " .. buffer.resolve(log_buf_name()))) nvim.win_set_cursor(0, {nvim.buf_line_count(buf), 0}) set_win_opts_21(0) return buffer.unlist(buf) @@ -467,17 +472,17 @@ end _2amodule_2a["buf"] = buf local function find_windows() local buf0 = upsert_buf() - local function _61_(win) + local function _62_(win) return ((state.hud.id ~= win) and (buf0 == nvim.win_get_buf(win))) end - return a.filter(_61_, nvim.tabpage_list_wins(0)) + return a.filter(_62_, nvim.tabpage_list_wins(0)) end _2amodule_locals_2a["find-windows"] = find_windows local function close(windows) - local function _62_(_241) + local function _63_(_241) return nvim.win_close(_241, true) end - return a["run!"](_62_, windows) + return a["run!"](_63_, windows) end _2amodule_locals_2a["close"] = close local function close_visible()