SquirrelConfig/lua/en_spacer.lua

21 lines
676 B
Lua
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

-- 这个 Lua 给英文单词后面自动加一个空格 #496
local function add_space_to_english_word(input)
-- 匹配纯英文单词don't 算纯英文单词)并在单词后添加空格
input = input:gsub("(%a+'?%a*)", "%1 ")
return input
end
-- 在候选项上屏时触发的函数
local function en_spacer(input, env)
for cand in input:iter() do
if cand.text:match("^[%a']+[%a']*$") then
-- 如果候选项是纯英文单词,则在输入后添加一个空格
cand = cand:to_shadow_candidate(cand.type, add_space_to_english_word(cand.text), cand.comment)
end
yield(cand)
end
end
return en_spacer