emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/pyim 91bcab3d2d: pyim-candidates-create-async -> pyim-c


From: ELPA Syncer
Subject: [elpa] externals/pyim 91bcab3d2d: pyim-candidates-create-async -> pyim-candidates-create-delay.
Date: Mon, 6 Jun 2022 20:57:47 -0400 (EDT)

branch: externals/pyim
commit 91bcab3d2dc80fb87e1b55b406cf6aff685a4596
Author: Feng Shu <tumashu@163.com>
Commit: Feng Shu <tumashu@163.com>

    pyim-candidates-create-async -> pyim-candidates-create-delay.
    
            * pyim-process.el (pyim-process-get-candidates-delay): New custom.
            (pyim-process-async-delay): obsolete.
            (pyim-process-get-candidates-delay-timer): New variable.
            (pyim-process-run-1): Use pyim-process-get-candidates-delay.
            (pyim-process-get-candidates-delay): New function.
            (pyim-process-get-candidates-delay-1): New function.
            (pyim-process-get-candidates-delay-timer-reset): New function.
            (pyim-process-terminate-really): Use 
pyim-process-get-candidates-delay-timer-reset.
    
            * pyim-liberime.el (pyim-candidates-create-delay): Rename from 
pyim-candidates-create-async.
    
            * pyim-candidates.el (pyim-candidates-create-delay): Rename from 
pyim-candidates-create-async.
---
 pyim-candidates.el | 24 +++++++++++++++---------
 pyim-liberime.el   |  4 ++--
 pyim-process.el    | 49 +++++++++++++++++++++++++++++--------------------
 3 files changed, 46 insertions(+), 31 deletions(-)

diff --git a/pyim-candidates.el b/pyim-candidates.el
index 1a63ef8169..e3133afe25 100644
--- a/pyim-candidates.el
+++ b/pyim-candidates.el
@@ -280,15 +280,21 @@
                                 (pyim-pymap-py2cchar-get pinyin))))))
     (cl-subseq chars 0 num)))
 
-(cl-defgeneric pyim-candidates-create-async (imobjs scheme)
-  "按照 SCHEME, 使用异步的方式从 IMOBJS 获得候选词条。")
+(cl-defgeneric pyim-candidates-create-delay (imobjs scheme)
+  "按照 SCHEME, 使用延迟的方式从 IMOBJS 获得候选词条。
 
-(cl-defmethod pyim-candidates-create-async (_imobjs _scheme)
-  "按照 SCHEME, 使用异步的方式从 IMOBJS 获得候选词条。"
+如果用户输入等待时间超过某个阈值时,输入法就会调用这个函数来获取额
+外词条,这个函数有三个特点:
+1. 这个函数是同步运行。
+2. 这个函数运行有时间限制,运行超过某个时间后,无论有没有结果,必须结束。
+3. 这个函数需要探测用户是否输入,如果用户开始输入,这个函数运行必须结束。")
+
+(cl-defmethod pyim-candidates-create-delay (_imobjs _scheme)
+  "按照 SCHEME, 使用延迟的方式从 IMOBJS 获得候选词条。"
   nil)
 
-(cl-defmethod pyim-candidates-create-async (imobjs (scheme 
pyim-scheme-quanpin))
-  "按照 SCHEME, 用异步的方式从 IMOBJS 获得候选词条,用于全拼输入法。"
+(cl-defmethod pyim-candidates-create-delay (imobjs (scheme 
pyim-scheme-quanpin))
+  "按照 SCHEME, 用延迟的方式从 IMOBJS 获得候选词条,用于全拼输入法。"
   ;; 构建一个搜索中文的正则表达式, 然后使用这个正则表达式在当前 buffer 中搜
   ;; 索词条。
   (let ((str (string-join (pyim-codes-create (car imobjs) scheme))))
@@ -330,10 +336,10 @@
                       (> (or (gethash a counts) 0)
                          (or (gethash b counts) 0))))))))
 
-(cl-defmethod pyim-candidates-create-async (imobjs (_scheme 
pyim-scheme-shuangpin))
-  "按照 SCHEME, 用异步的方式从 IMOBJS 获得候选词条,用于双拼输入法。"
+(cl-defmethod pyim-candidates-create-delay (imobjs (_scheme 
pyim-scheme-shuangpin))
+  "按照 SCHEME, 用延迟的方式从 IMOBJS 获得候选词条,用于双拼输入法。"
   ;; 注意:pyim 支持的双拼输入法,内部使用全拼的 imobjs, 所以这里直接调用全拼的
-  ;; `pyim-candidates-create-async' 方法来处理 imobjs。
+  ;; `pyim-candidates-create-delay' 方法来处理 imobjs。
   (cl-call-next-method imobjs (pyim-scheme-get 'quanpin)))
 
 ;; * Footer
diff --git a/pyim-liberime.el b/pyim-liberime.el
index 44622cf201..1da74f13b6 100644
--- a/pyim-liberime.el
+++ b/pyim-liberime.el
@@ -141,8 +141,8 @@
          (words (liberime-search s (* pyim-page-length 2))))
     words))
 
-(cl-defmethod pyim-candidates-create-async (imobjs (scheme pyim-scheme-rime))
-  "适用于 rime 的 `pyim-candidates-create-async' 方法。"
+(cl-defmethod pyim-candidates-create-delay (imobjs (scheme pyim-scheme-rime))
+  "适用于 rime 的 `pyim-candidates-create-delay' 方法。"
   (let* ((code (car (pyim-codes-create (car imobjs) scheme)))
          (code-prefix (pyim-scheme-code-prefix scheme))
          (s (replace-regexp-in-string "-" "" code))
diff --git a/pyim-process.el b/pyim-process.el
index af5337358f..11c921fcf2 100644
--- a/pyim-process.el
+++ b/pyim-process.el
@@ -87,8 +87,11 @@ entered (nihaom) 的第一个候选词。
 如果为 0 或者 nil, 则不等待立刻显示可选词."
   :type 'integer)
 
-(defcustom pyim-process-async-delay 0.3
-  "延迟多少秒开始异步获取词条。"
+(define-obsolete-variable-alias
+  'pyim-process-async-delay 'pyim-process-get-candidates-delay "5.0")
+
+(defcustom pyim-process-get-candidates-delay 0.5
+  "延迟多少秒开始延迟获取词条。"
   :type 'integer)
 
 (defvar pyim-process-input-ascii nil
@@ -115,7 +118,7 @@ entered (nihaom) 的第一个候选词。
 这个变量主要用于全拼和双拼输入法的多音字矫正,其取值一般使用用户
 输入生成的 imobjs 转换得到,保留了用户原始输入的许多信息。")
 
-(defvar pyim-process-run-async-timer nil
+(defvar pyim-process-get-candidates-delay-timer nil
   "异步处理 entered 时,使用的 timer.")
 
 (defvar pyim-process-self-insert-commands nil
@@ -284,14 +287,7 @@ entered (nihaom) 的第一个候选词。
     (setq pyim-candidates
           (or (delete-dups (pyim-candidates-create pyim-imobjs scheme))
               (list entered-to-translate)))
-    (pyim-process-run-async-timer-reset)
-    ;; 当用户选择词条时,如果停顿超过1秒,就激活异步流程,不同的输入法异步流程定
-    ;; 义也可能不同,比如:全拼输入法目前的异步流程是搜索当前 buffer 获取词条。
-    ;; 而 rime 的异步流程是获取所有的词条。
-    (setq pyim-process-run-async-timer
-          (run-with-timer
-           pyim-process-async-delay
-           nil #'pyim-process-run-async))
+    (pyim-process-get-candidates-delay)
     ;; 自动上屏功能
     (let ((autoselector-results
            (mapcar (lambda (x)
@@ -357,19 +353,32 @@ entered (nihaom) 的第一个候选词。
   "测试 CMD 是否是一个 pyim self insert command."
   (member cmd pyim-process-self-insert-commands))
 
-(defun pyim-process-run-async ()
-  "Function used by `pyim-process-run-async-timer'"
+(defun pyim-process-get-candidates-delay ()
+  "延迟获取候选词条。
+
+当用户选择词条时,如果停顿时间超过某个阈值,就激活延迟候选词获取
+流程,不同的输入法对延迟获取候选词流程定义也可能不同,比如:全拼
+输入法目前的延迟获取候选词流程是搜索当前 buffer 获取词条。而 rime
+的延迟获取候选词流程是获取所有的词条。"
+  (pyim-process-get-candidates-delay-timer-reset)
+  (setq pyim-process-get-candidates-delay-timer
+        (run-with-timer
+         pyim-process-get-candidates-delay
+         nil #'pyim-process-get-candidates-delay-1)))
+
+(defun pyim-process-get-candidates-delay-1 ()
+  "Function used by `pyim-process-get-candidates-delay-timer'"
   (let* ((scheme (pyim-scheme-current))
-         (words (delete-dups (pyim-candidates-create-async pyim-imobjs 
scheme))))
+         (words (delete-dups (pyim-candidates-create-delay pyim-imobjs 
scheme))))
     (when words
       (setq pyim-candidates words)
       (pyim-process-ui-refresh))))
 
-(defun pyim-process-run-async-timer-reset ()
-  "Reset `pyim-process-run-async-timer'."
-  (when pyim-process-run-async-timer
-    (cancel-timer pyim-process-run-async-timer)
-    (setq pyim-process-run-async-timer nil)))
+(defun pyim-process-get-candidates-delay-timer-reset ()
+  "Reset `pyim-process-get-candidates-delay-timer'."
+  (when pyim-process-get-candidates-delay-timer
+    (cancel-timer pyim-process-get-candidates-delay-timer)
+    (setq pyim-process-get-candidates-delay-timer nil)))
 
 (defun pyim-process-get-candidates ()
   pyim-candidates)
@@ -674,7 +683,7 @@ BUG:拼音无法有效地处理多音字。"
   (setq pyim-process-force-input-chinese nil)
   (setq pyim-candidates nil)
   (setq pyim-candidates-last nil)
-  (pyim-process-run-async-timer-reset)
+  (pyim-process-get-candidates-delay-timer-reset)
   (pyim-process-ui-hide))
 
 (defun pyim-process-ui-hide ()



reply via email to

[Prev in Thread] Current Thread [Next in Thread]