branch: externals/pyim commit 6332a104208a3ef7ae822830f0489a749bc63653 Author: Feng Shu <tuma...@163.com> Commit: Feng Shu <tuma...@163.com>
cl-defgeneric pyim-dcache-backend --- README.org | 11 +++++++++++ pyim-dcache.el | 10 ++++------ pyim-dregcache.el | 10 ++++++++++ 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/README.org b/README.org index 81e423139b..2a6b2905a6 100644 --- a/README.org +++ b/README.org @@ -9,6 +9,17 @@ * 不兼容更新 +** <2022-06-13 Mon> pyim-dcache-backend 所需的 package 需要用户手工加载了。 + +以前 pyim 可以根据 pyim-dcache-backend 的取值自动加载需要的 package, 这样做虽然 +方便,但代码特别容易出现问题,考虑到 pyim 未来支持的后端不会有太大变化,我删除了 +这个功能,为了向后兼容,pyim 目前会自动加载 pyim-dregcache 包, 但这个兼容代码未 +来可能会删除,所以使用 pyim-dregcache 的用户,建议给自己的配置中添加: + +#+begin_src elisp +(require 'pyim-dregcache) +#+end_src + ** <2022-05-29 Sun> pyim-cregexp-utils, pyim-cstring-utils 和 pyim-dict-manager 需要用户手动 require. 为降低 pyim 代码的复杂度,减少 pyim 依赖包的数量,下面三个包不会自动加载,需要用 diff --git a/pyim-dcache.el b/pyim-dcache.el index 119a969e8d..d57058d569 100644 --- a/pyim-dcache.el +++ b/pyim-dcache.el @@ -175,13 +175,11 @@ AUTO-BACKUP-THRESHOLD 倍, 那么原值将自动备份到 FILE 对应的备份 (setq ,variable (or (pyim-dcache-get-value ',variable) (make-hash-table :test #'equal))))) -;; ** Dcache 获取当前可用后端 -(defun pyim-dcache-backend () +;; ** Dcache 获取当前可用后端接口 +(cl-defgeneric pyim-dcache-backend () "返回当前可用的 dcache backend." - (if (and (eq pyim-dcache-backend 'pyim-dregcache) - (featurep 'pyim-dregcache) - (pyim-scheme-quanpin-p (pyim-scheme-current))) - 'pyim-dregcache + (if (featurep pyim-dcache-backend) + pyim-dcache-backend 'pyim-dhashcache)) ;; ** Dcache 初始化功能接口 diff --git a/pyim-dregcache.el b/pyim-dregcache.el index 038c58b38b..1919adfa30 100644 --- a/pyim-dregcache.el +++ b/pyim-dregcache.el @@ -44,6 +44,16 @@ (defvar pyim-dregcache-iword2count nil) (defvar pyim-dregcache-dicts-md5 nil) +;; ** 获取当前可用后端 +(cl-defmethod pyim-dcache-backend + (&context (pyim-dcache-backend (eql pyim-dregcache))) + "返回当前可用的 dcache backend." + (if (and (featurep 'pyim-dregcache) + ;; pyim-dregcache 后端目前只支持全拼或者双拼。 + (pyim-scheme-quanpin-p (pyim-scheme-current))) + 'pyim-dregcache + 'pyim-dhashcache)) + ;; ** 初始化 dregcache 相关函数 (cl-defmethod pyim-dcache-init-variables (&context ((pyim-dcache-backend) (eql pyim-dregcache)))