1

Regenerate nvim config

This commit is contained in:
2024-06-02 03:29:20 +02:00
parent 75eea0c030
commit ef2e28883d
5576 changed files with 604886 additions and 503 deletions

View File

@ -0,0 +1,22 @@
# cmp-emoji
nvim-cmp source for emojis.
# Setup
```lua
require'cmp'.setup {
sources = {
{ name = 'emoji' }
}
}
```
# Option
#### insert (type: boolean)
Speficy emoji should be insert or not.
Default: `false`

View File

@ -0,0 +1,2 @@
require'cmp'.register_source('emoji', require'cmp_emoji'.new())

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,47 @@
local source = {}
source.new = function()
local self = setmetatable({}, { __index = source })
self.commit_items = nil
self.insert_items = nil
return self
end
source.get_trigger_characters = function()
return { ':' }
end
source.get_keyword_pattern = function()
return [=[\%([[:space:]"'`]\|^\)\zs:[[:alnum:]_\-\+]*:\?]=]
end
source.complete = function(self, params, callback)
-- Avoid unexpected completion.
if not vim.regex(self.get_keyword_pattern() .. '$'):match_str(params.context.cursor_before_line) then
return callback()
end
if self:option(params).insert then
if not self.insert_items then
self.insert_items = vim.tbl_map(function(item)
item.word = nil
return item
end, require('cmp_emoji.items')())
end
callback(self.insert_items)
else
if not self.commit_items then
self.commit_items = require('cmp_emoji.items')()
end
callback(self.commit_items)
end
end
source.option = function(_, params)
return vim.tbl_extend('force', {
insert = false,
}, params.option)
end
return source

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,58 @@
-- Generates the emoji data Lua file using this as a source: https://raw.githubusercontent.com/iamcal/emoji-data/master/emoji.json
local M = {}
M._read = function(path)
return vim.fn.json_decode(vim.fn.readfile(path))
end
M._write = function(path, data)
local h = io.open(path, 'w')
h:write(data)
io.close(h)
end
M.to_string = function(chars)
local nrs = {}
for _, char in ipairs(chars) do
table.insert(nrs, vim.fn.eval(([[char2nr("\U%s")]]):format(char)))
end
return vim.fn.list2str(nrs, true)
end
M.to_item = function(emoji, short_name)
short_name = ':' .. short_name .. ':'
return ("{ word = '%s'; label = '%s'; insertText = '%s'; filterText = '%s' };\n"):format(
short_name,
emoji .. ' ' .. short_name,
emoji,
short_name
)
end
M.to_items = function(emoji, short_names)
local variants = ''
for _, short_name in ipairs(short_names) do
variants = variants .. M.to_item(emoji, short_name)
end
return variants
end
M.update = function()
local items = ''
for _, emoji in ipairs(M._read('./emoji.json')) do
local char = M.to_string(vim.split(emoji.unified, '-'))
local valid = true
valid = valid and vim.fn.strdisplaywidth(char) <= 2 -- Ignore invalid ligatures
if valid then
items = items .. M.to_items(char, emoji.short_names)
end
end
M._write('./items.lua', ('return function() return {\n%s} end'):format(items))
end
return M