Skip to content

Commit

Permalink
Handle changing theme #148 #172
Browse files Browse the repository at this point in the history
Delete existing frames to rebuild them from scratch.
They will use the colors of the new theme.
  • Loading branch information
sebastiencs committed Sep 9, 2022
1 parent 4dc0d98 commit 82c1a30
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions company-box-doc.el
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,13 @@ just grab the first candidate and press forward."
(and (frame-live-p frame)
(make-frame-invisible frame))))

(defun company-box-doc--delete-frame ()
"Delete the child frame if it exists."
(-when-let (frame (frame-local-getq company-box-doc-frame))
(and (frame-live-p frame)
(delete-frame frame))
(frame-local-setq company-box-doc-frame nil)))

(defun company-box-doc-manually ()
(interactive)
(company-box-doc--show company-selection (or (frame-parent) (selected-frame))))
Expand Down
14 changes: 14 additions & 0 deletions company-box.el
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,13 @@ COMMAND: See `company-frontends'."
(company-box--ensure-full-window-is-rendered)
(company-box--update-frame-position frame))))

(defun company-box--delete-frame ()
"Delete the child frame if it exists."
(-when-let (frame (company-box--get-frame))
(and (frame-live-p frame)
(delete-frame frame))
(company-box--set-frame nil)))

(defun company-box--kill-delay (buffer)
(run-with-idle-timer
0 nil (lambda nil
Expand All @@ -1128,6 +1135,12 @@ COMMAND: See `company-frontends'."
(defun company-box--dimmer-hide (&rest _)
(frame-local-setq company-box--dimmer-parent nil))

(defun company-box--handle-theme-change (&rest _)
;; Deleting frames will force to rebuild them from scratch
;; and use the correct new colors
(company-box-doc--delete-frame)
(company-box--delete-frame))

(defun company-box--tweak-external-packages nil
(with-eval-after-load 'dimmer
(when (boundp 'dimmer-prevent-dimming-predicates)
Expand All @@ -1138,6 +1151,7 @@ COMMAND: See `company-frontends'."
(add-to-list
'dimmer-buffer-exclusion-predicates
'company-box--is-box-buffer))
(advice-add 'load-theme :before 'company-box--handle-theme-change)
(advice-add 'company-box-show :before 'company-box--dimmer-show)
(advice-add 'company-box-hide :before 'company-box--dimmer-hide))
(with-eval-after-load 'golden-ratio
Expand Down

0 comments on commit 82c1a30

Please sign in to comment.