branch: externals/pyim commit afd2bbe9cc425c2d271cb7d546caddfabec0ce91 Author: Feng Shu <tuma...@163.com> Commit: Feng Shu <tuma...@163.com>
Add pyim-split-list --- pyim-common.el | 10 ++++++++++ tests/pyim-tests.el | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/pyim-common.el b/pyim-common.el index 082450c6f2..2d89cf27cf 100644 --- a/pyim-common.el +++ b/pyim-common.el @@ -131,6 +131,16 @@ When CARE-FIRST-ONE is no-nil, ((a b c) (d e)) => (a d)." (push (string-join list (or sep "")) output))) (nreverse output))) +(defun pyim-split-list (list separator) + "Split LIST into sublists bounded by equal SEPARATOR." + (let (group result) + (dolist (x (append list (list separator))) + (if (not (equal x separator)) + (push x group) + (push (nreverse group) result) + (setq group nil))) + (reverse result))) + (defun pyim-char-before-to-string (num) "得到光标前第 NUM 个字符,并将其转换为字符串。" (let* ((point (point)) diff --git a/tests/pyim-tests.el b/tests/pyim-tests.el index d181629be4..eaa3ed9de3 100644 --- a/tests/pyim-tests.el +++ b/tests/pyim-tests.el @@ -199,6 +199,12 @@ '("a-b-c-d" "a-b-c" "a-b"))) (should (equal (pyim-subconcat nil) nil))) +(ert-deftest pyim-tests-pyim-split-list () + (should (equal (pyim-split-list '(a b sep c d) 'sep) + '((a b) (c d)))) + (should (equal (pyim-split-list '(sep b sep c sep) 'sep) + '(nil (b) (c) nil)))) + (ert-deftest pyim-tests-pyim-string-distance () (should (equal (pyim-string-distance "nihaoma" "nihaoma") 0)) (should (equal (pyim-string-distance "nihaoma" "nhm") 4))