(or emacs irrelevant)

Select the previous window with ace-window

It's strange that I haven't implemented this feature before, as it's quite a common usage pattern:

  1. You select a window with ace-window.
  2. You do some stuff there.
  3. You want to return the previous window.


In the step 3, you have to go though the whole aw-keys dispatch, only to select a window which can be pre-determined. Not any more, if you call aw-flip-window:

(defun aw-flip-window ()
  "Switch to the window you were previously in."
  (aw-switch-to-window (aw--pop-window)))

So now, you could have a grid of 10 windows, select one of them with ace-window, and switch indefinitely between it and the previous window with ace-flip-window, while ignoring the other 8.


Remember that if you have some window that you never want to switch to with ace-window, you can add it to aw-ignored-buffers:

(defcustom aw-ignored-buffers '("*Calc Trail*" "*LV*")
  "List of buffers to ignore when selecting window."
  :type '(repeat string))

It's not a big deal, but it's convenient at least for this scenario:

  1. I start with one active window.
  2. M-x calc; now I have three windows.
  3. I can toggle back and forth between calc and the main window with ace-window without having to type aw-keys, since *Calc Trail* is ignored, so that makes only two total windows.

Selecting last window during the ace-window dispatch

This is a really cool feature, in my opinion: for all three actions - aw-select-window, aw-swap-window, and aw-delete-window, you can select the previous window as a target with the same key n. This is, of course, customizable:

(defcustom aw-flip-keys '("n")
  "Keys which should select the last window."
  :set (lambda (sym val)
         (set sym val)
         (setq aw--flip-keys
               (mapcar (lambda (x) (aref (kbd x) 0)) val))))

So you could have a whole list of bindings that select the previous window during the aw-keys dispatch. This is cool because there's no visual feedback necessary, so this binding can be easily added to the muscle memory. The bindings don't necessarily need to be single keys, anything with one chord, e.g. C-f, is acceptable.

Here's how I've set it up for myself:

(global-set-key "ν" 'ace-window)
(csetq aw-flip-keys '("n" "ν"))

This means that:

  • I can select the previous window with νν - a double call to ace-window.
  • I can swap with the previous window with ψνν, ψ calls universal-argument for me.
  • I can delete the previous window with ψψνν.


Thanks to @luciferasm for the idea, I hope you'll enjoy the new feature.