CCE

Consult Buffer shouldn't preview buffers

: extracted this to its own page for now... I don't use this but here it is for the internet to learn about.

via consult wiki, to prevent Consult Buffer from always popping exwm buffers and moving things around, I apply this monkeypatch which filters them out of consideration for preview.

emacs-lisp
(defun consult-buffer-state-no-x ()
  "Buffer state function that doesn't preview X buffers."
  (lexical-let ((orig-state (consult--buffer-state))
        (filter (lambda (action cand)
                  (if (or (not cand)
                          (eq action 'return)
                          (let ((buffer (get-buffer cand)))
                            (and buffer
                                 (not (eq 'exwm-mode (buffer-local-value 'major-mode buffer))))))
                      cand
                    nil))))
    (lambda (action cand)
      (funcall orig-state action (funcall filter action cand)))))

(with-eval-after-load 'consult
  (setq consult--source-buffer
        (plist-put consult--source-buffer :state #'consult-buffer-state-no-x)))