emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/pyim 47a4c51: New pyim-magic.el


From: ELPA Syncer
Subject: [elpa] externals/pyim 47a4c51: New pyim-magic.el
Date: Thu, 10 Jun 2021 00:57:12 -0400 (EDT)

branch: externals/pyim
commit 47a4c5131be4e5586c44b112a05d9a7062b8a021
Author: Feng Shu <tumashu@163.com>
Commit: Feng Shu <tumashu@163.com>

    New pyim-magic.el
---
 pyim-magic.el   | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 pyim-preview.el |  5 ++---
 pyim-process.el | 26 +++++---------------------
 pyim.el         |  2 +-
 4 files changed, 66 insertions(+), 25 deletions(-)

diff --git a/pyim-magic.el b/pyim-magic.el
new file mode 100644
index 0000000..b304e29
--- /dev/null
+++ b/pyim-magic.el
@@ -0,0 +1,58 @@
+;;; pyim-magic.el --- magic convert 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 'cl-lib)
+
+(defgroup pyim-magic nil
+  "Magic converter for pyim."
+  :group 'pyim)
+
+(defcustom pyim-magic-converter nil
+  "将 “待选词条” 在 “上屏” 之前自动转换为其他字符串.
+这个功能可以实现“简转繁”,“输入中文得到英文”之类的功能。"
+  :type 'boolean)
+
+(defvar pyim-magic-convert-cache nil
+  "用来临时保存 `pyim-magic-convert' 的结果.
+从而加快同一个字符串第二次的转换速度。")
+
+(defun pyim-magic-convert (str)
+  "用于处理 `pyim-magic-converter' 的函数。"
+  (if (functionp pyim-magic-converter)
+      (or (cdr (assoc str pyim-magic-convert-cache))
+          (let ((result (funcall pyim-magic-converter str)))
+            (setq pyim-magic-convert-cache
+                  `((,str . ,result)))
+            result))
+    str))
+
+;; * Footer
+(provide 'pyim-magic)
+
+;;; pyim-magic.el ends here
diff --git a/pyim-preview.el b/pyim-preview.el
index 300ce87..7b2b223 100644
--- a/pyim-preview.el
+++ b/pyim-preview.el
@@ -29,6 +29,7 @@
 ;; * 代码                                                           :code:
 (require 'cl-lib)
 (require 'pyim-common)
+(require 'pyim-magic)
 
 (defgroup pyim-preview nil
   "Preview libs for pyim."
@@ -64,8 +65,6 @@
   (if (and (overlayp pyim-preview-overlay) (overlay-start 
pyim-preview-overlay))
       (delete-overlay pyim-preview-overlay)))
 
-(declare-function pyim-process-magic-convert "pyim")
-
 (defun pyim-preview-refresh ()
   "刷新光标处预览.
 
@@ -86,7 +85,7 @@ pyim 会使用 Emacs overlay 机制在 *待输入buffer* 光标处高亮显示
                    "'")))
         (when (string< "" rest)
           (setq preview (concat preview rest)))))
-    (setq preview (pyim-process-magic-convert preview))
+    (setq preview (pyim-magic-convert preview))
     ;; Delete old preview string.
     (pyim-preview-delete-string)
     ;; Insert new preview string.
diff --git a/pyim-process.el b/pyim-process.el
index 58984a6..2df402e 100644
--- a/pyim-process.el
+++ b/pyim-process.el
@@ -41,6 +41,7 @@
 (require 'pyim-punctuation)
 (require 'pyim-autoselector)
 (require 'pyim-cstring)
+(require 'pyim-magic)
 
 (defcustom pyim-english-input-switch-functions nil
   "让 pyim 开启英文输入功能.
@@ -55,11 +56,6 @@
 如果为 0 或者 nil, 则不等待立刻显示可选词."
   :type 'integer)
 
-(defcustom pyim-magic-converter nil
-  "将 “待选词条” 在 “上屏” 之前自动转换为其他字符串.
-这个功能可以实现“简转繁”,“输入中文得到英文”之类的功能。"
-  :type 'boolean)
-
 (defvar pyim-process-input-ascii nil
   "是否开启 pyim 英文输入模式.")
 
@@ -72,10 +68,6 @@
 (defvar pyim-process-translating nil
   "记录是否在转换状态.")
 
-(defvar pyim-process-magic-convert-cache nil
-  "用来临时保存 `pyim-magic-convert' 的结果.
-从而加快同一个字符串第二次的转换速度。")
-
 (defvar pyim-process-last-created-word nil
   "记录最近一次创建的词条, 用于实现快捷删词功能: `pyim-delete-last-word' .")
 
@@ -301,19 +293,11 @@
 (defun pyim-process-get-imobjs ()
   pyim-imobjs)
 
-(defun pyim-process-get-outcome (&optional n)
+(defun pyim-process-get-outcome (&optional n magic-convert)
   "PYIM 流程的输出"
-  (pyim-outcome-get n))
-
-(defun pyim-process-magic-convert (str)
-  "用于处理 `pyim-magic-convert' 的函数。"
-  (if (functionp pyim-magic-converter)
-      (or (cdr (assoc str pyim-process-magic-convert-cache))
-          (let ((result (funcall pyim-magic-converter str)))
-            (setq pyim-process-magic-convert-cache
-                  `((,str . ,result)))
-            result))
-    str))
+  (if magic-convert
+      (pyim-magic-convert (pyim-outcome-get n))
+    (pyim-outcome-get n)))
 
 (defun pyim-process-outcome-handle (type)
   "依照 TYPE, 获取 pyim 的 outcome,并将其加入 `pyim-outcome-history'."
diff --git a/pyim.el b/pyim.el
index 3e76141..2de0639 100644
--- a/pyim.el
+++ b/pyim.el
@@ -213,7 +213,7 @@ Tip: 用户也可以利用 `pyim-outcome-trigger-function-default' 函数
               ;; (message "unread-command-events: %s" unread-command-events)
               (pyim-process-terminate))))
         ;; (message "return: %s" (pyim-process-get-outcome))
-        (pyim-process-magic-convert (pyim-process-get-outcome)))
+        (pyim-process-get-outcome nil t))
     ;; Since KEY doesn't start any translation, just return it.
     ;; But translate KEY if necessary.
     (char-to-string key)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]