2

I have a function

(defun bad-fn ()
  (interactive)
  (split-window-right)
  (windmove-right)
  )

If I go to a frame with just one window visiting EXWM buffer A (and buffer B is next), and call

  • split-window-right
  • windmove-right

Manually with M-x, I have A to the left of B, and B is the selected window.

If I use the above function, I have B to the left of A, and A is the selected window.

Changing the above to

(defun bad-fn ()
  (interactive)
  (split-window-right)
    (sit-for 0.5)
  (windmove-right)
  )

fixes things.

Emacs version info: "GNU Emacs 27.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.22, cairo version 1.17.3) of 2020-08-28"

As a note, I don't think this happened in Emacs 26.3.

phils
  • 48,657
  • 3
  • 76
  • 115
extremeaxe5
  • 639
  • 3
  • 10
  • If I split a window, I'll have (and *expect* to have) the same buffer in each window -- i.e. A and B are the same buffer -- so I'm confused by your question from the outset. Is your recipe starting from `emacs -Q` ? – phils Oct 08 '20 at 23:04
  • Oh, shoot my bad. Edited my question. – extremeaxe5 Oct 08 '20 at 23:11

1 Answers1

2

You may have more control, no timing issues and fewer layers of debugging to do using built-in functions.

My equivalent to your function is something I use every day in EXWM.

(defun gjg/split-window-right ()
  "Split window right, switch to the new window AND switch buffer in that window"
  (interactive)
  (split-window-right)
  (other-window 1)
  (switch-to-buffer (other-buffer)))

gregoryg
  • 915
  • 6
  • 8