home
home copied to clipboard
請問如何爲半角符號添加註釋
以預設的symbol中的半角頓號爲例,預設的情形並沒有添加半角註釋,而在有些字體下半角頓號與全角頓號難以區分,請問有無方法主動爲其添加〔半角〕註釋呢?
沒有專門做這項功能。 有人用編碼提示加拼寫運算迂迴實現,做法極其複雜。
使用Lua腳本實現了這一功能,代碼如下:
local full_sym = {
",", "。", "、", "・", "|", "/", "\", "[", "]", "~", "{", "}"
}
local full_com = "〔全角〕"
local half_sym = {
",", ".", "、", "·", "|", "/", "\\", "[", "]", "~", "{", "}"
}
local half_com = "〔半角〕"
local function table_include_value(loc_table, loc_value)
for _, loop_value in pairs(loc_table) do
if loop_value == loc_value then
return true
end
end
return false
end
local function filter(input)
for cand in input:iter() do
local str = cand.text
if utf8.len(str) == 1 then
if table_include_value(full_sym, str) then
cand:get_genuine().comment = full_com
elseif table_include_value(half_sym, str) then
cand:get_genuine().comment = half_com
end
end
yield(cand)
end
end
return filter
思路就是在候選項僅一位時對表,利用Filter修改註釋

效果大致就是這樣
用 [[ ]] 和 match
-- lua_filter
local full_sym= [['",<.>;:+-/=_!@#$%^&*()[]{}\]]
local half_sym= [[''",<.>;:+-/=_!@#$%^&*()[]{}\]]
local full_com = "〔全角〕"
local half_com = "〔半角〕"
function M.func(inp,env)
for cand in inp:iter() do
local comment = (full_sym:match( cand.text) and full_com)
or (half_sym:match(cand.text) and half_com)
if comment then
cand.comment = cand.comment .. comment
end
yield(cand)
end
end
return M