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

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

[elpa] externals/pyim c9cd6bf 27/36: Add pyim-autoselector.el


From: ELPA Syncer
Subject: [elpa] externals/pyim c9cd6bf 27/36: Add pyim-autoselector.el
Date: Thu, 22 Apr 2021 22:57:20 -0400 (EDT)

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

    Add pyim-autoselector.el
---
 pyim-autoselector.el | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 pyim.el              | 36 +-------------------------
 2 files changed, 72 insertions(+), 35 deletions(-)

diff --git a/pyim-autoselector.el b/pyim-autoselector.el
new file mode 100644
index 0000000..3212085
--- /dev/null
+++ b/pyim-autoselector.el
@@ -0,0 +1,71 @@
+;;; pyim-autoselector.el --- autoselector 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)
+
+(defcustom pyim-autoselector '(pyim-autoselector-xingma)
+  "已经启用的自动上屏器.
+
+自动上屏器是一个函数。假设用户已经输入 \"nihao\", 并按下 \"m\" 键,
+那么当前entered 就是 \"nihaom\". 上次 entered 是 \"nihao\". 那么
+返回值有3种情况(优先级按照下面的顺序):
+
+1. (:select last :replace-with \"xxx\")    自动上屏上次 entered (nihao) 的第一个候选词,m 
键下一轮处理。
+3. (:select current :replace-with \"xxx\") 自动上屏当前 entered (nihaom) 的第一个候选词。
+4. nil                                     不自动上屏。
+
+如果 :replace-with 设置为一个字符串,则选择最终会被这个字符串替代。
+
+注意:多个 autoselector 函数运行时,最好不要相互影响,如果相互有
+影响,需要用户自己管理。"
+  :type '(choice (const nil)
+                 (repeat function)))
+
+(defun pyim-autoselector-xingma (&rest _args)
+  "适用于型码输入法的自动上屏器.
+
+比如:五笔等型码输入法,重码率很低,90%以上的情况都是选择第一个词
+条,自动选择可以减少按空格强制选词的机会。"
+  (let* ((scheme-name (pyim-scheme-name))
+         (class (pyim-scheme-get-option scheme-name :class))
+         (n (pyim-scheme-get-option scheme-name :code-split-length)))
+    (when (eq class 'xingma)
+      (cond
+       ((and (= (length (pyim-entered-get 'point-before)) n)
+             (= (length pyim-candidates) 1))
+        '(:select current))
+       ((> (length (pyim-entered-get 'point-before)) n)
+        '(:select last))
+       (t nil)))))
+
+
+;; * Footer
+(provide 'pyim-autoselector)
+
+;;; pyim-autoselector.el ends here
diff --git a/pyim.el b/pyim.el
index 6f186ee..52704b0 100644
--- a/pyim.el
+++ b/pyim.el
@@ -588,6 +588,7 @@
 (require 'pyim-entered)
 (require 'pyim-candidates)
 (require 'pyim-preview)
+(require 'pyim-autoselector)
 
 (defgroup pyim nil
   "Pyim is a Chinese input method support quanpin, shuangpin, wubi and 
cangjie."
@@ -682,24 +683,6 @@ pyim 使用函数 `pyim-translate' 来处理特殊功能触发字符。当待输
 这个功能可以实现“简转繁”,“输入中文得到英文”之类的功能。"
   :type 'boolean)
 
-(defcustom pyim-autoselector '(pyim-autoselector-xingma)
-  "已经启用的自动上屏器.
-
-自动上屏器是一个函数。假设用户已经输入 \"nihao\", 并按下 \"m\" 键,
-那么当前entered 就是 \"nihaom\". 上次 entered 是 \"nihao\". 那么
-返回值有3种情况(优先级按照下面的顺序):
-
-1. (:select last :replace-with \"xxx\")    自动上屏上次 entered (nihao) 的第一个候选词,m 
键下一轮处理。
-3. (:select current :replace-with \"xxx\") 自动上屏当前 entered (nihaom) 的第一个候选词。
-4. nil                                     不自动上屏。
-
-如果 :replace-with 设置为一个字符串,则选择最终会被这个字符串替代。
-
-注意:多个 autoselector 函数运行时,最好不要相互影响,如果相互有
-影响,需要用户自己管理。"
-  :type '(choice (const nil)
-                 (repeat function)))
-
 ;;;###autoload
 (defvar pyim-titles '("PYIM " "PYIM-EN " "PYIM-AU ") "Pyim 在 mode-line 
中显示的名称.")
 
@@ -1263,23 +1246,6 @@ Return the input string.
                    (mapcar #'identity rest-chars)))
          (setq current-input-method-title (nth 0 pyim-titles)))))
 
-(defun pyim-autoselector-xingma (&rest _args)
-  "适用于型码输入法的自动上屏器.
-
-比如:五笔等型码输入法,重码率很低,90%以上的情况都是选择第一个词
-条,自动选择可以减少按空格强制选词的机会。"
-  (let* ((scheme-name (pyim-scheme-name))
-         (class (pyim-scheme-get-option scheme-name :class))
-         (n (pyim-scheme-get-option scheme-name :code-split-length)))
-    (when (eq class 'xingma)
-      (cond
-       ((and (= (length (pyim-entered-get 'point-before)) n)
-             (= (length pyim-candidates) 1))
-        '(:select current))
-       ((> (length (pyim-entered-get 'point-before)) n)
-        '(:select last))
-       (t nil)))))
-
 (defun pyim-self-insert-command ()
   "Pyim 版本的 self-insert-command."
   (interactive "*")



reply via email to

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