From 90519d3f7d89539739d0124bbca65c8c1b25e2c9 Mon Sep 17 00:00:00 2001 From: Feng Shu Date: Mon, 23 Mar 2015 18:31:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9=E8=AF=8D=E5=BA=93=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=8E=92=E5=BA=8F=E6=97=B6=EF=BC=8C=E4=BC=98=E5=85=88=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=20unix=20=E5=B7=A5=E5=85=B7=20"sort"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chinese-pyim-dictools.el | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/chinese-pyim-dictools.el b/chinese-pyim-dictools.el index bde9125f..5509ee06 100644 --- a/chinese-pyim-dictools.el +++ b/chinese-pyim-dictools.el @@ -187,9 +187,8 @@ first-char total-char currw) (goto-char (point-min)) (perform-replace "[ \t]+$" "" nil t nil nil nil (point-min) (point-max)) - (sort-regexp-fields nil "^.*$" "[a-z-]+[ ]+" - (point-min) - (point-max)) + (pyim-sort-dict-region (point-min) + (point-max)) (goto-char (point-min)) (while (not (eobp)) (if (looking-at "^[ \t]*$") ; 如果有空行,删除 @@ -206,6 +205,17 @@ (if (looking-at "^$") (delete-char -1)))))) +(defun pyim-sort-dict-region (start end) + "将词库 buffer 中 `start' 和 `end' 范围内的词条信息按照拼音code排序 +当 unix 工具 sort 存在时,优先使用这个工具,否则使用emacs自带函数 +`sort-regexp-fields'。" + (if (and (executable-find "sort") + (executable-find "env")) + (call-process-region start end + "env" t t nil "LC_ALL=C" + "sort" "-k1,1" "-s") + (sort-regexp-fields nil "^.*$" "[a-z-]+[ ]+" start end))) + (defun pyim-convert-current-line-to-dict-format () "将当前行对应的汉语词条转换为 Chinese-pyim 可以识别的词库格式(ni-hao 你好)。" (interactive)