branch: externals/pyim commit 3405968a1a1226f03afe146098c87796d4e6351b Author: Feng Shu <tuma...@163.com> Commit: Feng Shu <tuma...@163.com>
Simplify pyim-convert-string-at-point --- pyim-process.el | 11 +++++++---- pyim.el | 17 ++++++++--------- tests/pyim-tests.el | 6 +++--- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/pyim-process.el b/pyim-process.el index cd37b9c397..66641d0cb0 100644 --- a/pyim-process.el +++ b/pyim-process.el @@ -390,13 +390,16 @@ imobj 组合构成在一起,构成了 imobjs 这个概念。比如: (buffer-substring (point) (line-beginning-position)))) (defun pyim-process-feed-entered-at-point-into-pyim () - (let* ((entered-info (pyim-process-find-entered-at-point)) + (let* ((entered-info (pyim-process--find-entered-at-point)) (entered (nth 0 entered-info)) (char-num-need-delete (nth 1 entered-info))) - (pyim-process--delete-region-or-chars char-num-need-delete) - (pyim-process--feed-entered-into-pyim entered))) + (when entered-info + (pyim-process--delete-region-or-chars char-num-need-delete) + (pyim-process--feed-entered-into-pyim entered) + ;; NOTE: 这里必须返回 t, 因为这个函数的返回结果会被作为判断条件使用。 + t))) -(defun pyim-process-find-entered-at-point () +(defun pyim-process--find-entered-at-point () "从光标处提取一个有效的 entered 字符串." (let* ((case-fold-search nil) (scheme (pyim-scheme-current)) diff --git a/pyim.el b/pyim.el index 631b0e4fb3..c7e4b3dbf1 100644 --- a/pyim.el +++ b/pyim.el @@ -292,8 +292,10 @@ REFRESH-COMMON-DCACHE 已经废弃,不要再使用了。" (if (not (string-match-p "^\\cc+\\'" string)) (error "不是纯中文字符串") (setq output (pyim-process-create-word string)) - (message "将词条: %S 插入 personal file。" output)))) - (deactivate-mark))) + (message "将词条: %S 插入 personal file。" output))) + (deactivate-mark) + ;; NOTE: 这里必须返回 t, 因为这个函数的返回结果会被用来做为判断条件。 + t))) ;; ** 导入词条功能 (defun pyim-import-words-and-counts (file &optional merge-method silent) @@ -579,13 +581,10 @@ FILE 的格式与 `pyim-dcache-export' 生成的文件格式相同, (interactive "P") (unless (equal input-method-function 'pyim-input-method) (activate-input-method 'pyim)) - (cond - ((region-active-p) (pyim-create-word-from-selection)) - ;; `pyim-process-trigger-feature-run-p' 函数本身就会做相应的操作。 - ((pyim-process-trigger-feature-run-p) nil) - ((pyim-process-find-entered-at-point) - (pyim-process-feed-entered-at-point-into-pyim)) - (t (message "PYIM: `pyim-convert-string-at-point' did nothing.")))) + (or (pyim-create-word-from-selection) + (pyim-process-trigger-feature-run-p) + (pyim-process-feed-entered-at-point-into-pyim) + (message "PYIM: `pyim-convert-string-at-point' did nothing."))) ;; ** 编码反查功能 (defun pyim-search-word-code () diff --git a/tests/pyim-tests.el b/tests/pyim-tests.el index a59d22d1f9..7c6176914c 100644 --- a/tests/pyim-tests.el +++ b/tests/pyim-tests.el @@ -2230,14 +2230,14 @@ abc 这是"))) (insert ",") (should (pyim-process--trigger-punctuation-to-half-width-p))))) -(ert-deftest pyim-tests-pyim-process-find-entered-at-point () +(ert-deftest pyim-tests-pyim-process--find-entered-at-point () (with-temp-buffer (insert "123abc'd ") - (should (equal (pyim-process-find-entered-at-point) '("abc'd" 8)))) + (should (equal (pyim-process--find-entered-at-point) '("abc'd" 8)))) (with-temp-buffer (insert "123'abcd ") - (should (equal (pyim-process-find-entered-at-point) '("abcd" 7))))) + (should (equal (pyim-process--find-entered-at-point) '("abcd" 7))))) (ert-run-tests-batch-and-exit)