[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/pyim 12b3e98f1b 5/8: 降低 pyim.el 对 pyim-cstring-utils 和
From: |
ELPA Syncer |
Subject: |
[elpa] externals/pyim 12b3e98f1b 5/8: 降低 pyim.el 对 pyim-cstring-utils 和 pyim-cregexp-utils 的依赖。 |
Date: |
Sat, 28 May 2022 18:57:48 -0400 (EDT) |
branch: externals/pyim
commit 12b3e98f1b5e9ddac58329b36a8b58570847267c
Author: Feng Shu <tumashu@163.com>
Commit: Feng Shu <tumashu@163.com>
降低 pyim.el 对 pyim-cstring-utils 和 pyim-cregexp-utils 的依赖。
---
README.org | 51 +++++++++++------
pyim-cstring-utils.el | 7 ++-
pyim-cstring.el | 6 ++
pyim.el | 149 +++++++++++++++++++++++---------------------------
4 files changed, 113 insertions(+), 100 deletions(-)
diff --git a/README.org b/README.org
index a886cf23b8..7a6ea128f3 100644
--- a/README.org
+++ b/README.org
@@ -9,6 +9,16 @@
* 不兼容更新
+** <2022-05-29 Sun> Cregexp 和 Cstring 部分命令需要用户自己 require.
+
+Pyim 将部分与输入法功能关联不大的 cregexp 和 cstring 命令独立出来了,默认不会加
+载,需要用户手动加载,这样可以减少 pyim 的依赖数量,降低 pyim 的代码复杂度。
+
+#+begin_src emacs-lisp
+(require 'pyim-cstring-utils)
+(require 'pyim-cregexp-utils)
+#+end_src
+
** <2021-04-28 Wed> 五笔输入法和仓颉输入法的不兼容更新
五笔输入法和仓颉输入法原来使用一个标点符号作为 code-prefix, 现在使用 "wubi/" 和
@@ -121,6 +131,7 @@ pyim 的目标是: *尽最大的努力成为一个好用的 Emacs 中文输入
;; pyim-probe-punctuation-after-punctuation))
;; 开启代码搜索中文功能(比如拼音,五笔码等)
+(require 'pyim-cregexp-utils)
(pyim-isearch-mode 1)
;; 显示5个候选词。
@@ -486,15 +497,16 @@ E-Neo 同学编写了一个词库转换工具: [[https://github.com/E-Neo/scel2p
2. `pyim-cstring-to-pinyin-simple' (不考虑多音字)
** 中文分词
-pyim 包含了一个简单的分词函数:`pyim-cstring-split-to-list', 可以将一个中文字符
-串分成一个词条列表,比如:
+pyim-cstring-utils 包含了一个简单的分词函数:`pyim-cstring-split-to-list', 可以
+将一个中文字符串分成一个词条列表,比如:
-#+begin_example
- (("天安" 5 7)
-我爱北京天安门 -> ("天安门" 5 8)
- ("北京" 3 5)
- ("我爱" 1 3))
-#+end_example
+#+begin_src emacs-lisp :results verbatim
+(require 'pyim-cstring-utils)
+(pyim-cstring-split-to-list "我爱北京天安门")
+#+end_src
+
+#+RESULTS:
+: (("天安" 4 6) ("天安门" 4 7) ("北京" 2 4) ("我爱" 0 2))
其中,每一个词条列表中包含三个元素,第一个元素为词条本身,第二个元素为词条相对于
字符串的起始位置,第三个元素为词条结束位置。
@@ -506,8 +518,8 @@ pyim 包含了一个简单的分词函数:`pyim-cstring-split-to-list', 可以
在的中文词条。
** 获取光标处的中文词条
-pyim 包含了一个简单的命令:`pyim-cstring-words-at-point', 这个命令可以得到光标处
-的 *英文* 或者 *中文* 词条的 *列表*,这个命令依赖分词函数:
+pyim-cstring-utils 包含了一个简单的命令:`pyim-cstring-words-at-point', 这个命令
+可以得到光标处的 *英文* 或者 *中文* 词条的 *列表*,这个命令依赖分词函数:
`pyim-cstring-split-to-list'。
** 让 `forward-word' 和 `back-backward’ 在中文环境下正常工作
@@ -520,17 +532,19 @@ pyim 包含了一个简单的命令:`pyim-cstring-words-at-point', 这个命
用户只需将其绑定到快捷键上就可以了,比如:
-#+begin_example
+#+begin_src emacs-lisp
+(require 'pyim-cstring-utils)
(global-set-key (kbd "M-f") 'pyim-forward-word)
(global-set-key (kbd "M-b") 'pyim-backward-word)
-#+end_example
+#+end_src
** 为 isearch 相关命令添加拼音搜索支持
pyim 安装后,可以通过下面的设置开启拼音搜索功能:
-#+begin_example
+#+begin_src emacs-lisp
+(require 'pyim-cregexp-utils)
(pyim-isearch-mode 1)
-#+end_example
+#+end_src
注意:这个功能有一些限制,搜索字符串中只能出现 “a-z” 和 “'”,如果有其他字符(比
如 regexp 操作符),则自动关闭拼音搜索功能。
@@ -557,10 +571,11 @@ pyim 安装后,可以通过下面的设置开启拼音搜索功能:
** 让 ivy 支持拼音搜索候选项功能
-#+begin_example
+#+begin_src emacs-lisp
+(require 'pyim-cregexp-utils)
(setq ivy-re-builders-alist
'((t . pyim-cregexp-ivy)))
-#+end_example
+#+end_src
** 让 avy 支持拼音搜索
#+begin_src emacs-lisp
@@ -572,10 +587,10 @@ pyim 安装后,可以通过下面的设置开启拼音搜索功能:
#+end_src
** 让 vertico, selectrum 等补全框架,通过 orderless 支持拼音搜索候选项功能。
-#+begin_example
+#+begin_src emacs-lisp
(defun my-orderless-regexp (orig-func component)
(let ((result (funcall orig-func component)))
(pyim-cregexp-build result)))
(advice-add 'orderless-regexp :around #'my-orderless-regexp)
-#+end_example
+#+end_src
diff --git a/pyim-cstring-utils.el b/pyim-cstring-utils.el
index 40f1a49251..034f583cb9 100644
--- a/pyim-cstring-utils.el
+++ b/pyim-cstring-utils.el
@@ -262,8 +262,11 @@ CHINESE-STRING 分词,得到一个词条 alist,这个 alist 的元素都是
(max-length (max (or max-length 1) 1)))
(backward-char max-length))))
+(defalias 'pyim-forward-word 'pyim-cstring-forward-word)
+(defalias 'pyim-backward-word 'pyim-cstring-backward-word)
+
;; * Footer
-(provide 'pyim-cstring)
+(provide 'pyim-cstring-utils)
-;;; pyim-cstring.el ends here
+;;; pyim-cstring-utils.el ends here
diff --git a/pyim-cstring.el b/pyim-cstring.el
index 6de6a96ee0..444fab28de 100644
--- a/pyim-cstring.el
+++ b/pyim-cstring.el
@@ -231,6 +231,12 @@ CRITERIA 字符串一般是通过 imobjs 构建的,它保留了用户原始的
(pyim-string-distance b criteria)))))
(list (car codes-sorted))))))))
+;; PYIM 重构以前使用的一些函数名称,alias 一下,便于兼容。
+(defalias 'pyim-hanzi2pinyin-simple 'pyim-cstring-to-pinyin-simple)
+(defalias 'pyim-hanzi2pinyin 'pyim-cstring-to-pinyin)
+(defalias 'pyim-hanzi2xingma 'pyim-cstring-to-xingma)
+(defalias 'pyim-cwords-at-point 'pyim-cstring-words-at-point)
+
;; * Footer
(provide 'pyim-cstring)
diff --git a/pyim.el b/pyim.el
index a5fb5b0ca7..8a983b6f7c 100644
--- a/pyim.el
+++ b/pyim.el
@@ -746,82 +746,76 @@ FILE 的格式与 `pyim-dcache-export' 生成的文件格式相同,
;; ** 金手指功能
;;;###autoload
-(defun pyim-convert-string-at-point (&optional return-cregexp)
- "将光标前的用户输入的字符串转换为中文.
-
-如果 RETURN-CREGEXP 为真, pyim 会把用户输入的字符串当作
-拼音,依照这个拼音来构建一个 regexp, 用户可以用这个 regexp
-搜索拼音对应的汉字。"
+(defun pyim-convert-string-at-point (&optional _)
+ "将光标前的用户输入的字符串转换为中文."
(interactive "P")
(unless (equal input-method-function 'pyim-input-method)
(activate-input-method 'pyim))
- (if return-cregexp
- (pyim-cregexp-convert-at-point t)
- (let* ((case-fold-search nil)
- (scheme-name (pyim-scheme-name))
- (first-chars (pyim-scheme-get-option scheme-name :first-chars))
- (rest-chars (pyim-scheme-get-option scheme-name :rest-chars))
- (string (if mark-active
- (buffer-substring-no-properties
- (region-beginning) (region-end))
- (buffer-substring (point) (line-beginning-position))))
- (str-before-1 (pyim-char-before-to-string 0))
- (str-before-2 (pyim-char-before-to-string 1))
- (str-before-3 (pyim-char-before-to-string 2))
- code length)
- (cond
- ;; 如果用户已经选择词条,就将此词条添加到个人词库。
- ((region-active-p)
- (pyim-create-word-from-selection)
- (deactivate-mark))
- ;; 删除用户自定义词条。比如:在一个中文字符串后输入 2-,运行此命令可以将
- ;; 光标前两个中文字符组成的字符串,从个人词库删除。
- ((and (eq (char-before) ?-)
- (pyim-string-match-p "[0-9]" str-before-2)
- (pyim-string-match-p "\\cc" str-before-3))
- (delete-char -2)
- (pyim-delete-word-at-point
- (string-to-number str-before-2)))
- ;; 输入"-"然后运行此命令,可以快速删除最近一次创建的词条。
- ((and (eq (char-before) ?-)
- (pyim-string-match-p "\\cc" str-before-2))
- (delete-char -1)
- (pyim-delete-last-word))
- ;; 快速保存用户自定义词条。比如:在一个中文字符串后输入 2,运行此命令可以
- ;; 将光标前两个中文字符组成的字符串,保存到个人词库。
- ((and (member (char-before) (number-sequence ?2 ?9))
- (pyim-string-match-p "\\cc" str-before-2))
- (delete-char -1)
- (pyim-create-word-at-point
- (string-to-number str-before-1)))
- ;; 金手指功能
- ((string-match
- ;; 创建一个 regexp, 用于提取出光标处一个适合
- ;; 转换的字符串。
- (format "[%s]+ *$"
- (cl-delete-duplicates
- (concat first-chars rest-chars "'-")))
- string)
- (setq code
- ;; 一些编程语言使用单引号 ' 做为字符串的标记,这里需要特殊处理。
- (replace-regexp-in-string
- "^[-']" ""
- (match-string 0 string)))
- (setq length (length code))
- (setq code (replace-regexp-in-string " +" "" code))
- (when mark-active
- (delete-region
- (region-beginning) (region-end)))
- (when (and (not mark-active) (> length 0))
- (delete-char (- 0 length)))
- (run-hooks 'pyim-convert-string-at-point-hook)
- (when (> length 0)
- (pyim-add-unread-command-events code)
- (setq pyim-process-force-input-chinese t)))
- ;; 当光标前的一个字符是标点符号时,半角/全角切换。
- ((pyim-string-match-p "[[:punct:]:-]" (pyim-char-before-to-string 0))
- (call-interactively 'pyim-punctuation-translate-at-point))
- (t (message "Pyim: pyim-convert-string-at-point did nothing."))))))
+ (let* ((case-fold-search nil)
+ (scheme-name (pyim-scheme-name))
+ (first-chars (pyim-scheme-get-option scheme-name :first-chars))
+ (rest-chars (pyim-scheme-get-option scheme-name :rest-chars))
+ (string (if mark-active
+ (buffer-substring-no-properties
+ (region-beginning) (region-end))
+ (buffer-substring (point) (line-beginning-position))))
+ (str-before-1 (pyim-char-before-to-string 0))
+ (str-before-2 (pyim-char-before-to-string 1))
+ (str-before-3 (pyim-char-before-to-string 2))
+ code length)
+ (cond
+ ;; 如果用户已经选择词条,就将此词条添加到个人词库。
+ ((region-active-p)
+ (pyim-create-word-from-selection)
+ (deactivate-mark))
+ ;; 删除用户自定义词条。比如:在一个中文字符串后输入 2-,运行此命令可以将
+ ;; 光标前两个中文字符组成的字符串,从个人词库删除。
+ ((and (eq (char-before) ?-)
+ (pyim-string-match-p "[0-9]" str-before-2)
+ (pyim-string-match-p "\\cc" str-before-3))
+ (delete-char -2)
+ (pyim-delete-word-at-point
+ (string-to-number str-before-2)))
+ ;; 输入"-"然后运行此命令,可以快速删除最近一次创建的词条。
+ ((and (eq (char-before) ?-)
+ (pyim-string-match-p "\\cc" str-before-2))
+ (delete-char -1)
+ (pyim-delete-last-word))
+ ;; 快速保存用户自定义词条。比如:在一个中文字符串后输入 2,运行此命令可以
+ ;; 将光标前两个中文字符组成的字符串,保存到个人词库。
+ ((and (member (char-before) (number-sequence ?2 ?9))
+ (pyim-string-match-p "\\cc" str-before-2))
+ (delete-char -1)
+ (pyim-create-word-at-point
+ (string-to-number str-before-1)))
+ ;; 金手指功能
+ ((string-match
+ ;; 创建一个 regexp, 用于提取出光标处一个适合
+ ;; 转换的字符串。
+ (format "[%s]+ *$"
+ (cl-delete-duplicates
+ (concat first-chars rest-chars "'-")))
+ string)
+ (setq code
+ ;; 一些编程语言使用单引号 ' 做为字符串的标记,这里需要特殊处理。
+ (replace-regexp-in-string
+ "^[-']" ""
+ (match-string 0 string)))
+ (setq length (length code))
+ (setq code (replace-regexp-in-string " +" "" code))
+ (when mark-active
+ (delete-region
+ (region-beginning) (region-end)))
+ (when (and (not mark-active) (> length 0))
+ (delete-char (- 0 length)))
+ (run-hooks 'pyim-convert-string-at-point-hook)
+ (when (> length 0)
+ (pyim-add-unread-command-events code)
+ (setq pyim-process-force-input-chinese t)))
+ ;; 当光标前的一个字符是标点符号时,半角/全角切换。
+ ((pyim-string-match-p "[[:punct:]:-]" (pyim-char-before-to-string 0))
+ (call-interactively 'pyim-punctuation-translate-at-point))
+ (t (message "Pyim: pyim-convert-string-at-point did nothing.")))))
;; ** 编码反查功能
(defun pyim-search-word-code ()
@@ -845,16 +839,11 @@ FILE 的格式与 `pyim-dcache-export' 生成的文件格式相同,
(require 'pyim-cloudim)
;; ** pyim 中文字符串工具
+;; FIXME: pyim 相关功能不依赖这个包,require 是由于向后兼容的原因,未来会删除。
(require 'pyim-cstring-utils)
-(defalias 'pyim-forward-word 'pyim-cstring-forward-word)
-(defalias 'pyim-backward-word 'pyim-cstring-backward-word)
-;; PYIM 重构以前使用的一些函数名称,alias 一下,便于兼容。
-(defalias 'pyim-hanzi2pinyin-simple 'pyim-cstring-to-pinyin-simple)
-(defalias 'pyim-hanzi2pinyin 'pyim-cstring-to-pinyin)
-(defalias 'pyim-hanzi2xingma 'pyim-cstring-to-xingma)
-(defalias 'pyim-cwords-at-point 'pyim-cstring-words-at-point)
;; ** pyim 中文 regexp 工具
+;; FIXME: pyim 相关功能不依赖这个包,require 是由于向后兼容的原因,未来会删除。
(require 'pyim-cregexp-utils)
;; * Footer
- [elpa] externals/pyim updated (c982b3fc3f -> 506ed8e1cd), ELPA Syncer, 2022/05/28
- [elpa] externals/pyim 3f8761b752 4/8: Sort pyim.el, ELPA Syncer, 2022/05/28
- [elpa] externals/pyim adf7958538 6/8: Update Development.org, ELPA Syncer, 2022/05/28
- [elpa] externals/pyim e00b7d633a 3/8: Add pyim-process-code-criteria variable., ELPA Syncer, 2022/05/28
- [elpa] externals/pyim 12b3e98f1b 5/8: 降低 pyim.el 对 pyim-cstring-utils 和 pyim-cregexp-utils 的依赖。,
ELPA Syncer <=
- [elpa] externals/pyim a36f2295cd 1/8: Add pyim-cregexp-utils.el, ELPA Syncer, 2022/05/28
- [elpa] externals/pyim 506ed8e1cd 8/8: Update README., ELPA Syncer, 2022/05/28
- [elpa] externals/pyim fa0d22689d 7/8: Add pyim-dict-manager.el, ELPA Syncer, 2022/05/28
- [elpa] externals/pyim 4b1ba0e47e 2/8: Add pyim-cstring-utils.el, ELPA Syncer, 2022/05/28