diff --git a/lua/telescope/actions/set.lua b/lua/telescope/actions/set.lua index d535df5b36..59eecfa3f3 100644 --- a/lua/telescope/actions/set.lua +++ b/lua/telescope/actions/set.lua @@ -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 diff --git a/lua/telescope/previewers/buffer_previewer.lua b/lua/telescope/previewers/buffer_previewer.lua index ad3779ea37..cd701027a4 100644 --- a/lua/telescope/previewers/buffer_previewer.lua +++ b/lua/telescope/previewers/buffer_previewer.lua @@ -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, @@ -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, diff --git a/lua/telescope/utils.lua b/lua/telescope/utils.lua index 6f3ef7e237..ac1c41a6ae 100644 --- a/lua/telescope/utils.lua +++ b/lua/telescope/utils.lua @@ -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() @@ -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 @@ -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