1

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.

2
  • 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 8 '20 at 23:04
  • Oh, shoot my bad. Edited my question. – extremeaxe5 Oct 8 '20 at 23:11
1

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)))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.