Skip to content

Instantly share code, notes, and snippets.

@panfeng
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save panfeng/3add30ab586f22a78e81 to your computer and use it in GitHub Desktop.
Save panfeng/3add30ab586f22a78e81 to your computer and use it in GitHub Desktop.
直接在_MAPPING_TABLE 加入“键”\tab”值“即可。谷歌中文输入法的词组导出后为dis文件后,记事本打开直接复制到_MAPPING_TABLE就可用了。当然也可把这个扩展放到dropbox里,可以随时编辑随时同步。我在谷歌拼音的自定义词虽然时时同步,但是丢了不少!还是拽在自己手里安心。
-- http://www.google.com/intl/zh-CN/ime/pinyin/api.html
--参考谷歌输入法 base.lua
-- Google pinyin 定义的数据结构,通过ime.parse_mapping函数parse为标准lua表
-- 之前见过的lua扩展都是里面的TABLE都是 key value1,value2,value2 ...
-- 不符合我输入的要求,例如value不能包含有分界符(默认逗号),每行一键多值,得多长啊
-- 每一行代表 "按键" \t "返回值"
-- TABLE内数据接近两千行的时候,虽然GooglePinyinApiConsole.exe能返回正确的值,但谷歌输入法无反应。
-- 一千行的时候还是还行的。
_MAPPING_TABLE = [[
addr 北京市宣武区广安门外北滨河路,甲一号恒物金属大厦515室
addr 北京市清华科技园科建大厦
aa http://www.amazon.com/
ac http://amazon.cn/
aj http://www.amazon.jp/
rss fullrss.net
rss ctrlq.org
rss fivefilters.org
rss feedex.net
code http://www.bentobox.io/index.html
code http://www.codecademy.com
code http://www.coderun.com/ide/
code http://www.codeschool.com/courses
code http://www.microsoftvirtualacademy.com/
]]
-- 解决右边多出空白影响输出的问题
function trim_map(map)
local lines = ime.split_string(_MAPPING_TABLE,'\n')
for i, line in ipairs(lines) do
lines[i] = ime.trim_string_right(lines[i])
end
local result = "\n" .. ime.join_string(lines, "\n") .. "\n"
return result
end
_MAPPING = trim_map(_MAPPING_TABLE)
-- 随便去了一个乱码,表示永远不会在TABLE里面一键多值
_MAPPING = ime.parse_mapping(_MAPPING, "\n", "\t","cyDeG71f9lN99pQdhWq+qDMZnRy52xbU7Y9dMWCXPoA=")
function Lookup(input)
if _MAPPING[input] then
return _MAPPING[input]
else
-- error("Invalid argument")
return "请继续输入字符"
end
end
-- 谷歌输入法中文状态 输入i jj 即出发了Lookup函数。
ime.register_command("jj", "Lookup", "CMD plz")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment