branch: externals/pyim commit 4fa972e9561d6320ef68ef1642808df8eeb50697 Author: Feng Shu <tuma...@163.com> Commit: Feng Shu <tuma...@163.com>
使用 hook 而不是 advice 来处理 indicator. * pyim-process.el (pyim-process-start-daemon-hook) (pyim-process-stop-daemon-hook): new hooks. (pyim-process-stop-daemon, pyim-process-start-daemon): Use hooks. * pyim-indicator.el (pyim-process-start-daemon-hook) (pyim-process-stop-daemon-hook): Use them. --- pyim-indicator.el | 4 ++-- pyim-process.el | 14 +++++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/pyim-indicator.el b/pyim-indicator.el index af407f709e..0299b6c696 100644 --- a/pyim-indicator.el +++ b/pyim-indicator.el @@ -92,7 +92,7 @@ timer 实现。" nil pyim-indicator-timer-repeat #'pyim-indicator-daemon-function))))) -(advice-add 'pyim-process-start-daemon :after #'pyim-indicator-start-daemon) +(add-hook 'pyim-process-start-daemon-hook #'pyim-indicator-start-daemon) (defun pyim-indicator-stop-daemon () "Stop indicator daemon." @@ -110,7 +110,7 @@ timer 实现。" (setq pyim-indicator-timer nil)) (pyim-indicator-revert-cursor-color))) -(advice-add 'pyim-process-stop-daemon :after #'pyim-indicator-stop-daemon) +(add-hook 'pyim-process-stop-daemon-hook #'pyim-indicator-stop-daemon) (defun pyim-indicator-daemon-function () "`pyim-indicator-daemon' 内部使用的函数。" diff --git a/pyim-process.el b/pyim-process.el index d1c8f47905..045808bf4a 100644 --- a/pyim-process.el +++ b/pyim-process.el @@ -128,6 +128,12 @@ entered (nihaom) 的第一个候选词。 (defvar pyim-process-ui-position-function #'point "The value is a function returned a position where ui place.") +(defvar pyim-process-start-daemon-hook nil + "Pyim start daemon hook.") + +(defvar pyim-process-stop-daemon-hook nil + "Pyim stop daemon hook.") + (pyim-register-local-variables '(pyim-process-input-ascii pyim-process-translating)) @@ -147,11 +153,13 @@ entered (nihaom) 的第一个候选词。 (pyim-dcache-call-api 'update-personal-words t)) (defun pyim-process-start-daemon () - "启动 pyim 流程需要的相关 daemon, 接口函数.") + "启动 pyim 流程需要的 daemon." + (run-hooks 'pyim-process-start-daemon-hook)) (defun pyim-process-stop-daemon () - "关闭 pyim 流程已经启动的 daemon, 接口函数." - (interactive)) + "关闭 pyim 流程已经启动的 daemon." + (interactive) + (run-hooks 'pyim-process-stop-daemon-hook)) (defmacro pyim-process-with-entered-buffer (&rest forms) "PYIM 流程的输入保存在一个 buffer 中,使用 FORMS 处理这个 buffer