Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP fix escapeing windows special chars #2652

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lua/telescope/actions/set.lua
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ action_set.edit = function(prompt_bufnr, command)
-- prevents restarting lsp server
if vim.api.nvim_buf_get_name(0) ~= filename or command ~= "edit" then
filename = Path:new(filename):normalize(vim.loop.cwd())
if utils.is_windows then
filename = utils.escape_windows_special_chars(filename)
end
pcall(vim.cmd, string.format("%s %s", command, vim.fn.fnameescape(filename)))
end
end
Expand Down
6 changes: 6 additions & 0 deletions lua/telescope/previewers/buffer_previewer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,9 @@ previewers.cat = defaulter(function(opts)
end,

get_buffer_by_name = function(_, entry)
if utils.is_windows then
entry.path = utils.escape_windows_special_chars(entry.path)
end
return from_entry.path(entry, false)
end,

Expand Down Expand Up @@ -552,6 +555,9 @@ previewers.vimgrep = defaulter(function(opts)
end,

get_buffer_by_name = function(_, entry)
if utils.is_windows then
entry.path = utils.escape_windows_special_chars(entry.path)
end
return from_entry.path(entry, false)
end,

Expand Down
11 changes: 11 additions & 0 deletions lua/telescope/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ local log = require "telescope.log"
local truncate = require("plenary.strings").truncate
local get_status = require("telescope.state").get_status

local is_windows = vim.fn.has "win32" == 1 or vim.fn.has "win32unix" == 1

local utils = {}

utils.get_separator = function()
Expand All @@ -31,6 +33,14 @@ utils.get_lazy_default = function(x, defaulter, ...)
end
end

utils.is_windows = function()
return is_windows
end

utils.escape_windows_special_chars = function(string)
return string:gsub("%(", "\\("):gsub("%)", "\\)")
end

utils.repeated_table = function(n, val)
local empty_lines = {}
for _ = 1, n do
Expand Down Expand Up @@ -187,6 +197,7 @@ local calc_result_length = function(truncate_len)
return type(truncate_len) == "number" and len - truncate_len or len
end


--- Transform path is a util function that formats a path based on path_display
--- found in `opts` or the default value from config.
--- It is meant to be used in make_entry to have a uniform interface for
Expand Down