From 6b1cab690c13be83d3f2a4279a0880cff8c7f9b2 Mon Sep 17 00:00:00 2001 From: Rishikesh Vaishnav Date: Fri, 2 Jun 2023 17:48:37 +0200 Subject: [PATCH 1/5] extract `with_highlight_chores` --- fnl/leap/highlight.fnl | 22 +-- fnl/leap/main.fnl | 60 ++++--- lua/leap/highlight.lua | 69 +++----- lua/leap/main.lua | 360 +++++++++++++++++++++-------------------- 4 files changed, 255 insertions(+), 256 deletions(-) diff --git a/fnl/leap/highlight.fnl b/fnl/leap/highlight.fnl index ac1e46c..b9b7123 100644 --- a/fnl/leap/highlight.fnl +++ b/fnl/leap/highlight.fnl @@ -34,23 +34,13 @@ (vim.fn.line "w$")))) -(fn M.apply-backdrop [self backward? ?target-windows] +(fn M.apply-backdrop [self ranges] (when (pcall api.nvim_get_hl_by_name self.group.backdrop false) ; group exists? - (if ?target-windows - (each [_ winid (ipairs ?target-windows)] - (local wininfo (. (vim.fn.getwininfo winid) 1)) - (vim.highlight.range wininfo.bufnr self.ns self.group.backdrop - [(dec wininfo.topline) 0] - [(dec wininfo.botline) -1] - {:priority self.priority.backdrop})) - (let [[curline curcol] (map dec [(vim.fn.line ".") (vim.fn.col ".")]) - [win-top win-bot] [(dec (vim.fn.line "w0")) (dec (vim.fn.line "w$"))] - [start finish] (if backward? - [[win-top 0] [curline curcol]] - [[curline (inc curcol)] [win-bot -1]])] - ; Expects 0,0-indexed args; `finish` is exclusive. - (vim.highlight.range 0 self.ns self.group.backdrop start finish - {:priority self.priority.backdrop}))))) + (each [_ range (ipairs ranges)] + (vim.highlight.range range.bufnr self.ns self.group.backdrop + [range.startrow range.startcol] + [range.endrow range.endcol] + {:priority self.priority.backdrop})))) (fn M.highlight-cursor [self ?pos] diff --git a/fnl/leap/main.fnl b/fnl/leap/main.fnl index ea6aeb9..ef14ad2 100644 --- a/fnl/leap/main.fnl +++ b/fnl/leap/main.fnl @@ -357,9 +357,17 @@ is either labeled (C) or not (B). (when aot? (resolve-conflicts targets))))) - -(fn light-up-beacons [targets ?start ?end] - (for [i (or ?start 1) (or ?end (length targets))] +(fn with-highlight-chores [opts task] + (do (local opts (or opts {})) + (hl:cleanup opts.hl-affected-windows) + (hl:apply-backdrop (or opts.backdrop-ranges [])) + (task) + (hl:highlight-cursor) + (vim.cmd :redraw))) + +(fn light-up-beacons [targets opts] + (local opts (or opts {})) + (for [i (or opts.start 1) (or opts.end (length targets))] (local target (. targets i)) (case target.beacon [offset virttext] @@ -486,13 +494,29 @@ is either labeled (C) or not (B). (when vars.errmsg (echo vars.errmsg)) (exit))) - (macro with-highlight-chores [...] - `(do (hl:cleanup hl-affected-windows) - (when-not count - (hl:apply-backdrop backward? ?target-windows)) - (do ,...) - (hl:highlight-cursor) - (vim.cmd :redraw))) + (local backdrop-ranges []) + (when (and (pcall api.nvim_get_hl_by_name hl.group.backdrop false) (not count)) + (if ?target-windows + (each [_ winid (ipairs ?target-windows)] + (local wininfo (. (vim.fn.getwininfo winid) 1)) + (local range {:bufnr wininfo.bufnr + :startrow (dec wininfo.topline) + :startcol 0 + :endrow (dec wininfo.botline) + :endcol -1}) + (table.insert backdrop-ranges range)) + (let [[curline curcol] (map dec [(vim.fn.line ".") (vim.fn.col ".")]) + [win-top win-bot] [(dec (vim.fn.line "w0")) (dec (vim.fn.line "w$"))] + [startrow startcol endrow endcol] (if backward? + [win-top 0 curline curcol] + [curline (inc curcol) win-bot -1])] + (local wininfo (. (vim.fn.getwininfo 0) 1)) + (local range {:bufnr wininfo.bufnr + :startrow startrow + :startcol startcol + :endrow endrow + :endcol endcol}) + (table.insert backdrop-ranges range)))) ; Helper functions /// @@ -644,7 +668,7 @@ is either labeled (C) or not (B). (values start end)))) (fn get-first-pattern-input [] - (with-highlight-chores (echo "")) ; clean up the command line + (with-highlight-chores {: backdrop-ranges : hl-affected-windows} (fn [] (echo ""))) ; clean up the command line (case (get-input-by-keymap prompt) ; Here we can handle any other modifier key as "zeroth" input, ; if the need arises. @@ -663,7 +687,7 @@ is either labeled (C) or not (B). ; char partial input (but it implies not needing ; to show beacons). (not count)) - (with-highlight-chores (light-up-beacons targets))) + (with-highlight-chores {: backdrop-ranges : hl-affected-windows} (fn [] (light-up-beacons targets)))) (get-input-by-keymap prompt)) (fn get-full-pattern-input [] @@ -685,9 +709,8 @@ is either labeled (C) or not (B). (when targets.label-set (set-label-states targets {: group-offset})) (set-beacons targets {:aot? vars.aot? : no-labels? : user-given-targets?}) - (with-highlight-chores - (local (start end) (get-highlighted-idx-range targets no-labels?)) - (light-up-beacons targets start end))) + (local (start end) (get-highlighted-idx-range targets no-labels?)) + (with-highlight-chores {: backdrop-ranges : hl-affected-windows} (fn [] (light-up-beacons targets {: start : end})))) ; --- (fn loop [group-offset first-invoc?] (display group-offset) @@ -751,9 +774,8 @@ is either labeled (C) or not (B). ; --- (fn display [] (set-beacons targets {: no-labels? :aot? vars.aot? : user-given-targets?}) - (with-highlight-chores - (local (start end) (get-highlighted-idx-range targets no-labels?)) - (light-up-beacons targets start end))) + (local (start end) (get-highlighted-idx-range targets no-labels?)) + (with-highlight-chores {: backdrop-ranges : hl-affected-windows} (fn [] (light-up-beacons targets {: start : end})))) ; --- (fn get-new-idx [idx in] (if (contains? spec-keys.next_target in) (min (inc idx) (length targets)) @@ -865,7 +887,7 @@ is either labeled (C) or not (B). targets** ; The action callback should expect a list in this case. ; It might also get user input, so keep the beacons highlighted. - (do (with-highlight-chores (light-up-beacons targets**)) + (do (with-highlight-chores {: backdrop-ranges : hl-affected-windows} (fn [] (light-up-beacons targets**))) (do-action targets**))) (exit)) diff --git a/lua/leap/highlight.lua b/lua/leap/highlight.lua index 2245cb1..7b1f924 100644 --- a/lua/leap/highlight.lua +++ b/lua/leap/highlight.lua @@ -23,42 +23,21 @@ M.cleanup = function(self, affected_windows) return nil end end -M["apply-backdrop"] = function(self, backward_3f, _3ftarget_windows) +M["apply-backdrop"] = function(self, ranges) if pcall(api.nvim_get_hl_by_name, self.group.backdrop, false) then - if _3ftarget_windows then - for _, winid in ipairs(_3ftarget_windows) do - local wininfo = vim.fn.getwininfo(winid)[1] - vim.highlight.range(wininfo.bufnr, self.ns, self.group.backdrop, {dec(wininfo.topline), 0}, {dec(wininfo.botline), -1}, {priority = self.priority.backdrop}) - end - return nil - else - local _let_5_ = map(dec, {vim.fn.line("."), vim.fn.col(".")}) - local curline = _let_5_[1] - local curcol = _let_5_[2] - local _let_6_ = {dec(vim.fn.line("w0")), dec(vim.fn.line("w$"))} - local win_top = _let_6_[1] - local win_bot = _let_6_[2] - local function _8_() - if backward_3f then - return {{win_top, 0}, {curline, curcol}} - else - return {{curline, inc(curcol)}, {win_bot, -1}} - end - end - local _let_7_ = _8_() - local start = _let_7_[1] - local finish = _let_7_[2] - return vim.highlight.range(0, self.ns, self.group.backdrop, start, finish, {priority = self.priority.backdrop}) + for _, range in ipairs(ranges) do + vim.highlight.range(range.bufnr, self.ns, self.group.backdrop, {range.startrow, range.startcol}, {range.endrow, range.endcol}, {priority = self.priority.backdrop}) end + return nil else return nil end end M["highlight-cursor"] = function(self, _3fpos) - local _let_11_ = (_3fpos or util["get-cursor-pos"]()) - local line = _let_11_[1] - local col = _let_11_[2] - local pos = _let_11_ + local _let_6_ = (_3fpos or util["get-cursor-pos"]()) + local line = _let_6_[1] + local col = _let_6_[2] + local pos = _let_6_ local ch_at_curpos = (util["get-char-at"](pos, {}) or " ") local id = api.nvim_buf_set_extmark(0, self.ns, dec(line), dec(col), {virt_text = {{ch_at_curpos, "Cursor"}}, virt_text_pos = "overlay", hl_mode = "combine", priority = self.priority.cursor}) return table.insert(self.extmarks, {api.nvim_get_current_buf(), id}) @@ -66,11 +45,23 @@ end M["init-highlight"] = function(self, force_3f) local bg = vim.o.background local defaults + local _8_ + do + local _7_ = bg + if (_7_ == "light") then + _8_ = "#222222" + elseif true then + local _ = _7_ + _8_ = "#ccff88" + else + _8_ = nil + end + end local _13_ do local _12_ = bg if (_12_ == "light") then - _13_ = "#222222" + _13_ = "#ff8877" elseif true then local _ = _12_ _13_ = "#ccff88" @@ -82,27 +73,15 @@ M["init-highlight"] = function(self, force_3f) do local _17_ = bg if (_17_ == "light") then - _18_ = "#ff8877" + _18_ = "#77aaff" elseif true then local _ = _17_ - _18_ = "#ccff88" + _18_ = "#99ccff" else _18_ = nil end end - local _23_ - do - local _22_ = bg - if (_22_ == "light") then - _23_ = "#77aaff" - elseif true then - local _ = _22_ - _23_ = "#99ccff" - else - _23_ = nil - end - end - defaults = {[self.group.match] = {fg = _13_, ctermfg = "red", underline = true, nocombine = true}, [self.group["label-primary"]] = {fg = "black", bg = _18_, ctermfg = "black", ctermbg = "red", nocombine = true}, [self.group["label-secondary"]] = {fg = "black", bg = _23_, ctermfg = "black", ctermbg = "blue", nocombine = true}, [self.group["label-selected"]] = {fg = "black", bg = "magenta", ctermfg = "black", ctermbg = "magenta", nocombine = true}} + defaults = {[self.group.match] = {fg = _8_, ctermfg = "red", underline = true, nocombine = true}, [self.group["label-primary"]] = {fg = "black", bg = _13_, ctermfg = "black", ctermbg = "red", nocombine = true}, [self.group["label-secondary"]] = {fg = "black", bg = _18_, ctermfg = "black", ctermbg = "blue", nocombine = true}, [self.group["label-selected"]] = {fg = "black", bg = "magenta", ctermfg = "black", ctermbg = "magenta", nocombine = true}} for group_name, def_map in pairs(defaults) do if not force_3f then def_map.default = true diff --git a/lua/leap/main.lua b/lua/leap/main.lua index 7d61460..14f550a 100644 --- a/lua/leap/main.lua +++ b/lua/leap/main.lua @@ -343,8 +343,17 @@ local function set_beacons(targets, _52_) end end end -local function light_up_beacons(targets, _3fstart, _3fend) - for i = (_3fstart or 1), (_3fend or #targets) do +local function with_highlight_chores(opts0, task) + local opts1 = (opts0 or {}) + hl:cleanup(opts1["hl-affected-windows"]) + hl["apply-backdrop"](hl, (opts1["backdrop-ranges"] or {})) + task() + hl["highlight-cursor"](hl) + return vim.cmd("redraw") +end +local function light_up_beacons(targets, opts0) + local opts1 = (opts0 or {}) + for i = (opts1.start or 1), (opts1["end"] or #targets) do local target = targets[i] local _57_ = target.beacon if ((_G.type(_57_) == "table") and (nil ~= (_57_)[1]) and (nil ~= (_57_)[2])) then @@ -480,6 +489,39 @@ local function leap(kwargs) spec_keys = setmetatable({}, {__index = __index}) end local vars = {["aot?"] = not ((max_phase_one_targets == 0) or empty_label_lists_3f or multi_select_3f or user_given_targets_3f), ["curr-idx"] = 0, errmsg = nil} + local backdrop_ranges = {} + if (pcall(api.nvim_get_hl_by_name, hl.group.backdrop, false) and not count) then + if _3ftarget_windows then + for _, winid in ipairs(_3ftarget_windows) do + local wininfo = vim.fn.getwininfo(winid)[1] + local range = {bufnr = wininfo.bufnr, startrow = dec(wininfo.topline), startcol = 0, endrow = dec(wininfo.botline), endcol = -1} + table.insert(backdrop_ranges, range) + end + else + local _let_77_ = map(dec, {vim.fn.line("."), vim.fn.col(".")}) + local curline = _let_77_[1] + local curcol = _let_77_[2] + local _let_78_ = {dec(vim.fn.line("w0")), dec(vim.fn.line("w$"))} + local win_top = _let_78_[1] + local win_bot = _let_78_[2] + local function _80_() + if backward_3f then + return {win_top, 0, curline, curcol} + else + return {curline, inc(curcol), win_bot, -1} + end + end + local _let_79_ = _80_() + local startrow = _let_79_[1] + local startcol = _let_79_[2] + local endrow = _let_79_[3] + local endcol = _let_79_[4] + local wininfo = (vim.fn.getwininfo(0))[1] + local range = {bufnr = wininfo.bufnr, startrow = startrow, startcol = startcol, endrow = endrow, endcol = endcol} + table.insert(backdrop_ranges, range) + end + else + end local function get_user_given_targets(targets) local targets_2a if (type(targets) == "function") then @@ -527,41 +569,41 @@ local function leap(kwargs) else pat = (pat1 .. pat2) end - local function _83_() + local function _89_() if opts.case_sensitive then return "\\C" else return "\\c" end end - return ("\\V" .. _83_() .. pat) + return ("\\V" .. _89_() .. pat) end local function get_targets(in1, _3fin2) local search = require("leap.search") local pattern = prepare_pattern(in1, _3fin2) local kwargs0 = {["backward?"] = backward_3f, ["match-xxx*-at-the-end?"] = match_xxx_2a_at_the_end_3f, ["target-windows"] = _3ftarget_windows} local targets = search["get-targets"](pattern, kwargs0) - local function _84_() + local function _90_() vars.errmsg = ("not found: " .. in1 .. (_3fin2 or "")) return nil end - return (targets or _84_()) + return (targets or _90_()) end local function prepare_targets(targets) local funny_edge_case_3f - local function _85_() - local _86_ = targets - if ((_G.type(_86_) == "table") and ((_G.type((_86_)[1]) == "table") and ((_G.type(((_86_)[1]).pos) == "table") and (nil ~= (((_86_)[1]).pos)[1]) and (nil ~= (((_86_)[1]).pos)[2]))) and ((_G.type((_86_)[2]) == "table") and ((_G.type(((_86_)[2]).pos) == "table") and (nil ~= (((_86_)[2]).pos)[1]) and (nil ~= (((_86_)[2]).pos)[2])))) then - local l1 = (((_86_)[1]).pos)[1] - local c1 = (((_86_)[1]).pos)[2] - local l2 = (((_86_)[2]).pos)[1] - local c2 = (((_86_)[2]).pos)[2] + local function _91_() + local _92_ = targets + if ((_G.type(_92_) == "table") and ((_G.type((_92_)[1]) == "table") and ((_G.type(((_92_)[1]).pos) == "table") and (nil ~= (((_92_)[1]).pos)[1]) and (nil ~= (((_92_)[1]).pos)[2]))) and ((_G.type((_92_)[2]) == "table") and ((_G.type(((_92_)[2]).pos) == "table") and (nil ~= (((_92_)[2]).pos)[1]) and (nil ~= (((_92_)[2]).pos)[2])))) then + local l1 = (((_92_)[1]).pos)[1] + local c1 = (((_92_)[1]).pos)[2] + local l2 = (((_92_)[2]).pos)[1] + local c2 = (((_92_)[2]).pos)[2] return ((l1 == l2) and (c1 == (c2 + 2))) else return nil end end - funny_edge_case_3f = (backward_3f and _85_()) + funny_edge_case_3f = (backward_3f and _91_()) local force_noautojump_3f = (op_mode_3f or multi_select_3f or not directional_3f or user_given_action or funny_edge_case_3f) set_autojump(targets, force_noautojump_3f) attach_label_set(targets) @@ -570,11 +612,11 @@ local function leap(kwargs) end local function get_target_with_active_primary_label(sublist, input) local res = {} - for idx, _88_ in ipairs(sublist) do - local _each_89_ = _88_ - local label = _each_89_["label"] - local label_state = _each_89_["label-state"] - local target = _each_89_ + for idx, _94_ in ipairs(sublist) do + local _each_95_ = _94_ + local label = _each_95_["label"] + local label_state = _each_95_["label-state"] + local target = _each_95_ if (next(res) or (label_state == "inactive")) then break end if ((label == input) and (label_state == "active-primary")) then res = {idx, target} @@ -602,18 +644,18 @@ local function leap(kwargs) local jump_to_21 do local first_jump_3f = true - local function _93_(target) + local function _99_(target) local jump = require("leap.jump") jump["jump-to!"](target.pos, {winid = target.wininfo.winid, ["add-to-jumplist?"] = first_jump_3f, mode = mode, offset = offset, ["backward?"] = backward_3f, ["inclusive-op?"] = inclusive_op_3f}) first_jump_3f = false return nil end - jump_to_21 = _93_ + jump_to_21 = _99_ end local function get_number_of_highlighted_targets() - local _94_ = opts.max_highlighted_traversal_targets - if (nil ~= _94_) then - local group_size = _94_ + local _100_ = opts.max_highlighted_traversal_targets + if (nil ~= _100_) then + local group_size = _100_ local consumed = (dec(vars["curr-idx"]) % group_size) local remaining = (group_size - consumed) if (remaining == 1) then @@ -634,16 +676,16 @@ local function leap(kwargs) local start = inc(vars["curr-idx"]) local _end if no_labels_3f then - local _97_ = get_number_of_highlighted_targets() - if (nil ~= _97_) then - local _98_ = (_97_ + dec(start)) - if (nil ~= _98_) then - _end = min(_98_, #targets) + local _103_ = get_number_of_highlighted_targets() + if (nil ~= _103_) then + local _104_ = (_103_ + dec(start)) + if (nil ~= _104_) then + _end = min(_104_, #targets) else - _end = _98_ + _end = _104_ end else - _end = _97_ + _end = _103_ end else _end = nil @@ -652,20 +694,12 @@ local function leap(kwargs) end end local function get_first_pattern_input() - do - hl:cleanup(hl_affected_windows) - if not count then - hl["apply-backdrop"](hl, backward_3f, _3ftarget_windows) - else - end - do - echo("") - end - hl["highlight-cursor"](hl) - vim.cmd("redraw") + local function _109_() + return echo("") end - local _104_, _105_ = get_input_by_keymap(prompt) - if (_104_ == spec_keys.repeat_search) then + with_highlight_chores({["backdrop-ranges"] = backdrop_ranges, ["hl-affected-windows"] = hl_affected_windows}, _109_) + local _110_, _111_ = get_input_by_keymap(prompt) + if (_110_ == spec_keys.repeat_search) then if state["repeat"].in1 then vars["aot?"] = false return state["repeat"].in1, state["repeat"].in2 @@ -673,8 +707,8 @@ local function leap(kwargs) vars.errmsg = "no previous search" return nil end - elseif (nil ~= _104_) then - local in1 = _104_ + elseif (nil ~= _110_) then + local in1 = _110_ return in1 else return nil @@ -682,31 +716,25 @@ local function leap(kwargs) end local function get_second_pattern_input(targets) if ((#targets <= max_phase_one_targets) and not count) then - hl:cleanup(hl_affected_windows) - if not count then - hl["apply-backdrop"](hl, backward_3f, _3ftarget_windows) - else - end - do - light_up_beacons(targets) + local function _114_() + return light_up_beacons(targets) end - hl["highlight-cursor"](hl) - vim.cmd("redraw") + with_highlight_chores({["backdrop-ranges"] = backdrop_ranges, ["hl-affected-windows"] = hl_affected_windows}, _114_) else end return get_input_by_keymap(prompt) end local function get_full_pattern_input() - local _110_, _111_ = get_first_pattern_input() - if ((nil ~= _110_) and (nil ~= _111_)) then - local in1 = _110_ - local in2 = _111_ + local _116_, _117_ = get_first_pattern_input() + if ((nil ~= _116_) and (nil ~= _117_)) then + local in1 = _116_ + local in2 = _117_ return in1, in2 - elseif ((nil ~= _110_) and (_111_ == nil)) then - local in1 = _110_ - local _112_ = get_input_by_keymap(prompt) - if (nil ~= _112_) then - local in2 = _112_ + elseif ((nil ~= _116_) and (_117_ == nil)) then + local in1 = _116_ + local _118_ = get_input_by_keymap(prompt) + if (nil ~= _118_) then + local in2 = _118_ return in1, in2 else return nil @@ -729,23 +757,17 @@ local function leap(kwargs) else end set_beacons(targets, {["aot?"] = vars["aot?"], ["no-labels?"] = no_labels_3f, ["user-given-targets?"] = user_given_targets_3f}) - hl:cleanup(hl_affected_windows) - if not count then - hl["apply-backdrop"](hl, backward_3f, _3ftarget_windows) - else + local start, _end = get_highlighted_idx_range(targets, no_labels_3f) + local function _123_() + return light_up_beacons(targets, {start = start, ["end"] = _end}) end - do - local start, _end = get_highlighted_idx_range(targets, no_labels_3f) - light_up_beacons(targets, start, _end) - end - hl["highlight-cursor"](hl) - return vim.cmd("redraw") + return with_highlight_chores({["backdrop-ranges"] = backdrop_ranges, ["hl-affected-windows"] = hl_affected_windows}, _123_) end local function loop(group_offset, first_invoc_3f0) display(group_offset) - local _118_ = get_input() - if (nil ~= _118_) then - local input = _118_ + local _124_ = get_input() + if (nil ~= _124_) then + local input = _124_ local switch_group_3f = ((_7cgroups_7c > 1) and ((input == spec_keys.next_group) or ((input == spec_keys.prev_group) and not first_invoc_3f0))) if switch_group_3f then local inc_2fdec @@ -772,32 +794,32 @@ local function leap(kwargs) local group_offset = 0 local first_invoc_3f = true local function loop(targets) - local _122_, _123_ = post_pattern_input_loop(targets, group_offset, first_invoc_3f) - if (_122_ == spec_keys.multi_accept) then + local _128_, _129_ = post_pattern_input_loop(targets, group_offset, first_invoc_3f) + if (_128_ == spec_keys.multi_accept) then if not empty_3f(selection) then return selection else return loop(targets) end - elseif (_122_ == spec_keys.multi_revert) then + elseif (_128_ == spec_keys.multi_revert) then do - local _125_ = table.remove(selection) - if (nil ~= _125_) then - _125_["label-state"] = nil + local _131_ = table.remove(selection) + if (nil ~= _131_) then + _131_["label-state"] = nil else end end return loop(targets) - elseif ((nil ~= _122_) and (nil ~= _123_)) then - local _in = _122_ - local group_offset_2a = _123_ + elseif ((nil ~= _128_) and (nil ~= _129_)) then + local _in = _128_ + local group_offset_2a = _129_ group_offset = group_offset_2a first_invoc_3f = false do - local _127_ = get_target_with_active_primary_label(targets, _in) - if ((_G.type(_127_) == "table") and true and (nil ~= (_127_)[2])) then - local _ = (_127_)[1] - local target = (_127_)[2] + local _133_ = get_target_with_active_primary_label(targets, _in) + if ((_G.type(_133_) == "table") and true and (nil ~= (_133_)[2])) then + local _ = (_133_)[1] + local target = (_133_)[2] if not contains_3f(selection, target) then table.insert(selection, target) target["label-state"] = "selected" @@ -813,9 +835,9 @@ local function leap(kwargs) end multi_select_loop = loop end - local function traversal_loop(targets, start_idx, _131_) - local _arg_132_ = _131_ - local no_labels_3f = _arg_132_["no-labels?"] + local function traversal_loop(targets, start_idx, _137_) + local _arg_138_ = _137_ + local no_labels_3f = _arg_138_["no-labels?"] local function on_first_invoc() if no_labels_3f then for _, t in ipairs(targets) do @@ -825,9 +847,9 @@ local function leap(kwargs) elseif not empty_3f(opts.safe_labels) then local last_labeled = inc(#opts.safe_labels) for i = inc(last_labeled), #targets do - local _133_ = targets[i] - _133_["label"] = nil - _133_["beacon"] = nil + local _139_ = targets[i] + _139_["label"] = nil + _139_["beacon"] = nil end return nil else @@ -836,17 +858,11 @@ local function leap(kwargs) end local function display() set_beacons(targets, {["no-labels?"] = no_labels_3f, ["aot?"] = vars["aot?"], ["user-given-targets?"] = user_given_targets_3f}) - hl:cleanup(hl_affected_windows) - if not count then - hl["apply-backdrop"](hl, backward_3f, _3ftarget_windows) - else + local start, _end = get_highlighted_idx_range(targets, no_labels_3f) + local function _141_() + return light_up_beacons(targets, {start = start, ["end"] = _end}) end - do - local start, _end = get_highlighted_idx_range(targets, no_labels_3f) - light_up_beacons(targets, start, _end) - end - hl["highlight-cursor"](hl) - return vim.cmd("redraw") + return with_highlight_chores({["backdrop-ranges"] = backdrop_ranges, ["hl-affected-windows"] = hl_affected_windows}, _141_) end local function get_new_idx(idx, _in) if contains_3f(spec_keys.next_target, _in) then @@ -864,32 +880,32 @@ local function leap(kwargs) end vars["curr-idx"] = idx display() - local _138_ = get_input() - if (nil ~= _138_) then - local _in = _138_ - local _139_ = get_new_idx(idx, _in) - if (nil ~= _139_) then - local new_idx = _139_ + local _144_ = get_input() + if (nil ~= _144_) then + local _in = _144_ + local _145_ = get_new_idx(idx, _in) + if (nil ~= _145_) then + local new_idx = _145_ do - local _140_ + local _146_ do - local t_141_ = targets - if (nil ~= t_141_) then - t_141_ = (t_141_)[new_idx] + local t_147_ = targets + if (nil ~= t_147_) then + t_147_ = (t_147_)[new_idx] else end - if (nil ~= t_141_) then - t_141_ = (t_141_).chars + if (nil ~= t_147_) then + t_147_ = (t_147_).chars else end - if (nil ~= t_141_) then - t_141_ = (t_141_)[2] + if (nil ~= t_147_) then + t_147_ = (t_147_)[2] else end - _140_ = t_141_ + _146_ = t_147_ end - if (nil ~= _140_) then - local ch2 = _140_ + if (nil ~= _146_) then + local ch2 = _146_ state["repeat"].in2 = ch2 else end @@ -897,14 +913,14 @@ local function leap(kwargs) jump_to_21(targets[new_idx]) return loop(new_idx, false) elseif true then - local _ = _139_ - local _146_ = get_target_with_active_primary_label(targets, _in) - if ((_G.type(_146_) == "table") and true and (nil ~= (_146_)[2])) then - local _0 = (_146_)[1] - local target = (_146_)[2] + local _ = _145_ + local _152_ = get_target_with_active_primary_label(targets, _in) + if ((_G.type(_152_) == "table") and true and (nil ~= (_152_)[2])) then + local _0 = (_152_)[1] + local target = (_152_)[2] return jump_to_21(target) elseif true then - local _0 = _146_ + local _0 = _152_ return vim.fn.feedkeys(_in, "i") else return nil @@ -971,15 +987,15 @@ local function leap(kwargs) else end if dot_repeat_3f then - local _159_ = targets[state.dot_repeat.target_idx] - if (nil ~= _159_) then - local target = _159_ + local _165_ = targets[state.dot_repeat.target_idx] + if (nil ~= _165_) then + local target = _165_ do_action(target) hl:cleanup(hl_affected_windows) exec_user_autocmds("LeapLeave") return elseif true then - local _ = _159_ + local _ = _165_ if change_op_3f then handle_interrupted_change_op_21() else @@ -1083,21 +1099,13 @@ local function leap(kwargs) end if multi_select_3f then do - local _179_ = multi_select_loop(targets_2a) - if (nil ~= _179_) then - local targets_2a_2a = _179_ - do - hl:cleanup(hl_affected_windows) - if not count then - hl["apply-backdrop"](hl, backward_3f, _3ftarget_windows) - else - end - do - light_up_beacons(targets_2a_2a) - end - hl["highlight-cursor"](hl) - vim.cmd("redraw") + local _185_ = multi_select_loop(targets_2a) + if (nil ~= _185_) then + local targets_2a_2a = _185_ + local function _186_() + return light_up_beacons(targets_2a_2a) end + with_highlight_chores({["backdrop-ranges"] = backdrop_ranges, ["hl-affected-windows"] = hl_affected_windows}, _186_) do_action(targets_2a_2a) else end @@ -1173,9 +1181,9 @@ local function leap(kwargs) end else end - local _local_193_ = get_target_with_active_primary_label(targets_2a, in_final) - local idx = _local_193_[1] - local _ = _local_193_[2] + local _local_199_ = get_target_with_active_primary_label(targets_2a, in_final) + local idx = _local_199_[1] + local _ = _local_199_[2] if idx then set_dot_repeat(in1, in2, idx) do_action((targets_2a)[idx]) @@ -1203,40 +1211,40 @@ local function leap(kwargs) return nil end do - local _197_ = opts.default.equivalence_classes - if (nil ~= _197_) then - opts.default.eq_class_of = eq_classes__3emembership_lookup(_197_) + local _203_ = opts.default.equivalence_classes + if (nil ~= _203_) then + opts.default.eq_class_of = eq_classes__3emembership_lookup(_203_) else - opts.default.eq_class_of = _197_ + opts.default.eq_class_of = _203_ end end api.nvim_create_augroup("LeapDefault", {}) hl["init-highlight"](hl) -local function _199_() +local function _205_() return hl["init-highlight"](hl) end -api.nvim_create_autocmd("ColorScheme", {callback = _199_, group = "LeapDefault"}) +api.nvim_create_autocmd("ColorScheme", {callback = _205_, group = "LeapDefault"}) local function set_editor_opts(t) state.saved_editor_opts = {} local wins = (state.args.target_windows or {state.source_window}) for opt, val in pairs(t) do - local _let_200_ = vim.split(opt, ".", {plain = true}) - local scope = _let_200_[1] - local name = _let_200_[2] - local _201_ = scope - if (_201_ == "w") then + local _let_206_ = vim.split(opt, ".", {plain = true}) + local scope = _let_206_[1] + local name = _let_206_[2] + local _207_ = scope + if (_207_ == "w") then for _, w in ipairs(wins) do state.saved_editor_opts[{"w", w, name}] = api.nvim_win_get_option(w, name) api.nvim_win_set_option(w, name, val) end - elseif (_201_ == "b") then + elseif (_207_ == "b") then for _, w in ipairs(wins) do local b = api.nvim_win_get_buf(w) do end (state.saved_editor_opts)[{"b", b, name}] = api.nvim_buf_get_option(b, name) api.nvim_buf_set_option(b, name, val) end elseif true then - local _ = _201_ + local _ = _207_ state.saved_editor_opts[name] = api.nvim_get_option(name) api.nvim_set_option(name, val) else @@ -1246,17 +1254,17 @@ local function set_editor_opts(t) end local function restore_editor_opts() for key, val in pairs(state.saved_editor_opts) do - local _203_ = key - if ((_G.type(_203_) == "table") and ((_203_)[1] == "w") and (nil ~= (_203_)[2]) and (nil ~= (_203_)[3])) then - local w = (_203_)[2] - local name = (_203_)[3] + local _209_ = key + if ((_G.type(_209_) == "table") and ((_209_)[1] == "w") and (nil ~= (_209_)[2]) and (nil ~= (_209_)[3])) then + local w = (_209_)[2] + local name = (_209_)[3] api.nvim_win_set_option(w, name, val) - elseif ((_G.type(_203_) == "table") and ((_203_)[1] == "b") and (nil ~= (_203_)[2]) and (nil ~= (_203_)[3])) then - local b = (_203_)[2] - local name = (_203_)[3] + elseif ((_G.type(_209_) == "table") and ((_209_)[1] == "b") and (nil ~= (_209_)[2]) and (nil ~= (_209_)[3])) then + local b = (_209_)[2] + local name = (_209_)[3] api.nvim_buf_set_option(b, name, val) - elseif (nil ~= _203_) then - local name = _203_ + elseif (nil ~= _209_) then + local name = _209_ api.nvim_set_option(name, val) else end @@ -1264,12 +1272,12 @@ local function restore_editor_opts() return nil end local temporary_editor_opts = {["w.conceallevel"] = 0, ["g.scrolloff"] = 0, ["w.scrolloff"] = 0, ["g.sidescrolloff"] = 0, ["w.sidescrolloff"] = 0, ["b.modeline"] = false} -local function _205_() +local function _211_() return set_editor_opts(temporary_editor_opts) end -api.nvim_create_autocmd("User", {pattern = "LeapEnter", callback = _205_, group = "LeapDefault"}) -local function _206_() +api.nvim_create_autocmd("User", {pattern = "LeapEnter", callback = _211_, group = "LeapDefault"}) +local function _212_() return restore_editor_opts() end -api.nvim_create_autocmd("User", {pattern = "LeapLeave", callback = _206_, group = "LeapDefault"}) +api.nvim_create_autocmd("User", {pattern = "LeapLeave", callback = _212_, group = "LeapDefault"}) return {state = state, leap = leap} From 1fbd605b34ceeb82957666c4e101c6ee8c4a2418 Mon Sep 17 00:00:00 2001 From: Rishikesh Vaishnav Date: Sun, 4 Jun 2023 19:11:07 +0200 Subject: [PATCH 2/5] allow to force remote over local dev repo --- fnl/leap/main.fnl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fnl/leap/main.fnl b/fnl/leap/main.fnl index ef14ad2..1212ce7 100644 --- a/fnl/leap/main.fnl +++ b/fnl/leap/main.fnl @@ -387,7 +387,7 @@ is either labeled (C) or not (B). ; Main ///1 -; State that is persisted between invocations. +; State that is persisted between usages. (local state {:args nil ; arguments passed to the current call :source_window nil :repeat {:in1 nil @@ -400,6 +400,11 @@ is either labeled (C) or not (B). :offset nil} :saved_editor_opts {}}) +; State that is persisted between the API invocations of a single usage +(local target-state {:backdrop-ranges nil + :hl-affected-windows nil + }) + (fn leap [kwargs] "Entry point for Leap motions." From 134068472c307883ae153930357285e1f440f07f Mon Sep 17 00:00:00 2001 From: Rishikesh Vaishnav Date: Sun, 4 Jun 2023 20:03:08 +0200 Subject: [PATCH 3/5] add `prebeacon` function (for setting pre-input highlights and highlight state) and extract `exit` function --- fnl/leap/main.fnl | 54 +++--- lua/leap/main.lua | 427 +++++++++++++++++++++++++--------------------- 2 files changed, 264 insertions(+), 217 deletions(-) diff --git a/fnl/leap/main.fnl b/fnl/leap/main.fnl index 1212ce7..0f57c23 100644 --- a/fnl/leap/main.fnl +++ b/fnl/leap/main.fnl @@ -357,14 +357,37 @@ is either labeled (C) or not (B). (when aot? (resolve-conflicts targets))))) -(fn with-highlight-chores [opts task] - (do (local opts (or opts {})) - (hl:cleanup opts.hl-affected-windows) - (hl:apply-backdrop (or opts.backdrop-ranges [])) +; State that is persisted between the API invocations of a single usage. +(local target-state {:backdrop-ranges nil + :hl-affected-windows nil + }) + + +(fn with-highlight-chores [task] + (do (local hl-affected-windows (or target-state.hl-affected-windows [])) + (local backdrop-ranges (or target-state.backdrop-ranges [])) + (hl:cleanup (or hl-affected-windows [])) + (hl:apply-backdrop (or backdrop-ranges [])) (task) (hl:highlight-cursor) (vim.cmd :redraw))) +(fn pre-exit [] + (set target-state.hl-affected-windows nil) + (set target-state.backdrop-ranges nil)) + +(macro exit [] + `(do (hl:cleanup target-state.hl-affected-windows) + (pre-exit) + (exec-user-autocmds :LeapLeave) + (lua :return))) + +(fn prebeacon [opts] + (set target-state.backdrop-ranges opts.backdrop-ranges) + (set target-state.hl-affected-windows opts.hl-affected-windows) + (with-highlight-chores (fn [])) +) + (fn light-up-beacons [targets opts] (local opts (or opts {})) (for [i (or opts.start 1) (or opts.end (length targets))] @@ -400,12 +423,6 @@ is either labeled (C) or not (B). :offset nil} :saved_editor_opts {}}) -; State that is persisted between the API invocations of a single usage -(local target-state {:backdrop-ranges nil - :hl-affected-windows nil - }) - - (fn leap [kwargs] "Entry point for Leap motions." (local {:dot_repeat dot-repeat? @@ -487,11 +504,6 @@ is either labeled (C) or not (B). ; Macros - (macro exit [] - `(do (hl:cleanup hl-affected-windows) - (exec-user-autocmds :LeapLeave) - (lua :return))) - ; Be sure not to call the macro twice accidentally, ; `handle-interrupted-change-op!` moves the cursor! (macro exit-early [] @@ -673,7 +685,7 @@ is either labeled (C) or not (B). (values start end)))) (fn get-first-pattern-input [] - (with-highlight-chores {: backdrop-ranges : hl-affected-windows} (fn [] (echo ""))) ; clean up the command line + (with-highlight-chores (fn [] (echo ""))) ; clean up the command line (case (get-input-by-keymap prompt) ; Here we can handle any other modifier key as "zeroth" input, ; if the need arises. @@ -692,7 +704,7 @@ is either labeled (C) or not (B). ; char partial input (but it implies not needing ; to show beacons). (not count)) - (with-highlight-chores {: backdrop-ranges : hl-affected-windows} (fn [] (light-up-beacons targets)))) + (with-highlight-chores (fn [] (light-up-beacons targets)))) (get-input-by-keymap prompt)) (fn get-full-pattern-input [] @@ -715,7 +727,7 @@ is either labeled (C) or not (B). (set-label-states targets {: group-offset})) (set-beacons targets {:aot? vars.aot? : no-labels? : user-given-targets?}) (local (start end) (get-highlighted-idx-range targets no-labels?)) - (with-highlight-chores {: backdrop-ranges : hl-affected-windows} (fn [] (light-up-beacons targets {: start : end})))) + (with-highlight-chores (fn [] (light-up-beacons targets {: start : end})))) ; --- (fn loop [group-offset first-invoc?] (display group-offset) @@ -780,7 +792,7 @@ is either labeled (C) or not (B). (fn display [] (set-beacons targets {: no-labels? :aot? vars.aot? : user-given-targets?}) (local (start end) (get-highlighted-idx-range targets no-labels?)) - (with-highlight-chores {: backdrop-ranges : hl-affected-windows} (fn [] (light-up-beacons targets {: start : end})))) + (with-highlight-chores (fn [] (light-up-beacons targets {: start : end})))) ; --- (fn get-new-idx [idx in] (if (contains? spec-keys.next_target in) (min (inc idx) (length targets)) @@ -817,6 +829,8 @@ is either labeled (C) or not (B). (exec-user-autocmds :LeapEnter) + (prebeacon {: backdrop-ranges : hl-affected-windows}) + (local (in1 ?in2) (if dot-repeat? (if state.dot_repeat.callback (values true true) (values state.dot_repeat.in1 @@ -892,7 +906,7 @@ is either labeled (C) or not (B). targets** ; The action callback should expect a list in this case. ; It might also get user input, so keep the beacons highlighted. - (do (with-highlight-chores {: backdrop-ranges : hl-affected-windows} (fn [] (light-up-beacons targets**))) + (do (with-highlight-chores (fn [] (light-up-beacons targets**))) (do-action targets**))) (exit)) diff --git a/lua/leap/main.lua b/lua/leap/main.lua index 14f550a..abb0919 100644 --- a/lua/leap/main.lua +++ b/lua/leap/main.lua @@ -343,26 +343,40 @@ local function set_beacons(targets, _52_) end end end -local function with_highlight_chores(opts0, task) - local opts1 = (opts0 or {}) - hl:cleanup(opts1["hl-affected-windows"]) - hl["apply-backdrop"](hl, (opts1["backdrop-ranges"] or {})) +local target_state = {["backdrop-ranges"] = nil, ["hl-affected-windows"] = nil} +local function with_highlight_chores(task) + local hl_affected_windows = (target_state["hl-affected-windows"] or {}) + local backdrop_ranges = (target_state["backdrop-ranges"] or {}) + hl:cleanup((hl_affected_windows or {})) + hl["apply-backdrop"](hl, (backdrop_ranges or {})) task() hl["highlight-cursor"](hl) return vim.cmd("redraw") end +local function pre_exit() + target_state["hl-affected-windows"] = nil + target_state["backdrop-ranges"] = nil + return nil +end +local function prebeacon(opts0) + target_state["backdrop-ranges"] = opts0["backdrop-ranges"] + target_state["hl-affected-windows"] = opts0["hl-affected-windows"] + local function _57_() + end + return with_highlight_chores(_57_) +end local function light_up_beacons(targets, opts0) local opts1 = (opts0 or {}) for i = (opts1.start or 1), (opts1["end"] or #targets) do local target = targets[i] - local _57_ = target.beacon - if ((_G.type(_57_) == "table") and (nil ~= (_57_)[1]) and (nil ~= (_57_)[2])) then - local offset = (_57_)[1] - local virttext = (_57_)[2] + local _58_ = target.beacon + if ((_G.type(_58_) == "table") and (nil ~= (_58_)[1]) and (nil ~= (_58_)[2])) then + local offset = (_58_)[1] + local virttext = (_58_)[2] local bufnr = target.wininfo.bufnr - local _let_58_ = map(dec, target.pos) - local lnum = _let_58_[1] - local col = _let_58_[2] + local _let_59_ = map(dec, target.pos) + local lnum = _let_59_[1] + local col = _let_59_[2] local id = api.nvim_buf_set_extmark(bufnr, hl.ns, lnum, (col + offset), {virt_text = virttext, virt_text_pos = "overlay", hl_mode = "combine", priority = hl.priority.label}) table.insert(hl.extmarks, {bufnr, id}) else @@ -372,32 +386,32 @@ local function light_up_beacons(targets, opts0) end local state = {args = nil, source_window = nil, ["repeat"] = {in1 = nil, in2 = nil}, dot_repeat = {in1 = nil, in2 = nil, target_idx = nil, backward = nil, inclusive_op = nil, offset = nil}, saved_editor_opts = {}} local function leap(kwargs) - local _local_60_ = kwargs - local dot_repeat_3f = _local_60_["dot_repeat"] - local target_windows = _local_60_["target_windows"] - local user_given_opts = _local_60_["opts"] - local user_given_targets = _local_60_["targets"] - local user_given_action = _local_60_["action"] - local multi_select_3f = _local_60_["multiselect"] - local function _62_() + local _local_61_ = kwargs + local dot_repeat_3f = _local_61_["dot_repeat"] + local target_windows = _local_61_["target_windows"] + local user_given_opts = _local_61_["opts"] + local user_given_targets = _local_61_["targets"] + local user_given_action = _local_61_["action"] + local multi_select_3f = _local_61_["multiselect"] + local function _63_() if dot_repeat_3f then return state.dot_repeat else return kwargs end end - local _local_61_ = _62_() - local backward_3f = _local_61_["backward"] - local match_xxx_2a_at_the_end_3f = _local_61_["match-xxx*-at-the-end?"] - local inclusive_op_3f = _local_61_["inclusive_op"] - local offset = _local_61_["offset"] + local _local_62_ = _63_() + local backward_3f = _local_62_["backward"] + local match_xxx_2a_at_the_end_3f = _local_62_["match-xxx*-at-the-end?"] + local inclusive_op_3f = _local_62_["inclusive_op"] + local offset = _local_62_["offset"] opts.current_call = (user_given_opts or {}) do - local _63_ = opts.current_call.equivalence_classes - if (nil ~= _63_) then - opts.current_call.eq_class_of = eq_classes__3emembership_lookup(_63_) + local _64_ = opts.current_call.equivalence_classes + if (nil ~= _64_) then + opts.current_call.eq_class_of = eq_classes__3emembership_lookup(_64_) else - opts.current_call.eq_class_of = _63_ + opts.current_call.eq_class_of = _64_ end end local directional_3f = not target_windows @@ -457,12 +471,12 @@ local function leap(kwargs) local spec_keys do local function __index(_, k) - local _71_ = opts.special_keys[k] - if (nil ~= _71_) then - local v = _71_ + local _72_ = opts.special_keys[k] + if (nil ~= _72_) then + local v = _72_ if ((k == "next_target") or (k == "prev_target")) then - local _72_ = type(v) - if (_72_ == "table") then + local _73_ = type(v) + if (_73_ == "table") then local tbl_17_auto = {} local i_18_auto = #tbl_17_auto for _0, str in ipairs(v) do @@ -474,7 +488,7 @@ local function leap(kwargs) end end return tbl_17_auto - elseif (_72_ == "string") then + elseif (_73_ == "string") then return {replace_keycodes(v)} else return nil @@ -498,24 +512,24 @@ local function leap(kwargs) table.insert(backdrop_ranges, range) end else - local _let_77_ = map(dec, {vim.fn.line("."), vim.fn.col(".")}) - local curline = _let_77_[1] - local curcol = _let_77_[2] - local _let_78_ = {dec(vim.fn.line("w0")), dec(vim.fn.line("w$"))} - local win_top = _let_78_[1] - local win_bot = _let_78_[2] - local function _80_() + local _let_78_ = map(dec, {vim.fn.line("."), vim.fn.col(".")}) + local curline = _let_78_[1] + local curcol = _let_78_[2] + local _let_79_ = {dec(vim.fn.line("w0")), dec(vim.fn.line("w$"))} + local win_top = _let_79_[1] + local win_bot = _let_79_[2] + local function _81_() if backward_3f then return {win_top, 0, curline, curcol} else return {curline, inc(curcol), win_bot, -1} end end - local _let_79_ = _80_() - local startrow = _let_79_[1] - local startcol = _let_79_[2] - local endrow = _let_79_[3] - local endcol = _let_79_[4] + local _let_80_ = _81_() + local startrow = _let_80_[1] + local startcol = _let_80_[2] + local endrow = _let_80_[3] + local endcol = _let_80_[4] local wininfo = (vim.fn.getwininfo(0))[1] local range = {bufnr = wininfo.bufnr, startrow = startrow, startcol = startcol, endrow = endrow, endcol = endcol} table.insert(backdrop_ranges, range) @@ -569,41 +583,41 @@ local function leap(kwargs) else pat = (pat1 .. pat2) end - local function _89_() + local function _90_() if opts.case_sensitive then return "\\C" else return "\\c" end end - return ("\\V" .. _89_() .. pat) + return ("\\V" .. _90_() .. pat) end local function get_targets(in1, _3fin2) local search = require("leap.search") local pattern = prepare_pattern(in1, _3fin2) local kwargs0 = {["backward?"] = backward_3f, ["match-xxx*-at-the-end?"] = match_xxx_2a_at_the_end_3f, ["target-windows"] = _3ftarget_windows} local targets = search["get-targets"](pattern, kwargs0) - local function _90_() + local function _91_() vars.errmsg = ("not found: " .. in1 .. (_3fin2 or "")) return nil end - return (targets or _90_()) + return (targets or _91_()) end local function prepare_targets(targets) local funny_edge_case_3f - local function _91_() - local _92_ = targets - if ((_G.type(_92_) == "table") and ((_G.type((_92_)[1]) == "table") and ((_G.type(((_92_)[1]).pos) == "table") and (nil ~= (((_92_)[1]).pos)[1]) and (nil ~= (((_92_)[1]).pos)[2]))) and ((_G.type((_92_)[2]) == "table") and ((_G.type(((_92_)[2]).pos) == "table") and (nil ~= (((_92_)[2]).pos)[1]) and (nil ~= (((_92_)[2]).pos)[2])))) then - local l1 = (((_92_)[1]).pos)[1] - local c1 = (((_92_)[1]).pos)[2] - local l2 = (((_92_)[2]).pos)[1] - local c2 = (((_92_)[2]).pos)[2] + local function _92_() + local _93_ = targets + if ((_G.type(_93_) == "table") and ((_G.type((_93_)[1]) == "table") and ((_G.type(((_93_)[1]).pos) == "table") and (nil ~= (((_93_)[1]).pos)[1]) and (nil ~= (((_93_)[1]).pos)[2]))) and ((_G.type((_93_)[2]) == "table") and ((_G.type(((_93_)[2]).pos) == "table") and (nil ~= (((_93_)[2]).pos)[1]) and (nil ~= (((_93_)[2]).pos)[2])))) then + local l1 = (((_93_)[1]).pos)[1] + local c1 = (((_93_)[1]).pos)[2] + local l2 = (((_93_)[2]).pos)[1] + local c2 = (((_93_)[2]).pos)[2] return ((l1 == l2) and (c1 == (c2 + 2))) else return nil end end - funny_edge_case_3f = (backward_3f and _91_()) + funny_edge_case_3f = (backward_3f and _92_()) local force_noautojump_3f = (op_mode_3f or multi_select_3f or not directional_3f or user_given_action or funny_edge_case_3f) set_autojump(targets, force_noautojump_3f) attach_label_set(targets) @@ -612,11 +626,11 @@ local function leap(kwargs) end local function get_target_with_active_primary_label(sublist, input) local res = {} - for idx, _94_ in ipairs(sublist) do - local _each_95_ = _94_ - local label = _each_95_["label"] - local label_state = _each_95_["label-state"] - local target = _each_95_ + for idx, _95_ in ipairs(sublist) do + local _each_96_ = _95_ + local label = _each_96_["label"] + local label_state = _each_96_["label-state"] + local target = _each_96_ if (next(res) or (label_state == "inactive")) then break end if ((label == input) and (label_state == "active-primary")) then res = {idx, target} @@ -644,18 +658,18 @@ local function leap(kwargs) local jump_to_21 do local first_jump_3f = true - local function _99_(target) + local function _100_(target) local jump = require("leap.jump") jump["jump-to!"](target.pos, {winid = target.wininfo.winid, ["add-to-jumplist?"] = first_jump_3f, mode = mode, offset = offset, ["backward?"] = backward_3f, ["inclusive-op?"] = inclusive_op_3f}) first_jump_3f = false return nil end - jump_to_21 = _99_ + jump_to_21 = _100_ end local function get_number_of_highlighted_targets() - local _100_ = opts.max_highlighted_traversal_targets - if (nil ~= _100_) then - local group_size = _100_ + local _101_ = opts.max_highlighted_traversal_targets + if (nil ~= _101_) then + local group_size = _101_ local consumed = (dec(vars["curr-idx"]) % group_size) local remaining = (group_size - consumed) if (remaining == 1) then @@ -676,16 +690,16 @@ local function leap(kwargs) local start = inc(vars["curr-idx"]) local _end if no_labels_3f then - local _103_ = get_number_of_highlighted_targets() - if (nil ~= _103_) then - local _104_ = (_103_ + dec(start)) - if (nil ~= _104_) then - _end = min(_104_, #targets) + local _104_ = get_number_of_highlighted_targets() + if (nil ~= _104_) then + local _105_ = (_104_ + dec(start)) + if (nil ~= _105_) then + _end = min(_105_, #targets) else - _end = _104_ + _end = _105_ end else - _end = _103_ + _end = _104_ end else _end = nil @@ -694,12 +708,12 @@ local function leap(kwargs) end end local function get_first_pattern_input() - local function _109_() + local function _110_() return echo("") end - with_highlight_chores({["backdrop-ranges"] = backdrop_ranges, ["hl-affected-windows"] = hl_affected_windows}, _109_) - local _110_, _111_ = get_input_by_keymap(prompt) - if (_110_ == spec_keys.repeat_search) then + with_highlight_chores(_110_) + local _111_, _112_ = get_input_by_keymap(prompt) + if (_111_ == spec_keys.repeat_search) then if state["repeat"].in1 then vars["aot?"] = false return state["repeat"].in1, state["repeat"].in2 @@ -707,8 +721,8 @@ local function leap(kwargs) vars.errmsg = "no previous search" return nil end - elseif (nil ~= _110_) then - local in1 = _110_ + elseif (nil ~= _111_) then + local in1 = _111_ return in1 else return nil @@ -716,25 +730,25 @@ local function leap(kwargs) end local function get_second_pattern_input(targets) if ((#targets <= max_phase_one_targets) and not count) then - local function _114_() + local function _115_() return light_up_beacons(targets) end - with_highlight_chores({["backdrop-ranges"] = backdrop_ranges, ["hl-affected-windows"] = hl_affected_windows}, _114_) + with_highlight_chores(_115_) else end return get_input_by_keymap(prompt) end local function get_full_pattern_input() - local _116_, _117_ = get_first_pattern_input() - if ((nil ~= _116_) and (nil ~= _117_)) then - local in1 = _116_ - local in2 = _117_ + local _117_, _118_ = get_first_pattern_input() + if ((nil ~= _117_) and (nil ~= _118_)) then + local in1 = _117_ + local in2 = _118_ return in1, in2 - elseif ((nil ~= _116_) and (_117_ == nil)) then - local in1 = _116_ - local _118_ = get_input_by_keymap(prompt) - if (nil ~= _118_) then - local in2 = _118_ + elseif ((nil ~= _117_) and (_118_ == nil)) then + local in1 = _117_ + local _119_ = get_input_by_keymap(prompt) + if (nil ~= _119_) then + local in2 = _119_ return in1, in2 else return nil @@ -758,16 +772,16 @@ local function leap(kwargs) end set_beacons(targets, {["aot?"] = vars["aot?"], ["no-labels?"] = no_labels_3f, ["user-given-targets?"] = user_given_targets_3f}) local start, _end = get_highlighted_idx_range(targets, no_labels_3f) - local function _123_() + local function _124_() return light_up_beacons(targets, {start = start, ["end"] = _end}) end - return with_highlight_chores({["backdrop-ranges"] = backdrop_ranges, ["hl-affected-windows"] = hl_affected_windows}, _123_) + return with_highlight_chores(_124_) end local function loop(group_offset, first_invoc_3f0) display(group_offset) - local _124_ = get_input() - if (nil ~= _124_) then - local input = _124_ + local _125_ = get_input() + if (nil ~= _125_) then + local input = _125_ local switch_group_3f = ((_7cgroups_7c > 1) and ((input == spec_keys.next_group) or ((input == spec_keys.prev_group) and not first_invoc_3f0))) if switch_group_3f then local inc_2fdec @@ -794,32 +808,32 @@ local function leap(kwargs) local group_offset = 0 local first_invoc_3f = true local function loop(targets) - local _128_, _129_ = post_pattern_input_loop(targets, group_offset, first_invoc_3f) - if (_128_ == spec_keys.multi_accept) then + local _129_, _130_ = post_pattern_input_loop(targets, group_offset, first_invoc_3f) + if (_129_ == spec_keys.multi_accept) then if not empty_3f(selection) then return selection else return loop(targets) end - elseif (_128_ == spec_keys.multi_revert) then + elseif (_129_ == spec_keys.multi_revert) then do - local _131_ = table.remove(selection) - if (nil ~= _131_) then - _131_["label-state"] = nil + local _132_ = table.remove(selection) + if (nil ~= _132_) then + _132_["label-state"] = nil else end end return loop(targets) - elseif ((nil ~= _128_) and (nil ~= _129_)) then - local _in = _128_ - local group_offset_2a = _129_ + elseif ((nil ~= _129_) and (nil ~= _130_)) then + local _in = _129_ + local group_offset_2a = _130_ group_offset = group_offset_2a first_invoc_3f = false do - local _133_ = get_target_with_active_primary_label(targets, _in) - if ((_G.type(_133_) == "table") and true and (nil ~= (_133_)[2])) then - local _ = (_133_)[1] - local target = (_133_)[2] + local _134_ = get_target_with_active_primary_label(targets, _in) + if ((_G.type(_134_) == "table") and true and (nil ~= (_134_)[2])) then + local _ = (_134_)[1] + local target = (_134_)[2] if not contains_3f(selection, target) then table.insert(selection, target) target["label-state"] = "selected" @@ -835,9 +849,9 @@ local function leap(kwargs) end multi_select_loop = loop end - local function traversal_loop(targets, start_idx, _137_) - local _arg_138_ = _137_ - local no_labels_3f = _arg_138_["no-labels?"] + local function traversal_loop(targets, start_idx, _138_) + local _arg_139_ = _138_ + local no_labels_3f = _arg_139_["no-labels?"] local function on_first_invoc() if no_labels_3f then for _, t in ipairs(targets) do @@ -847,9 +861,9 @@ local function leap(kwargs) elseif not empty_3f(opts.safe_labels) then local last_labeled = inc(#opts.safe_labels) for i = inc(last_labeled), #targets do - local _139_ = targets[i] - _139_["label"] = nil - _139_["beacon"] = nil + local _140_ = targets[i] + _140_["label"] = nil + _140_["beacon"] = nil end return nil else @@ -859,10 +873,10 @@ local function leap(kwargs) local function display() set_beacons(targets, {["no-labels?"] = no_labels_3f, ["aot?"] = vars["aot?"], ["user-given-targets?"] = user_given_targets_3f}) local start, _end = get_highlighted_idx_range(targets, no_labels_3f) - local function _141_() + local function _142_() return light_up_beacons(targets, {start = start, ["end"] = _end}) end - return with_highlight_chores({["backdrop-ranges"] = backdrop_ranges, ["hl-affected-windows"] = hl_affected_windows}, _141_) + return with_highlight_chores(_142_) end local function get_new_idx(idx, _in) if contains_3f(spec_keys.next_target, _in) then @@ -880,32 +894,32 @@ local function leap(kwargs) end vars["curr-idx"] = idx display() - local _144_ = get_input() - if (nil ~= _144_) then - local _in = _144_ - local _145_ = get_new_idx(idx, _in) - if (nil ~= _145_) then - local new_idx = _145_ + local _145_ = get_input() + if (nil ~= _145_) then + local _in = _145_ + local _146_ = get_new_idx(idx, _in) + if (nil ~= _146_) then + local new_idx = _146_ do - local _146_ + local _147_ do - local t_147_ = targets - if (nil ~= t_147_) then - t_147_ = (t_147_)[new_idx] + local t_148_ = targets + if (nil ~= t_148_) then + t_148_ = (t_148_)[new_idx] else end - if (nil ~= t_147_) then - t_147_ = (t_147_).chars + if (nil ~= t_148_) then + t_148_ = (t_148_).chars else end - if (nil ~= t_147_) then - t_147_ = (t_147_)[2] + if (nil ~= t_148_) then + t_148_ = (t_148_)[2] else end - _146_ = t_147_ + _147_ = t_148_ end - if (nil ~= _146_) then - local ch2 = _146_ + if (nil ~= _147_) then + local ch2 = _147_ state["repeat"].in2 = ch2 else end @@ -913,14 +927,14 @@ local function leap(kwargs) jump_to_21(targets[new_idx]) return loop(new_idx, false) elseif true then - local _ = _145_ - local _152_ = get_target_with_active_primary_label(targets, _in) - if ((_G.type(_152_) == "table") and true and (nil ~= (_152_)[2])) then - local _0 = (_152_)[1] - local target = (_152_)[2] + local _ = _146_ + local _153_ = get_target_with_active_primary_label(targets, _in) + if ((_G.type(_153_) == "table") and true and (nil ~= (_153_)[2])) then + local _0 = (_153_)[1] + local target = (_153_)[2] return jump_to_21(target) elseif true then - local _0 = _152_ + local _0 = _153_ return vim.fn.feedkeys(_in, "i") else return nil @@ -936,6 +950,7 @@ local function leap(kwargs) end local do_action = (user_given_action or jump_to_21) exec_user_autocmds("LeapEnter") + prebeacon({["backdrop-ranges"] = backdrop_ranges, ["hl-affected-windows"] = hl_affected_windows}) local in1, _3fin2 = nil, nil if dot_repeat_3f then if state.dot_repeat.callback then @@ -959,7 +974,8 @@ local function leap(kwargs) echo(vars.errmsg) else end - hl:cleanup(hl_affected_windows) + hl:cleanup(target_state["hl-affected-windows"]) + pre_exit() exec_user_autocmds("LeapLeave") return else @@ -981,21 +997,23 @@ local function leap(kwargs) echo(vars.errmsg) else end - hl:cleanup(hl_affected_windows) + hl:cleanup(target_state["hl-affected-windows"]) + pre_exit() exec_user_autocmds("LeapLeave") return else end if dot_repeat_3f then - local _165_ = targets[state.dot_repeat.target_idx] - if (nil ~= _165_) then - local target = _165_ + local _166_ = targets[state.dot_repeat.target_idx] + if (nil ~= _166_) then + local target = _166_ do_action(target) - hl:cleanup(hl_affected_windows) + hl:cleanup(target_state["hl-affected-windows"]) + pre_exit() exec_user_autocmds("LeapLeave") return elseif true then - local _ = _165_ + local _ = _166_ if change_op_3f then handle_interrupted_change_op_21() else @@ -1004,7 +1022,8 @@ local function leap(kwargs) echo(vars.errmsg) else end - hl:cleanup(hl_affected_windows) + hl:cleanup(target_state["hl-affected-windows"]) + pre_exit() exec_user_autocmds("LeapLeave") return else @@ -1039,7 +1058,8 @@ local function leap(kwargs) echo(vars.errmsg) else end - hl:cleanup(hl_affected_windows) + hl:cleanup(target_state["hl-affected-windows"]) + pre_exit() exec_user_autocmds("LeapLeave") return else @@ -1056,7 +1076,8 @@ local function leap(kwargs) echo(vars.errmsg) else end - hl:cleanup(hl_affected_windows) + hl:cleanup(target_state["hl-affected-windows"]) + pre_exit() exec_user_autocmds("LeapLeave") return else @@ -1070,7 +1091,8 @@ local function leap(kwargs) else set_dot_repeat(in1, in2_2a, n) end - hl:cleanup(hl_affected_windows) + hl:cleanup(target_state["hl-affected-windows"]) + pre_exit() exec_user_autocmds("LeapLeave") return else @@ -1092,25 +1114,27 @@ local function leap(kwargs) echo(vars.errmsg) else end - hl:cleanup(hl_affected_windows) + hl:cleanup(target_state["hl-affected-windows"]) + pre_exit() exec_user_autocmds("LeapLeave") return else end if multi_select_3f then do - local _185_ = multi_select_loop(targets_2a) - if (nil ~= _185_) then - local targets_2a_2a = _185_ - local function _186_() + local _186_ = multi_select_loop(targets_2a) + if (nil ~= _186_) then + local targets_2a_2a = _186_ + local function _187_() return light_up_beacons(targets_2a_2a) end - with_highlight_chores({["backdrop-ranges"] = backdrop_ranges, ["hl-affected-windows"] = hl_affected_windows}, _186_) + with_highlight_chores(_187_) do_action(targets_2a_2a) else end end - hl:cleanup(hl_affected_windows) + hl:cleanup(target_state["hl-affected-windows"]) + pre_exit() exec_user_autocmds("LeapLeave") return else @@ -1125,20 +1149,23 @@ local function leap(kwargs) echo(vars.errmsg) else end - hl:cleanup(hl_affected_windows) + hl:cleanup(target_state["hl-affected-windows"]) + pre_exit() exec_user_autocmds("LeapLeave") return else set_dot_repeat(in1, in2, count) do_action((targets_2a)[count]) - hl:cleanup(hl_affected_windows) + hl:cleanup(target_state["hl-affected-windows"]) + pre_exit() exec_user_autocmds("LeapLeave") return end elseif (#targets_2a == 1) then set_dot_repeat(in1, in2, 1) do_action((targets_2a)[1]) - hl:cleanup(hl_affected_windows) + hl:cleanup(target_state["hl-affected-windows"]) + pre_exit() exec_user_autocmds("LeapLeave") return else @@ -1158,7 +1185,8 @@ local function leap(kwargs) echo(vars.errmsg) else end - hl:cleanup(hl_affected_windows) + hl:cleanup(target_state["hl-affected-windows"]) + pre_exit() exec_user_autocmds("LeapLeave") return else @@ -1169,30 +1197,34 @@ local function leap(kwargs) local new_idx = inc(vars["curr-idx"]) do_action((targets_2a)[new_idx]) traversal_loop(targets_2a, new_idx, {["no-labels?"] = (empty_label_lists_3f or not targets_2a["autojump?"])}) - hl:cleanup(hl_affected_windows) + hl:cleanup(target_state["hl-affected-windows"]) + pre_exit() exec_user_autocmds("LeapLeave") return else set_dot_repeat(in1, in2, 1) do_action((targets_2a)[1]) - hl:cleanup(hl_affected_windows) + hl:cleanup(target_state["hl-affected-windows"]) + pre_exit() exec_user_autocmds("LeapLeave") return end else end - local _local_199_ = get_target_with_active_primary_label(targets_2a, in_final) - local idx = _local_199_[1] - local _ = _local_199_[2] + local _local_200_ = get_target_with_active_primary_label(targets_2a, in_final) + local idx = _local_200_[1] + local _ = _local_200_[2] if idx then set_dot_repeat(in1, in2, idx) do_action((targets_2a)[idx]) - hl:cleanup(hl_affected_windows) + hl:cleanup(target_state["hl-affected-windows"]) + pre_exit() exec_user_autocmds("LeapLeave") return elseif targets_2a["autojump?"] then vim.fn.feedkeys(in_final, "i") - hl:cleanup(hl_affected_windows) + hl:cleanup(target_state["hl-affected-windows"]) + pre_exit() exec_user_autocmds("LeapLeave") return else @@ -1204,47 +1236,48 @@ local function leap(kwargs) echo(vars.errmsg) else end - hl:cleanup(hl_affected_windows) + hl:cleanup(target_state["hl-affected-windows"]) + pre_exit() exec_user_autocmds("LeapLeave") return end return nil end do - local _203_ = opts.default.equivalence_classes - if (nil ~= _203_) then - opts.default.eq_class_of = eq_classes__3emembership_lookup(_203_) + local _204_ = opts.default.equivalence_classes + if (nil ~= _204_) then + opts.default.eq_class_of = eq_classes__3emembership_lookup(_204_) else - opts.default.eq_class_of = _203_ + opts.default.eq_class_of = _204_ end end api.nvim_create_augroup("LeapDefault", {}) hl["init-highlight"](hl) -local function _205_() +local function _206_() return hl["init-highlight"](hl) end -api.nvim_create_autocmd("ColorScheme", {callback = _205_, group = "LeapDefault"}) +api.nvim_create_autocmd("ColorScheme", {callback = _206_, group = "LeapDefault"}) local function set_editor_opts(t) state.saved_editor_opts = {} local wins = (state.args.target_windows or {state.source_window}) for opt, val in pairs(t) do - local _let_206_ = vim.split(opt, ".", {plain = true}) - local scope = _let_206_[1] - local name = _let_206_[2] - local _207_ = scope - if (_207_ == "w") then + local _let_207_ = vim.split(opt, ".", {plain = true}) + local scope = _let_207_[1] + local name = _let_207_[2] + local _208_ = scope + if (_208_ == "w") then for _, w in ipairs(wins) do state.saved_editor_opts[{"w", w, name}] = api.nvim_win_get_option(w, name) api.nvim_win_set_option(w, name, val) end - elseif (_207_ == "b") then + elseif (_208_ == "b") then for _, w in ipairs(wins) do local b = api.nvim_win_get_buf(w) do end (state.saved_editor_opts)[{"b", b, name}] = api.nvim_buf_get_option(b, name) api.nvim_buf_set_option(b, name, val) end elseif true then - local _ = _207_ + local _ = _208_ state.saved_editor_opts[name] = api.nvim_get_option(name) api.nvim_set_option(name, val) else @@ -1254,17 +1287,17 @@ local function set_editor_opts(t) end local function restore_editor_opts() for key, val in pairs(state.saved_editor_opts) do - local _209_ = key - if ((_G.type(_209_) == "table") and ((_209_)[1] == "w") and (nil ~= (_209_)[2]) and (nil ~= (_209_)[3])) then - local w = (_209_)[2] - local name = (_209_)[3] + local _210_ = key + if ((_G.type(_210_) == "table") and ((_210_)[1] == "w") and (nil ~= (_210_)[2]) and (nil ~= (_210_)[3])) then + local w = (_210_)[2] + local name = (_210_)[3] api.nvim_win_set_option(w, name, val) - elseif ((_G.type(_209_) == "table") and ((_209_)[1] == "b") and (nil ~= (_209_)[2]) and (nil ~= (_209_)[3])) then - local b = (_209_)[2] - local name = (_209_)[3] + elseif ((_G.type(_210_) == "table") and ((_210_)[1] == "b") and (nil ~= (_210_)[2]) and (nil ~= (_210_)[3])) then + local b = (_210_)[2] + local name = (_210_)[3] api.nvim_buf_set_option(b, name, val) - elseif (nil ~= _209_) then - local name = _209_ + elseif (nil ~= _210_) then + local name = _210_ api.nvim_set_option(name, val) else end @@ -1272,12 +1305,12 @@ local function restore_editor_opts() return nil end local temporary_editor_opts = {["w.conceallevel"] = 0, ["g.scrolloff"] = 0, ["w.scrolloff"] = 0, ["g.sidescrolloff"] = 0, ["w.sidescrolloff"] = 0, ["b.modeline"] = false} -local function _211_() +local function _212_() return set_editor_opts(temporary_editor_opts) end -api.nvim_create_autocmd("User", {pattern = "LeapEnter", callback = _211_, group = "LeapDefault"}) -local function _212_() +api.nvim_create_autocmd("User", {pattern = "LeapEnter", callback = _212_, group = "LeapDefault"}) +local function _213_() return restore_editor_opts() end -api.nvim_create_autocmd("User", {pattern = "LeapLeave", callback = _212_, group = "LeapDefault"}) +api.nvim_create_autocmd("User", {pattern = "LeapLeave", callback = _213_, group = "LeapDefault"}) return {state = state, leap = leap} From 6303b823103734dd738c561504a6fe9a286b7a8d Mon Sep 17 00:00:00 2001 From: Rishikesh Vaishnav Date: Sat, 1 Jul 2023 19:37:56 +0200 Subject: [PATCH 4/5] genericize `set-beacon-for-labeled` --- fnl/leap/main.fnl | 47 +++-- lua/leap/main.lua | 467 +++++++++++++++++++++++----------------------- 2 files changed, 263 insertions(+), 251 deletions(-) diff --git a/fnl/leap/main.fnl b/fnl/leap/main.fnl index 0f57c23..ed1a5f6 100644 --- a/fnl/leap/main.fnl +++ b/fnl/leap/main.fnl @@ -196,22 +196,17 @@ char separately. (+ (ch1:len) (ch2:len))))) -(fn set-beacon-for-labeled [target {: user-given-targets? : aot?}] - (let [offset (if aot? (get-label-offset target) 0) ; user-given-targets implies (not aot) - pad (if (or user-given-targets? aot?) "" " ") +(fn set-beacon-for-labeled [target] + (let [offset (or target.beacon-offset 0) + pad (or target.pad "") label (or (. opts.substitute_chars target.label) target.label) - text (.. label pad) + text (or target.text (.. label pad)) virttext (case target.label-state :selected [[text hl.group.label-selected]] :active-primary [[text hl.group.label-primary]] :active-secondary [[text hl.group.label-secondary]] - :inactive (if (and aot? (not opts.highlight_unlabeled_phase_one_targets)) - ; In this case, "no highlight" should - ; unambiguously signal "no further keystrokes - ; needed", so it is mandatory to show all labeled - ; positions in some way. - [[(.. " " pad) hl.group.label-secondary]] - :else nil))] + ; only show text on inactive targets if explicitly set + :inactive (if target.text [[target.text hl.group.label-secondary]] :else nil))] (set target.beacon (when virttext [offset virttext])))) @@ -344,13 +339,13 @@ is either labeled (C) or not (B). other (set-beacon-to-match-hl target))))))))) -(fn set-beacons [targets {: no-labels? : user-given-targets? : aot?}] +(fn set-beacons [targets {: no-labels? : aot?}] (if (and no-labels? (. targets 1 :chars)) ; user-given targets might not have :chars (each [_ target (ipairs targets)] (set-beacon-to-match-hl target)) (do (each [_ target (ipairs targets)] (if target.label - (set-beacon-for-labeled target {: user-given-targets? : aot?}) + (set-beacon-for-labeled target) (and aot? opts.highlight_unlabeled_phase_one_targets) (set-beacon-to-match-hl target))) @@ -725,7 +720,7 @@ is either labeled (C) or not (B). ; setting the initial label states if using `spec-keys.repeat_search`. (when targets.label-set (set-label-states targets {: group-offset})) - (set-beacons targets {:aot? vars.aot? : no-labels? : user-given-targets?}) + (set-beacons targets {:aot? vars.aot? : no-labels?}) (local (start end) (get-highlighted-idx-range targets no-labels?)) (with-highlight-chores (fn [] (light-up-beacons targets {: start : end})))) ; --- @@ -790,7 +785,7 @@ is either labeled (C) or not (B). (doto (. targets i) (tset :label nil) (tset :beacon nil)))))) ; --- (fn display [] - (set-beacons targets {: no-labels? :aot? vars.aot? : user-given-targets?}) + (set-beacons targets {: no-labels? :aot? vars.aot?}) (local (start end) (get-highlighted-idx-range targets no-labels?)) (with-highlight-chores (fn [] (light-up-beacons targets {: start : end})))) ; --- @@ -864,13 +859,27 @@ is either labeled (C) or not (B). (prepare-targets targets)) (do (when (> (length targets) max-phase-one-targets) - (set vars.aot? false)) + (do + (set vars.aot? false) + (each [_ target (ipairs targets)] + (set target.beacon-offset 0)))) (populate-sublists targets) (each [_ sublist (pairs targets.sublists)] (prepare-targets sublist)) - (doto targets - (set-initial-label-states) - (set-beacons {:aot? vars.aot?})))) + (set-initial-label-states targets) + (each [_ target (ipairs targets)] + (if vars.aot? + (do + (set target.beacon-offset (get-label-offset target)) + (when (and (not opts.highlight_unlabeled_phase_one_targets) (= target.label-state :inactive)) + ; In this case, "no highlight" should + ; unambiguously signal "no further keystrokes + ; needed", so it is mandatory to show all labeled + ; positions in some way. + (set target.text " ") + )) + (when (not user-given-targets?) (set target.pad " ")))) + (set-beacons targets {:aot? vars.aot?}))) (local in2 (or ?in2 (get-second-pattern-input targets))) ; REDRAW (when-not in2 (exit-early)) diff --git a/lua/leap/main.lua b/lua/leap/main.lua index abb0919..44c34fb 100644 --- a/lua/leap/main.lua +++ b/lua/leap/main.lua @@ -183,36 +183,23 @@ local function get_label_offset(target) return (ch1:len() + ch2:len()) end end -local function set_beacon_for_labeled(target, _27_) - local _arg_28_ = _27_ - local user_given_targets_3f = _arg_28_["user-given-targets?"] - local aot_3f = _arg_28_["aot?"] - local offset - if aot_3f then - offset = get_label_offset(target) - else - offset = 0 - end - local pad - if (user_given_targets_3f or aot_3f) then - pad = "" - else - pad = " " - end +local function set_beacon_for_labeled(target) + local offset = (target["beacon-offset"] or 0) + local pad = (target.pad or "") local label = (opts.substitute_chars[target.label] or target.label) - local text = (label .. pad) + local text = (target.text or (label .. pad)) local virttext do - local _31_ = target["label-state"] - if (_31_ == "selected") then + local _27_ = target["label-state"] + if (_27_ == "selected") then virttext = {{text, hl.group["label-selected"]}} - elseif (_31_ == "active-primary") then + elseif (_27_ == "active-primary") then virttext = {{text, hl.group["label-primary"]}} - elseif (_31_ == "active-secondary") then + elseif (_27_ == "active-secondary") then virttext = {{text, hl.group["label-secondary"]}} - elseif (_31_ == "inactive") then - if (aot_3f and not opts.highlight_unlabeled_phase_one_targets) then - virttext = {{(" " .. pad), hl.group["label-secondary"]}} + elseif (_27_ == "inactive") then + if target.text then + virttext = {{target.text, hl.group["label-secondary"]}} elseif "else" then virttext = nil else @@ -231,10 +218,10 @@ local function set_beacon_for_labeled(target, _27_) end local function set_beacon_to_match_hl(target) local virttext - local function _35_(_241) + local function _31_(_241) return (opts.substitute_chars[_241] or _241) end - virttext = table.concat(map(_35_, target.chars)) + virttext = table.concat(map(_31_, target.chars)) target.beacon = {0, {{virttext, hl.group.match}}} return nil end @@ -248,39 +235,39 @@ local function resolve_conflicts(targets) local label_positions = {} for _, target in ipairs(targets) do if not target["empty-line?"] then - local _let_36_ = target.wininfo - local bufnr = _let_36_["bufnr"] - local winid = _let_36_["winid"] - local _let_37_ = target.pos - local lnum = _let_37_[1] - local col_ch1 = _let_37_[2] + local _let_32_ = target.wininfo + local bufnr = _let_32_["bufnr"] + local winid = _let_32_["winid"] + local _let_33_ = target.pos + local lnum = _let_33_[1] + local col_ch1 = _let_33_[2] local col_ch2 = (col_ch1 + string.len(target.chars[1])) if (target.label and target.beacon) then local label_offset = target.beacon[1] local col_label = (col_ch1 + label_offset) local shifted_label_3f = (col_label == col_ch2) do - local _38_ = unlabeled_match_positions[(bufnr .. " " .. winid .. " " .. lnum .. " " .. col_label)] - if (nil ~= _38_) then - local other = _38_ + local _34_ = unlabeled_match_positions[(bufnr .. " " .. winid .. " " .. lnum .. " " .. col_label)] + if (nil ~= _34_) then + local other = _34_ target.beacon = nil set_beacon_to_match_hl(other) else end end if shifted_label_3f then - local _40_ = unlabeled_match_positions[(bufnr .. " " .. winid .. " " .. lnum .. " " .. col_ch1)] - if (nil ~= _40_) then - local other = _40_ + local _36_ = unlabeled_match_positions[(bufnr .. " " .. winid .. " " .. lnum .. " " .. col_ch1)] + if (nil ~= _36_) then + local other = _36_ set_beacon_to_match_hl(other) else end else end do - local _43_ = label_positions[(bufnr .. " " .. winid .. " " .. lnum .. " " .. col_label)] - if (nil ~= _43_) then - local other = _43_ + local _39_ = label_positions[(bufnr .. " " .. winid .. " " .. lnum .. " " .. col_label)] + if (nil ~= _39_) then + local other = _39_ target.beacon = nil set_beacon_to_empty_label(other) else @@ -295,18 +282,18 @@ local function resolve_conflicts(targets) elseif not target.label then for _0, key in ipairs({(bufnr .. " " .. winid .. " " .. lnum .. " " .. col_ch1), (bufnr .. " " .. winid .. " " .. lnum .. " " .. col_ch2)}) do unlabeled_match_positions[key] = target - local _46_ = label_positions[key] - if (nil ~= _46_) then - local other = _46_ + local _42_ = label_positions[key] + if (nil ~= _42_) then + local other = _42_ other.beacon = nil set_beacon_to_match_hl(target) else end end local col_after = (col_ch2 + string.len(target.chars[2])) - local _48_ = label_positions[(bufnr .. " " .. winid .. " " .. lnum .. " " .. col_after)] - if (nil ~= _48_) then - local other = _48_ + local _44_ = label_positions[(bufnr .. " " .. winid .. " " .. lnum .. " " .. col_after)] + if (nil ~= _44_) then + local other = _44_ set_beacon_to_match_hl(target) else end @@ -317,11 +304,10 @@ local function resolve_conflicts(targets) end return nil end -local function set_beacons(targets, _52_) - local _arg_53_ = _52_ - local no_labels_3f = _arg_53_["no-labels?"] - local user_given_targets_3f = _arg_53_["user-given-targets?"] - local aot_3f = _arg_53_["aot?"] +local function set_beacons(targets, _48_) + local _arg_49_ = _48_ + local no_labels_3f = _arg_49_["no-labels?"] + local aot_3f = _arg_49_["aot?"] if (no_labels_3f and targets[1].chars) then for _, target in ipairs(targets) do set_beacon_to_match_hl(target) @@ -330,7 +316,7 @@ local function set_beacons(targets, _52_) else for _, target in ipairs(targets) do if target.label then - set_beacon_for_labeled(target, {["user-given-targets?"] = user_given_targets_3f, ["aot?"] = aot_3f}) + set_beacon_for_labeled(target) elseif (aot_3f and opts.highlight_unlabeled_phase_one_targets) then set_beacon_to_match_hl(target) else @@ -361,22 +347,22 @@ end local function prebeacon(opts0) target_state["backdrop-ranges"] = opts0["backdrop-ranges"] target_state["hl-affected-windows"] = opts0["hl-affected-windows"] - local function _57_() + local function _53_() end - return with_highlight_chores(_57_) + return with_highlight_chores(_53_) end local function light_up_beacons(targets, opts0) local opts1 = (opts0 or {}) for i = (opts1.start or 1), (opts1["end"] or #targets) do local target = targets[i] - local _58_ = target.beacon - if ((_G.type(_58_) == "table") and (nil ~= (_58_)[1]) and (nil ~= (_58_)[2])) then - local offset = (_58_)[1] - local virttext = (_58_)[2] + local _54_ = target.beacon + if ((_G.type(_54_) == "table") and (nil ~= (_54_)[1]) and (nil ~= (_54_)[2])) then + local offset = (_54_)[1] + local virttext = (_54_)[2] local bufnr = target.wininfo.bufnr - local _let_59_ = map(dec, target.pos) - local lnum = _let_59_[1] - local col = _let_59_[2] + local _let_55_ = map(dec, target.pos) + local lnum = _let_55_[1] + local col = _let_55_[2] local id = api.nvim_buf_set_extmark(bufnr, hl.ns, lnum, (col + offset), {virt_text = virttext, virt_text_pos = "overlay", hl_mode = "combine", priority = hl.priority.label}) table.insert(hl.extmarks, {bufnr, id}) else @@ -386,32 +372,32 @@ local function light_up_beacons(targets, opts0) end local state = {args = nil, source_window = nil, ["repeat"] = {in1 = nil, in2 = nil}, dot_repeat = {in1 = nil, in2 = nil, target_idx = nil, backward = nil, inclusive_op = nil, offset = nil}, saved_editor_opts = {}} local function leap(kwargs) - local _local_61_ = kwargs - local dot_repeat_3f = _local_61_["dot_repeat"] - local target_windows = _local_61_["target_windows"] - local user_given_opts = _local_61_["opts"] - local user_given_targets = _local_61_["targets"] - local user_given_action = _local_61_["action"] - local multi_select_3f = _local_61_["multiselect"] - local function _63_() + local _local_57_ = kwargs + local dot_repeat_3f = _local_57_["dot_repeat"] + local target_windows = _local_57_["target_windows"] + local user_given_opts = _local_57_["opts"] + local user_given_targets = _local_57_["targets"] + local user_given_action = _local_57_["action"] + local multi_select_3f = _local_57_["multiselect"] + local function _59_() if dot_repeat_3f then return state.dot_repeat else return kwargs end end - local _local_62_ = _63_() - local backward_3f = _local_62_["backward"] - local match_xxx_2a_at_the_end_3f = _local_62_["match-xxx*-at-the-end?"] - local inclusive_op_3f = _local_62_["inclusive_op"] - local offset = _local_62_["offset"] + local _local_58_ = _59_() + local backward_3f = _local_58_["backward"] + local match_xxx_2a_at_the_end_3f = _local_58_["match-xxx*-at-the-end?"] + local inclusive_op_3f = _local_58_["inclusive_op"] + local offset = _local_58_["offset"] opts.current_call = (user_given_opts or {}) do - local _64_ = opts.current_call.equivalence_classes - if (nil ~= _64_) then - opts.current_call.eq_class_of = eq_classes__3emembership_lookup(_64_) + local _60_ = opts.current_call.equivalence_classes + if (nil ~= _60_) then + opts.current_call.eq_class_of = eq_classes__3emembership_lookup(_60_) else - opts.current_call.eq_class_of = _64_ + opts.current_call.eq_class_of = _60_ end end local directional_3f = not target_windows @@ -471,12 +457,12 @@ local function leap(kwargs) local spec_keys do local function __index(_, k) - local _72_ = opts.special_keys[k] - if (nil ~= _72_) then - local v = _72_ + local _68_ = opts.special_keys[k] + if (nil ~= _68_) then + local v = _68_ if ((k == "next_target") or (k == "prev_target")) then - local _73_ = type(v) - if (_73_ == "table") then + local _69_ = type(v) + if (_69_ == "table") then local tbl_17_auto = {} local i_18_auto = #tbl_17_auto for _0, str in ipairs(v) do @@ -488,7 +474,7 @@ local function leap(kwargs) end end return tbl_17_auto - elseif (_73_ == "string") then + elseif (_69_ == "string") then return {replace_keycodes(v)} else return nil @@ -512,24 +498,24 @@ local function leap(kwargs) table.insert(backdrop_ranges, range) end else - local _let_78_ = map(dec, {vim.fn.line("."), vim.fn.col(".")}) - local curline = _let_78_[1] - local curcol = _let_78_[2] - local _let_79_ = {dec(vim.fn.line("w0")), dec(vim.fn.line("w$"))} - local win_top = _let_79_[1] - local win_bot = _let_79_[2] - local function _81_() + local _let_74_ = map(dec, {vim.fn.line("."), vim.fn.col(".")}) + local curline = _let_74_[1] + local curcol = _let_74_[2] + local _let_75_ = {dec(vim.fn.line("w0")), dec(vim.fn.line("w$"))} + local win_top = _let_75_[1] + local win_bot = _let_75_[2] + local function _77_() if backward_3f then return {win_top, 0, curline, curcol} else return {curline, inc(curcol), win_bot, -1} end end - local _let_80_ = _81_() - local startrow = _let_80_[1] - local startcol = _let_80_[2] - local endrow = _let_80_[3] - local endcol = _let_80_[4] + local _let_76_ = _77_() + local startrow = _let_76_[1] + local startcol = _let_76_[2] + local endrow = _let_76_[3] + local endcol = _let_76_[4] local wininfo = (vim.fn.getwininfo(0))[1] local range = {bufnr = wininfo.bufnr, startrow = startrow, startcol = startcol, endrow = endrow, endcol = endcol} table.insert(backdrop_ranges, range) @@ -583,41 +569,41 @@ local function leap(kwargs) else pat = (pat1 .. pat2) end - local function _90_() + local function _86_() if opts.case_sensitive then return "\\C" else return "\\c" end end - return ("\\V" .. _90_() .. pat) + return ("\\V" .. _86_() .. pat) end local function get_targets(in1, _3fin2) local search = require("leap.search") local pattern = prepare_pattern(in1, _3fin2) local kwargs0 = {["backward?"] = backward_3f, ["match-xxx*-at-the-end?"] = match_xxx_2a_at_the_end_3f, ["target-windows"] = _3ftarget_windows} local targets = search["get-targets"](pattern, kwargs0) - local function _91_() + local function _87_() vars.errmsg = ("not found: " .. in1 .. (_3fin2 or "")) return nil end - return (targets or _91_()) + return (targets or _87_()) end local function prepare_targets(targets) local funny_edge_case_3f - local function _92_() - local _93_ = targets - if ((_G.type(_93_) == "table") and ((_G.type((_93_)[1]) == "table") and ((_G.type(((_93_)[1]).pos) == "table") and (nil ~= (((_93_)[1]).pos)[1]) and (nil ~= (((_93_)[1]).pos)[2]))) and ((_G.type((_93_)[2]) == "table") and ((_G.type(((_93_)[2]).pos) == "table") and (nil ~= (((_93_)[2]).pos)[1]) and (nil ~= (((_93_)[2]).pos)[2])))) then - local l1 = (((_93_)[1]).pos)[1] - local c1 = (((_93_)[1]).pos)[2] - local l2 = (((_93_)[2]).pos)[1] - local c2 = (((_93_)[2]).pos)[2] + local function _88_() + local _89_ = targets + if ((_G.type(_89_) == "table") and ((_G.type((_89_)[1]) == "table") and ((_G.type(((_89_)[1]).pos) == "table") and (nil ~= (((_89_)[1]).pos)[1]) and (nil ~= (((_89_)[1]).pos)[2]))) and ((_G.type((_89_)[2]) == "table") and ((_G.type(((_89_)[2]).pos) == "table") and (nil ~= (((_89_)[2]).pos)[1]) and (nil ~= (((_89_)[2]).pos)[2])))) then + local l1 = (((_89_)[1]).pos)[1] + local c1 = (((_89_)[1]).pos)[2] + local l2 = (((_89_)[2]).pos)[1] + local c2 = (((_89_)[2]).pos)[2] return ((l1 == l2) and (c1 == (c2 + 2))) else return nil end end - funny_edge_case_3f = (backward_3f and _92_()) + funny_edge_case_3f = (backward_3f and _88_()) local force_noautojump_3f = (op_mode_3f or multi_select_3f or not directional_3f or user_given_action or funny_edge_case_3f) set_autojump(targets, force_noautojump_3f) attach_label_set(targets) @@ -626,11 +612,11 @@ local function leap(kwargs) end local function get_target_with_active_primary_label(sublist, input) local res = {} - for idx, _95_ in ipairs(sublist) do - local _each_96_ = _95_ - local label = _each_96_["label"] - local label_state = _each_96_["label-state"] - local target = _each_96_ + for idx, _91_ in ipairs(sublist) do + local _each_92_ = _91_ + local label = _each_92_["label"] + local label_state = _each_92_["label-state"] + local target = _each_92_ if (next(res) or (label_state == "inactive")) then break end if ((label == input) and (label_state == "active-primary")) then res = {idx, target} @@ -658,18 +644,18 @@ local function leap(kwargs) local jump_to_21 do local first_jump_3f = true - local function _100_(target) + local function _96_(target) local jump = require("leap.jump") jump["jump-to!"](target.pos, {winid = target.wininfo.winid, ["add-to-jumplist?"] = first_jump_3f, mode = mode, offset = offset, ["backward?"] = backward_3f, ["inclusive-op?"] = inclusive_op_3f}) first_jump_3f = false return nil end - jump_to_21 = _100_ + jump_to_21 = _96_ end local function get_number_of_highlighted_targets() - local _101_ = opts.max_highlighted_traversal_targets - if (nil ~= _101_) then - local group_size = _101_ + local _97_ = opts.max_highlighted_traversal_targets + if (nil ~= _97_) then + local group_size = _97_ local consumed = (dec(vars["curr-idx"]) % group_size) local remaining = (group_size - consumed) if (remaining == 1) then @@ -690,16 +676,16 @@ local function leap(kwargs) local start = inc(vars["curr-idx"]) local _end if no_labels_3f then - local _104_ = get_number_of_highlighted_targets() - if (nil ~= _104_) then - local _105_ = (_104_ + dec(start)) - if (nil ~= _105_) then - _end = min(_105_, #targets) + local _100_ = get_number_of_highlighted_targets() + if (nil ~= _100_) then + local _101_ = (_100_ + dec(start)) + if (nil ~= _101_) then + _end = min(_101_, #targets) else - _end = _105_ + _end = _101_ end else - _end = _104_ + _end = _100_ end else _end = nil @@ -708,12 +694,12 @@ local function leap(kwargs) end end local function get_first_pattern_input() - local function _110_() + local function _106_() return echo("") end - with_highlight_chores(_110_) - local _111_, _112_ = get_input_by_keymap(prompt) - if (_111_ == spec_keys.repeat_search) then + with_highlight_chores(_106_) + local _107_, _108_ = get_input_by_keymap(prompt) + if (_107_ == spec_keys.repeat_search) then if state["repeat"].in1 then vars["aot?"] = false return state["repeat"].in1, state["repeat"].in2 @@ -721,8 +707,8 @@ local function leap(kwargs) vars.errmsg = "no previous search" return nil end - elseif (nil ~= _111_) then - local in1 = _111_ + elseif (nil ~= _107_) then + local in1 = _107_ return in1 else return nil @@ -730,25 +716,25 @@ local function leap(kwargs) end local function get_second_pattern_input(targets) if ((#targets <= max_phase_one_targets) and not count) then - local function _115_() + local function _111_() return light_up_beacons(targets) end - with_highlight_chores(_115_) + with_highlight_chores(_111_) else end return get_input_by_keymap(prompt) end local function get_full_pattern_input() - local _117_, _118_ = get_first_pattern_input() - if ((nil ~= _117_) and (nil ~= _118_)) then - local in1 = _117_ - local in2 = _118_ + local _113_, _114_ = get_first_pattern_input() + if ((nil ~= _113_) and (nil ~= _114_)) then + local in1 = _113_ + local in2 = _114_ return in1, in2 - elseif ((nil ~= _117_) and (_118_ == nil)) then - local in1 = _117_ - local _119_ = get_input_by_keymap(prompt) - if (nil ~= _119_) then - local in2 = _119_ + elseif ((nil ~= _113_) and (_114_ == nil)) then + local in1 = _113_ + local _115_ = get_input_by_keymap(prompt) + if (nil ~= _115_) then + local in2 = _115_ return in1, in2 else return nil @@ -770,18 +756,18 @@ local function leap(kwargs) set_label_states(targets, {["group-offset"] = group_offset}) else end - set_beacons(targets, {["aot?"] = vars["aot?"], ["no-labels?"] = no_labels_3f, ["user-given-targets?"] = user_given_targets_3f}) + set_beacons(targets, {["aot?"] = vars["aot?"], ["no-labels?"] = no_labels_3f}) local start, _end = get_highlighted_idx_range(targets, no_labels_3f) - local function _124_() + local function _120_() return light_up_beacons(targets, {start = start, ["end"] = _end}) end - return with_highlight_chores(_124_) + return with_highlight_chores(_120_) end local function loop(group_offset, first_invoc_3f0) display(group_offset) - local _125_ = get_input() - if (nil ~= _125_) then - local input = _125_ + local _121_ = get_input() + if (nil ~= _121_) then + local input = _121_ local switch_group_3f = ((_7cgroups_7c > 1) and ((input == spec_keys.next_group) or ((input == spec_keys.prev_group) and not first_invoc_3f0))) if switch_group_3f then local inc_2fdec @@ -808,32 +794,32 @@ local function leap(kwargs) local group_offset = 0 local first_invoc_3f = true local function loop(targets) - local _129_, _130_ = post_pattern_input_loop(targets, group_offset, first_invoc_3f) - if (_129_ == spec_keys.multi_accept) then + local _125_, _126_ = post_pattern_input_loop(targets, group_offset, first_invoc_3f) + if (_125_ == spec_keys.multi_accept) then if not empty_3f(selection) then return selection else return loop(targets) end - elseif (_129_ == spec_keys.multi_revert) then + elseif (_125_ == spec_keys.multi_revert) then do - local _132_ = table.remove(selection) - if (nil ~= _132_) then - _132_["label-state"] = nil + local _128_ = table.remove(selection) + if (nil ~= _128_) then + _128_["label-state"] = nil else end end return loop(targets) - elseif ((nil ~= _129_) and (nil ~= _130_)) then - local _in = _129_ - local group_offset_2a = _130_ + elseif ((nil ~= _125_) and (nil ~= _126_)) then + local _in = _125_ + local group_offset_2a = _126_ group_offset = group_offset_2a first_invoc_3f = false do - local _134_ = get_target_with_active_primary_label(targets, _in) - if ((_G.type(_134_) == "table") and true and (nil ~= (_134_)[2])) then - local _ = (_134_)[1] - local target = (_134_)[2] + local _130_ = get_target_with_active_primary_label(targets, _in) + if ((_G.type(_130_) == "table") and true and (nil ~= (_130_)[2])) then + local _ = (_130_)[1] + local target = (_130_)[2] if not contains_3f(selection, target) then table.insert(selection, target) target["label-state"] = "selected" @@ -849,9 +835,9 @@ local function leap(kwargs) end multi_select_loop = loop end - local function traversal_loop(targets, start_idx, _138_) - local _arg_139_ = _138_ - local no_labels_3f = _arg_139_["no-labels?"] + local function traversal_loop(targets, start_idx, _134_) + local _arg_135_ = _134_ + local no_labels_3f = _arg_135_["no-labels?"] local function on_first_invoc() if no_labels_3f then for _, t in ipairs(targets) do @@ -861,9 +847,9 @@ local function leap(kwargs) elseif not empty_3f(opts.safe_labels) then local last_labeled = inc(#opts.safe_labels) for i = inc(last_labeled), #targets do - local _140_ = targets[i] - _140_["label"] = nil - _140_["beacon"] = nil + local _136_ = targets[i] + _136_["label"] = nil + _136_["beacon"] = nil end return nil else @@ -871,12 +857,12 @@ local function leap(kwargs) end end local function display() - set_beacons(targets, {["no-labels?"] = no_labels_3f, ["aot?"] = vars["aot?"], ["user-given-targets?"] = user_given_targets_3f}) + set_beacons(targets, {["no-labels?"] = no_labels_3f, ["aot?"] = vars["aot?"]}) local start, _end = get_highlighted_idx_range(targets, no_labels_3f) - local function _142_() + local function _138_() return light_up_beacons(targets, {start = start, ["end"] = _end}) end - return with_highlight_chores(_142_) + return with_highlight_chores(_138_) end local function get_new_idx(idx, _in) if contains_3f(spec_keys.next_target, _in) then @@ -894,32 +880,32 @@ local function leap(kwargs) end vars["curr-idx"] = idx display() - local _145_ = get_input() - if (nil ~= _145_) then - local _in = _145_ - local _146_ = get_new_idx(idx, _in) - if (nil ~= _146_) then - local new_idx = _146_ + local _141_ = get_input() + if (nil ~= _141_) then + local _in = _141_ + local _142_ = get_new_idx(idx, _in) + if (nil ~= _142_) then + local new_idx = _142_ do - local _147_ + local _143_ do - local t_148_ = targets - if (nil ~= t_148_) then - t_148_ = (t_148_)[new_idx] + local t_144_ = targets + if (nil ~= t_144_) then + t_144_ = (t_144_)[new_idx] else end - if (nil ~= t_148_) then - t_148_ = (t_148_).chars + if (nil ~= t_144_) then + t_144_ = (t_144_).chars else end - if (nil ~= t_148_) then - t_148_ = (t_148_)[2] + if (nil ~= t_144_) then + t_144_ = (t_144_)[2] else end - _147_ = t_148_ + _143_ = t_144_ end - if (nil ~= _147_) then - local ch2 = _147_ + if (nil ~= _143_) then + local ch2 = _143_ state["repeat"].in2 = ch2 else end @@ -927,14 +913,14 @@ local function leap(kwargs) jump_to_21(targets[new_idx]) return loop(new_idx, false) elseif true then - local _ = _146_ - local _153_ = get_target_with_active_primary_label(targets, _in) - if ((_G.type(_153_) == "table") and true and (nil ~= (_153_)[2])) then - local _0 = (_153_)[1] - local target = (_153_)[2] + local _ = _142_ + local _149_ = get_target_with_active_primary_label(targets, _in) + if ((_G.type(_149_) == "table") and true and (nil ~= (_149_)[2])) then + local _0 = (_149_)[1] + local target = (_149_)[2] return jump_to_21(target) elseif true then - local _0 = _153_ + local _0 = _149_ return vim.fn.feedkeys(_in, "i") else return nil @@ -1004,16 +990,16 @@ local function leap(kwargs) else end if dot_repeat_3f then - local _166_ = targets[state.dot_repeat.target_idx] - if (nil ~= _166_) then - local target = _166_ + local _162_ = targets[state.dot_repeat.target_idx] + if (nil ~= _162_) then + local target = _162_ do_action(target) hl:cleanup(target_state["hl-affected-windows"]) pre_exit() exec_user_autocmds("LeapLeave") return elseif true then - local _ = _166_ + local _ = _162_ if change_op_3f then handle_interrupted_change_op_21() else @@ -1039,6 +1025,9 @@ local function leap(kwargs) else if (#targets > max_phase_one_targets) then vars["aot?"] = false + for _, target in ipairs(targets) do + target["beacon-offset"] = 0 + end else end populate_sublists(targets) @@ -1046,6 +1035,20 @@ local function leap(kwargs) prepare_targets(sublist) end set_initial_label_states(targets) + for _, target in ipairs(targets) do + if vars["aot?"] then + target["beacon-offset"] = get_label_offset(target) + if (not opts.highlight_unlabeled_phase_one_targets and (target["label-state"] == "inactive")) then + target.text = " " + else + end + else + if not user_given_targets_3f then + target.pad = " " + else + end + end + end set_beacons(targets, {["aot?"] = vars["aot?"]}) end local in2 = (_3fin2 or get_second_pattern_input(targets)) @@ -1122,13 +1125,13 @@ local function leap(kwargs) end if multi_select_3f then do - local _186_ = multi_select_loop(targets_2a) - if (nil ~= _186_) then - local targets_2a_2a = _186_ - local function _187_() + local _185_ = multi_select_loop(targets_2a) + if (nil ~= _185_) then + local targets_2a_2a = _185_ + local function _186_() return light_up_beacons(targets_2a_2a) end - with_highlight_chores(_187_) + with_highlight_chores(_186_) do_action(targets_2a_2a) else end @@ -1211,9 +1214,9 @@ local function leap(kwargs) end else end - local _local_200_ = get_target_with_active_primary_label(targets_2a, in_final) - local idx = _local_200_[1] - local _ = _local_200_[2] + local _local_199_ = get_target_with_active_primary_label(targets_2a, in_final) + local idx = _local_199_[1] + local _ = _local_199_[2] if idx then set_dot_repeat(in1, in2, idx) do_action((targets_2a)[idx]) @@ -1244,40 +1247,40 @@ local function leap(kwargs) return nil end do - local _204_ = opts.default.equivalence_classes - if (nil ~= _204_) then - opts.default.eq_class_of = eq_classes__3emembership_lookup(_204_) + local _203_ = opts.default.equivalence_classes + if (nil ~= _203_) then + opts.default.eq_class_of = eq_classes__3emembership_lookup(_203_) else - opts.default.eq_class_of = _204_ + opts.default.eq_class_of = _203_ end end api.nvim_create_augroup("LeapDefault", {}) hl["init-highlight"](hl) -local function _206_() +local function _205_() return hl["init-highlight"](hl) end -api.nvim_create_autocmd("ColorScheme", {callback = _206_, group = "LeapDefault"}) +api.nvim_create_autocmd("ColorScheme", {callback = _205_, group = "LeapDefault"}) local function set_editor_opts(t) state.saved_editor_opts = {} local wins = (state.args.target_windows or {state.source_window}) for opt, val in pairs(t) do - local _let_207_ = vim.split(opt, ".", {plain = true}) - local scope = _let_207_[1] - local name = _let_207_[2] - local _208_ = scope - if (_208_ == "w") then + local _let_206_ = vim.split(opt, ".", {plain = true}) + local scope = _let_206_[1] + local name = _let_206_[2] + local _207_ = scope + if (_207_ == "w") then for _, w in ipairs(wins) do state.saved_editor_opts[{"w", w, name}] = api.nvim_win_get_option(w, name) api.nvim_win_set_option(w, name, val) end - elseif (_208_ == "b") then + elseif (_207_ == "b") then for _, w in ipairs(wins) do local b = api.nvim_win_get_buf(w) do end (state.saved_editor_opts)[{"b", b, name}] = api.nvim_buf_get_option(b, name) api.nvim_buf_set_option(b, name, val) end elseif true then - local _ = _208_ + local _ = _207_ state.saved_editor_opts[name] = api.nvim_get_option(name) api.nvim_set_option(name, val) else @@ -1287,17 +1290,17 @@ local function set_editor_opts(t) end local function restore_editor_opts() for key, val in pairs(state.saved_editor_opts) do - local _210_ = key - if ((_G.type(_210_) == "table") and ((_210_)[1] == "w") and (nil ~= (_210_)[2]) and (nil ~= (_210_)[3])) then - local w = (_210_)[2] - local name = (_210_)[3] + local _209_ = key + if ((_G.type(_209_) == "table") and ((_209_)[1] == "w") and (nil ~= (_209_)[2]) and (nil ~= (_209_)[3])) then + local w = (_209_)[2] + local name = (_209_)[3] api.nvim_win_set_option(w, name, val) - elseif ((_G.type(_210_) == "table") and ((_210_)[1] == "b") and (nil ~= (_210_)[2]) and (nil ~= (_210_)[3])) then - local b = (_210_)[2] - local name = (_210_)[3] + elseif ((_G.type(_209_) == "table") and ((_209_)[1] == "b") and (nil ~= (_209_)[2]) and (nil ~= (_209_)[3])) then + local b = (_209_)[2] + local name = (_209_)[3] api.nvim_buf_set_option(b, name, val) - elseif (nil ~= _210_) then - local name = _210_ + elseif (nil ~= _209_) then + local name = _209_ api.nvim_set_option(name, val) else end @@ -1305,12 +1308,12 @@ local function restore_editor_opts() return nil end local temporary_editor_opts = {["w.conceallevel"] = 0, ["g.scrolloff"] = 0, ["w.scrolloff"] = 0, ["g.sidescrolloff"] = 0, ["w.sidescrolloff"] = 0, ["b.modeline"] = false} -local function _212_() +local function _211_() return set_editor_opts(temporary_editor_opts) end -api.nvim_create_autocmd("User", {pattern = "LeapEnter", callback = _212_, group = "LeapDefault"}) -local function _213_() +api.nvim_create_autocmd("User", {pattern = "LeapEnter", callback = _211_, group = "LeapDefault"}) +local function _212_() return restore_editor_opts() end -api.nvim_create_autocmd("User", {pattern = "LeapLeave", callback = _213_, group = "LeapDefault"}) +api.nvim_create_autocmd("User", {pattern = "LeapLeave", callback = _212_, group = "LeapDefault"}) return {state = state, leap = leap} From 8580563daabb72cabbf3a0b6e7d5ae6d3987eba1 Mon Sep 17 00:00:00 2001 From: Rishikesh Vaishnav Date: Sun, 16 Jul 2023 18:45:30 +0000 Subject: [PATCH 5/5] pull `autojump?` out of `set-labels` and `set-label-states` --- fnl/leap/main.fnl | 53 +++-- lua/leap/main.lua | 498 ++++++++++++++++++++++------------------------ 2 files changed, 274 insertions(+), 277 deletions(-) diff --git a/fnl/leap/main.fnl b/fnl/leap/main.fnl index ed1a5f6..8767337 100644 --- a/fnl/leap/main.fnl +++ b/fnl/leap/main.fnl @@ -75,24 +75,26 @@ interrupted change operation." ; Processing targets ///1 -(fn set-autojump [targets force-noautojump?] - "Set a flag indicating whether we should autojump to the first target, +; default-specific helper method +(fn should-autojump [targets force-noautojump?] + "Return whether we should autojump to the first target, without having to select a label. Note that there is no one-to-one correspondence between this flag and the `label-set` field set by `attach-label-set`. No-autojump might be forced implicitly, regardless of using safe labels." - (set targets.autojump? (and (not (or force-noautojump? - (empty? opts.safe_labels))) - (or (empty? opts.labels) - ; Smart mode. - (>= (length opts.safe_labels) - ; Skipping the first if autojumping. - (dec (length targets))))))) + (and (not (or force-noautojump? + (empty? opts.safe_labels))) + (or (empty? opts.labels) + ; Smart mode. + (>= (length opts.safe_labels) + ; Skipping the first if autojumping. + (dec (length targets)))))) +; default-specific helper method (fn attach-label-set [targets] "Set a field referencing the label set to be used for `targets`. -NOTE: `set-autojump` should be called BEFORE this function." +NOTE: `targets.autojump?` should be set BEFORE calling this function." ; (assert (not (and (empty? opts.labels) (empty? opts.safe_labels)))) (set targets.label-set (if (empty? opts.labels) opts.safe_labels (empty? opts.safe_labels) opts.labels @@ -100,26 +102,26 @@ NOTE: `set-autojump` should be called BEFORE this function." opts.labels))) +; generic API helper method (fn set-labels [targets multi-select?] "Assign label characters to each target, using the given label set repeated indefinitely. Note: `label` is a once and for all fixed attribute - whether and how it should actually be displayed depends on the `label-state` flag." (when (or (> (length targets) 1) multi-select?) ; else we jump unconditionally - (local {: autojump? : label-set} targets) + (local {: label-set} targets) (each [i target (ipairs targets)] - ; Skip labeling the first target if autojump is set. - (local i* (if autojump? (dec i) i)) - (when (> i* 0) - (set target.label (case (% i* (length label-set)) + (when (not target.no-label) + (set target.label (case (% i (length label-set)) 0 (. label-set (length label-set)) n (. label-set n))))))) +; generic API helper method (fn set-label-states [targets {: group-offset}] (let [|label-set| (length targets.label-set) offset (* group-offset |label-set|) - primary-start (+ offset (if targets.autojump? 2 1)) + primary-start (+ offset 1) primary-end (+ primary-start (dec |label-set|)) secondary-start (inc primary-end) secondary-end (+ primary-end |label-set|)] @@ -594,7 +596,7 @@ is either labeled (C) or not (B). targets (search.get-targets pattern kwargs)] (or targets (set vars.errmsg (.. "not found: " in1 (or ?in2 "")))))) - (fn prepare-targets [targets] + (fn should-autojump? [targets] (let [funny-edge-case? ; <----- backward search ; ab target #1 @@ -609,10 +611,15 @@ is either labeled (C) or not (B). (not directional?) ; potentially disorienting user-given-action ; no jump, doing sg else funny-edge-case?)] ; see above - (doto targets - (set-autojump force-noautojump?) - (attach-label-set) - (set-labels multi-select?)))) + (should-autojump force-noautojump? targets))) + + (fn prepare-targets [targets] + (set targets.autojump? (should-autojump? targets)) + (attach-label-set targets) + (local first-target (. targets 1)) + ; Skip labeling the first target if autojump is set. + (when targets.autojump? (set first-target.no-label true)) + (set-labels multi-select? targets)) (fn get-target-with-active-primary-label [sublist input] (var res []) @@ -854,11 +861,13 @@ is either labeled (C) or not (B). _ (exit-early))) (if ?in2 + ; no sublists, so we operate directly on targets (if empty-label-lists? (set targets.autojump? true) (prepare-targets targets)) + ; we must prepare the targets for each sublist individually (do - (when (> (length targets) max-phase-one-targets) + (when (> (length targets) max-phase-one-targets) ; TODO what's going on here again? (do (set vars.aot? false) (each [_ target (ipairs targets)] diff --git a/lua/leap/main.lua b/lua/leap/main.lua index 44c34fb..b438963 100644 --- a/lua/leap/main.lua +++ b/lua/leap/main.lua @@ -61,9 +61,8 @@ local function eq_classes__3emembership_lookup(eqcls) end return res end -local function set_autojump(targets, force_noautojump_3f) - targets["autojump?"] = (not (force_noautojump_3f or empty_3f(opts.safe_labels)) and (empty_3f(opts.labels) or (#opts.safe_labels >= dec(#targets)))) - return nil +local function should_autojump(targets, force_noautojump_3f) + return (not (force_noautojump_3f or empty_3f(opts.safe_labels)) and (empty_3f(opts.labels) or (#opts.safe_labels >= dec(#targets)))) end local function attach_label_set(targets) if empty_3f(opts.labels) then @@ -80,21 +79,14 @@ end local function set_labels(targets, multi_select_3f) if ((#targets > 1) or multi_select_3f) then local _local_7_ = targets - local autojump_3f = _local_7_["autojump?"] local label_set = _local_7_["label-set"] for i, target in ipairs(targets) do - local i_2a - if autojump_3f then - i_2a = dec(i) - else - i_2a = i - end - if (i_2a > 0) then - local _9_ = (i_2a % #label_set) - if (_9_ == 0) then + if not target["no-label"] then + local _8_ = (i % #label_set) + if (_8_ == 0) then target.label = label_set[#label_set] - elseif (nil ~= _9_) then - local n = _9_ + elseif (nil ~= _8_) then + local n = _8_ target.label = label_set[n] else target.label = nil @@ -107,28 +99,20 @@ local function set_labels(targets, multi_select_3f) return nil end end -local function set_label_states(targets, _13_) - local _arg_14_ = _13_ - local group_offset = _arg_14_["group-offset"] +local function set_label_states(targets, _12_) + local _arg_13_ = _12_ + local group_offset = _arg_13_["group-offset"] local _7clabel_set_7c = #targets["label-set"] local offset = (group_offset * _7clabel_set_7c) - local primary_start - local function _15_() - if targets["autojump?"] then - return 2 - else - return 1 - end - end - primary_start = (offset + _15_()) + local primary_start = (offset + 1) local primary_end = (primary_start + dec(_7clabel_set_7c)) local secondary_start = inc(primary_end) local secondary_end = (primary_end + _7clabel_set_7c) for i, target in ipairs(targets) do if (target.label and (target["label-state"] ~= "selected")) then - if (primary_start <= i) and (i <= primary_end) then + if ((primary_start <= i) and (i <= primary_end)) then target["label-state"] = "active-primary" - elseif (secondary_start <= i) and (i <= secondary_end) then + elseif ((secondary_start <= i) and (i <= secondary_end)) then target["label-state"] = "active-secondary" elseif (i > secondary_end) then target["label-state"] = "inactive" @@ -142,19 +126,19 @@ local function set_label_states(targets, _13_) end local function populate_sublists(targets) targets.sublists = {} - local function _18_(self, ch, sublist) + local function _16_(self, ch, sublist) return rawset(self, __3erepresentative_char(ch), sublist) end - local function _19_(self, ch) + local function _17_(self, ch) return rawget(self, __3erepresentative_char(ch)) end - setmetatable(targets.sublists, {__newindex = _18_, __index = _19_}) - for _, _20_ in ipairs(targets) do - local _each_21_ = _20_ - local _each_22_ = _each_21_["chars"] - local _0 = _each_22_[1] - local ch2 = _each_22_[2] - local target = _each_21_ + setmetatable(targets.sublists, {__newindex = _16_, __index = _17_}) + for _, _18_ in ipairs(targets) do + local _each_19_ = _18_ + local _each_20_ = _each_19_["chars"] + local _0 = _each_20_[1] + local ch2 = _each_20_[2] + local target = _each_19_ local ch20 = (ch2 or "\n") if not targets.sublists[ch20] then targets.sublists[ch20] = {} @@ -171,10 +155,10 @@ local function set_initial_label_states(targets) return nil end local function get_label_offset(target) - local _let_24_ = target - local _let_25_ = _let_24_["chars"] - local ch1 = _let_25_[1] - local ch2 = _let_25_[2] + local _let_22_ = target + local _let_23_ = _let_22_["chars"] + local ch1 = _let_23_[1] + local ch2 = _let_23_[2] if target["empty-line?"] then return 0 elseif target["edge-pos?"] then @@ -190,14 +174,14 @@ local function set_beacon_for_labeled(target) local text = (target.text or (label .. pad)) local virttext do - local _27_ = target["label-state"] - if (_27_ == "selected") then + local _25_ = target["label-state"] + if (_25_ == "selected") then virttext = {{text, hl.group["label-selected"]}} - elseif (_27_ == "active-primary") then + elseif (_25_ == "active-primary") then virttext = {{text, hl.group["label-primary"]}} - elseif (_27_ == "active-secondary") then + elseif (_25_ == "active-secondary") then virttext = {{text, hl.group["label-secondary"]}} - elseif (_27_ == "inactive") then + elseif (_25_ == "inactive") then if target.text then virttext = {{target.text, hl.group["label-secondary"]}} elseif "else" then @@ -218,10 +202,10 @@ local function set_beacon_for_labeled(target) end local function set_beacon_to_match_hl(target) local virttext - local function _31_(_241) + local function _29_(_241) return (opts.substitute_chars[_241] or _241) end - virttext = table.concat(map(_31_, target.chars)) + virttext = table.concat(map(_29_, target.chars)) target.beacon = {0, {{virttext, hl.group.match}}} return nil end @@ -235,39 +219,39 @@ local function resolve_conflicts(targets) local label_positions = {} for _, target in ipairs(targets) do if not target["empty-line?"] then - local _let_32_ = target.wininfo - local bufnr = _let_32_["bufnr"] - local winid = _let_32_["winid"] - local _let_33_ = target.pos - local lnum = _let_33_[1] - local col_ch1 = _let_33_[2] + local _let_30_ = target.wininfo + local bufnr = _let_30_["bufnr"] + local winid = _let_30_["winid"] + local _let_31_ = target.pos + local lnum = _let_31_[1] + local col_ch1 = _let_31_[2] local col_ch2 = (col_ch1 + string.len(target.chars[1])) if (target.label and target.beacon) then local label_offset = target.beacon[1] local col_label = (col_ch1 + label_offset) local shifted_label_3f = (col_label == col_ch2) do - local _34_ = unlabeled_match_positions[(bufnr .. " " .. winid .. " " .. lnum .. " " .. col_label)] - if (nil ~= _34_) then - local other = _34_ + local _32_ = unlabeled_match_positions[(bufnr .. " " .. winid .. " " .. lnum .. " " .. col_label)] + if (nil ~= _32_) then + local other = _32_ target.beacon = nil set_beacon_to_match_hl(other) else end end if shifted_label_3f then - local _36_ = unlabeled_match_positions[(bufnr .. " " .. winid .. " " .. lnum .. " " .. col_ch1)] - if (nil ~= _36_) then - local other = _36_ + local _34_ = unlabeled_match_positions[(bufnr .. " " .. winid .. " " .. lnum .. " " .. col_ch1)] + if (nil ~= _34_) then + local other = _34_ set_beacon_to_match_hl(other) else end else end do - local _39_ = label_positions[(bufnr .. " " .. winid .. " " .. lnum .. " " .. col_label)] - if (nil ~= _39_) then - local other = _39_ + local _37_ = label_positions[(bufnr .. " " .. winid .. " " .. lnum .. " " .. col_label)] + if (nil ~= _37_) then + local other = _37_ target.beacon = nil set_beacon_to_empty_label(other) else @@ -282,18 +266,18 @@ local function resolve_conflicts(targets) elseif not target.label then for _0, key in ipairs({(bufnr .. " " .. winid .. " " .. lnum .. " " .. col_ch1), (bufnr .. " " .. winid .. " " .. lnum .. " " .. col_ch2)}) do unlabeled_match_positions[key] = target - local _42_ = label_positions[key] - if (nil ~= _42_) then - local other = _42_ + local _40_ = label_positions[key] + if (nil ~= _40_) then + local other = _40_ other.beacon = nil set_beacon_to_match_hl(target) else end end local col_after = (col_ch2 + string.len(target.chars[2])) - local _44_ = label_positions[(bufnr .. " " .. winid .. " " .. lnum .. " " .. col_after)] - if (nil ~= _44_) then - local other = _44_ + local _42_ = label_positions[(bufnr .. " " .. winid .. " " .. lnum .. " " .. col_after)] + if (nil ~= _42_) then + local other = _42_ set_beacon_to_match_hl(target) else end @@ -304,10 +288,10 @@ local function resolve_conflicts(targets) end return nil end -local function set_beacons(targets, _48_) - local _arg_49_ = _48_ - local no_labels_3f = _arg_49_["no-labels?"] - local aot_3f = _arg_49_["aot?"] +local function set_beacons(targets, _46_) + local _arg_47_ = _46_ + local no_labels_3f = _arg_47_["no-labels?"] + local aot_3f = _arg_47_["aot?"] if (no_labels_3f and targets[1].chars) then for _, target in ipairs(targets) do set_beacon_to_match_hl(target) @@ -347,22 +331,22 @@ end local function prebeacon(opts0) target_state["backdrop-ranges"] = opts0["backdrop-ranges"] target_state["hl-affected-windows"] = opts0["hl-affected-windows"] - local function _53_() + local function _51_() end - return with_highlight_chores(_53_) + return with_highlight_chores(_51_) end local function light_up_beacons(targets, opts0) local opts1 = (opts0 or {}) for i = (opts1.start or 1), (opts1["end"] or #targets) do local target = targets[i] - local _54_ = target.beacon - if ((_G.type(_54_) == "table") and (nil ~= (_54_)[1]) and (nil ~= (_54_)[2])) then - local offset = (_54_)[1] - local virttext = (_54_)[2] + local _52_ = target.beacon + if ((_G.type(_52_) == "table") and (nil ~= (_52_)[1]) and (nil ~= (_52_)[2])) then + local offset = (_52_)[1] + local virttext = (_52_)[2] local bufnr = target.wininfo.bufnr - local _let_55_ = map(dec, target.pos) - local lnum = _let_55_[1] - local col = _let_55_[2] + local _let_53_ = map(dec, target.pos) + local lnum = _let_53_[1] + local col = _let_53_[2] local id = api.nvim_buf_set_extmark(bufnr, hl.ns, lnum, (col + offset), {virt_text = virttext, virt_text_pos = "overlay", hl_mode = "combine", priority = hl.priority.label}) table.insert(hl.extmarks, {bufnr, id}) else @@ -372,32 +356,32 @@ local function light_up_beacons(targets, opts0) end local state = {args = nil, source_window = nil, ["repeat"] = {in1 = nil, in2 = nil}, dot_repeat = {in1 = nil, in2 = nil, target_idx = nil, backward = nil, inclusive_op = nil, offset = nil}, saved_editor_opts = {}} local function leap(kwargs) - local _local_57_ = kwargs - local dot_repeat_3f = _local_57_["dot_repeat"] - local target_windows = _local_57_["target_windows"] - local user_given_opts = _local_57_["opts"] - local user_given_targets = _local_57_["targets"] - local user_given_action = _local_57_["action"] - local multi_select_3f = _local_57_["multiselect"] - local function _59_() + local _local_55_ = kwargs + local dot_repeat_3f = _local_55_["dot_repeat"] + local target_windows = _local_55_["target_windows"] + local user_given_opts = _local_55_["opts"] + local user_given_targets = _local_55_["targets"] + local user_given_action = _local_55_["action"] + local multi_select_3f = _local_55_["multiselect"] + local function _57_() if dot_repeat_3f then return state.dot_repeat else return kwargs end end - local _local_58_ = _59_() - local backward_3f = _local_58_["backward"] - local match_xxx_2a_at_the_end_3f = _local_58_["match-xxx*-at-the-end?"] - local inclusive_op_3f = _local_58_["inclusive_op"] - local offset = _local_58_["offset"] + local _local_56_ = _57_() + local backward_3f = _local_56_["backward"] + local match_xxx_2a_at_the_end_3f = _local_56_["match-xxx*-at-the-end?"] + local inclusive_op_3f = _local_56_["inclusive_op"] + local offset = _local_56_["offset"] opts.current_call = (user_given_opts or {}) do - local _60_ = opts.current_call.equivalence_classes - if (nil ~= _60_) then - opts.current_call.eq_class_of = eq_classes__3emembership_lookup(_60_) + local _58_ = opts.current_call.equivalence_classes + if (nil ~= _58_) then + opts.current_call.eq_class_of = eq_classes__3emembership_lookup(_58_) else - opts.current_call.eq_class_of = _60_ + opts.current_call.eq_class_of = _58_ end end local directional_3f = not target_windows @@ -457,12 +441,12 @@ local function leap(kwargs) local spec_keys do local function __index(_, k) - local _68_ = opts.special_keys[k] - if (nil ~= _68_) then - local v = _68_ + local _66_ = opts.special_keys[k] + if (nil ~= _66_) then + local v = _66_ if ((k == "next_target") or (k == "prev_target")) then - local _69_ = type(v) - if (_69_ == "table") then + local _67_ = type(v) + if (_67_ == "table") then local tbl_17_auto = {} local i_18_auto = #tbl_17_auto for _0, str in ipairs(v) do @@ -474,7 +458,7 @@ local function leap(kwargs) end end return tbl_17_auto - elseif (_69_ == "string") then + elseif (_67_ == "string") then return {replace_keycodes(v)} else return nil @@ -498,24 +482,24 @@ local function leap(kwargs) table.insert(backdrop_ranges, range) end else - local _let_74_ = map(dec, {vim.fn.line("."), vim.fn.col(".")}) - local curline = _let_74_[1] - local curcol = _let_74_[2] - local _let_75_ = {dec(vim.fn.line("w0")), dec(vim.fn.line("w$"))} - local win_top = _let_75_[1] - local win_bot = _let_75_[2] - local function _77_() + local _let_72_ = map(dec, {vim.fn.line("."), vim.fn.col(".")}) + local curline = _let_72_[1] + local curcol = _let_72_[2] + local _let_73_ = {dec(vim.fn.line("w0")), dec(vim.fn.line("w$"))} + local win_top = _let_73_[1] + local win_bot = _let_73_[2] + local function _75_() if backward_3f then return {win_top, 0, curline, curcol} else return {curline, inc(curcol), win_bot, -1} end end - local _let_76_ = _77_() - local startrow = _let_76_[1] - local startcol = _let_76_[2] - local endrow = _let_76_[3] - local endcol = _let_76_[4] + local _let_74_ = _75_() + local startrow = _let_74_[1] + local startcol = _let_74_[2] + local endrow = _let_74_[3] + local endcol = _let_74_[4] local wininfo = (vim.fn.getwininfo(0))[1] local range = {bufnr = wininfo.bufnr, startrow = startrow, startcol = startcol, endrow = endrow, endcol = endcol} table.insert(backdrop_ranges, range) @@ -569,54 +553,60 @@ local function leap(kwargs) else pat = (pat1 .. pat2) end - local function _86_() + local function _84_() if opts.case_sensitive then return "\\C" else return "\\c" end end - return ("\\V" .. _86_() .. pat) + return ("\\V" .. _84_() .. pat) end local function get_targets(in1, _3fin2) local search = require("leap.search") local pattern = prepare_pattern(in1, _3fin2) local kwargs0 = {["backward?"] = backward_3f, ["match-xxx*-at-the-end?"] = match_xxx_2a_at_the_end_3f, ["target-windows"] = _3ftarget_windows} local targets = search["get-targets"](pattern, kwargs0) - local function _87_() + local function _85_() vars.errmsg = ("not found: " .. in1 .. (_3fin2 or "")) return nil end - return (targets or _87_()) + return (targets or _85_()) end - local function prepare_targets(targets) + local function should_autojump_3f(targets) local funny_edge_case_3f - local function _88_() - local _89_ = targets - if ((_G.type(_89_) == "table") and ((_G.type((_89_)[1]) == "table") and ((_G.type(((_89_)[1]).pos) == "table") and (nil ~= (((_89_)[1]).pos)[1]) and (nil ~= (((_89_)[1]).pos)[2]))) and ((_G.type((_89_)[2]) == "table") and ((_G.type(((_89_)[2]).pos) == "table") and (nil ~= (((_89_)[2]).pos)[1]) and (nil ~= (((_89_)[2]).pos)[2])))) then - local l1 = (((_89_)[1]).pos)[1] - local c1 = (((_89_)[1]).pos)[2] - local l2 = (((_89_)[2]).pos)[1] - local c2 = (((_89_)[2]).pos)[2] + local function _86_() + if ((_G.type(targets) == "table") and ((_G.type(targets[1]) == "table") and ((_G.type((targets[1]).pos) == "table") and (nil ~= ((targets[1]).pos)[1]) and (nil ~= ((targets[1]).pos)[2]))) and ((_G.type(targets[2]) == "table") and ((_G.type((targets[2]).pos) == "table") and (nil ~= ((targets[2]).pos)[1]) and (nil ~= ((targets[2]).pos)[2])))) then + local l1 = ((targets[1]).pos)[1] + local c1 = ((targets[1]).pos)[2] + local l2 = ((targets[2]).pos)[1] + local c2 = ((targets[2]).pos)[2] return ((l1 == l2) and (c1 == (c2 + 2))) else return nil end end - funny_edge_case_3f = (backward_3f and _88_()) + funny_edge_case_3f = (backward_3f and _86_()) local force_noautojump_3f = (op_mode_3f or multi_select_3f or not directional_3f or user_given_action or funny_edge_case_3f) - set_autojump(targets, force_noautojump_3f) + return should_autojump(force_noautojump_3f, targets) + end + local function prepare_targets(targets) + targets["autojump?"] = should_autojump_3f(targets) attach_label_set(targets) - set_labels(targets, multi_select_3f) - return targets + local first_target = targets[1] + if targets["autojump?"] then + first_target["no-label"] = true + else + end + return set_labels(multi_select_3f, targets) end local function get_target_with_active_primary_label(sublist, input) local res = {} - for idx, _91_ in ipairs(sublist) do - local _each_92_ = _91_ - local label = _each_92_["label"] - local label_state = _each_92_["label-state"] - local target = _each_92_ + for idx, _89_ in ipairs(sublist) do + local _each_90_ = _89_ + local label = _each_90_["label"] + local label_state = _each_90_["label-state"] + local target = _each_90_ if (next(res) or (label_state == "inactive")) then break end if ((label == input) and (label_state == "active-primary")) then res = {idx, target} @@ -644,18 +634,18 @@ local function leap(kwargs) local jump_to_21 do local first_jump_3f = true - local function _96_(target) + local function _94_(target) local jump = require("leap.jump") jump["jump-to!"](target.pos, {winid = target.wininfo.winid, ["add-to-jumplist?"] = first_jump_3f, mode = mode, offset = offset, ["backward?"] = backward_3f, ["inclusive-op?"] = inclusive_op_3f}) first_jump_3f = false return nil end - jump_to_21 = _96_ + jump_to_21 = _94_ end local function get_number_of_highlighted_targets() - local _97_ = opts.max_highlighted_traversal_targets - if (nil ~= _97_) then - local group_size = _97_ + local _95_ = opts.max_highlighted_traversal_targets + if (nil ~= _95_) then + local group_size = _95_ local consumed = (dec(vars["curr-idx"]) % group_size) local remaining = (group_size - consumed) if (remaining == 1) then @@ -676,16 +666,16 @@ local function leap(kwargs) local start = inc(vars["curr-idx"]) local _end if no_labels_3f then - local _100_ = get_number_of_highlighted_targets() - if (nil ~= _100_) then - local _101_ = (_100_ + dec(start)) - if (nil ~= _101_) then - _end = min(_101_, #targets) + local _98_ = get_number_of_highlighted_targets() + if (nil ~= _98_) then + local _99_ = (_98_ + dec(start)) + if (nil ~= _99_) then + _end = min(_99_, #targets) else - _end = _101_ + _end = _99_ end else - _end = _100_ + _end = _98_ end else _end = nil @@ -694,12 +684,12 @@ local function leap(kwargs) end end local function get_first_pattern_input() - local function _106_() + local function _104_() return echo("") end - with_highlight_chores(_106_) - local _107_, _108_ = get_input_by_keymap(prompt) - if (_107_ == spec_keys.repeat_search) then + with_highlight_chores(_104_) + local _105_, _106_ = get_input_by_keymap(prompt) + if (_105_ == spec_keys.repeat_search) then if state["repeat"].in1 then vars["aot?"] = false return state["repeat"].in1, state["repeat"].in2 @@ -707,8 +697,8 @@ local function leap(kwargs) vars.errmsg = "no previous search" return nil end - elseif (nil ~= _107_) then - local in1 = _107_ + elseif (nil ~= _105_) then + local in1 = _105_ return in1 else return nil @@ -716,25 +706,25 @@ local function leap(kwargs) end local function get_second_pattern_input(targets) if ((#targets <= max_phase_one_targets) and not count) then - local function _111_() + local function _109_() return light_up_beacons(targets) end - with_highlight_chores(_111_) + with_highlight_chores(_109_) else end return get_input_by_keymap(prompt) end local function get_full_pattern_input() - local _113_, _114_ = get_first_pattern_input() - if ((nil ~= _113_) and (nil ~= _114_)) then - local in1 = _113_ - local in2 = _114_ + local _111_, _112_ = get_first_pattern_input() + if ((nil ~= _111_) and (nil ~= _112_)) then + local in1 = _111_ + local in2 = _112_ return in1, in2 - elseif ((nil ~= _113_) and (_114_ == nil)) then - local in1 = _113_ - local _115_ = get_input_by_keymap(prompt) - if (nil ~= _115_) then - local in2 = _115_ + elseif ((nil ~= _111_) and (_112_ == nil)) then + local in1 = _111_ + local _113_ = get_input_by_keymap(prompt) + if (nil ~= _113_) then + local in2 = _113_ return in1, in2 else return nil @@ -758,16 +748,16 @@ local function leap(kwargs) end set_beacons(targets, {["aot?"] = vars["aot?"], ["no-labels?"] = no_labels_3f}) local start, _end = get_highlighted_idx_range(targets, no_labels_3f) - local function _120_() + local function _118_() return light_up_beacons(targets, {start = start, ["end"] = _end}) end - return with_highlight_chores(_120_) + return with_highlight_chores(_118_) end local function loop(group_offset, first_invoc_3f0) display(group_offset) - local _121_ = get_input() - if (nil ~= _121_) then - local input = _121_ + local _119_ = get_input() + if (nil ~= _119_) then + local input = _119_ local switch_group_3f = ((_7cgroups_7c > 1) and ((input == spec_keys.next_group) or ((input == spec_keys.prev_group) and not first_invoc_3f0))) if switch_group_3f then local inc_2fdec @@ -794,32 +784,32 @@ local function leap(kwargs) local group_offset = 0 local first_invoc_3f = true local function loop(targets) - local _125_, _126_ = post_pattern_input_loop(targets, group_offset, first_invoc_3f) - if (_125_ == spec_keys.multi_accept) then + local _123_, _124_ = post_pattern_input_loop(targets, group_offset, first_invoc_3f) + if (_123_ == spec_keys.multi_accept) then if not empty_3f(selection) then return selection else return loop(targets) end - elseif (_125_ == spec_keys.multi_revert) then + elseif (_123_ == spec_keys.multi_revert) then do - local _128_ = table.remove(selection) - if (nil ~= _128_) then - _128_["label-state"] = nil + local _126_ = table.remove(selection) + if (nil ~= _126_) then + _126_["label-state"] = nil else end end return loop(targets) - elseif ((nil ~= _125_) and (nil ~= _126_)) then - local _in = _125_ - local group_offset_2a = _126_ + elseif ((nil ~= _123_) and (nil ~= _124_)) then + local _in = _123_ + local group_offset_2a = _124_ group_offset = group_offset_2a first_invoc_3f = false do - local _130_ = get_target_with_active_primary_label(targets, _in) - if ((_G.type(_130_) == "table") and true and (nil ~= (_130_)[2])) then - local _ = (_130_)[1] - local target = (_130_)[2] + local _128_ = get_target_with_active_primary_label(targets, _in) + if ((_G.type(_128_) == "table") and true and (nil ~= (_128_)[2])) then + local _ = (_128_)[1] + local target = (_128_)[2] if not contains_3f(selection, target) then table.insert(selection, target) target["label-state"] = "selected" @@ -835,9 +825,9 @@ local function leap(kwargs) end multi_select_loop = loop end - local function traversal_loop(targets, start_idx, _134_) - local _arg_135_ = _134_ - local no_labels_3f = _arg_135_["no-labels?"] + local function traversal_loop(targets, start_idx, _132_) + local _arg_133_ = _132_ + local no_labels_3f = _arg_133_["no-labels?"] local function on_first_invoc() if no_labels_3f then for _, t in ipairs(targets) do @@ -847,9 +837,9 @@ local function leap(kwargs) elseif not empty_3f(opts.safe_labels) then local last_labeled = inc(#opts.safe_labels) for i = inc(last_labeled), #targets do - local _136_ = targets[i] - _136_["label"] = nil - _136_["beacon"] = nil + local _134_ = targets[i] + _134_["label"] = nil + _134_["beacon"] = nil end return nil else @@ -859,10 +849,10 @@ local function leap(kwargs) local function display() set_beacons(targets, {["no-labels?"] = no_labels_3f, ["aot?"] = vars["aot?"]}) local start, _end = get_highlighted_idx_range(targets, no_labels_3f) - local function _138_() + local function _136_() return light_up_beacons(targets, {start = start, ["end"] = _end}) end - return with_highlight_chores(_138_) + return with_highlight_chores(_136_) end local function get_new_idx(idx, _in) if contains_3f(spec_keys.next_target, _in) then @@ -880,32 +870,32 @@ local function leap(kwargs) end vars["curr-idx"] = idx display() - local _141_ = get_input() - if (nil ~= _141_) then - local _in = _141_ - local _142_ = get_new_idx(idx, _in) - if (nil ~= _142_) then - local new_idx = _142_ + local _139_ = get_input() + if (nil ~= _139_) then + local _in = _139_ + local _140_ = get_new_idx(idx, _in) + if (nil ~= _140_) then + local new_idx = _140_ do - local _143_ + local _141_ do - local t_144_ = targets - if (nil ~= t_144_) then - t_144_ = (t_144_)[new_idx] + local t_142_ = targets + if (nil ~= t_142_) then + t_142_ = (t_142_)[new_idx] else end - if (nil ~= t_144_) then - t_144_ = (t_144_).chars + if (nil ~= t_142_) then + t_142_ = (t_142_).chars else end - if (nil ~= t_144_) then - t_144_ = (t_144_)[2] + if (nil ~= t_142_) then + t_142_ = (t_142_)[2] else end - _143_ = t_144_ + _141_ = t_142_ end - if (nil ~= _143_) then - local ch2 = _143_ + if (nil ~= _141_) then + local ch2 = _141_ state["repeat"].in2 = ch2 else end @@ -913,14 +903,14 @@ local function leap(kwargs) jump_to_21(targets[new_idx]) return loop(new_idx, false) elseif true then - local _ = _142_ - local _149_ = get_target_with_active_primary_label(targets, _in) - if ((_G.type(_149_) == "table") and true and (nil ~= (_149_)[2])) then - local _0 = (_149_)[1] - local target = (_149_)[2] + local _ = _140_ + local _147_ = get_target_with_active_primary_label(targets, _in) + if ((_G.type(_147_) == "table") and true and (nil ~= (_147_)[2])) then + local _0 = (_147_)[1] + local target = (_147_)[2] return jump_to_21(target) elseif true then - local _0 = _149_ + local _0 = _147_ return vim.fn.feedkeys(_in, "i") else return nil @@ -990,16 +980,16 @@ local function leap(kwargs) else end if dot_repeat_3f then - local _162_ = targets[state.dot_repeat.target_idx] - if (nil ~= _162_) then - local target = _162_ + local _160_ = targets[state.dot_repeat.target_idx] + if (nil ~= _160_) then + local target = _160_ do_action(target) hl:cleanup(target_state["hl-affected-windows"]) pre_exit() exec_user_autocmds("LeapLeave") return elseif true then - local _ = _162_ + local _ = _160_ if change_op_3f then handle_interrupted_change_op_21() else @@ -1125,13 +1115,13 @@ local function leap(kwargs) end if multi_select_3f then do - local _185_ = multi_select_loop(targets_2a) - if (nil ~= _185_) then - local targets_2a_2a = _185_ - local function _186_() + local _183_ = multi_select_loop(targets_2a) + if (nil ~= _183_) then + local targets_2a_2a = _183_ + local function _184_() return light_up_beacons(targets_2a_2a) end - with_highlight_chores(_186_) + with_highlight_chores(_184_) do_action(targets_2a_2a) else end @@ -1214,9 +1204,9 @@ local function leap(kwargs) end else end - local _local_199_ = get_target_with_active_primary_label(targets_2a, in_final) - local idx = _local_199_[1] - local _ = _local_199_[2] + local _local_197_ = get_target_with_active_primary_label(targets_2a, in_final) + local idx = _local_197_[1] + local _ = _local_197_[2] if idx then set_dot_repeat(in1, in2, idx) do_action((targets_2a)[idx]) @@ -1247,40 +1237,39 @@ local function leap(kwargs) return nil end do - local _203_ = opts.default.equivalence_classes - if (nil ~= _203_) then - opts.default.eq_class_of = eq_classes__3emembership_lookup(_203_) + local _201_ = opts.default.equivalence_classes + if (nil ~= _201_) then + opts.default.eq_class_of = eq_classes__3emembership_lookup(_201_) else - opts.default.eq_class_of = _203_ + opts.default.eq_class_of = _201_ end end api.nvim_create_augroup("LeapDefault", {}) hl["init-highlight"](hl) -local function _205_() +local function _203_() return hl["init-highlight"](hl) end -api.nvim_create_autocmd("ColorScheme", {callback = _205_, group = "LeapDefault"}) +api.nvim_create_autocmd("ColorScheme", {callback = _203_, group = "LeapDefault"}) local function set_editor_opts(t) state.saved_editor_opts = {} local wins = (state.args.target_windows or {state.source_window}) for opt, val in pairs(t) do - local _let_206_ = vim.split(opt, ".", {plain = true}) - local scope = _let_206_[1] - local name = _let_206_[2] - local _207_ = scope - if (_207_ == "w") then + local _let_204_ = vim.split(opt, ".", {plain = true}) + local scope = _let_204_[1] + local name = _let_204_[2] + if (scope == "w") then for _, w in ipairs(wins) do state.saved_editor_opts[{"w", w, name}] = api.nvim_win_get_option(w, name) api.nvim_win_set_option(w, name, val) end - elseif (_207_ == "b") then + elseif (scope == "b") then for _, w in ipairs(wins) do local b = api.nvim_win_get_buf(w) do end (state.saved_editor_opts)[{"b", b, name}] = api.nvim_buf_get_option(b, name) api.nvim_buf_set_option(b, name, val) end elseif true then - local _ = _207_ + local _ = scope state.saved_editor_opts[name] = api.nvim_get_option(name) api.nvim_set_option(name, val) else @@ -1290,17 +1279,16 @@ local function set_editor_opts(t) end local function restore_editor_opts() for key, val in pairs(state.saved_editor_opts) do - local _209_ = key - if ((_G.type(_209_) == "table") and ((_209_)[1] == "w") and (nil ~= (_209_)[2]) and (nil ~= (_209_)[3])) then - local w = (_209_)[2] - local name = (_209_)[3] + if ((_G.type(key) == "table") and (key[1] == "w") and (nil ~= key[2]) and (nil ~= key[3])) then + local w = key[2] + local name = key[3] api.nvim_win_set_option(w, name, val) - elseif ((_G.type(_209_) == "table") and ((_209_)[1] == "b") and (nil ~= (_209_)[2]) and (nil ~= (_209_)[3])) then - local b = (_209_)[2] - local name = (_209_)[3] + elseif ((_G.type(key) == "table") and (key[1] == "b") and (nil ~= key[2]) and (nil ~= key[3])) then + local b = key[2] + local name = key[3] api.nvim_buf_set_option(b, name, val) - elseif (nil ~= _209_) then - local name = _209_ + elseif (nil ~= key) then + local name = key api.nvim_set_option(name, val) else end @@ -1308,12 +1296,12 @@ local function restore_editor_opts() return nil end local temporary_editor_opts = {["w.conceallevel"] = 0, ["g.scrolloff"] = 0, ["w.scrolloff"] = 0, ["g.sidescrolloff"] = 0, ["w.sidescrolloff"] = 0, ["b.modeline"] = false} -local function _211_() +local function _207_() return set_editor_opts(temporary_editor_opts) end -api.nvim_create_autocmd("User", {pattern = "LeapEnter", callback = _211_, group = "LeapDefault"}) -local function _212_() +api.nvim_create_autocmd("User", {pattern = "LeapEnter", callback = _207_, group = "LeapDefault"}) +local function _208_() return restore_editor_opts() end -api.nvim_create_autocmd("User", {pattern = "LeapLeave", callback = _212_, group = "LeapDefault"}) +api.nvim_create_autocmd("User", {pattern = "LeapLeave", callback = _208_, group = "LeapDefault"}) return {state = state, leap = leap}