[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/pyim dfed7ddeaf 50/58: Sort pyim-pinyin.el
From: |
ELPA Syncer |
Subject: |
[elpa] externals/pyim dfed7ddeaf 50/58: Sort pyim-pinyin.el |
Date: |
Fri, 24 Jun 2022 06:57:56 -0400 (EDT) |
branch: externals/pyim
commit dfed7ddeaf978456c774278c993ccd5fc476b6c2
Author: Feng Shu <tumashu@163.com>
Commit: Feng Shu <tumashu@163.com>
Sort pyim-pinyin.el
---
pyim-pinyin.el | 104 ++++++++++++++++++++++++++++-----------------------------
1 file changed, 52 insertions(+), 52 deletions(-)
diff --git a/pyim-pinyin.el b/pyim-pinyin.el
index 5c39b09080..4f07414245 100644
--- a/pyim-pinyin.el
+++ b/pyim-pinyin.el
@@ -34,6 +34,13 @@
"Pinyin libs for pyim."
:group 'pyim)
+(defcustom pyim-pinyin-fuzzy-alist
+ '(("en" "eng")
+ ("in" "ing")
+ ("un" "ong"))
+ "设定模糊音."
+ :type 'sexp)
+
(defvar pyim-pinyin--shenmu
'("b" "p" "m" "f" "d" "t" "n" "l" "g" "k" "h"
"j" "q" "x" "z" "c" "s" "zh" "ch" "sh" "r" "y" "w"))
@@ -48,13 +55,6 @@
'("a" "o" "e" "ai" "ei" "ui" "ao" "ou" "er" "an" "en"
"ang" "eng"))
-(defcustom pyim-pinyin-fuzzy-alist
- '(("en" "eng")
- ("in" "ing")
- ("un" "ong"))
- "设定模糊音."
- :type 'sexp)
-
(defconst pyim-pinyin-shuangpin-invalid-pinyin-regexp
(format "^\\(%s\\)$"
(string-join
@@ -76,29 +76,28 @@
因为用户有即时界面反馈,不可能连续输入无效拼音.")
;; 分解拼音的相关函数
-(defun pyim-pinyin--get-shenmu (pinyin)
- "从一个拼音字符串 PINYIN 中提出第一个声母。"
- (let ((i (min (length pinyin) 2))
- shenmu)
- (while (> i 0)
- (setq shenmu (substring pinyin 0 i))
- (if (member shenmu pyim-pinyin--shenmu)
- (setq i 0)
- (setq i (1- i))
- (setq shenmu "")))
- (cons shenmu
- (substring pinyin (length shenmu)))))
+(defun pyim-pinyin-split (pinyin)
+ "将一个代表拼音的字符串 PINYIN, 分解为声母韵母对组成的列表.
-(defun pyim-pinyin--valid-charpy-p (shenmu yunmu)
- "测试由 SHENMU 和 YUNMU 组成的拼音,是否是一个有效的汉字拼音。
-这个函数尊重 `pyim-pinyin-fuzzy-alist' 模糊音设置。"
- (cl-some
- (lambda (char-pinyin)
- (pyim-pymap-py2cchar-get char-pinyin t))
- (mapcar (lambda (x)
- (concat (nth 0 x) (nth 1 x)))
- (pyim-pinyin-find-fuzzy
- (list shenmu yunmu shenmu yunmu)))))
+这个过程通过循环的调用 `pyim-pinyin--get-charpy' 来实现,整个过程
+类似用菜刀切黄瓜片,将一个拼音字符串逐渐切开。"
+ (let ((py pinyin)
+ charpy spinyin)
+ (while (when (string< "" pinyin)
+ (setq charpy (pyim-pinyin--get-charpy pinyin))
+ (if (and (equal (nth 0 (car charpy)) "")
+ (equal (nth 1 (car charpy)) ""))
+ (progn
+ (setq spinyin nil)
+ (setq pinyin ""))
+ (setq spinyin (append spinyin (list (car charpy))))
+ (setq pinyin (cdr charpy)))))
+ (or spinyin
+ ;; 如果无法按照拼音的规则来分解字符串,
+ ;; 就将字符串简单的包装一下,然后返回。
+ ;; 目前这个功能用于: 以u或者i开头的词库 #226
+ ;; https://github.com/tumashu/pyim/issues/226
+ (list (list "" py "" py)))))
(defun pyim-pinyin--get-charpy (pinyin)
"将拼音字符串 PINYIN 分解成声母,韵母和剩余部分."
@@ -135,6 +134,30 @@
(cons (list shenmu yunmu shenmu yunmu)
(substring yunmu-and-rest (length yunmu)))))
+(defun pyim-pinyin--get-shenmu (pinyin)
+ "从一个拼音字符串 PINYIN 中提出第一个声母。"
+ (let ((i (min (length pinyin) 2))
+ shenmu)
+ (while (> i 0)
+ (setq shenmu (substring pinyin 0 i))
+ (if (member shenmu pyim-pinyin--shenmu)
+ (setq i 0)
+ (setq i (1- i))
+ (setq shenmu "")))
+ (cons shenmu
+ (substring pinyin (length shenmu)))))
+
+(defun pyim-pinyin--valid-charpy-p (shenmu yunmu)
+ "测试由 SHENMU 和 YUNMU 组成的拼音,是否是一个有效的汉字拼音。
+这个函数尊重 `pyim-pinyin-fuzzy-alist' 模糊音设置。"
+ (cl-some
+ (lambda (char-pinyin)
+ (pyim-pymap-py2cchar-get char-pinyin t))
+ (mapcar (lambda (x)
+ (concat (nth 0 x) (nth 1 x)))
+ (pyim-pinyin-find-fuzzy
+ (list shenmu yunmu shenmu yunmu)))))
+
(defun pyim-pinyin-find-fuzzy (info)
"Find all fuzzy pinyins, INFO is (shenmu yunmu shenmu yunmu).
@@ -155,29 +178,6 @@
(push `(,a ,b ,@(nthcdr 2 info)) result)))
(reverse result)))
-(defun pyim-pinyin-split (pinyin)
- "将一个代表拼音的字符串 PINYIN, 分解为声母韵母对组成的列表.
-
-这个过程通过循环的调用 `pyim-pinyin--get-charpy' 来实现,整个过程
-类似用菜刀切黄瓜片,将一个拼音字符串逐渐切开。"
- (let ((py pinyin)
- charpy spinyin)
- (while (when (string< "" pinyin)
- (setq charpy (pyim-pinyin--get-charpy pinyin))
- (if (and (equal (nth 0 (car charpy)) "")
- (equal (nth 1 (car charpy)) ""))
- (progn
- (setq spinyin nil)
- (setq pinyin ""))
- (setq spinyin (append spinyin (list (car charpy))))
- (setq pinyin (cdr charpy)))))
- (or spinyin
- ;; 如果无法按照拼音的规则来分解字符串,
- ;; 就将字符串简单的包装一下,然后返回。
- ;; 目前这个功能用于: 以u或者i开头的词库 #226
- ;; https://github.com/tumashu/pyim/issues/226
- (list (list "" py "" py)))))
-
;; * Footer
(provide 'pyim-pinyin)
- [elpa] externals/pyim 40ed5dc8a4 10/58: pyim-cregexp-quanpin- -> pyim-cregexp-quanpin--, (continued)
- [elpa] externals/pyim 40ed5dc8a4 10/58: pyim-cregexp-quanpin- -> pyim-cregexp-quanpin--, ELPA Syncer, 2022/06/24
- [elpa] externals/pyim 2064692d35 40/58: pyim-liberime-get-code -> pyim-liberime--get-code, ELPA Syncer, 2022/06/24
- [elpa] externals/pyim 48e904bbe6 42/58: pyim-outcome-magic-convert-cache -> pyim-outcome--magic-convert-cache, ELPA Syncer, 2022/06/24
- [elpa] externals/pyim d5d98bdbdb 12/58: pyim-cstring-partition -> pyim-cstring--partition, ELPA Syncer, 2022/06/24
- [elpa] externals/pyim 68e406ed4f 19/58: pyim-candidates-znabc-words -> pyim-candidates--znabc-words, ELPA Syncer, 2022/06/24
- [elpa] externals/pyim df48854299 22/58: pyim-cloudim-parse-baidu-buffer -> pyim-cloudim--parse-baidu-buffer, ELPA Syncer, 2022/06/24
- [elpa] externals/pyim 67f800c819 23/58: pyim-cloudim-parse-google-buffer -> pyim-cloudim--parse-google-buffer, ELPA Syncer, 2022/06/24
- [elpa] externals/pyim 0629a400d9 31/58: pyim-indicator-timer -> pyim-indicator--timer, ELPA Syncer, 2022/06/24
- [elpa] externals/pyim d40f7c4f86 45/58: pyim-pinyin-yunmu -> pyim-pinyin--yunmu, ELPA Syncer, 2022/06/24
- [elpa] externals/pyim 889db4b5ab 49/58: pyim-pinyin-get-charpy -> pyim-pinyin--get-charpy, ELPA Syncer, 2022/06/24
- [elpa] externals/pyim dfed7ddeaf 50/58: Sort pyim-pinyin.el,
ELPA Syncer <=
- [elpa] externals/pyim 067ba514bd 56/58: pyim-pymap-py2cchar-cache3 -> pyim-pymap--py2cchar-cache3, ELPA Syncer, 2022/06/24
- [elpa] externals/pyim 29516cfd7a 35/58: pyim-indicator-update-mode-line -> pyim-indicator--update-mode-line, ELPA Syncer, 2022/06/24
- [elpa] externals/pyim 2a22da363a 39/58: pyim-liberime-create-word -> pyim-liberime--create-word, ELPA Syncer, 2022/06/24
- [elpa] externals/pyim 04ae08aa0f 41/58: Sort pyim-liberime.el, ELPA Syncer, 2022/06/24
- [elpa] externals/pyim ed2c79b7f9 46/58: pyim-pinyin-valid-yunmu -> pyim-pinyin--valid-yunmu, ELPA Syncer, 2022/06/24
- [elpa] externals/pyim 4c223b5f50 52/58: pyim-preview-overlay -> pyim-preview--overlay, ELPA Syncer, 2022/06/24
- [elpa] externals/pyim b79026ab38 54/58: pyim-pymap-py2cchar-cache1 -> pyim-pymap--py2cchar-cache1, ELPA Syncer, 2022/06/24
- [elpa] externals/pyim 43b48b5d97 30/58: pyim-indicator-original-cursor-color -> pyim-indicator--original-cursor-color, ELPA Syncer, 2022/06/24
- [elpa] externals/pyim 1516af70bc 53/58: pyim-punctuation-pair-status -> pyim-punctuation--pair-status, ELPA Syncer, 2022/06/24