TL;DR: Any suggestions as to what function(s) can help me restore (to any given window) the buffer that was visible most recently? It's important that the currently visible buffer is not killed, just moved to the back.
This is partly an exercise in Elisp for me so my preference is for building such a function myself instead of using off-the-shelf packages.
The long version:
I'm trying to create a function which effectively "throws" a newly created buffer to the other window. I've captured some but not all of the necessary functionality.
- Let's say that my current frame is split vertically into two windows,
|Window 1|Window 2|; I'm editing
- Now, let's say that I open a file
bar.elwhich I want to see alongside
- However, I accidentally opened
Window 1, thereby covering up
- (I find myself in similar non-accidental situations, hence the motivation for such a function)
The goal is to have a function which will "throw"
Window 2, i.e., two steps: (i) have
Window 2 show
bar.el and (ii) have
Window 1 show
So far, I've been able to come up with an implementation of (i) but am stuck on (ii). in other words, I can get
Window 2 to show
bar.el but I'm having trouble getting
Window 1 to revert to
(defun dc/move-top-buffer-to-other-window () (interactive) (let* ((current (selected-window)) (other (next-window)) (current-buffer (window-buffer current))) (set-window-buffer other current-buffer) (other-window 1)))
I thought there might be a variable that represents a notion of "buffer-order" for each window (e.g., in the example 1, such a variable for
Window 2 would hold a list of buffers in the following order, as per the example above, [
foo.el ...]), since Emacs is able to "remember" which buffer I had open last. But I haven't been able to find it.