瀏覽代碼

image commented still freeze + typst in treesitter

Thomas 1 年之前
父節點
當前提交
1fd49e4425
共有 4 個文件被更改,包括 201 次插入17 次删除
  1. 41 2
      init.lua
  2. 14 12
      lua/plugins/conform.lua
  3. 131 0
      lua/plugins/telescope.lua
  4. 15 3
      lua/plugins/treesitter.lua

+ 41 - 2
init.lua

@@ -14,8 +14,8 @@ local opt = vim.opt
 opt.number = true
 opt.relativenumber = true
 
--- copy/paste 
-vim.o.clipboard = 'unnamedplus'
+-- copy/paste
+vim.o.clipboard = "unnamedplus"
 vim.cmd("xnoremap p pgvy")
 
 -- undo
@@ -43,3 +43,42 @@ vim.diagnostic.config({
 require("config.lazy")
 require("config.mappings")
 require("config.autocmd")
+
+-- default config
+--  luarocks --local --lua-version=5.1 install magick
+-- package.path = package.path .. ";" .. vim.fn.expand("$HOME") .. "/.luarocks/share/lua/5.1/?/init.lua"
+-- package.path = package.path .. ";" .. vim.fn.expand("$HOME") .. "/.luarocks/share/lua/5.1/?.lua"
+-- require("image").setup({
+-- 	backend = "kitty",
+-- 	integrations = {
+-- 		markdown = {
+-- 			enabled = true,
+-- 			clear_in_insert_mode = false,
+-- 			download_remote_images = true,
+-- 			only_render_image_at_cursor = false,
+-- 			filetypes = { "markdown", "vimwiki" }, -- markdown extensions (ie. quarto) can go here
+-- 		},
+-- 		neorg = {
+-- 			enabled = true,
+-- 			clear_in_insert_mode = false,
+-- 			download_remote_images = true,
+-- 			only_render_image_at_cursor = false,
+-- 			filetypes = { "norg" },
+-- 		},
+-- 		html = {
+-- 			enabled = false,
+-- 		},
+-- 		css = {
+-- 			enabled = false,
+-- 		},
+-- 	},
+-- 	max_width = nil,
+-- 	max_height = nil,
+-- 	max_width_window_percentage = nil,
+-- 	max_height_window_percentage = 50,
+-- 	window_overlap_clear_enabled = false, -- toggles images when windows are overlapped
+-- 	window_overlap_clear_ft_ignore = { "cmp_menu", "cmp_docs", "" },
+-- 	editor_only_render_when_focused = false, -- auto show/hide images when the editor gains/looses focus
+-- 	tmux_show_only_in_active_window = false, -- auto show/hide images in the correct Tmux window (needs visual-activity off)
+-- 	hijack_file_patterns = { "*.png", "*.jpg", "*.jpeg", "*.gif", "*.webp", "*.avif" }, -- render image files as images when opened
+-- })

+ 14 - 12
lua/plugins/conform.lua

@@ -1,14 +1,16 @@
 return {
-  'stevearc/conform.nvim',
-  opts = {},
-  config = function()
-    require("conform").setup({
-      formatters_by_ft = {
-        lua = { "stylua" },
-        -- Conform will run multiple formatters sequentially
-        -- Use a sub-list to run only the first available formatter
-        javascript = { { "prettierd", "prettier" } },
-      },
-    })
-  end
+	"stevearc/conform.nvim",
+	opts = {},
+	config = function()
+		require("conform").setup({
+			formatters_by_ft = {
+				lua = { "stylua" },
+				-- Conform will run multiple formatters sequentially
+				-- Use a sub-list to run only the first available formatter
+				javascript = { { "prettierd", "prettier" } },
+				rust = { "rustfmt", lsp_format = "fallback" },
+        typst = { "typstyle" }
+			},
+		})
+	end,
 }

+ 131 - 0
lua/plugins/telescope.lua

@@ -1,3 +1,130 @@
+-- Function for image preview with image.nvim 
+-- Still experimental and freeze:
+-- https://github.com/3rd/image.nvim/issues/183
+--
+-- function telescope_image_preview()
+-- 	local supported_images = { "svg", "png", "jpg", "jpeg", "gif", "webp", "avif" }
+-- 	local from_entry = require("telescope.from_entry")
+-- 	local Path = require("plenary.path")
+-- 	local conf = require("telescope.config").values
+-- 	local Previewers = require("telescope.previewers")
+--
+-- 	local previewers = require("telescope.previewers")
+-- 	local image_api = require("image")
+--
+-- 	local is_image_preview = false
+-- 	local image = nil
+-- 	local last_file_path = ""
+--
+-- 	local is_supported_image = function(filepath)
+-- 		local split_path = vim.split(filepath:lower(), ".", { plain = true })
+-- 		local extension = split_path[#split_path]
+-- 		return vim.tbl_contains(supported_images, extension)
+-- 	end
+--
+-- 	local delete_image = function()
+-- 		if not image then
+-- 			return
+-- 		end
+--
+-- 		image:clear()
+--
+-- 		is_image_preview = false
+-- 	end
+--
+-- 	local create_image = function(filepath, winid, bufnr)
+-- 		image = image_api.hijack_buffer(filepath, winid, bufnr)
+--
+-- 		if not image then
+-- 			return
+-- 		end
+--
+-- 		vim.schedule(function()
+-- 			image:render()
+-- 		end)
+--
+-- 		is_image_preview = true
+-- 	end
+--
+-- 	local function defaulter(f, default_opts)
+-- 		default_opts = default_opts or {}
+-- 		return {
+-- 			new = function(opts)
+-- 				if conf.preview == false and not opts.preview then
+-- 					return false
+-- 				end
+-- 				opts.preview = type(opts.preview) ~= "table" and {} or opts.preview
+-- 				if type(conf.preview) == "table" then
+-- 					for k, v in pairs(conf.preview) do
+-- 						opts.preview[k] = vim.F.if_nil(opts.preview[k], v)
+-- 					end
+-- 				end
+-- 				return f(opts)
+-- 			end,
+-- 			__call = function()
+-- 				local ok, err = pcall(f(default_opts))
+-- 				if not ok then
+-- 					error(debug.traceback(err))
+-- 				end
+-- 			end,
+-- 		}
+-- 	end
+--
+-- 	-- NOTE: Add teardown to cat previewer to clear image when close Telescope
+-- 	local file_previewer = defaulter(function(opts)
+-- 		opts = opts or {}
+-- 		local cwd = opts.cwd or vim.loop.cwd()
+-- 		return Previewers.new_buffer_previewer({
+-- 			title = "File Preview",
+-- 			dyn_title = function(_, entry)
+-- 				return Path:new(from_entry.path(entry, true)):normalize(cwd)
+-- 			end,
+--
+-- 			get_buffer_by_name = function(_, entry)
+-- 				return from_entry.path(entry, true)
+-- 			end,
+--
+-- 			define_preview = function(self, entry, _)
+-- 				local p = from_entry.path(entry, true)
+-- 				if p == nil or p == "" then
+-- 					return
+-- 				end
+--
+-- 				conf.buffer_previewer_maker(p, self.state.bufnr, {
+-- 					bufname = self.state.bufname,
+-- 					winid = self.state.winid,
+-- 					preview = opts.preview,
+-- 				})
+-- 			end,
+--
+-- 			teardown = function(_)
+-- 				if is_image_preview then
+-- 					delete_image()
+-- 				end
+-- 			end,
+-- 		})
+-- 	end, {})
+--
+-- 	local buffer_previewer_maker = function(filepath, bufnr, opts)
+-- 		-- NOTE: Clear image when preview other file
+-- 		if is_image_preview and last_file_path ~= filepath then
+-- 			delete_image()
+-- 		end
+--
+-- 		last_file_path = filepath
+--
+-- 		if is_supported_image(filepath) then
+-- 			create_image(filepath, opts.winid, bufnr)
+-- 		else
+-- 			previewers.buffer_previewer_maker(filepath, bufnr, opts)
+-- 		end
+-- 	end
+--
+-- 	return { buffer_previewer_maker = buffer_previewer_maker, file_previewer = file_previewer.new }
+-- end
+--
+-- local image_preview = telescope_image_preview()
+
 return {
 	{
 		"nvim-telescope/telescope.nvim",
@@ -6,6 +133,9 @@ return {
 		config = function()
 			require("telescope").setup({
 				defaults = {
+					-- file_previewer = image_preview.file_previewer,
+					-- buffer_previewer_maker = image_preview.buffer_previewer_maker,
+
 					-- Default configuration for telescope goes here:
 					-- config_key = value,
 					mappings = {
@@ -27,6 +157,7 @@ return {
 					-- builtin picker
 				},
 				extensions = {
+          -- file_browser = { hijack_netrw = true },
 					-- Your extension configuration goes here:
 					-- extension_name = {
 					--   extension_config_key = value,

+ 15 - 3
lua/plugins/treesitter.lua

@@ -6,7 +6,19 @@ return {
 			local configs = require("nvim-treesitter.configs")
 
 			configs.setup({
-				ensure_installed = { "c", "lua", "vim", "vimdoc", "javascript", "html", "rust", "regex", "typescript", "tsx" },
+				ensure_installed = {
+					"c",
+					"lua",
+					"vim",
+					"vimdoc",
+					"javascript",
+					"html",
+					"rust",
+					"regex",
+					"typescript",
+					"tsx",
+					"typst",
+				},
 				sync_install = false,
 				highlight = { enable = true },
 				indent = { enable = true },
@@ -35,8 +47,8 @@ return {
 							["ic"] = { query = "@class.inner", desc = "Select inner part of a class region" },
 							-- You can also use captures from other query groups like `locals.scm`
 							["as"] = { query = "@scope", query_group = "locals", desc = "Select language scope" },
-              ["ap"] = "@parameter.outer",
-              ["ip"] = "@parameter.inner",
+							["ap"] = "@parameter.outer",
+							["ip"] = "@parameter.inner",
 						},
 						-- You can choose the select mode (default is charwise 'v')
 						--