[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/pyim 413d3cfdec 3/4: 让 pyim-indicator 依赖 pyim-process.
From: |
ELPA Syncer |
Subject: |
[elpa] externals/pyim 413d3cfdec 3/4: 让 pyim-indicator 依赖 pyim-process. |
Date: |
Sun, 17 Apr 2022 09:57:48 -0400 (EDT) |
branch: externals/pyim
commit 413d3cfdec28a4d6ef090cb7b65c1d1b885a0174
Author: Feng Shu <tumashu@163.com>
Commit: Feng Shu <tumashu@163.com>
让 pyim-indicator 依赖 pyim-process.
* pyim-indicator.el (pyim-process): Require.
(pyim-indicator-start-daemon): Simplify.
(pyim-process-start-daemon): Add pyim-indicator-start-daemon advice.
(pyim-indicator-stop-daemon): Update.
(pyim-process-stop-daemon): Add pyim-indicator-stop-daemon advice.
* pyim-process.el (pyim-process-start-daemon)
(pyim-process-stop-daemon): Do not call pyim-indicator*.
(pyim-indicator): Do not require.
---
pyim-indicator.el | 28 ++++++++++++++++++++--------
pyim-process.el | 15 +++------------
2 files changed, 23 insertions(+), 20 deletions(-)
diff --git a/pyim-indicator.el b/pyim-indicator.el
index 55421f9ec9..af407f709e 100644
--- a/pyim-indicator.el
+++ b/pyim-indicator.el
@@ -29,6 +29,7 @@
;; * 代码 :code:
(require 'cl-lib)
(require 'pyim-common)
+(require 'pyim-process)
(require 'posframe nil t)
(defgroup pyim-indicator nil
@@ -76,12 +77,13 @@ timer 实现。"
(defvar pyim-indicator-last-input-method-title nil
"记录上一次 `current-input-method-title' 的取值。")
-(defun pyim-indicator-start-daemon (func)
+(defun pyim-indicator-start-daemon ()
"Indicator daemon, 用于实时显示输入法当前输入状态。"
(unless pyim-indicator-original-cursor-color
(setq pyim-indicator-original-cursor-color
(frame-parameter nil 'cursor-color)))
- (setq pyim-indicator-daemon-function-argument func)
+ (setq pyim-indicator-daemon-function-argument
+ #'pyim-process-indicator-function)
(if pyim-indicator-use-post-command-hook
(add-hook 'post-command-hook #'pyim-indicator-daemon-function)
(unless (timerp pyim-indicator-timer)
@@ -90,15 +92,25 @@ timer 实现。"
nil pyim-indicator-timer-repeat
#'pyim-indicator-daemon-function)))))
+(advice-add 'pyim-process-start-daemon :after #'pyim-indicator-start-daemon)
+
(defun pyim-indicator-stop-daemon ()
"Stop indicator daemon."
(interactive)
- (setq pyim-indicator-daemon-function-argument nil)
- (remove-hook 'post-command-hook #'pyim-indicator-daemon-function)
- (when (timerp pyim-indicator-timer)
- (cancel-timer pyim-indicator-timer)
- (setq pyim-indicator-timer nil))
- (pyim-indicator-revert-cursor-color))
+ ;; 只有其它的 buffer 中没有启动 pyim 时,才停止 daemon.
+ ;; 因为 daemon 是服务所有 buffer 的。
+ (unless (cl-find-if
+ (lambda (buf)
+ (buffer-local-value 'current-input-method buf))
+ (remove (current-buffer) (buffer-list)))
+ (setq pyim-indicator-daemon-function-argument nil)
+ (remove-hook 'post-command-hook #'pyim-indicator-daemon-function)
+ (when (timerp pyim-indicator-timer)
+ (cancel-timer pyim-indicator-timer)
+ (setq pyim-indicator-timer nil))
+ (pyim-indicator-revert-cursor-color)))
+
+(advice-add 'pyim-process-stop-daemon :after #'pyim-indicator-stop-daemon)
(defun pyim-indicator-daemon-function ()
"`pyim-indicator-daemon' 内部使用的函数。"
diff --git a/pyim-process.el b/pyim-process.el
index 2f6a80929f..88ba61ed07 100644
--- a/pyim-process.el
+++ b/pyim-process.el
@@ -35,7 +35,6 @@
(require 'pyim-imobjs)
(require 'pyim-codes)
(require 'pyim-candidates)
-(require 'pyim-indicator)
(require 'pyim-outcome)
(require 'pyim-punctuation)
(require 'pyim-autoselector)
@@ -117,19 +116,11 @@
"PYIM 流程,用户界面相关的初始化工作。")
(defun pyim-process-start-daemon ()
- "启动 pyim 流程需要的相关 daemon."
- (pyim-indicator-start-daemon #'pyim-process-indicator-function))
+ "启动 pyim 流程需要的相关 daemon, 接口函数.")
(defun pyim-process-stop-daemon ()
- "关闭 pyim 流程已经启动的 daemon."
- (interactive)
- ;; 只有其它的 buffer 中没有启动 pyim 时,才停止 daemon.
- ;; 因为 daemon 是服务所有 buffer 的。
- (unless (cl-find-if
- (lambda (buf)
- (buffer-local-value 'current-input-method buf))
- (remove (current-buffer) (buffer-list)))
- (pyim-indicator-stop-daemon)))
+ "关闭 pyim 流程已经启动的 daemon, 接口函数."
+ (interactive))
(defmacro pyim-process-with-entered-buffer (&rest forms)
"PYIM 流程的输入保存在一个 buffer 中,使用 FORMS 处理这个 buffer