[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/pyim 3b0275c: Add pyim-indicator.el
From: |
ELPA Syncer |
Subject: |
[elpa] externals/pyim 3b0275c: Add pyim-indicator.el |
Date: |
Sun, 4 Jul 2021 22:57:13 -0400 (EDT) |
branch: externals/pyim
commit 3b0275c9232835d4ac4afb0a073a77269bd5e394
Author: Feng Shu <tumashu@163.com>
Commit: Feng Shu <tumashu@163.com>
Add pyim-indicator.el
* pyim-indicater.el: New file.
* pyim-process.el (pyim-indicator): required.
(pyim-process-init-ui): init pyim indicator.
(pyim-process-auto-switch-english-input-p)
(pyim-process-input-chinese-p): Remove setq current-input-method-title.
(pyim-process-indicator-function): New function.
* pyim.el (pyim-titles): Removed.
("pyim"): use pyim-title in register-input-method.
---
pyim-indicator.el | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
pyim-process.el | 19 ++++++------
pyim.el | 4 +--
3 files changed, 99 insertions(+), 10 deletions(-)
diff --git a/pyim-indicator.el b/pyim-indicator.el
new file mode 100644
index 0000000..3b2dc66
--- /dev/null
+++ b/pyim-indicator.el
@@ -0,0 +1,86 @@
+;;; pyim-indicator.el --- pyim indicator 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)
+(require 'pyim-common)
+
+(defgroup pyim-indicator nil
+ "Indicator for pyim."
+ :group 'pyim)
+
+(defcustom pyim-indicator #'pyim-indicator-default
+ "PYIM 当前使用的 indicator.
+Indicator 用于显示输入法当前输入状态(英文还是中文)。"
+ :type 'function)
+
+(defvar pyim-indicator-cursor-color (list "white" "green")
+ "`pyim-indicator-default' 使用的 cursor 颜色。")
+
+(defvar pyim-indicator-modeline-string (list "PYIM " "PYIM-EN ")
+ "`pyim-indicator-default' 使用的 modeline 字符串。")
+
+(defvar pyim-indicator-timer nil
+ "`pyim-indicator-daemon' 使用的 timer.")
+
+(defvar pyim-indicator-timer-repeat 0.2)
+
+(defun pyim-indicator-daemon (func)
+ "Indicator daemon, 用于实时显示输入法当前输入状态。"
+ (pyim-indicator-daemon-stop)
+ (setq pyim-indicator-timer
+ (run-with-timer
+ nil pyim-indicator-timer-repeat
+ #'pyim-indicator-daemon-function func)))
+
+(defun pyim-indicator-daemon-stop ()
+ "Stop indicator daemon."
+ (interactive)
+ (when (timerp pyim-indicator-timer)
+ (cancel-timer pyim-indicator-timer)))
+
+(defun pyim-indicator-daemon-function (func)
+ "`pyim-indicator-daemon' 内部使用的函数。"
+ (let ((chinese-input-p
+ (and (functionp func)
+ (funcall func))))
+ (funcall pyim-indicator chinese-input-p)))
+
+(defun pyim-indicator-default (chinese-input-p)
+ "Pyim 默认使用的 indicator, 主要通过光标颜色和 mode-line 来显示输入状态。"
+ (if chinese-input-p
+ (progn
+ (setq current-input-method-title (nth 1
pyim-indicator-modeline-string))
+ (set-cursor-color (nth 1 pyim-indicator-cursor-color)))
+ (setq current-input-method-title (nth 0 pyim-indicator-modeline-string))
+ (set-cursor-color (nth 0 pyim-indicator-cursor-color))))
+
+;; * Footer
+(provide 'pyim-indicator)
+
+;;; pyim-indicator.el ends here
diff --git a/pyim-process.el b/pyim-process.el
index 65f6c66..00f3a2e 100644
--- a/pyim-process.el
+++ b/pyim-process.el
@@ -37,6 +37,7 @@
(require 'pyim-page)
(require 'pyim-candidates)
(require 'pyim-preview)
+(require 'pyim-indicator)
(require 'pyim-outcome)
(require 'pyim-punctuation)
(require 'pyim-autoselector)
@@ -100,7 +101,8 @@
(defun pyim-process-init-ui ()
"PYIM 流程,用户界面相关的初始化工作。"
- (pyim-preview-setup-overlay))
+ (pyim-preview-setup-overlay)
+ (pyim-indicator-daemon #'pyim-process-indicator-function))
(defmacro pyim-process-with-entered-buffer (&rest forms)
"PYIM 流程的输入保存在一个 buffer 中,使用 FORMS 处理这个 buffer
@@ -155,11 +157,7 @@
nil))
(cond ((functionp func-or-list) (list func-or-list))
((listp func-or-list) func-or-list)
- (t nil)))
- (setq current-input-method-title
- (if pyim-process-input-ascii
- (nth 1 pyim-titles)
- (nth 2 pyim-titles))))))
+ (t nil))))))
(defun pyim-process-input-chinese-p ()
"确定 pyim 是否需要启动中文输入模式."
@@ -173,8 +171,13 @@
(member last-command-event
(mapcar #'identity first-chars))
(member last-command-event
- (mapcar #'identity rest-chars)))
- (setq current-input-method-title (nth 0 pyim-titles)))))
+ (mapcar #'identity rest-chars))))))
+
+(defun pyim-process-indicator-function ()
+ "Indicator function."
+ (or pyim-process-force-input-chinese
+ (and (not pyim-process-input-ascii)
+ (not (pyim-process-auto-switch-english-input-p)))))
(defun pyim-process-run (&optional no-delay)
"延迟 `pyim-exhibit-delay-ms' 显示备选词等待用户选择。"
diff --git a/pyim.el b/pyim.el
index a2794bf..048b24b 100644
--- a/pyim.el
+++ b/pyim.el
@@ -70,7 +70,7 @@ Tip: 用户也可以利用 `pyim-outcome-trigger-function-default' 函数
:type 'boolean)
;;;###autoload
-(defvar pyim-titles '("PYIM " "PYIM-EN " "PYIM-AU ") "Pyim 在 mode-line
中显示的名称.")
+(defvar pyim-title "PYIM ")
(defvar pyim-load-hook nil)
(defvar pyim-active-hook nil)
@@ -220,7 +220,7 @@ Tip: 用户也可以利用 `pyim-outcome-trigger-function-default' 函数
;; ** Pyim 输入法注册
;;;###autoload
-(register-input-method "pyim" "euc-cn" 'pyim-active (nth 0 pyim-titles))
+(register-input-method "pyim" "euc-cn" 'pyim-active pyim-title)
;; ** PYim 输入法启动功能
;;;###autoload
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [elpa] externals/pyim 3b0275c: Add pyim-indicator.el,
ELPA Syncer <=