laishulu / emacs-smart-input-source

Less manual switch for native or OS input source (input method).
GNU General Public License v3.0
244 stars 15 forks source link

当切换主题后, sis-default-cursor-color 应当更新. #78

Open unifreak opened 3 months ago

unifreak commented 3 months ago

现在的 sis-default-cursor-color 在第一次从当前主题拿到值后, 就定下来不会变了. 如果此时切换到另一个主题 (比如从亮色主题切到了暗色主题), 旧的光标颜色, 大概率是很难在新主题中有比较好的显示效果的.

Emacs 没有内置的主题切换相关的 hook, 我现在是通过下面的方式, 绕过了这个问题:

;; taken from:
;; https://www.gnu.org/software/emacs/manual/html_node/modus-themes/A-theme_002dagnostic-hook-for-theme-loading.html
;; (sis need this to reset default cursor color after theme change)
(defvar after-enable-theme-hook nil
   "Normal hook run after enabling a theme.")

(defun run-after-enable-theme-hook (&rest _args)
   "Run `after-enable-theme-hook'."
   (run-hooks 'after-enable-theme-hook))

(advice-add 'enable-theme :after #'run-after-enable-theme-hook)

;; input method
(use-package sis
  :config
  (defun reset-sis-cursor-color ()
    "Reset sis cursor color to nil, to trigger updates after theme change"
    (setq sis-default-cursor-color nil))
  (add-hook 'after-enable-theme-hook 'reset-sis-cursor-color)) 

希望能在 sis 内部解决这个 bug, 这样就不需要这个 hack 了.

laishulu commented 3 months ago

挺好的建议。这几天我抽空写进去。