branch: externals/pyim commit 6e1551ebdefff21dd1320710d6d88164da7e9539 Author: Feng Shu <tuma...@163.com> Commit: Feng Shu <tuma...@163.com>
优化标点符号处理 * tests/pyim-tests.el (pyim-test-pyim-punctuation): New test. * pyim-punctuation.el (pyim-punctuation-translate-at-point): Use pyim-punctuation-translate. (pyim-punctuation-translate): Use pyim-flatten-tree instead. --- pyim-punctuation.el | 7 +++---- tests/pyim-tests.el | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/pyim-punctuation.el b/pyim-punctuation.el index d5ceb09..7ab4313 100644 --- a/pyim-punctuation.el +++ b/pyim-punctuation.el @@ -134,10 +134,9 @@ If you don't like this function, set the variable to nil") (when (member current-char x) x)) pyim-punctuation-dict))) (when punc-list - (delete-char -1) (if (equal current-char (car punc-list)) - (insert (pyim-punctuation-return-proper-punct punc-list)) - (insert (car punc-list)))))) + (pyim-punctuation-translate 'full-width) + (pyim-punctuation-translate 'half-width))))) (defun pyim-punctuation-translate (&optional punct-style) "将光标前1个或前后连续成对的n个标点符号进行全角/半角转换. @@ -145,7 +144,7 @@ If you don't like this function, set the variable to nil") 当 PUNCT-STYLE 设置为 'full-width 时,所有的标点符号转换为全角符 号,设置为 'half-width 时,转换为半角符号。" (interactive) - (let ((punc-list (flatten-tree pyim-punctuation-dict)) + (let ((punc-list (pyim-flatten-tree pyim-punctuation-dict)) (punct-style (or punct-style (intern (completing-read diff --git a/tests/pyim-tests.el b/tests/pyim-tests.el index a8ed90f..162658f 100644 --- a/tests/pyim-tests.el +++ b/tests/pyim-tests.el @@ -194,6 +194,48 @@ (should (equal (pyim-pinyin-build-regexp "ni-hao" t t) "^ni-hao[a-z]*"))) +;; ** pyim-punctuation 相关单元测试 +(ert-deftest pyim-test-pyim-punctuation () + (with-temp-buffer + (insert ",") + (pyim-punctuation-translate 'full-width) + (should (equal (buffer-string) ",")) + (pyim-punctuation-translate 'half-width) + (should (equal (buffer-string) ","))) + + (with-temp-buffer + (insert "[]") + (backward-char 1) + (pyim-punctuation-translate 'full-width) + (should (equal (buffer-string) "【】")) + (pyim-punctuation-translate 'half-width) + (should (equal (buffer-string) "[]"))) + + (with-temp-buffer + (let ((pyim-punctuation-pair-status + '(("\"" nil) ("'" nil)))) + (insert "[{''}]") + (backward-char 3) + (pyim-punctuation-translate 'full-width) + (should (equal (buffer-string) "【『‘’』】")) + (pyim-punctuation-translate 'half-width) + (should (equal (buffer-string) "[{''}]")))) + + (with-temp-buffer + (let ((pyim-punctuation-pair-status + '(("\"" nil) ("'" nil)))) + (insert "[{''}]") + (backward-char 3) + (pyim-punctuation-translate-at-point) + (should (equal (buffer-string) "【『‘’』】")) + (pyim-punctuation-translate-at-point) + (should (equal (buffer-string) "[{''}]")))) + + (let ((pyim-punctuation-pair-status + '(("\"" nil) ("'" nil)))) + (should (equal (pyim-punctuation-return-proper-punct '("'" "‘" "’")) "‘")) + (should (equal (pyim-punctuation-return-proper-punct '("'" "‘" "’")) "’")))) + ;; ** pyim-impobjs 相关单元测试 (ert-deftest pyim-test-pyim-imobjs () (let ((pyim-pinyin-fuzzy-alist '(("en" "eng")