Mercurial > dotfiles
view dot_config/nvim/plugin/filetypo.lua @ 840:f3e87577dd3a
fix: sort keys from template dicts to determistically generate scripts
From http://masterminds.github.io/sprig/dicts.html
> The keys function will return a list of all of the keys in one or more dict types.
> Since a dictionary is unordered, the keys will not be in a predictable order.
> They can be sorted with sortAlpha.
This results in a different ordering of commands in the generated scripts
which break the hashing in chezmoi to determine whether the scripts needs to
be re-run.
author | zegervdv <zegervdv@me.com> |
---|---|
date | Fri, 02 Feb 2024 17:44:49 +0100 |
parents | 1e6287df57f5 |
children |
line wrap: on
line source
-- Inspired by https://github.com/EinfachToll/DidYouMean/blob/master/plugin/DidYouMean.vim local filetypo = function() if vim.fn.filereadable(vim.fn.expand '%') == 1 then return end local filename = vim.fn.expand '%' local matching_files = vim.fn.split(vim.fn.glob(filename .. '*', 0), '\n') if matching_files == nil or vim.tbl_isempty(matching_files) then matching_files = vim.fn.split(vim.fn.glob(filename .. '*', 1), '\n') end if matching_files == nil or vim.tbl_isempty(matching_files) then return end local buf = vim.api.nvim_get_current_buf() vim.schedule(function() vim.ui.select(matching_files, { prompt = 'Select File:' }, function(choice) vim.cmd.edit(vim.fn.fnameescape(choice)) vim.api.nvim_buf_delete(buf, { force = true }) vim.cmd.doautocmd { 'BufReadPre', mods = { silent = true } } vim.cmd.doautocmd { 'BufRead', mods = { silent = true } } vim.cmd.doautocmd { 'BufReadPost', mods = { silent = true } } vim.cmd.doautocmd { 'TextChanged', mods = { silent = true } } end) end) end vim.api.nvim_create_autocmd('BufNewFile', { pattern = '*', callback = filetypo })