[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/pyim abb3e7c 1/5: * pyim-outcome.el (pyim-outcome-trigg
From: |
ELPA Syncer |
Subject: |
[elpa] externals/pyim abb3e7c 1/5: * pyim-outcome.el (pyim-outcome-trigger-function-default): Improve code. |
Date: |
Mon, 26 Apr 2021 00:57:09 -0400 (EDT) |
branch: externals/pyim
commit abb3e7c44cd1a5bc7fdb51ba69024a5f58768beb
Author: Feng Shu <tumashu@163.com>
Commit: Feng Shu <tumashu@163.com>
* pyim-outcome.el (pyim-outcome-trigger-function-default): Improve code.
---
pyim-outcome.el | 37 +++++++++++++++++++++----------------
1 file changed, 21 insertions(+), 16 deletions(-)
diff --git a/pyim-outcome.el b/pyim-outcome.el
index 78aa5ec..613fb36 100644
--- a/pyim-outcome.el
+++ b/pyim-outcome.el
@@ -312,22 +312,27 @@ alist 列表。"
new-string)
(when (> (length string) 0)
(delete-region begin end)
- (setq new-string
- (with-temp-buffer
- (insert string)
- (goto-char (point-min))
- (while (re-search-forward "\\([,。;?!;、)】]\\) +\\([[:ascii:]]\\)"
nil t)
- (replace-match (concat (match-string 1) (match-string 2)) nil
t))
- (goto-char (point-min))
- (while (re-search-forward "\\([[:ascii:]]\\) +\\([(【]\\)" nil t)
- (replace-match (concat (match-string 1) (match-string 2)) nil
t))
- (goto-char (point-min))
- (while (re-search-forward "\\([[:ascii:]]\\) +\\(\\cc\\)" nil t)
- (replace-match (concat (match-string 1) sep (match-string 2))
nil t))
- (goto-char (point-min))
- (while (re-search-forward "\\(\\cc\\) +\\([[:ascii:]]\\)" nil t)
- (replace-match (concat (match-string 1) sep (match-string 2))
nil t))
- (buffer-string)))
+ (with-temp-buffer
+ (insert string)
+ (dotimes (_ 3) ;NOTE: 数字3是一个经验数字。
+ (dolist (x `(;; 中文标点与英文之间的空格
+ ("\\([,。;?!;、)】]\\) +\\([[:ascii:]]\\)" . "")
+ ;; 英文与中文标点之间的空格
+ ("\\([[:ascii:]]\\) +\\([(【]\\)" . "")
+ ;; 汉字与汉字之间的空格
+ ("\\(\\cc\\) +\\(\\cc\\)" . "")
+ ;; 英文与汉字之间的空格
+ ("\\([[:ascii:]]\\) +\\(\\cc\\)" . ,sep)
+ ;; 汉字与英文之间的空格
+ ("\\(\\cc\\) +\\([[:ascii:]]\\)" . ,sep)))
+ (goto-char (point-min))
+ (while (re-search-forward (car x) nil t)
+ (replace-match
+ (concat (match-string 1)
+ (cdr x)
+ (match-string 2))
+ nil t))))
+ (setq new-string (buffer-string)))
(insert new-string))))
;; * Footer