abo-abo / ace-window

Quickly switch windows in Emacs
991 stars 87 forks source link

Directly jump to nth window #224

Open nurdann opened 2 years ago

nurdann commented 2 years ago

Is it possible to have a keybinding to directly jump to nth window? Most of the time I have few window splits that I want to navigate between.

I tried sending char to ace-window but it's a blocking call,

(progn
  (ace-select-window)
  (insert-char ?1))
bradhowes commented 3 months ago

If you don't mind using ace-window internals, you can use aw-window-list and choose the nth one. I have my own hacks to move to the next/prev window in this list:

(defun my/do-next-window (wins)
  "Jump to window in WINS after the current one."
  (let *((here (get-buffer-window))
         (found (memq here wins))
         (next (car-safe (cdr-safe found))))
    (when next
      (aw-switch-to-window next))))

(defun my/ace-next-window ()
  "Jump to next window according to `ace-window'."
  (interactive)
  (my/do-next-window (aw-window-list)))

(defun my/ace-previous-window () 
  (interactive)
  (my/do-next-window (reverse (aw-window-list))))

You could do something similar but use (nth N (aw-window-list)) to get window N.