Skip to content

Commit

Permalink
对词库文件排序时,优先使用 unix 工具 "sort"
Browse files Browse the repository at this point in the history
  • Loading branch information
tumashu committed Mar 23, 2015
1 parent 191580d commit 90519d3
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions chinese-pyim-dictools.el
Original file line number Diff line number Diff line change
Expand Up @@ -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]*$") ; 如果有空行,删除
Expand All @@ -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)
Expand Down

0 comments on commit 90519d3

Please sign in to comment.