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

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

[elpa] externals/pyim 95e4dd4b27 04/26: pyim-select-word-really -> pyim-


From: ELPA Syncer
Subject: [elpa] externals/pyim 95e4dd4b27 04/26: pyim-select-word-really -> pyim-process-select-word
Date: Sun, 26 Jun 2022 10:57:51 -0400 (EDT)

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

    pyim-select-word-really -> pyim-process-select-word
---
 pyim-liberime.el |  2 +-
 pyim-process.el  | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 pyim.el          | 80 +-------------------------------------------------------
 3 files changed, 80 insertions(+), 80 deletions(-)

diff --git a/pyim-liberime.el b/pyim-liberime.el
index 573f82400e..fec2326add 100644
--- a/pyim-liberime.el
+++ b/pyim-liberime.el
@@ -182,7 +182,7 @@
 
 (defvar pyim-liberime-code-log nil)
 (defvar pyim-liberime-word-log nil)
-(cl-defmethod pyim-select-word-really ((_scheme pyim-scheme-rime))
+(cl-defmethod pyim-process-select-word ((_scheme pyim-scheme-rime))
   "从选词框中选择当前词条,然后删除该词条对应拼音。"
   (pyim-process-outcome-handle 'candidate)
   (let* ((entered (pyim-entered-get 'point-before))
diff --git a/pyim-process.el b/pyim-process.el
index 7a46e6a69b..f6b33b8d8c 100644
--- a/pyim-process.el
+++ b/pyim-process.el
@@ -566,6 +566,84 @@ imobj 组合构成在一起,构成了 imobjs 这个概念。比如:
   (setq pyim-process--candidate-position
         word-position-in-candidates))
 
+(cl-defgeneric pyim-process-select-word (scheme))
+
+(cl-defmethod pyim-process-select-word ((_scheme pyim-scheme-quanpin))
+  "从选词框中选择当前词条,然后删除该词条对应拼音。"
+  (pyim-process-outcome-handle 'candidate)
+  (let* ((imobj (pyim-process-get-first-imobj))
+         (length-selected-word
+          ;; 获取 *这一次* 选择词条的长度, 在“多次选择词条才能上屏”的情况下,
+          ;; 一定要和 output 的概念作区别。
+          ;; 比如: xiaolifeidao
+          ;; 第一次选择:小李, output = 小李
+          ;; 第二次选择:飞,   output = 小李飞
+          ;; 第三次选择:刀,   output = 小李飞刀
+          (- (length (pyim-process-get-outcome))
+             (length (pyim-process-get-outcome 1))))
+         ;; pyim-imobjs 包含 *pyim-entered--buffer* 里面光标前面的字符
+         ;; 串,通过与 selected-word 做比较,获取光标前未转换的字符串。
+         ;; to-be-translated.
+         (to-be-translated
+          (string-join (mapcar (lambda (w)
+                                 (concat (nth 2 w) (nth 3 w)))
+                               (nthcdr length-selected-word imobj)))))
+    ;; 大体来说,entered 字符串可以分解为三个部分:
+
+    ;; 1. 光标前字符串
+    ;;    1. 光标前已经转换的字符串
+    ;;    2. 光标前还没有转换的字符串。
+    ;; 2. 光标后字符串
+
+    ;; 下面对 entered 字符串的大体思路是:截取已经转换的字符串,把未转
+    ;; 换的字符串和光标后的字符串合并后下一轮递归的处理。
+
+    ;; 比如:entered 为 xiaolifeidao, 本次选择 “小李” 之后,需要将
+    ;; entered 截断,“小李” 这个词条长度为2, 就将 entered从头开始缩减
+    ;; 2 个 imelem 对应的字符,变成 feidao, 为下一次选择 “飞” 做准备。
+
+    ;; 注意事项: 这里有一个假设前提是: 一个 imelem 对应一个汉字,
+    ;; 在全拼输入法中,这个假设大多数情况是成立的,但在型码输入法
+    ;; 中,比如五笔输入法,就不成立,好在型码输入法一般不需要多次
+    ;; 选择。
+    (if (and (not (pyim-process-select-subword-p)) ;以词定字的时候,不连续选择,处理起来太复杂。
+             (or (< length-selected-word (length imobj)) ;是否有未转换的光标前字符串
+                 (> (length (pyim-process-get-entered 'point-after)) 0))) 
;是否有光标后字符串
+        (progn
+          (pyim-process-with-entered-buffer
+            ;; 把光标前已转换的 entered 字符串, 从 entered字符串里面剪
+            ;; 掉,保留未转换的字符串和光标之后的字符串。
+            (delete-region (point-min) (point))
+            (insert to-be-translated)
+            ;; 为下一次选词作准备,一般情况下词库里面的词条不会超过20
+            ;; 个汉字,所以这里光标向前移动不超过20个 imelem. 从而让下
+            ;; 一轮处理时的“光标前字符串”比较长,这种方式可能比逐字选
+            ;; 择更加好用。
+            (goto-char (pyim-process-next-imelem-position 20 t 1)))
+          (pyim-process-run))
+      (pyim-process-create-word (pyim-process-get-outcome) t)
+      (pyim-process-terminate)
+      ;; pyim 使用这个 hook 来处理联想词。
+      (run-hooks 'pyim-select-finish-hook))))
+
+(cl-defmethod pyim-process-select-word ((_scheme pyim-scheme-xingma))
+  "从选词框中选择当前词条,然后删除该词条对应编码。"
+  (pyim-process-outcome-handle 'candidate)
+  (if (pyim-process-with-entered-buffer
+        (and (> (point) 1)
+             (< (point) (point-max))))
+      (progn
+        (pyim-process-with-entered-buffer
+          ;; 把本次已经选择的词条对应的子 entered, 从 entered
+          ;; 字符串里面剪掉。
+          (delete-region (point-min) (point)))
+        (pyim-process-run))
+    ;; NOTE: 以词定字的时候,到底应不应该保存词条呢,需要进一步研究。
+    (pyim-process-create-word (pyim-process-get-outcome) t)
+    (pyim-process-terminate)
+    ;; pyim 使用这个 hook 来处理联想词。
+    (run-hooks 'pyim-select-finish-hook)))
+
 ;; ** 上屏相关
 (defun pyim-process-toggle-set-subword-info (n)
   (if (member n pyim-outcome-subword-info)
diff --git a/pyim.el b/pyim.el
index 1ff8c99ad6..f8250992c1 100644
--- a/pyim.el
+++ b/pyim.el
@@ -542,85 +542,7 @@ FILE 的格式与 `pyim-dcache-export' 生成的文件格式相同,
       (progn
         (pyim-process-outcome-handle 'last-char)
         (pyim-process-terminate))
-    (pyim-select-word-really (pyim-scheme-current))))
-
-(cl-defgeneric pyim-select-word-really (scheme))
-
-(cl-defmethod pyim-select-word-really ((_scheme pyim-scheme-quanpin))
-  "从选词框中选择当前词条,然后删除该词条对应拼音。"
-  (pyim-process-outcome-handle 'candidate)
-  (let* ((imobj (pyim-process-get-first-imobj))
-         (length-selected-word
-          ;; 获取 *这一次* 选择词条的长度, 在“多次选择词条才能上屏”的情况下,
-          ;; 一定要和 output 的概念作区别。
-          ;; 比如: xiaolifeidao
-          ;; 第一次选择:小李, output = 小李
-          ;; 第二次选择:飞,   output = 小李飞
-          ;; 第三次选择:刀,   output = 小李飞刀
-          (- (length (pyim-process-get-outcome))
-             (length (pyim-process-get-outcome 1))))
-         ;; pyim-imobjs 包含 *pyim-entered--buffer* 里面光标前面的字符
-         ;; 串,通过与 selected-word 做比较,获取光标前未转换的字符串。
-         ;; to-be-translated.
-         (to-be-translated
-          (string-join (mapcar (lambda (w)
-                                 (concat (nth 2 w) (nth 3 w)))
-                               (nthcdr length-selected-word imobj)))))
-    ;; 大体来说,entered 字符串可以分解为三个部分:
-
-    ;; 1. 光标前字符串
-    ;;    1. 光标前已经转换的字符串
-    ;;    2. 光标前还没有转换的字符串。
-    ;; 2. 光标后字符串
-
-    ;; 下面对 entered 字符串的大体思路是:截取已经转换的字符串,把未转
-    ;; 换的字符串和光标后的字符串合并后下一轮递归的处理。
-
-    ;; 比如:entered 为 xiaolifeidao, 本次选择 “小李” 之后,需要将
-    ;; entered 截断,“小李” 这个词条长度为2, 就将 entered从头开始缩减
-    ;; 2 个 imelem 对应的字符,变成 feidao, 为下一次选择 “飞” 做准备。
-
-    ;; 注意事项: 这里有一个假设前提是: 一个 imelem 对应一个汉字,
-    ;; 在全拼输入法中,这个假设大多数情况是成立的,但在型码输入法
-    ;; 中,比如五笔输入法,就不成立,好在型码输入法一般不需要多次
-    ;; 选择。
-    (if (and (not (pyim-process-select-subword-p)) ;以词定字的时候,不连续选择,处理起来太复杂。
-             (or (< length-selected-word (length imobj)) ;是否有未转换的光标前字符串
-                 (> (length (pyim-process-get-entered 'point-after)) 0))) 
;是否有光标后字符串
-        (progn
-          (pyim-process-with-entered-buffer
-            ;; 把光标前已转换的 entered 字符串, 从 entered字符串里面剪
-            ;; 掉,保留未转换的字符串和光标之后的字符串。
-            (delete-region (point-min) (point))
-            (insert to-be-translated)
-            ;; 为下一次选词作准备,一般情况下词库里面的词条不会超过20
-            ;; 个汉字,所以这里光标向前移动不超过20个 imelem. 从而让下
-            ;; 一轮处理时的“光标前字符串”比较长,这种方式可能比逐字选
-            ;; 择更加好用。
-            (goto-char (pyim-process-next-imelem-position 20 t 1)))
-          (pyim-process-run))
-      (pyim-process-create-word (pyim-process-get-outcome) t)
-      (pyim-process-terminate)
-      ;; pyim 使用这个 hook 来处理联想词。
-      (run-hooks 'pyim-select-finish-hook))))
-
-(cl-defmethod pyim-select-word-really ((_scheme pyim-scheme-xingma))
-  "从选词框中选择当前词条,然后删除该词条对应编码。"
-  (pyim-process-outcome-handle 'candidate)
-  (if (pyim-process-with-entered-buffer
-        (and (> (point) 1)
-             (< (point) (point-max))))
-      (progn
-        (pyim-process-with-entered-buffer
-          ;; 把本次已经选择的词条对应的子 entered, 从 entered
-          ;; 字符串里面剪掉。
-          (delete-region (point-min) (point)))
-        (pyim-process-run))
-    ;; NOTE: 以词定字的时候,到底应不应该保存词条呢,需要进一步研究。
-    (pyim-process-create-word (pyim-process-get-outcome) t)
-    (pyim-process-terminate)
-    ;; pyim 使用这个 hook 来处理联想词。
-    (run-hooks 'pyim-select-finish-hook)))
+    (pyim-process-select-word (pyim-scheme-current))))
 
 (defun pyim-select-word-by-number (&optional num)
   "使用数字编号来选择对应的词条。"



reply via email to

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