[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/pyim d630fa5 1/2: Let code-prefix can be like "wubi/" i
From: |
ELPA Syncer |
Subject: |
[elpa] externals/pyim d630fa5 1/2: Let code-prefix can be like "wubi/" instead of a punct. |
Date: |
Wed, 28 Apr 2021 00:57:11 -0400 (EDT) |
branch: externals/pyim
commit d630fa5524e2c69e9cf632dc45fb51a273f9f209
Author: Feng Shu <tumashu@163.com>
Commit: Feng Shu <tumashu@163.com>
Let code-prefix can be like "wubi/" instead of a punct.
* pyim-liberime.el (rime, rime-quanpin)
(rime-microsoft-shuangpin): Use "rime/" as code-prefix.
(pyim-candidates-create:rime): Use string-remove-prefix to remove
code-prefix.
* pyim-dhashcache.el (pyim-dhashcache-get-shortcode): Use
pyim-dcache-code-split.
* pyim-codes.el (pyim-code-search): Use pyim-dcache-code-split.
(pyim-dcache): require.
* pyim-dhashcache.el (pyim-dcache-code-split): New function.
---
pyim-codes.el | 17 +++++++++--------
pyim-dhashcache.el | 22 ++++++++++++++++++----
pyim-liberime.el | 10 ++++++----
3 files changed, 33 insertions(+), 16 deletions(-)
diff --git a/pyim-codes.el b/pyim-codes.el
index f8c8b71..4dc7054 100644
--- a/pyim-codes.el
+++ b/pyim-codes.el
@@ -30,6 +30,7 @@
(require 'cl-lib)
(require 'pyim-scheme)
(require 'pyim-imobjs)
+(require 'pyim-dcache)
(defun pyim-codes-create (imobj scheme-name &optional first-n)
"按照 SCHEME-NAME 对应的输入法方案,从一个 IMOBJ 创建一个列表 codes, 这个列表
@@ -80,14 +81,14 @@
(when (and (stringp word)
(> (length word) 0))
(let* ((prefix (pyim-scheme-get-option scheme-name :code-prefix))
- (code
- (cl-find-if
- (lambda (x)
- (equal (substring (or x " ") 0 1) prefix))
- (sort
- (cl-copy-list (pyim-dcache-call-api 'search-word-code word))
- (lambda (a b) (> (length a) (length b)))))))
- (substring (or code " ") 1))))
+ (code (cl-find-if
+ (lambda (x)
+ (equal (nth 0 (pyim-dcache-code-split (or x " ")))
+ prefix))
+ (sort
+ (cl-copy-list (pyim-dcache-call-api 'search-word-code word))
+ (lambda (a b) (> (length a) (length b)))))))
+ (nth 1 (pyim-dcache-code-split (or code " "))))))
;; * Footer
(provide 'pyim-codes)
diff --git a/pyim-dhashcache.el b/pyim-dhashcache.el
index 9acf34a..fc99cd5 100644
--- a/pyim-dhashcache.el
+++ b/pyim-dhashcache.el
@@ -58,15 +58,29 @@
(> (or (gethash a pyim-dhashcache-iword2count) 0)
(or (gethash b pyim-dhashcache-iword2count) 0)))))
+(defun pyim-dcache-code-split (code)
+ "将 CODE 分成 code-prefix 和 rest code."
+ (cond
+ ;; 兼容性代码:旧版本的 pyim 使用一个标点符号作为 code-prefix
+ ((pyim-string-match-p "^[[:punct:]]" code)
+ (list (substring code 0 1) (substring code 1)))
+ ;; 拼音输入法不使用 code-prefix.
+ ((not (pyim-string-match-p "[[:punct:]]" code))
+ (list "" code))
+ ;; 新 code-prefix 使用类似 "wubi/" 的格式。
+ (t (let ((x (split-string code "/")))
+ (list (concat (nth 0 x) "/")
+ (nth 1 x))))))
+
(defun pyim-dhashcache-get-shortcode (code)
"获取一个 CODE 的所有简写.
比如:.nihao -> .nihao .niha .nih .ni .n"
(when (and (> (length code) 0)
- (not (string-match-p "-" code))
- (pyim-string-match-p "^[[:punct:]]" code))
- (let* ((code1 (substring code 1))
- (prefix (substring code 0 1))
+ (not (string-match-p "-" code)))
+ (let* ((x (pyim-dcache-code-split code))
+ (prefix (nth 0 x))
+ (code1 (nth 1 x))
(n (length code1))
results)
(dotimes (i n)
diff --git a/pyim-liberime.el b/pyim-liberime.el
index 89d4211..10d128a 100644
--- a/pyim-liberime.el
+++ b/pyim-liberime.el
@@ -54,7 +54,7 @@
这个 scheme 适用于 librime 支持的所有输入法,通用性较好,但无法支
持 trigger, 所以类似 pyim 全拼支持的v快捷键将无法使用。"
:class rime
- :code-prefix "&"
+ :code-prefix "rime/"
:first-chars "abcdefghijklmnopqrstuvwxyz"
:rest-chars "abcdefghijklmnopqrstuvwxyz'-a"
:prefer-triggers nil))
@@ -67,7 +67,7 @@
这个 scheme 专门用于 librime 全拼输入法,同时支持 trigger,
也就是 v 快捷键,使用 rime 全拼的朋友建议使用这个 scheme。"
:class rime
- :code-prefix "&"
+ :code-prefix "rime/"
:first-chars "abcdefghjklmnopqrstwxyz"
:rest-chars "vmpfwckzyjqdltxuognbhsrei'-a"
:prefer-triggers ("v")))
@@ -76,7 +76,7 @@
'(rime-microsoft-shuangpin
:document "rime 微软双拼输入法。"
:class rime
- :code-prefix "&"
+ :code-prefix "rime/"
:first-chars "abcdefghijklmnopqrstuvwxyz"
:rest-chars "abcdefghijklmnopqrstuvwxyz;"
:prefer-triggers nil))
@@ -115,7 +115,9 @@
(code-prefix (pyim-scheme-get-option scheme-name :code-prefix))
(s (replace-regexp-in-string "-" "" code))
;; `liberime-search' 搜索的时候不需要 code-prefix, 去除。
- (s (if code-prefix (substring s 1) s))
+ (s (if code-prefix
+ (string-remove-prefix code-prefix s)
+ s))
(words (liberime-search s (if async
nil
(* pyim-page-length 2)))))