jdtsmith / kind-icon

Completion kind text/icon prefix labelling for emacs in-region completion
GNU Affero General Public License v3.0
174 stars 4 forks source link

Clear icon cache on theme change #34

Closed brongulus closed 1 year ago

brongulus commented 1 year ago

Hi, thanks for the great work!

I have an automatic timer for changing themes, however upon theme change the kind-icon still follow the old colorscheme.

I can manually clear the cache by using kind-icon-reset-cache, however I was wondering if it is possible to automate that upon invocation of load-theme.

I tried advising load-theme as

(advice-add 'load-theme :after #'kind-icon-reset-cache)

however that wasn't working. Do you have any idea on how I can proceed with this?

jdtsmith commented 1 year ago

I think you are on the right track. I don't change themes myself but I understand there is no theme-change hook. So your advice looks reasonable to me. Perhaps it was not correctly enabled?

jdtsmith commented 1 year ago

Update: Prot (of ef-themes fame) recommends:

(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)

Presumably because load-theme is too early. Can you test this and let me know?

brongulus commented 1 year ago

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

Presumably because load-theme is too early. Can you test this and let me know?

Unfortunately this didn't work either.

jdtsmith commented 1 year ago

Unfortunately this didn't work either.

Did you add kind-icon-reset to after-enable-theme-hook with add-hook?

brongulus commented 1 year ago

No, would that make a difference? I tried doing it that way too, didn't work.

  (use-package kind-icon
    :after nerd-icons
    :init
    (load "~/.emacs.d/+icons" nil t)
    (push 'kind-icon-margin-formatter corfu-margin-formatters)
    :custom
    (defvar after-enable-theme-hook nil)
    (defun run-after-enable-theme-hook (&rest _args)
      (run-hooks 'after-enable-theme-hook))
    (add-hook 'after-enable-theme-hook #'kind-icon-reset-cache)
    :config
    (advice-add 'enable-theme :after #'run-after-enable-theme-hook)) ;; FIXME
jdtsmith commented 1 year ago

None of that should go under :custom in your use-package, that's strictly for custom set variables.

If you define the enable-theme hooks elsewhere, you can use them in all your packages. I set this up and it works fine:

(use-package custom
  :init
  (defvar after-enable-theme-hook nil)
  (defun run-after-enable-theme-hook (&rest _args)
    (run-hooks 'after-enable-theme-hook))
  (advice-add 'enable-theme :after #'run-after-enable-theme-hook))

(use-package kind-icon
  :after corfu
  :custom
  (kind-icon-default-face 'corfu-default)
  :config
  (add-to-list 'corfu-margin-formatters #'kind-icon-margin-formatter)
  (add-hook 'after-enable-theme-hook  #'kind-icon-reset-cache))