branch: externals/pyim commit 024e96706c262da941bf99128f9e62bcba1fa786 Author: Feng Shu <tuma...@163.com> Commit: Feng Shu <tuma...@163.com>
Add pyim-liberime-create-word-at-point --- pyim-liberime.el | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/pyim-liberime.el b/pyim-liberime.el index 38113355fb..689c55746e 100644 --- a/pyim-liberime.el +++ b/pyim-liberime.el @@ -295,6 +295,34 @@ Please see: https://github.com/rime/librime/issues/349" (setq words nil)) (t (liberime-process-key 65366)))))))))) +(defun pyim-liberime-create-word-at-point (&optional number silent) + "将光标前字符数为 NUMBER 的中文字符串添加到 RIME 数据库中。 +当 SILENT 设置为 t 是,不显示提醒信息。 + +这个命令对多音字处理比较弱,所以有可能在 RIME 数据库中添加一些不 +合理的词条,比如: + + yin-xing -> 银行 + +这个问题暂时还没有好的方法解决。" + (interactive) + (when-let* ((rime-quanpin-p + (equal (pyim-scheme-name (pyim-scheme-current)) + 'rime-quanpin)) + (string (pyim-cstring-at-point (or number 2))) + (chars (remove "" (split-string string ""))) + (codes-list + (mapcar (lambda (x) + (split-string x "-")) + (pyim-cstring-to-pinyin string nil "-" t nil t)))) + (dolist (codes codes-list) + (pyim-liberime--create-word codes chars) + (unless silent + (message "将词条: %S -> %S 加入 rime 数据库。" + (string-join codes "-") string))))) + +(advice-add 'pyim-process-create-word-at-point :after #'pyim-liberime-create-word-at-point) + (cl-defmethod pyim-process-terminate-really ((_scheme pyim-scheme-rime)) (cl-call-next-method) (liberime-clear-commit)