Skip to main content

C'est la Z

Using Emacs 36 - A Touch of Elisp

I've been working on a vue.js project this summer. During the school year I really can't dive into code so it's been fun.

I've already showed you most of the Emacs tools I use for development. Projectile, Ace-Window, IBuffer, Swiper / Ivy and all. One thing I couldn't easily do was arrange windows the way I wanted.

I've been setting up Emacs with one large window and a couple of smaller ones:


I can easily switch the buffer in the window and I can easily switch windows but what I wanted to do was swap the buffer in the large window with one of the smaller buffers and leave focus in the larger buffer:


I started looking at perspective mode and persp mode but neither work with the latest Emacs. After poking around at other packages I realized that ace-window does most of what I wanted. Ace-window has a function that swaps the buffers in two windows named ace-swap-window. The only problem is that it leaves the focus on the window you swap to not the one you started in. Ace-window also has aw-flip-window which then returns the cursor to the previous window.

With a little elisp, we get the behavior I was looking for which I then bound to C-1 z:

(defun z/swap-windowsn ()

(define-key z-map (kbd "w") 'z/swap-windows)

The video goes into more details but it shows that if you're not afraid to explore a bit you can pretty much get Emacs to do whatever you want.

comments powered by Disqus