Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ibhagwan committed Aug 8, 2024
1 parent 2c4f76a commit 247b9d8
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 11 deletions.
49 changes: 48 additions & 1 deletion lua/fzf-lua/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,54 @@ M.vimcmd = function(vimcmd, selected, noesc)
end
end

M.vimcmd_entry = function(vimcmd, selected, opts, pcall_vimcmd)
for _, sel in ipairs(selected) do
(function()
-- Lua 5.1 goto compatiblity hack (function wrap)
local entry = path.entry_to_file(sel, opts, opts.force_uri)
-- "<none>" could be set by `autocmds`
if entry.path == "<none>" then return end
-- Is valid and loaded buffer?
local fullpath = entry.bufname or entry.path or entry.uri and entry.uri:match("^%a+://(.*)")
if not path.is_absolute(fullpath) then
fullpath = path.join({ opts.cwd or opts._cwd or uv.cwd(), fullpath })
end
-- Are we replacing the origin buffer?
local will_replace_curbuf = vimcmd == "e" and path.equals(fullpath, utils.CTX().bname)
or vimcmd == "b" and entry.bufnr and entry.bufnr == utils.CTX().bufnr
if will_replace_curbuf
and not vim.o.hidden
and not vim.o.autowriteall
and utils.buffer_is_dirty(nil, false, true) then
-- when `:set nohidden`, confirm with the user when trying to switch
-- from a dirty buffer, abort if declined, save buffer if requested
if utils.save_dialog(nil) then
vimcmd = vimcmd .. "!"
else
return
end
end
if will_replace_curbuf
and vim.fn.exists("&winfixbuf") == 1
and vim.wo.winfixbuf
then
utils.warn("'winfixbuf' is set for current window, will open in a split.")
vimcmd = "split | " .. vimcmd
end
-- Add current location to jumplist
if not entry.term then vim.cmd("normal! m`") end
-- Killing term buffers requires "!" (#1078)
if entry.term and vimcmd == "bd" then
vimcmd = vimcmd .. "!"
end
-- Only change from current buffer if target is different
if (vimcmd == "b" or vimcmd == "e") then
else
end
end)()
end
end

M.vimcmd_file = function(vimcmd, selected, opts, pcall_vimcmd)
local curbuf = vim.api.nvim_buf_get_name(0)
local is_term = utils.is_term_buffer(0)
Expand All @@ -122,7 +170,6 @@ M.vimcmd_file = function(vimcmd, selected, opts, pcall_vimcmd)
-- Lua 5.1 goto compatiblity hack (function wrap)
local entry = path.entry_to_file(selected[i], opts, opts.force_uri)
if entry.path == "<none>" then return end
entry.ctag = opts._ctag and path.entry_to_ctag(selected[i])
local fullpath = entry.path or entry.uri and entry.uri:match("^%a+://(.*)")
if not path.is_absolute(fullpath) then
fullpath = path.join({ opts.cwd or opts._cwd or uv.cwd(), fullpath })
Expand Down
1 change: 1 addition & 0 deletions lua/fzf-lua/path.lua
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ function M.entry_to_file(entry, opts, force_uri)
path = file,
line = tonumber(line) or 0,
col = tonumber(col) or 0,
ctag = opts._ctag and M.entry_to_ctag(stripped) or nil,
}
end

Expand Down
10 changes: 0 additions & 10 deletions lua/fzf-lua/previewer/builtin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1118,16 +1118,6 @@ function Previewer.tags:new(o, opts, fzf_win)
return self
end

function Previewer.tags:parse_entry(entry_str)
-- first parse as normal entry
-- must use 'super.' and send self as 1st arg
-- or the ':' syntactic sugar will send super's
-- self which doesn't have self.opts
local entry = self.super.parse_entry(self, entry_str)
entry.ctag = path.entry_to_ctag(entry_str)
return entry
end

function Previewer.tags:set_cursor_hl(entry)
-- pcall(vim.fn.clearmatches, self.win.preview_winid)
pcall(api.nvim_win_call, self.win.preview_winid, function()
Expand Down
1 change: 1 addition & 0 deletions lua/fzf-lua/previewer/fzf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ function Previewer.cmd_async:parse_entry_and_verify(entrystr)
-- make relative for bat's header display
local filepath = path.relative_to(entry.bufname or entry.path or "", uv.cwd())
if self.opts._ctag then
-- NOTE: override `entry.ctag` with the unescaped version
entry.ctag = path.entry_to_ctag(entry.stripped, true)
if not tonumber(entry.line) or tonumber(entry.line) < 1 then
-- default tags are without line numbers
Expand Down
1 change: 1 addition & 0 deletions lua/fzf-lua/profiles/fzf-vim.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ local function setup_commands(no_override, prefix)
["Changes"] = utils.create_user_command_callback("changes"),
["Marks"] = utils.create_user_command_callback("marks"),
["Jumps"] = utils.create_user_command_callback("jumps"),
["Commands"] = utils.create_user_command_callback("commands"),
["History"] = utils.create_user_command_callback("oldfiles", "query", {
[":"] = "command_history",
["/"] = "search_history",
Expand Down
4 changes: 4 additions & 0 deletions lua/fzf-lua/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,10 @@ function M.fzf_winobj()
return loadstring("return require'fzf-lua'.win.__SELF()")()
end

function M.CTX()
return loadstring("return require'fzf-lua'.core.CTX()")()
end

function M.resume_get(what, opts)
local f = loadstring("return require'fzf-lua'.config.resume_get")()
return f(what, opts)
Expand Down

0 comments on commit 247b9d8

Please sign in to comment.