branch: externals/pyim
commit b6eb72c8493b45a376203e29b012e77162283f3c
Author: Feng Shu <tuma...@163.com>
Commit: Feng Shu <tuma...@163.com>

    pyim-autoselector 依赖 pyim-process.
    
            * pyim-liberime.el (pyim-process-autoselector): Use.
            (pyim-autoselector): Removed.
    
            * pyim.el (pyim-autoselector): Required.
    
            * pyim-process.el (pyim-process-autoselector): New custom.
            (pyim-autoselector): Alias to pyim-process-autoselector.
    
            * pyim-autoselector.el (pyim-entered, pyim-candidates): Do not 
require.
            (pyim-process): Require.
            (pyim-autoselector): Removed.
            (pyim-autoselector-xingma): Prefer functions in pyim-process.
    
            * Development.org (整体架构): 调整自动上屏器的位置。
---
 Development.org      |  8 ++++----
 pyim-autoselector.el | 35 +++++++----------------------------
 pyim-liberime.el     |  2 +-
 pyim-process.el      | 29 +++++++++++++++++++++++++++--
 pyim.el              |  1 +
 5 files changed, 40 insertions(+), 35 deletions(-)

diff --git a/Development.org b/Development.org
index 3819afcf4c..70fc29976f 100644
--- a/Development.org
+++ b/Development.org
@@ -16,9 +16,9 @@
 |     | Dict 管理命令,标点用户命令,Pymap 管理命令                       Indicator     |     |
 |     |                                                                        
         |     |
 |     |                 +---------------------------------------------+        
         |     |
-|     |                 | PYIM 用例层: Process                       |            
     |     |
-|     |                 |                                             |        
         |     |
-|     |                 |      +-------------------------------+      |        
         |     |
+|     | 自动上屏器:     | PYIM 用例层: Process                       |                 
|     |
+|     | ----------      |                                             |        
         |     |
+|     | Autoselector    |      +-------------------------------+      |        
         |     |
 |     |                 |      | PYIM 实体层:                 |      |            
     |     |
 |     |                 |      | -----------                   |      |        
         |     |
 |     |                 |      | Entered, Imobjs, Codes,       |      |        
         |     |
@@ -31,7 +31,7 @@
 |     |                 |      |                               |      |        
         |     |
 |     |                 |      +-------------------------------+      |        
         |     |
 |     |                 |                                             |        
         |     |
-|     |                 | 自动上屏器: Autoselector                   |              
   |     |
+|     |                 |                                             |        
         |     |
 |     |                 +---------------------------------------------+        
         |     |
 |     |                                                                        
         |     |
 |     |  PYIM 持久化层:                                                   探针:      
  |     |
diff --git a/pyim-autoselector.el b/pyim-autoselector.el
index b082abd9ec..973d6b3a6f 100644
--- a/pyim-autoselector.el
+++ b/pyim-autoselector.el
@@ -29,35 +29,12 @@
 ;; * 代码                                                           :code:
 (require 'cl-lib)
 (require 'pyim-scheme)
-(require 'pyim-entered)
-(require 'pyim-candidates)
+(require 'pyim-process)
 
 (defgroup pyim-autoselector nil
   "Autoselector for pyim."
   :group 'pyim)
 
-(defcustom pyim-autoselector '(pyim-autoselector-xingma)
-  "已经启用的自动上屏器.
-
-自动上屏器是一个函数。假设用户已经输入 \"nihao\", 并按下 \"m\" 键,
-那么当前entered 就是 \"nihaom\". 上次 entered 是 \"nihao\". 那么
-返回值有3种情况(优先级按照下面的顺序):
-
-1. (:select last :replace-with \"xxx\") 自动上屏上次
-entered (nihao) 的第一个候选词,m 键下一轮处理。
-
-2. (:select current :replace-with \"xxx\") 自动上屏当前
-entered (nihaom) 的第一个候选词。
-
-3. nil  不自动上屏。
-
-如果 :replace-with 设置为一个字符串,则选择最终会被这个字符串替代。
-
-注意:多个 autoselector 函数运行时,最好不要相互影响,如果相互有
-影响,需要用户自己管理。"
-  :type '(choice (const nil)
-                 (repeat function)))
-
 (defun pyim-autoselector-xingma (&rest _args)
   "适用于型码输入法的自动上屏器.
 
@@ -66,18 +43,20 @@ entered (nihaom) 的第一个候选词。
   (let* ((scheme-name (pyim-scheme-name))
          (class (pyim-scheme-get-option scheme-name :class))
          (n (pyim-scheme-get-option scheme-name :code-split-length))
-         (entered (pyim-entered-get 'point-before)))
+         (entered (pyim-process-get-entered 'point-before))
+         (candidates (pyim-process-get-candidates))
+         (last-candidates (pyim-process-get-last-candidates)))
     (when (eq class 'xingma)
       (cond
        ((and (= (length entered) n)
-             (= (length pyim-candidates) 1)
+             (= (length candidates) 1)
              ;; 如果没有候选词,pyim 默认将用户输入当做候选词,这时不能自动上屏,
              ;; 因为这种情况往往是用户输入有误,自动上屏之后,调整输入就变得麻烦了。
-             (not (equal entered (car pyim-candidates))))
+             (not (equal entered (car candidates))))
         '(:select current))
        ((and (> (length entered) n)
              (equal (substring entered 0 n)
-                    (car pyim-candidates-last)))
+                    (car last-candidates)))
         ;; 自动清除错误输入模式,类似微软五笔:敲第五个字母的时候,前面四个字母自
         ;; 动清除。
         '(:select last :replace-with ""))
diff --git a/pyim-liberime.el b/pyim-liberime.el
index 5d0d140419..b7167796a8 100644
--- a/pyim-liberime.el
+++ b/pyim-liberime.el
@@ -190,7 +190,7 @@
           `(:select current :replace-with ,commit))
          (t nil))))))
 
-(add-to-list 'pyim-autoselector 'pyim-autoselector-rime)
+(add-to-list 'pyim-process-autoselector 'pyim-autoselector-rime)
 
 (defun pyim-liberime-create-word (codes words)
   "通过 CODES 和 WORDS 的信息,在 rime 后端重新造词和调整词频。
diff --git a/pyim-process.el b/pyim-process.el
index b511a5b958..1fce8061fe 100644
--- a/pyim-process.el
+++ b/pyim-process.el
@@ -37,7 +37,6 @@
 (require 'pyim-candidates)
 (require 'pyim-outcome)
 (require 'pyim-punctuation)
-(require 'pyim-autoselector)
 (require 'pyim-cstring)
 
 (defgroup pyim-process nil
@@ -61,6 +60,29 @@
 `pyim-english-input-switch-functions' 的设置."
   :type 'symbol)
 
+(defvaralias 'pyim-autoselector 'pyim-process-autoselector)
+(defcustom pyim-process-autoselector '(pyim-autoselector-xingma)
+  "已经启用的自动上屏器.
+
+自动上屏器是一个函数。假设用户已经输入 \"nihao\", 并按下 \"m\" 键,
+那么当前entered 就是 \"nihaom\". 上次 entered 是 \"nihao\". 那么
+返回值有3种情况(优先级按照下面的顺序):
+
+1. (:select last :replace-with \"xxx\") 自动上屏上次
+entered (nihao) 的第一个候选词,m 键下一轮处理。
+
+2. (:select current :replace-with \"xxx\") 自动上屏当前
+entered (nihaom) 的第一个候选词。
+
+3. nil  不自动上屏。
+
+如果 :replace-with 设置为一个字符串,则选择最终会被这个字符串替代。
+
+注意:多个 autoselector 函数运行时,最好不要相互影响,如果相互有
+影响,需要用户自己管理。"
+  :type '(choice (const nil)
+                 (repeat function)))
+
 (defcustom pyim-exhibit-delay-ms 0
   "输入或者删除拼音字符后等待多少毫秒后才显示可选词
 当用户快速输入连续的拼音时可提升用户体验.
@@ -251,7 +273,7 @@
                      (when (functionp x)
                        (ignore-errors
                          (funcall x))))
-                   (cl-remove-duplicates pyim-autoselector :from-end t)))
+                   (cl-remove-duplicates pyim-process-autoselector :from-end 
t)))
           result)
       (cond
        ;; 假如用户输入 "nihao", 然后按了 "m" 键, 那么当前的 entered
@@ -331,6 +353,9 @@
 (defun pyim-process-get-candidates ()
   pyim-candidates)
 
+(defun pyim-process-get-last-candidates ()
+  pyim-candidates-last)
+
 (defun pyim-process-get-candidate-position ()
   pyim-candidate-position)
 
diff --git a/pyim.el b/pyim.el
index 363ba1c4c0..d6cf4cc473 100644
--- a/pyim.el
+++ b/pyim.el
@@ -41,6 +41,7 @@
 (require 'pyim-preview)
 (require 'pyim-indicator)
 (require 'pyim-process)
+(require 'pyim-autoselector)
 (require 'pyim-cstring)
 (require 'pyim-dict)
 

Reply via email to