2022-04-04 01:10:26 +02:00
|
|
|
|
local M = {}
|
|
|
|
|
local pickers = require "telescope.pickers"
|
|
|
|
|
local finders = require "telescope.finders"
|
|
|
|
|
local conf = require("telescope.config").values
|
|
|
|
|
local actions = require "telescope.actions"
|
|
|
|
|
local action_state = require "telescope.actions.state"
|
|
|
|
|
local previewers = require "telescope.previewers"
|
|
|
|
|
local utils = require "telescope.utils"
|
|
|
|
|
|
|
|
|
|
local add_abbreviations = false
|
|
|
|
|
|
|
|
|
|
local unicodeChars = {
|
2022-08-05 19:11:10 +02:00
|
|
|
|
nats = "ℕ",
|
|
|
|
|
rationals = "ℚ",
|
|
|
|
|
reals = "ℝ",
|
|
|
|
|
integers = "ℤ",
|
|
|
|
|
forall = "∀",
|
|
|
|
|
lambda = "λ",
|
|
|
|
|
arrow = "→",
|
|
|
|
|
compose = "∘",
|
|
|
|
|
inverse = "⁻¹",
|
|
|
|
|
dots = "…",
|
|
|
|
|
alpha = "ɑ",
|
|
|
|
|
beta = "β",
|
|
|
|
|
pi = "π",
|
|
|
|
|
Pi = 'Π',
|
|
|
|
|
sigma = "σ",
|
|
|
|
|
Sigma = "Σ",
|
|
|
|
|
tau = "τ",
|
|
|
|
|
theta = "θ",
|
|
|
|
|
gamma = "γ",
|
|
|
|
|
Gamma = "Γ",
|
|
|
|
|
context = "Γ"
|
2022-04-04 01:10:26 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-- our picker function for unicode chars
|
|
|
|
|
function M.picker(opts)
|
2022-08-05 19:11:10 +02:00
|
|
|
|
opts = opts or {}
|
|
|
|
|
local results = {}
|
2022-04-04 01:10:26 +02:00
|
|
|
|
|
2022-08-05 19:11:10 +02:00
|
|
|
|
for key, value in pairs(unicodeChars) do
|
|
|
|
|
-- Name: char pair
|
|
|
|
|
table.insert(results, { key, value })
|
|
|
|
|
end
|
2022-04-04 01:10:26 +02:00
|
|
|
|
|
2022-08-05 19:11:10 +02:00
|
|
|
|
print(results)
|
2022-04-04 01:10:26 +02:00
|
|
|
|
|
2022-08-05 19:11:10 +02:00
|
|
|
|
pickers.new(opts, {
|
|
|
|
|
prompt_title = "Unicode characters",
|
|
|
|
|
finder = finders.new_table {
|
|
|
|
|
results = results,
|
|
|
|
|
entry_maker = function(entry)
|
|
|
|
|
return { value = entry, display = entry[1], ordinal = entry[1] }
|
|
|
|
|
end
|
|
|
|
|
},
|
|
|
|
|
sorter = conf.generic_sorter(opts),
|
|
|
|
|
previewer = previewers.new {
|
|
|
|
|
preview_fn = function(_, entry) return entry.value[2] end
|
|
|
|
|
},
|
|
|
|
|
attach_mappings = function(prompt_bufnr)
|
|
|
|
|
actions.select_default:replace(function()
|
|
|
|
|
actions.close(prompt_bufnr)
|
|
|
|
|
local selection = action_state.get_selected_entry()
|
2022-04-04 01:10:26 +02:00
|
|
|
|
|
2022-08-05 19:11:10 +02:00
|
|
|
|
if selection == nil then
|
|
|
|
|
utils.__warn_no_selection "my.abbreviations"
|
|
|
|
|
return
|
2022-04-04 01:10:26 +02:00
|
|
|
|
end
|
2022-08-05 19:11:10 +02:00
|
|
|
|
|
|
|
|
|
vim.api.nvim_put({ selection.value[2] }, "", false, true)
|
|
|
|
|
vim.cmd("startinsert")
|
|
|
|
|
end)
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
}):find()
|
2022-04-04 01:10:26 +02:00
|
|
|
|
end
|
|
|
|
|
|
2022-06-18 23:09:21 +02:00
|
|
|
|
function M.setupAbbreviations(prefix, ending)
|
2022-08-05 19:11:10 +02:00
|
|
|
|
prefix = prefix or ""
|
|
|
|
|
ending = ending or ""
|
2022-04-04 01:10:26 +02:00
|
|
|
|
|
2022-08-05 19:11:10 +02:00
|
|
|
|
if not add_abbreviations then return end
|
2022-04-04 01:10:26 +02:00
|
|
|
|
|
2022-08-05 19:11:10 +02:00
|
|
|
|
local abbreviate = require("my.abbreviations").abbr
|
2022-04-04 01:10:26 +02:00
|
|
|
|
|
2022-08-05 19:11:10 +02:00
|
|
|
|
for key, value in pairs(unicodeChars) do
|
|
|
|
|
-- By default abbreviations are triggered using "_"
|
|
|
|
|
abbreviate(prefix .. key .. ending, value)
|
|
|
|
|
end
|
2022-04-04 01:10:26 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return M
|