[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/pyim a36f2295cd 1/8: Add pyim-cregexp-utils.el
From: |
ELPA Syncer |
Subject: |
[elpa] externals/pyim a36f2295cd 1/8: Add pyim-cregexp-utils.el |
Date: |
Sat, 28 May 2022 18:57:47 -0400 (EDT) |
branch: externals/pyim
commit a36f2295cd2c60250610050c5a73a1403da7e434
Author: Feng Shu <tumashu@163.com>
Commit: Feng Shu <tumashu@163.com>
Add pyim-cregexp-utils.el
---
Development.org | 7 +--
pyim-cregexp-utils.el | 131 ++++++++++++++++++++++++++++++++++++++++++++++++++
pyim-cregexp.el | 44 +----------------
pyim.el | 48 +-----------------
tests/pyim-tests.el | 1 +
5 files changed, 138 insertions(+), 93 deletions(-)
diff --git a/Development.org b/Development.org
index 63f72f38fb..cc78ac6a63 100644
--- a/Development.org
+++ b/Development.org
@@ -11,9 +11,10 @@
|
+---------------------------------------------------------------------------------+
|
| | PYIM 用户命令层: PYIM 视图层:
| |
| | ----------------
------------ | |
-| | Pyim 用户命令, Entered 用户命令 Page
| |
-| | Cregexp 用户命令,Cstring 用户命令 Preview
| |
-| | Dict 管理命令,标点用户命令,Pymap-utils Indicator |
|
+| | Pyim 输入法用户命令 Page
| |
+| | Cregexp-utils
Preview | |
+| | Cstring-utils
Indicator | |
+| | Pymap-utils
| |
| |
| |
| | +---------------------------------------------+
| |
| | 自动上屏器: | PYIM 用例层: Process |
| |
diff --git a/pyim-cregexp-utils.el b/pyim-cregexp-utils.el
new file mode 100644
index 0000000000..f4dbc8453c
--- /dev/null
+++ b/pyim-cregexp-utils.el
@@ -0,0 +1,131 @@
+;;; pyim-cregexp-utils.el --- Chinese regexp tools for pyim. -*-
lexical-binding: t; -*-
+
+;; * Header
+;; Copyright (C) 2021 Free Software Foundation, Inc.
+
+;; Author: Feng Shu <tumashu@163.com>
+;; Maintainer: Feng Shu <tumashu@163.com>
+;; URL: https://github.com/tumashu/pyim
+;; Keywords: convenience, Chinese, pinyin, input-method
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;; Code:
+;; * 代码 :code:
+(require 'pyim-cregexp)
+
+(defgroup pyim-cregexp nil
+ "Chinese regexp tools for pyim."
+ :group 'pyim)
+
+(defcustom pyim-cregexp-convert-at-point-function
+ #'pyim-cregexp-convert-at-point-function
+ "`pyim-cregexp-convert-at-point' 使用的函数。
+
+此函数有一个参数 cregexp, 表示生成的 cregexp. 其返回值会插入当前
+buffer."
+ :type 'function)
+
+;;;###autoload
+(defun pyim-cregexp-convert-at-point (&optional insert-only)
+ "将光标前的字符串按拼音的规则转换为一个搜索中文的 regexp.
+用于实现拼音搜索中文的功能。
+
+在 minibuffer 中,这个命令默认会自动运行 `exit-minibuffer'.
+这个可以使用 INSERT-ONLY 参数控制。"
+ (interactive "P")
+ (pyim-pymap-cache-create)
+ (let* ((string (if mark-active
+ (buffer-substring-no-properties
+ (region-beginning) (region-end))
+ (buffer-substring
+ (point)
+ (save-excursion
+ (skip-syntax-backward "w")
+ (point)))))
+ (length (length string))
+ (cregexp (pyim-cregexp-build string)))
+ (delete-char (- 0 length))
+ (insert (funcall pyim-cregexp-convert-at-point-function cregexp))
+ (when (and (not insert-only)
+ (window-minibuffer-p))
+ (exit-minibuffer))))
+
+(defun pyim-cregexp-convert-at-point-function (cregexp)
+ "这个函数是变量 `pyim-cregexp-convert-at-point-function' 的默认取值。"
+ (cond
+ ;; Deal with `org-search-view'
+ ((and (window-minibuffer-p)
+ (string-match-p
+ (regexp-quote "[+-]Word/{Regexp}")
+ (buffer-substring (point-min) (point-max))))
+ (format "{%s}" cregexp))
+ (t cregexp)))
+
+;; 让 isearch 支持用 code 搜索中文功能
+(declare-function isearch-search-fun "isearch")
+(defvar isearch-forward)
+
+;;;###autoload
+(define-minor-mode pyim-isearch-mode
+ "这个 mode 为 isearch 添加拼音搜索功能."
+ :global t
+ :require 'pyim
+ :lighter " pyim-isearch"
+ (if pyim-isearch-mode
+ (progn
+ (advice-add 'isearch-search-fun :override #'pyim-isearch-search-fun)
+ (message "PYIM: `pyim-isearch-mode' 已经激活,激活后,一些 isearch 扩展包有可能失效。"))
+ (advice-remove 'isearch-search-fun #'pyim-isearch-search-fun)))
+
+(defun pyim-isearch-search-fun ()
+ "这个函数为 isearch 相关命令添加中文拼音搜索功能,
+做为 `isearch-search-fun' 函数的 advice 使用。"
+ (funcall
+ (lambda ()
+ `(lambda (string &optional bound noerror count)
+ (funcall (if ,isearch-forward
+ 're-search-forward
+ 're-search-backward)
+ (pyim-cregexp-build string) bound noerror count)))))
+
+;; 让 ivy 支持 code 搜索。
+(declare-function ivy--regex-plus "ivy")
+
+;; pyim-cregexp.el 是核心库,为保持稳定,不能添加太多的依赖,所以我把这个函数从
+;; pyim-cregexp.el 移到这里,也许我应该更改一下这个函数的名称,让其不使用
+;; pyim-cregexp 前缀,但由于向后兼容的原因,我决定再观察观察。
+(defun pyim-cregexp-ivy (str)
+ "Let ivy support search Chinese with pinyin feature."
+ (let ((x (ivy--regex-plus str))
+ (case-fold-search nil))
+ (if (listp x)
+ (mapcar (lambda (y)
+ (if (cdr y)
+ (list (if (equal (car y) "")
+ ""
+ (pyim-cregexp-build (car y)))
+ (cdr y))
+ (list (pyim-cregexp-build (car y)))))
+ x)
+ (pyim-cregexp-build x))))
+
+;; * Footer
+(provide 'pyim-cregexp-utils)
+
+;;; pyim-cregexp-utils.el ends here
diff --git a/pyim-cregexp.el b/pyim-cregexp.el
index acd42994fa..69a9829a12 100644
--- a/pyim-cregexp.el
+++ b/pyim-cregexp.el
@@ -1,4 +1,4 @@
-;;; pyim-cregexp.el --- Chinese regexp tools for pyim. -*-
lexical-binding: t; -*-
+;;; pyim-cregexp.el --- Chinese regexp core for pyim. -*-
lexical-binding: t; -*-
;; * Header
;; Copyright (C) 2021 Free Software Foundation, Inc.
@@ -46,14 +46,6 @@
将使用这个 scheme."
:type 'symbol)
-(defcustom pyim-cregexp-convert-at-point-function
- #'pyim-cregexp-convert-at-point-function
- "`pyim-cregexp-convert-at-point' 使用的函数。
-
-此函数有一个参数 cregexp, 表示生成的 cregexp. 其返回值会插入当前
-buffer."
- :type 'function)
-
(defun pyim-cregexp-char-level-num (num)
"根据 NUM 返回一个有效的常用汉字级别。"
(if (numberp num)
@@ -222,40 +214,6 @@ regexp, 所以搜索单字的时候一般可以搜到生僻字,但搜索句子
(unless (equal regexp "")
(concat (if match-beginning "^" "") regexp)))))
-(defun pyim-cregexp-convert-at-point (&optional insert-only)
- "将光标前的字符串按拼音的规则转换为一个搜索中文的 regexp.
-用于实现拼音搜索中文的功能。
-
-在 minibuffer 中,这个命令默认会自动运行 `exit-minibuffer'.
-这个可以使用 INSERT-ONLY 参数控制。"
- (interactive "P")
- (pyim-pymap-cache-create)
- (let* ((string (if mark-active
- (buffer-substring-no-properties
- (region-beginning) (region-end))
- (buffer-substring
- (point)
- (save-excursion
- (skip-syntax-backward "w")
- (point)))))
- (length (length string))
- (cregexp (pyim-cregexp-build string)))
- (delete-char (- 0 length))
- (insert (funcall pyim-cregexp-convert-at-point-function cregexp))
- (when (and (not insert-only)
- (window-minibuffer-p))
- (exit-minibuffer))))
-
-(defun pyim-cregexp-convert-at-point-function (cregexp)
- "这个函数是变量 `pyim-cregexp-convert-at-point-function' 的默认取值。"
- (cond
- ;; Deal with `org-search-view'
- ((and (window-minibuffer-p)
- (string-match-p
- (regexp-quote "[+-]Word/{Regexp}")
- (buffer-substring (point-min) (point-max))))
- (format "{%s}" cregexp))
- (t cregexp)))
;; * Footer
(provide 'pyim-cregexp)
diff --git a/pyim.el b/pyim.el
index 97b9111598..e016c050d1 100644
--- a/pyim.el
+++ b/pyim.el
@@ -849,53 +849,7 @@ FILE 的格式与 `pyim-dcache-export' 生成的文件格式相同,
(defalias 'pyim-cwords-at-point 'pyim-cstring-words-at-point)
;; ** pyim 中文 regexp 工具
-(require 'pyim-cregexp)
-
-(declare-function isearch-search-fun "isearch")
-(defvar isearch-forward)
-
-;;;###autoload
-(define-minor-mode pyim-isearch-mode
- "这个 mode 为 isearch 添加拼音搜索功能."
- :global t
- :require 'pyim
- :lighter " pyim-isearch"
- (if pyim-isearch-mode
- (progn
- (advice-add 'isearch-search-fun :override #'pyim-isearch-search-fun)
- (message "PYIM: `pyim-isearch-mode' 已经激活,激活后,一些 isearch 扩展包有可能失效。"))
- (advice-remove 'isearch-search-fun #'pyim-isearch-search-fun)))
-
-(defun pyim-isearch-search-fun ()
- "这个函数为 isearch 相关命令添加中文拼音搜索功能,
-做为 `isearch-search-fun' 函数的 advice 使用。"
- (funcall
- (lambda ()
- `(lambda (string &optional bound noerror count)
- (funcall (if ,isearch-forward
- 're-search-forward
- 're-search-backward)
- (pyim-cregexp-build string) bound noerror count)))))
-
-(declare-function ivy--regex-plus "ivy")
-
-;; pyim-cregexp.el 是核心库,为保持稳定,不能添加太多的依赖,所以我把这个函数从
-;; pyim-cregexp.el 移到这里,也许我应该更改一下这个函数的名称,让其不使用
-;; pyim-cregexp 前缀,但由于向后兼容的原因,我决定再观察观察。
-(defun pyim-cregexp-ivy (str)
- "Let ivy support search Chinese with pinyin feature."
- (let ((x (ivy--regex-plus str))
- (case-fold-search nil))
- (if (listp x)
- (mapcar (lambda (y)
- (if (cdr y)
- (list (if (equal (car y) "")
- ""
- (pyim-cregexp-build (car y)))
- (cdr y))
- (list (pyim-cregexp-build (car y)))))
- x)
- (pyim-cregexp-build x))))
+(require 'pyim-cregexp-utils)
;; ** pyim 探针
(require 'pyim-probe)
diff --git a/tests/pyim-tests.el b/tests/pyim-tests.el
index ce629ffca4..0f48bc54d8 100644
--- a/tests/pyim-tests.el
+++ b/tests/pyim-tests.el
@@ -32,6 +32,7 @@
(require 'ert)
(require 'pyim)
(require 'pyim-basedict) ;pyim-test.el use pyim-basedict v0.5.0.
+(require 'pyim-cstring-utils)
(require 'pyim-dhashcache)
(require 'pyim-dregcache)
(require 'pyim-pymap-utils)
- [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, 2022/05/28
- [elpa] externals/pyim a36f2295cd 1/8: Add pyim-cregexp-utils.el,
ELPA Syncer <=
- [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