[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/pyim 21eb4d60d0 2/2: Add pyim-process-merge-candidates
From: |
ELPA Syncer |
Subject: |
[elpa] externals/pyim 21eb4d60d0 2/2: Add pyim-process-merge-candidates |
Date: |
Tue, 7 Jun 2022 23:57:59 -0400 (EDT) |
branch: externals/pyim
commit 21eb4d60d0af85099ddd820e4a367e662185beac
Author: Feng Shu <tumashu@163.com>
Commit: Feng Shu <tumashu@163.com>
Add pyim-process-merge-candidates
---
pyim-candidates.el | 21 ++++++++-------------
pyim-liberime.el | 2 +-
pyim-process.el | 26 +++++++++++++++-----------
3 files changed, 24 insertions(+), 25 deletions(-)
diff --git a/pyim-candidates.el b/pyim-candidates.el
index a31acb41ab..a5f0b000ac 100644
--- a/pyim-candidates.el
+++ b/pyim-candidates.el
@@ -287,22 +287,17 @@
2. 这个函数运行有时间限制,运行超过某个时间后,无论有没有结果,必须结束。
3. 这个函数需要探测用户是否输入,如果用户开始输入,这个函数运行必须结束。")
-(cl-defmethod pyim-candidates-create-limit-time (_imobjs _scheme
orig-candidates)
- "按照 SCHEME, 使用限时运行的方式从 IMOBJS 获得候选词条。"
- orig-candidates)
+(cl-defmethod pyim-candidates-create-limit-time (_imobjs _scheme)
+ "按照 SCHEME, 使用限时运行的方式从 IMOBJS 获得候选词条。")
-(cl-defmethod pyim-candidates-create-limit-time (imobjs (scheme
pyim-scheme-quanpin) orig-candidates)
+(cl-defmethod pyim-candidates-create-limit-time (imobjs (scheme
pyim-scheme-quanpin))
"按照 SCHEME, 用限时运行的方式从 IMOBJS 获得候选词条,用于全拼输入法。"
;; 构建一个搜索中文的正则表达式, 然后使用这个正则表达式在当前 buffer 中搜
;; 索词条。
(let ((str (string-join (pyim-codes-create (car imobjs) scheme))))
- (if (< (length str) 1)
- orig-candidates
- ;; NOTE: 让第一个词保持不变是不是合理,有待进一步的观察。
- `(,(car orig-candidates)
- ,@(pyim-candidates-search-buffer
- (pyim-cregexp-create str scheme 3 t))
- ,@(cdr orig-candidates)))))
+ (when (> (length str) 0)
+ (pyim-candidates-search-buffer
+ (pyim-cregexp-create str scheme 3 t)))))
(defun pyim-candidates-search-buffer (regexp)
"在当前 buffer 中使用 REGEXP 搜索词条。"
@@ -326,11 +321,11 @@
(> (or (gethash a counts) 0)
(or (gethash b counts) 0))))))))
-(cl-defmethod pyim-candidates-create-limit-time (imobjs (_scheme
pyim-scheme-shuangpin) orig-candidates)
+(cl-defmethod pyim-candidates-create-limit-time (imobjs (_scheme
pyim-scheme-shuangpin))
"按照 SCHEME, 用限时运行的方式从 IMOBJS 获得候选词条,用于双拼输入法。"
;; 注意:pyim 支持的双拼输入法,内部使用全拼的 imobjs, 所以这里直接调用全拼的
;; `pyim-candidates-create-limit-time' 方法来处理 imobjs。
- (cl-call-next-method imobjs (pyim-scheme-get 'quanpin) orig-candidates))
+ (cl-call-next-method imobjs (pyim-scheme-get 'quanpin)))
(cl-defgeneric pyim-candidates-create-async (imobjs scheme callback)
"按照 SCHEME, 使用异步的方式从 IMOBJS 获得候选词条。
diff --git a/pyim-liberime.el b/pyim-liberime.el
index 5372abe449..dc75849cde 100644
--- a/pyim-liberime.el
+++ b/pyim-liberime.el
@@ -141,7 +141,7 @@
(words (liberime-search s (* pyim-page-length 2))))
words))
-(cl-defmethod pyim-candidates-create-limit-time (imobjs (scheme
pyim-scheme-rime) _orig-candidates)
+(cl-defmethod pyim-candidates-create-limit-time (imobjs (scheme
pyim-scheme-rime))
"适用于 rime 的 `pyim-candidates-create-limit-time' 方法。"
(let* ((code (car (pyim-codes-create (car imobjs) scheme)))
(code-prefix (pyim-scheme-code-prefix scheme))
diff --git a/pyim-process.el b/pyim-process.el
index d9f888bd84..10c4f91cb5 100644
--- a/pyim-process.el
+++ b/pyim-process.el
@@ -377,29 +377,33 @@ entered (nihaom) 的第一个候选词。
(defun pyim-process-handle-candidates-limit-time ()
"使用限时的方式获取候选词。"
(let* ((scheme (pyim-scheme-current))
- (words (delete-dups
- (pyim-candidates-create-limit-time
- pyim-imobjs scheme
- pyim-candidates))))
+ (words (pyim-candidates-create-limit-time
+ pyim-imobjs scheme)))
(when words
- (setq pyim-candidates words)
+ (setq pyim-candidates
+ (pyim-process-merge-candidates words pyim-candidates))
(pyim-process-ui-refresh))))
+(defun pyim-process-merge-candidates (new-candidates old-candidates)
+ "将 OLD-CANDIDATES 和 NEW-CANDIDATES 合并的默认策略。"
+ (remove nil (delete-dups
+ `(,(car old-candidates)
+ ,@new-candidates
+ ,@(cdr old-candidates)))))
+
(defun pyim-process-handle-candidates-async ()
"使用异步的方式获取候选词条词条。"
- (let ((buffer (current-buffer)))
+ (let ((scheme (pyim-scheme-current))
+ (buffer (current-buffer)))
(pyim-candidates-create-async
- pyim-imobjs (pyim-scheme-current)
+ pyim-imobjs scheme
(lambda (async-return)
(with-current-buffer buffer
(when (and pyim-process-translating
(not (input-pending-p))
(equal (car async-return) pyim-imobjs))
(setq pyim-candidates
- (delete-dups
- `(,(car pyim-candidates)
- ,@(cdr async-return)
- ,@(cdr pyim-candidates))))
+ (pyim-process-merge-candidates (cdr async-return)
pyim-candidates))
(pyim-process-ui-refresh)))))))
(defun pyim-process-get-candidates ()