branch: externals/pyim commit ba2036d944bbae9b567bf4ba6971b646df0689cc Author: Feng Shu <tuma...@163.com> Commit: Feng Shu <tuma...@163.com>
Fix error when use pyim-dregcache. * pyim-candidates.el (pyim-candidates-get-chief): pyim-dcache-get's from is list. * pyim-dcache.el (pyim-dcache-get): Handle code is nil. * pyim-dregcache.el (pyim-dregcache-get): Ignore iword2count-recent1 and iword2count-recent2 --- pyim-candidates.el | 4 ++-- pyim-dcache.el | 5 +++-- pyim-dregcache.el | 33 +++++++++++++++++++-------------- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/pyim-candidates.el b/pyim-candidates.el index bd0b12bb2d..c6652b4e15 100644 --- a/pyim-candidates.el +++ b/pyim-candidates.el @@ -86,12 +86,12 @@ IMOBJS 获得候选词条。" ;; 最近输入的10个不同的词中出现一次以上。 (cl-find-if (lambda (word) - (> (or (car (pyim-dcache-get word 'iword2count-recent1)) 0) 1)) + (> (or (car (pyim-dcache-get word '(iword2count-recent1))) 0) 1)) personal-words) ;; 最近输入的50个不同的词中出现过三次以上。 (cl-find-if (lambda (word) - (> (or (car (pyim-dcache-get word 'iword2count-recent2)) 0) 3)) + (> (or (car (pyim-dcache-get word '(iword2count-recent2))) 0) 3)) personal-words) ;; 个人词条中的第一个词。 (car personal-words)))))) diff --git a/pyim-dcache.el b/pyim-dcache.el index 96e515a18b..58e8235120 100644 --- a/pyim-dcache.el +++ b/pyim-dcache.el @@ -270,8 +270,9 @@ non-nil,文件存在时将会提示用户是否覆盖,默认为覆盖模式" 当词库文件加载完成后,pyim 就可以用这个函数从词库缓存中搜索某个 code 对应的中文词条了." - `(,@(pyim-dcache-call-api 'get code from) - ,@(pyim-pymap-py2cchar-get code t t))) + (when code + `(,@(pyim-dcache-call-api 'get code from) + ,@(pyim-pymap-py2cchar-get code t t)))) ;; * Footer (provide 'pyim-dcache) diff --git a/pyim-dregcache.el b/pyim-dregcache.el index f7523f2977..18e0a8d3c0 100644 --- a/pyim-dregcache.el +++ b/pyim-dregcache.el @@ -283,20 +283,25 @@ DICT-FILES 是词库文件列表. DICTS-MD5 是词库的MD5校验码. (defun pyim-dregcache-get (code &optional from) "从 `pyim-dregcache-cache' 搜索 CODE, 得到对应的词条." - (if (or (memq 'icode2word from) - (memq 'ishortcode2word from)) - (pyim-dregcache-get-icode2word-ishortcode2word code) - (let ((dict-files (pyim-dregcache-all-dict-files)) - result) - (when pyim-debug (message "pyim-dregcache-get is called. code=%s" code)) - (when dict-files - (dolist (file dict-files) - (let* ((file-info (lax-plist-get pyim-dregcache-cache file)) - (content (pyim-dregcache-get-content code file-info))) - (setq result (append (pyim-dregcache-get-1 content code) result))))) - ;; `push' plus `nreverse' is more efficient than `add-to-list' - ;; Many examples exist in Emacs' own code - (nreverse result)))) + (cond ((or (memq 'icode2word from) + (memq 'ishortcode2word from)) + (pyim-dregcache-get-icode2word-ishortcode2word code)) + ;; FIXME: pyim-dregcache 暂时不支持 iword2count-recent1 和 + ;; iword2count-recent2. + ((or (memq 'iword2count-recent1 from) + (memq 'iword2count-recent2 from)) + nil) + (t (let ((dict-files (pyim-dregcache-all-dict-files)) + result) + (when pyim-debug (message "pyim-dregcache-get is called. code=%s" code)) + (when dict-files + (dolist (file dict-files) + (let* ((file-info (lax-plist-get pyim-dregcache-cache file)) + (content (pyim-dregcache-get-content code file-info))) + (setq result (append (pyim-dregcache-get-1 content code) result))))) + ;; `push' plus `nreverse' is more efficient than `add-to-list' + ;; Many examples exist in Emacs' own code + (nreverse result))))) (defun pyim-dregcache-get-icode2word-ishortcode2word (code) "以 CODE 搜索个人词和个人联想词. 正则表达式搜索词库,不需要为联想词开单独缓存."