2

Imagine I have an Emacs Lisp script which I execute using M-x eval-buffer. In this script, I want to call :vsp (vertical split) several times.

How can I do it programmatically?

C-h k takes me to the evil-ex command. However, I cannot find there anything like vsp or split.

Update 1:

I found evil-window-vsplit in evil-commands.el.

However, it doesn't work like :vsp. If I execute the script

(evil-window-split)
(evil-window-vsplit)
(evil-window-down 1)

the window looks like shown below.

Actual result (screenshot)

If I execute the commands C-w s, :vsp, and C-w j manually, the result is this:

Expected result

Update 2: It looks like (evil-window-down 1) causes the problem.

Here is why: If I run the script

(evil-window-split)
(evil-window-vsplit)
(evil-window-vsplit)

I get the correct result (window split horizontally in two parts, the upper parts split in three parts). The bottom part is not split because there are no commands to split it in the script.

Screenshot without navigation to the bottom window

Then, I add the command for navigating to the bottom part of the horizontal split ((evil-window-down 1), equivalent of C-w j):

(evil-window-split)
(evil-window-vsplit)
(evil-window-vsplit)
(evil-window-down 1)

This script produces the wrong result: Not only the upper half is split in three (like it should), but also the bottom one (it shouldn't be split).

Screenshot showing Emacs windows after running the script with navigation to the bottom

Update 3: The above error does not occur, if I execute the script using M-x load-file.

Glory to Russia
  • 17,289
  • 56
  • 182
  • 325
  • Hmm, interesting. If you execute those three commands individually, it gives the result you are looking for. But the resulting window layout changes if you `eval-buffer`. EDIT: It works if you wrap the three commands in `progn`. – 0x5453 Jan 26 '21 at 13:59
  • Removing the `(evil-window-down 1)` also makes this work from `eval-buffer`. Weird. – 0x5453 Jan 26 '21 at 14:04

0 Answers0