gonewest818 / dimmer.el

Interactively highlight which buffer is active by dimming the others.
GNU General Public License v3.0
265 stars 14 forks source link

How to make dimmer compatible with corfu? #62

Open Eason0210 opened 2 years ago

Eason0210 commented 2 years ago

Hi @gonewest818

Thanks for making this awesome package.

Recently I try to setup corfu(it is a new completion font end made by @minad ) with dimmer, and I found that dimmer.el will affect corfu's popup window which uses child frames to show the popup.

I tried to add following config, but no effect, do you have any advice for making dimmer works with corfu?

(use-package dimmer
  :hook (after-init . dimmer-mode)
  :config
  (setq-default dimmer-fraction 0.15)
  (add-to-list 'dimmer-exclusion-regexp-list "^ \\*corfu\\*$"))

my corfu config:

(use-package corfu
  :init
  (setq corfu-cycle t)
  (setq corfu-auto t)
  (setq corfu-quit-at-boundary t)
  (setq corfu-quit-no-match t)
  (setq corfu-preview-current nil)
  (corfu-global-mode))
gonewest818 commented 2 years ago

Completion popups in general have been hard to get right, it seems to me. If you have time I would check that the regexp is correct, first of all. (It looks reasonable to me but I’m not familiar with Corfu).

Second I would look for a predicate you can use for dimmer-prevent-dimming-predicates

Which should have the benefit not only preventing the child frame from being highlighted but also prevents anything else from being dimmed while the child frame is active.

It’s certainly possible there’s something deeper I need to do about child frames, and when time permits I can also try these experiments if you’re not in a position to.

On Jan 19, 2022, at 12:25 AM, Eason Huang @.***> wrote:

 Hi @gonewest818

Thanks for making this awesome package.

Recently I try to setup corfu(it is an new completion font end make by @minad ) with dimmer, and I found that dimmer.el will affect corfu's popup window which uses child frames to show the popup.

I tried to add following config, but no effect, do you have any advice for making dimmer works with corfu?

(use-package dimmer :hook (after-init . dimmer-mode) :config (setq-default dimmer-fraction 0.15) (add-to-list 'dimmer-exclusion-regexp-list "^ \corfu\$")) my corfu config:

(use-package corfu :init (setq corfu-cycle t) (setq corfu-auto t) (setq corfu-quit-at-boundary t) (setq corfu-quit-no-match t) (setq corfu-preview-current nil) (corfu-global-mode)) — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.

Eason0210 commented 2 years ago

@gonewest818 Thanks for your advice, I will try the dimmer-prevent-dimming-predicates when I have time.

It’s certainly possible there’s something deeper I need to do about child frames

Actually, I saw dimmer.el already support posframe which is also implemented by child frame. And corfu use its own implementation.

gonewest818 commented 2 years ago

True. Under the hood all we’re really doing about posframe is set a regexp

(add-to-list 'dimmer-exclusion-regexp-list "^ \.posframe.buffer.\*$"))

Because posframe frames tend to have names that include the text “posframe” and “buffer”. It might be similar with Corfu actually.

On Jan 19, 2022, at 8:06 AM, Eason Huang @.***> wrote:

 @gonewest818 Thanks for your advice, I will try the dimmer-prevent-dimming-predicates when I have time.

It’s certainly possible there’s something deeper I need to do about child frames

Actually, I saw dimmer.el already support posframe which is also implemented by child frame. And corfu use its own implementation.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.

Walheimat commented 2 years ago

For me the solution buzztaki had for lsp-doc works here as well:

(defun advise-dimmer-config-change-handler ()
  "Advise to only force process if no predicate is truthy."
  (let ((ignore (cl-some (lambda (f) (and (fboundp f) (funcall f)))
                         dimmer-prevent-dimming-predicates)))
    (unless ignore
      (when (fboundp 'dimmer-process-all)
        (dimmer-process-all t)))))

(defun corfu-frame-p ()
  "Check if the buffer is a corfu frame buffer."
  (string-match-p "\\` \\*corfu" (buffer-name)))

(defun dimmer-configure-corfu ()
  "Convenience settings for corfu users."
  (add-to-list
   'dimmer-prevent-dimming-predicates
   #'corfu-frame-p))

(use-package dimmer
  :config
  (advice-add
   'dimmer-config-change-handler
   :override 'advise-dimmer-config-change-handler)
  (dimmer-configure-corfu)
  (dimmer-mode t)
  :defer 1)
Eason0210 commented 2 years ago

@Walheimat Thanks for sharing your solution. I works for me too.

gonewest818 commented 2 years ago

keeping this issue open as a reminder to improve documentation or add to the implementation.

simurgh9 commented 8 months ago

I tried putting everything under one use package declaration,

(use-package dimmer
  :ensure
  :defer
  :init
    (defun advise-dimmer-config-change-handler ()
      "Advise to only force process if no predicate is truthy."
      (let ((ignore (cl-some (lambda (f) (and (fboundp f) (funcall f)))
                             dimmer-prevent-dimming-predicates)))
        (unless ignore
          (when (fboundp 'dimmer-process-all)
            (dimmer-process-all t)))))

    (defun corfu-frame-p ()
      "Check if the buffer is a corfu frame buffer."
      (string-match-p "\\` \\*corfu" (buffer-name)))

    (defun dimmer-configure-corfu ()
      "Convenience settings for corfu users."
      (add-to-list
       'dimmer-prevent-dimming-predicates
       #'corfu-frame-p))
  :config
    (advice-add
     'dimmer-config-change-handler
     :override 'advise-dimmer-config-change-handler)
    (dimmer-configure-corfu)
    (dimmer-mode t))

Anyways, could the (dimmer-configure-corfu) not be added to the source?

sho-87 commented 6 months ago

@simurgh9 thanks for the config

would love to see this get merged as well

curable-online commented 1 month ago

@simurgh9 @Walheimat

I also have used your code to solve the same problem with show-paren's child-frame

Replacing those functions for Corfu with these.

 ;;; Instead of corfu-frame-p
  (defun show-paren-child-frame-p ()
    "Check if the buffer is a show-paren's context child frame."
    (string-prefix-p " *show-paren context*" (buffer-name)))
  ;;; instead of dimmer-configure-corfu
  (defun dimmer-configure-show-paren-child-frame ()
    "Convenience settings for show-paren’s child-frame users."
    (add-to-list
     'dimmer-prevent-dimming-predicates
     #'show-paren-child-frame-p))