branch: externals/pyim commit 371d2ee0959f060e44f1688cddd94eee46de486c Author: Feng Shu <tuma...@163.com> Commit: Feng Shu <tuma...@163.com>
cl-defgeneric pyim-dcache-export-* --- pyim-dcache.el | 16 ++++------------ pyim-dhashcache.el | 10 ++++++++-- pyim-dregcache.el | 5 ++++- pyim.el | 19 +++++++++++++++++-- tests/pyim-tests.el | 3 ++- 5 files changed, 35 insertions(+), 18 deletions(-) diff --git a/pyim-dcache.el b/pyim-dcache.el index edc8392a3d..68bacf8a42 100644 --- a/pyim-dcache.el +++ b/pyim-dcache.el @@ -193,25 +193,17 @@ AUTO-BACKUP-THRESHOLD 倍, 那么原值将自动备份到 FILE 对应的备份 t) ;; ** Dcache 导出功能 -(defun pyim-dcache-export-words-and-counts (file &optional confirm ignore-counts) +(cl-defgeneric pyim-dcache-export-words-and-counts (file &optional confirm ignore-counts) "将个人词条以及词条对应的词频信息导出到文件 FILE. 如果 FILE 为 nil, 提示用户指定导出文件位置, 如果 CONFIRM 为 -non-nil,文件存在时将会提示用户是否覆盖,默认为覆盖模式" - (interactive "F将词条和词频信息导出到文件: ") - (pyim-dcache-init-variables) - (pyim-dcache-call-api 'export-words-and-counts file confirm ignore-counts) - (message "PYIM: 词条和词频信息导出完成。")) +non-nil,文件存在时将会提示用户是否覆盖,默认为覆盖模式") -(defun pyim-dcache-export-personal-words (file &optional confirm) +(cl-defgeneric pyim-dcache-export-personal-words (file &optional confirm) "将用户的个人词条导出为 pyim 词库文件. 如果 FILE 为 nil, 提示用户指定导出文件位置, 如果 CONFIRM 为 non-nil, -文件存在时将会提示用户是否覆盖,默认为覆盖模式。" - (interactive "F将个人词条导出到文件:") - (pyim-dcache-init-variables) - (pyim-dcache-call-api 'export-personal-words file confirm) - (message "PYIM: 个人词条导出完成。")) +文件存在时将会提示用户是否覆盖,默认为覆盖模式。") ;; ** Dcache 更新功能 (cl-defgeneric pyim-dcache-update (&optional force) diff --git a/pyim-dhashcache.el b/pyim-dhashcache.el index d9dd07b130..913d77bf14 100644 --- a/pyim-dhashcache.el +++ b/pyim-dhashcache.el @@ -711,11 +711,17 @@ code 对应的中文词条了。 (defun pyim-dhashcache-search-word-code (string) (gethash string pyim-dhashcache-word2code)) -(defun pyim-dhashcache-export-personal-words (file &optional confirm) +(cl-defmethod pyim-dcache-export-personal-words + (file &context (pyim-dcache-backend (eql pyim-dhashcache)) + &optional confirm) "导出个人词库到 FILE." + (pyim-dhashcache-init-variables) (pyim-dhashcache-export pyim-dhashcache-icode2word file confirm)) -(defun pyim-dhashcache-export-words-and-counts (file &optional confirm ignore-counts) +(cl-defmethod pyim-dcache-export-words-and-counts + (file &context (pyim-dcache-backend (eql pyim-dhashcache)) + &optional confirm ignore-counts) + (pyim-dhashcache-init-variables) (with-temp-buffer (insert ";;; -*- coding: utf-8-unix -*-\n") (maphash diff --git a/pyim-dregcache.el b/pyim-dregcache.el index 1b9487ece5..ad33976ae4 100644 --- a/pyim-dregcache.el +++ b/pyim-dregcache.el @@ -474,8 +474,11 @@ update-icode2word 目前只要是用于更新型码输入法的 code-prefix, 所 (setq code (pyim-dregcache-search-word-code-1 word content)) (when code (throw 'result (list code)))))))))) -(defun pyim-dregcache-export-personal-words (file &optional confirm) +(cl-defmethod pyim-dcache-export-personal-words + (file &context (pyim-dcache-backend (eql pyim-dregcache)) + &optional confirm) "将个人词库存入 FILE." + (pyim-dregcache-init-variables) (when pyim-dregcache-icode2word ;; 按词频排序,把词频信息保存到用户词典 (pyim-dregcache-sort-icode2word) diff --git a/pyim.el b/pyim.el index cf5c4f3c81..3b1bf7e2bd 100644 --- a/pyim.el +++ b/pyim.el @@ -435,8 +435,23 @@ MERGE-METHOD 是一个函数,这个函数需要两个数字参数,代表词 (message "PYIM: 词条和词频信息导入完成!"))) ;; ** 导出功能 -(defalias 'pyim-export-words-and-counts 'pyim-dcache-export-words-and-counts) -(defalias 'pyim-export-personal-words 'pyim-dcache-export-personal-words) +(defun pyim-export-words-and-counts (file &optional confirm ignore-counts) + "将个人词条以及词条对应的词频信息导出到文件 FILE. + +如果 FILE 为 nil, 提示用户指定导出文件位置, 如果 CONFIRM 为 +non-nil,文件存在时将会提示用户是否覆盖,默认为覆盖模式" + (interactive "F将词条和词频信息导出到文件: ") + (pyim-dcache-export-words-and-counts file confirm ignore-counts) + (message "PYIM: 词条和词频信息导出完成。")) + +(defun pyim-export-personal-words (file &optional confirm) + "将用户的个人词条导出为 pyim 词库文件. + +如果 FILE 为 nil, 提示用户指定导出文件位置, 如果 CONFIRM 为 non-nil, +文件存在时将会提示用户是否覆盖,默认为覆盖模式。" + (interactive "F将个人词条导出到文件:") + (pyim-dcache-export-personal-words file confirm) + (message "PYIM: 个人词条导出完成。")) ;; ** 删词功能 (defun pyim-delete-words-in-file (file) diff --git a/tests/pyim-tests.el b/tests/pyim-tests.el index 0e339e5d07..336f6b2cb1 100644 --- a/tests/pyim-tests.el +++ b/tests/pyim-tests.el @@ -982,7 +982,8 @@ (should (equal my/test:1 "hello")))) (ert-deftest pyim-tests-pyim-dcache-export () - (let ((pyim-dhashcache-iword2count (make-hash-table :test #'equal)) + (let ((pyim-dcache-backend 'pyim-dhashcache) + (pyim-dhashcache-iword2count (make-hash-table :test #'equal)) (pyim-dhashcache-icode2word (make-hash-table :test #'equal)) (file (pyim-tests-make-temp-file))) (puthash "你好" 10 pyim-dhashcache-iword2count)