branch: externals/pyim commit 3561e298ba91d84acd96166443bd0a598b089393 Author: Feng Shu <tuma...@163.com> Commit: Feng Shu <tuma...@163.com>
Add pyim-outcome-add/erase --- pyim-outcome.el | 14 +++++++++++--- pyim-process.el | 21 ++++++++++----------- tests/pyim-tests.el | 8 ++++---- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/pyim-outcome.el b/pyim-outcome.el index d18f2d4907..3ed942c793 100644 --- a/pyim-outcome.el +++ b/pyim-outcome.el @@ -99,7 +99,7 @@ pyim 使用函数 `pyim-process-select-handle-char' 来处理特殊功能触发 光标前面的文字内容。" :type 'function) -(defvar pyim-outcome-history nil +(defvar pyim-outcome--history nil "记录 pyim outcome 的变化的历史 在 pyim 中 outcome 代表用户通过输入法选择,并最终插入到 buffer @@ -123,12 +123,20 @@ pyim 使用函数 `pyim-process-select-handle-char' 来处理特殊功能触发 "用来临时保存 `pyim-outcome-magic-convert' 的结果. 从而加快同一个字符串第二次的转换速度。") -(pyim-register-local-variables '(pyim-outcome-history)) +(pyim-register-local-variables '(pyim-outcome--history)) ;; ** 选词框相关函数 (defun pyim-outcome-get (&optional n) "获取 outcome" - (nth (or n 0) pyim-outcome-history)) + (nth (or n 0) pyim-outcome--history)) + +(defun pyim-outcome-add (outcome) + "添加 OUTCOME." + (push outcome pyim-outcome--history)) + +(defun pyim-outcome-erase () + "清除 OUTCOME." + (setq pyim-outcome--history nil)) (defun pyim-outcome-magic-convert (str) "用于处理 `pyim-outcome-magic-converter' 的函数。" diff --git a/pyim-process.el b/pyim-process.el index f4a24a4cf3..b91b6766ff 100644 --- a/pyim-process.el +++ b/pyim-process.el @@ -276,7 +276,7 @@ imobj 组合构成在一起,构成了 imobjs 这个概念。比如: (pyim-entered-erase-buffer) (pyim-process--set-translating-flag t) (setq pyim-process--char-position-in-word nil) - (setq pyim-outcome-history nil)) + (pyim-outcome-erase)) (defun pyim-process--set-translating-flag (value) (setq pyim-process--translating value)) @@ -648,11 +648,11 @@ imobj 组合构成在一起,构成了 imobjs 这个概念。比如: ;; ** 选词造词相关 (defun pyim-process-select-nothing () "不选择任何东西。" - (setq pyim-outcome-history nil) + (pyim-outcome-erase) (pyim-process-terminate)) (defun pyim-process-select-entered () - (push (pyim-entered-get 'point-before) pyim-outcome-history) + (pyim-outcome-add (pyim-entered-get 'point-before)) (pyim-process-terminate)) (cl-defgeneric pyim-process-select-word (scheme) @@ -732,8 +732,7 @@ imobj 组合构成在一起,构成了 imobjs 这个概念。比如: "选择词条但不保存词条。" (let ((word (nth pyim-process--word-position pyim-process--candidates))) - (push (concat (pyim-outcome-get) word) - pyim-outcome-history) + (pyim-outcome-add (concat (pyim-outcome-get) word)) (unless do-not-terminate (pyim-process-terminate)))) @@ -837,9 +836,9 @@ BUG:拼音无法有效地处理多音字。" (defun pyim-process-select-last-char () "选择上一个输入的字符。" - (push (concat (pyim-outcome-get) - (pyim-process-select-handle-char last-command-event)) - pyim-outcome-history) + (pyim-outcome-add + (concat (pyim-outcome-get) + (pyim-process-select-handle-char last-command-event))) (pyim-process-terminate)) ;; Fix compile warn. @@ -972,9 +971,9 @@ alist 列表。" "选择预选词条和上一次输入的字符。" (let ((word (nth (1- pyim-process--word-position) pyim-process--candidates))) - (push (concat (pyim-outcome-get) word - (pyim-process-select-handle-char last-command-event)) - pyim-outcome-history) + (pyim-outcome-add + (concat (pyim-outcome-get) word + (pyim-process-select-handle-char last-command-event))) (pyim-process-terminate))) ;; ** 删词相关 diff --git a/tests/pyim-tests.el b/tests/pyim-tests.el index 21315b9d51..ce2fb94abd 100644 --- a/tests/pyim-tests.el +++ b/tests/pyim-tests.el @@ -1850,7 +1850,7 @@ abc 这是"))) (ert-deftest pyim-tests-pyim-preview-string () (let ((pyim-process--candidates '("世界" "时节" "使节" "视界" )) (pyim-process--word-position 0) - (pyim-outcome-history '("你好")) + (pyim-outcome--history '("你好")) (pyim-process--imobjs '((("sh" "i" "sh" "i") ("j" "ie" "j" "ie")))) (scheme (pyim-scheme-get 'quanpin))) (should (equal (pyim-preview-string scheme) @@ -1858,7 +1858,7 @@ abc 这是"))) (let ((pyim-process--candidates '("世界" "时节" "使节" "视界" )) (pyim-process--word-position 1) - (pyim-outcome-history nil) + (pyim-outcome--history nil) (pyim-process--imobjs '((("sh" "i" "sh" "i") ("j" "ie" "j" "ie")))) (scheme (pyim-scheme-get 'quanpin))) (should (equal (pyim-preview-string scheme) @@ -1866,7 +1866,7 @@ abc 这是"))) (let ((pyim-process--candidates '("这是" "蛰是" "这时" "真实" "这使" "这事" "这" "者" "着" "折" "哲" "浙" "遮")) (pyim-process--word-position 9) - (pyim-outcome-history nil) + (pyim-outcome--history nil) (pyim-process--imobjs '((("zh" "e" "zh" "e") ("sh" "i" "sh" "i")))) (scheme (pyim-scheme-get 'quanpin))) (should (equal (pyim-preview-string scheme) @@ -1874,7 +1874,7 @@ abc 这是"))) (let ((pyim-process--candidates '("工" "藏匿" "工工" "花花草草" "㠭")) (pyim-process--word-position 3) - (pyim-outcome-history nil) + (pyim-outcome--history nil) (pyim-process--imobjs '(("aaaa"))) (scheme (pyim-scheme-get 'wubi))) (should (equal (pyim-preview-string scheme)