syl20bnr / spacemacs

A community-driven Emacs distribution - The best editor is neither Emacs nor Vim, it's Emacs *and* Vim!
http://spacemacs.org
GNU General Public License v3.0
23.58k stars 4.9k forks source link

Entering transient states replaces current buffer contents with transient buffer contents #16281

Closed fleimgruber closed 4 months ago

fleimgruber commented 4 months ago

Description :octocat:

Transient state replaces current buffer contents with transient buffer contents

Reproduction guide :beetle:

Tested with two different transient states: paste and spell-checking

OR:

Observed behaviour: :eyes: :broken_heart: Current buffer gets replaced with transient state buffer, e.g. in case of spell checking

Spell Checking Transient State
Spell Commands            Add To Dictionary               Other
------------------------  ------------------------------  --------------------------------
[b] check whole buffer    [B] add word to dict (buffer)   [t] toggle spell check
[r] check region          [G] add word to dict (global)   [q] exit
[d] change dictionary     [S] add word to dict (session)  [Q] exit and disable spell check
[n] next spell error
[c] correct before point
[s] correct at point
[KEY] exits state  [KEY] will not exit

Expected behaviour: :heart: :smile: Transient state buffer gets created in a different window, current buffer contents are not replaced.

System Info :computer:

Backtrace :paw_prints:

fleimgruber commented 4 months ago

I narrowed this down to my local layer config, will bisect some more.

fleimgruber commented 4 months ago

It turns out the offending parts were these, based on https://www.masteringemacs.org/article/demystifying-emacs-window-manager#example-2-reusing-windows. Might well be an oversight on my part. I did not dissect it further, just wanted to have it here for reference if others stumble in a similar way.

(setq switch-to-buffer-obey-display-actions t)

(add-to-list 'display-buffer-alist
             `(,(rx (| "*xref*"
                       "*grep*"
                       "*Occur*"
                       (and "*deadgrep" (* not-newline) "*")))
               display-buffer-reuse-window
               (inhibit-same-window . nil)))

(add-to-list 'display-buffer-alist
             '(,(rx (and "*deadgrep" (* not-newline) "*"))
               display-buffer-reuse-mode-window
               ;; change to `t' to not reuse same window
               (inhibit-same-window . nil)
               (mode deadgrep-mode)))

(defun make-display-buffer-matcher-function (major-modes)
  (lambda (buffer-name action)
    (with-current-buffer buffer-name (apply #'derived-mode-p major-modes))))

(add-to-list 'display-buffer-alist
             `(,(make-display-buffer-matcher-function '(deadgrep-mode))
               (display-buffer-reuse-mode-window
                display-buffer-in-direction)
               (mode deadgrep-mode)))