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

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

[elpa] externals/pyim 216ab9e80a: pyim-select-subword-by-number -> pyim-


From: ELPA Syncer
Subject: [elpa] externals/pyim 216ab9e80a: pyim-select-subword-by-number -> pyim-select-char-in-word-by-number
Date: Sun, 26 Jun 2022 23:59:10 -0400 (EDT)

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

    pyim-select-subword-by-number -> pyim-select-char-in-word-by-number
---
 pyim-outcome.el | 13 -------------
 pyim-page.el    |  7 -------
 pyim-preview.el |  4 ++--
 pyim-process.el | 44 +++++++++++++++++++++++---------------------
 pyim.el         |  8 ++++----
 5 files changed, 29 insertions(+), 47 deletions(-)

diff --git a/pyim-outcome.el b/pyim-outcome.el
index 751a22acfd..d18f2d4907 100644
--- a/pyim-outcome.el
+++ b/pyim-outcome.el
@@ -119,9 +119,6 @@ pyim 使用函数 `pyim-process-select-handle-char' 来处理特殊功能触发
 5. 第三次选择:四
 6. 变量取值为: (\"一二三四\" \"一二三\" \"一二\")")
 
-(defvar pyim-outcome-subword-info nil
-  "在以词定字功能中,用来保存字的位置。")
-
 (defvar pyim-outcome--magic-convert-cache nil
   "用来临时保存 `pyim-outcome-magic-convert' 的结果.
 从而加快同一个字符串第二次的转换速度。")
@@ -133,16 +130,6 @@ pyim 使用函数 `pyim-process-select-handle-char' 来处理特殊功能触发
   "获取 outcome"
   (nth (or n 0) pyim-outcome-history))
 
-(defun pyim-outcome-get-subword (word)
-  "根据 `pyim-outcome-subword-info' 的信息,获取 WORD 的一个子词条。"
-  (if pyim-outcome-subword-info
-      (let (output)
-        (dolist (i (sort pyim-outcome-subword-info #'>))
-          (when (<= i (length word))
-            (push (substring word (- i 1) i) output)))
-        (string-join output))
-    word))
-
 (defun pyim-outcome-magic-convert (str)
   "用于处理 `pyim-outcome-magic-converter' 的函数。"
   (if (functionp pyim-outcome-magic-converter)
diff --git a/pyim-page.el b/pyim-page.el
index 49b4adedc6..435f25f9cc 100644
--- a/pyim-page.el
+++ b/pyim-page.el
@@ -118,10 +118,6 @@ Only useful when use posframe.")
   '((t (:background "gray44")))
   "选词框中已选词条的 face.")
 
-(defface pyim-page-subword
-  '((t (:background "gray44")))
-  "使用以词选字功能时,选择的汉字所使用的 face.")
-
 (defvar pyim-page-tooltip-infos
   '((posframe   :package posframe :test posframe-workable-p)
     (popup      :package popup)
@@ -546,9 +542,6 @@ pyim-page 的核心的功能,为此增加代码的复杂度和测试的难度
                   (if (consp candidate)
                       (concat (car candidate) (cdr candidate))
                     candidate))))
-        (dolist (n (pyim-process-get-outcome-subword-info))
-          (when (<= n (length str))
-            (set-text-properties (- n 1) n '(face pyim-page-subword) str)))
         (setq i (1+ i))
         ;; 高亮当前选择的词条,用于 `pyim-page-next-word'
         (push
diff --git a/pyim-preview.el b/pyim-preview.el
index 580b856339..808165066f 100644
--- a/pyim-preview.el
+++ b/pyim-preview.el
@@ -99,7 +99,7 @@ pyim 会使用 Emacs overlay 机制在 *待输入buffer* 光标处高亮显示
                    (1- (length candidates))))
          (preview (concat (pyim-process-get-select-result)
                           (nth pos candidates))))
-    (pyim-process-subword-and-magic-convert preview)))
+    (pyim-process-magic-convert preview)))
 
 (cl-defmethod pyim-preview-string ((_scheme pyim-scheme-quanpin))
   "获得 preview 字符串,适用于全拼输入法。"
@@ -116,7 +116,7 @@ pyim 会使用 Emacs overlay 机制在 *待输入buffer* 光标处高亮显示
                 "'")))
     (when (string< "" rest)
       (setq preview (concat preview rest)))
-    (pyim-process-subword-and-magic-convert preview)))
+    (pyim-process-magic-convert preview)))
 
 (defun pyim-preview--delete-string ()
   "删除已经插入 buffer 的 preview 预览字符串。"
diff --git a/pyim-process.el b/pyim-process.el
index 4fa8c1b533..f4912258b2 100644
--- a/pyim-process.el
+++ b/pyim-process.el
@@ -188,6 +188,9 @@ imobj 组合构成在一起,构成了 imobjs 这个概念。比如:
 
 细节信息请参考 `pyim-page--refresh' 的 docstring.")
 
+(defvar pyim-process--char-position-in-word nil
+  "“以词定字”功能中“字”在“词”中的位置.")
+
 (defvar pyim-process--run-delay-timer nil
   "异步处理 entered 时,使用的 timer.")
 
@@ -226,9 +229,6 @@ imobj 组合构成在一起,构成了 imobjs 这个概念。比如:
 (defun pyim-process-update-last-candidates ()
   (setq pyim-process--candidates-last pyim-process--candidates))
 
-(defun pyim-process-get-outcome-subword-info ()
-  pyim-outcome-subword-info)
-
 ;; ** pyim-input-method 核心函数
 (defvar pyim-mode-map)
 
@@ -300,7 +300,7 @@ imobj 组合构成在一起,构成了 imobjs 这个概念。比如:
 (defun pyim-process--init-cleanup ()
   (pyim-entered-erase-buffer)
   (pyim-process--set-translating-flag t)
-  (setq pyim-outcome-subword-info nil)
+  (setq pyim-process--char-position-in-word nil)
   (setq pyim-outcome-history nil))
 
 (defun pyim-process--set-translating-flag (value)
@@ -618,12 +618,9 @@ imobj 组合构成在一起,构成了 imobjs 这个概念。比如:
   "预选 candidates 列表中 WORD-POSITION 位置的词条。"
   (setq pyim-process--word-position word-position))
 
-(defun pyim-process-plan-to-toggle-select-subword (char-position)
-  "Toggle 子字符串选择,CHAR-POSITION 是组成字字符串字符的位置。"
-  (if (member char-position pyim-outcome-subword-info)
-      (setq pyim-outcome-subword-info
-            (remove char-position pyim-outcome-subword-info))
-    (push char-position pyim-outcome-subword-info)))
+(defun pyim-process-plan-to-select-char-in-word (char-position)
+  "以词定字功能中,通过 CHAR-POSITION 预选词条中的汉字。"
+  (setq pyim-process--char-position-in-word char-position))
 
 (defun pyim-process-next-word-position (n)
   "返回已选词条后面地 N 个词条对应的位置。"
@@ -699,7 +696,7 @@ imobj 组合构成在一起,构成了 imobjs 这个概念。比如:
     ;; 在全拼输入法中,这个假设大多数情况是成立的,但在型码输入法
     ;; 中,比如五笔输入法,就不成立,好在型码输入法一般不需要多次
     ;; 选择。
-    (if (and (not (pyim-process-select-subword-p)) ;以词定字的时候,不连续选择,处理起来太复杂。
+    (if (and (not (pyim-process--select-char-in-word-p)) 
;以词定字的时候,不连续选择,处理起来太复杂。
              (or (< length-selected-word (length imobj)) ;是否有未转换的光标前字符串
                  (> (length (pyim-process-get-entered 'point-after)) 0))) 
;是否有光标后字符串
         (progn
@@ -739,8 +736,8 @@ imobj 组合构成在一起,构成了 imobjs 这个概念。比如:
     (unless do-not-terminate
       (pyim-process-terminate))))
 
-(defun pyim-process-select-subword-p ()
-  pyim-outcome-subword-info)
+(defun pyim-process--select-char-in-word-p ()
+  pyim-process--char-position-in-word)
 
 (defun pyim-process-get-first-imobj ()
   (car pyim-process--imobjs))
@@ -767,12 +764,9 @@ BUG:拼音无法有效地处理多音字。"
              ;; 观的一个数字,也许应该添加一个配置选项?
              (< (length word) 12)
              (not (pyim-string-match-p "\\CC" word)))
-    ;; PYIM 有些功能(比如:以词定字功能)会用到 text property, 保存词条之前将
-    ;; text property 去除,防止不必要的数据进入 cache.
+    ;; PYIM 有些功能会用到 text property, 保存词条之前将 text property 去除,防
+    ;; 止不必要的数据进入 cache.
     (setq word (substring-no-properties word))
-    ;; 以词定字功能使用时,保存的词条应该是定字后的词条。
-    (when (pyim-process-select-subword-p)
-      (setq word (pyim-outcome-get-subword word)))
     (pyim-process-add-last-created-word word)
     (let* ((scheme (pyim-scheme-current))
            (code-prefix (pyim-scheme-code-prefix scheme))
@@ -806,13 +800,21 @@ BUG:拼音无法有效地处理多音字。"
 
 (defun pyim-process-get-select-result ()
   "返回 PYIM 选择操作的结果。"
-  (pyim-process-subword-and-magic-convert
+  (pyim-process-magic-convert
    (pyim-outcome-get)))
 
-(defun pyim-process-subword-and-magic-convert (string)
+(defun pyim-process-magic-convert (string)
   "返回 STRING 以词定字和魔术转换后的新字符串."
   (pyim-outcome-magic-convert
-   (pyim-outcome-get-subword string)))
+   (pyim-process--char-in-word string)))
+
+(defun pyim-process--char-in-word (word)
+  (let ((pos pyim-process--char-position-in-word)
+        (length (length word)))
+    (if (and (integerp pos)
+             (< pos length))
+        (substring word pos (1+ pos))
+      word)))
 
 (cl-defmethod pyim-process-select-word ((_scheme pyim-scheme-xingma))
   "按照形码规则,对预选词条进行选词操作。"
diff --git a/pyim.el b/pyim.el
index bb65b703c3..2c52aaa5f5 100644
--- a/pyim.el
+++ b/pyim.el
@@ -100,7 +100,7 @@ Tip: 用户也可以利用 `pyim-outcome-trigger-function-default' 函数
       (define-key map (kbd (car x))
                   (lambda ()
                     (interactive)
-                    (pyim-select-subword-by-number (cdr x)))))
+                    (pyim-select-char-in-word-by-number (cdr x)))))
     (define-key map " " #'pyim-select-word)
     (define-key map (kbd "C-SPC") #'pyim-select-word-simple)
     (define-key map [backspace] #'pyim-delete-backward-char)
@@ -483,11 +483,11 @@ FILE 的格式与 `pyim-dcache-export' 生成的文件格式相同,
       (pyim-process-select-word (pyim-scheme-current))
     (pyim-process-select-last-char)))
 
-(defun pyim-select-subword-by-number (&optional n)
+(defun pyim-select-char-in-word-by-number (&optional n)
   "以词定字功能。"
   (interactive)
-  (pyim-process-plan-to-toggle-select-subword (or n 1))
-  (pyim-select-word))
+  (pyim-process-plan-to-select-char-in-word (1- (or n 1)))
+  (pyim-process-select-word (pyim-scheme-current)))
 
 ;; ** 翻页和翻词功能
 (defalias 'pyim-previous-page #'pyim-page-previous-page)



reply via email to

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