abo-abo / ace-window

Quickly switch windows in Emacs
970 stars 86 forks source link

changing windows programatically (in a function) not interactively #170

Closed TRSx80 closed 5 years ago

TRSx80 commented 5 years ago

I have been trying to do as stated in the title, but cannot seem to figure out a way by using either ace-window or ace-select-window?

I want to do something like (ace-select-window 2) but that returns (wrong-number-of-arguments (0 . 0) 1). I have tried a bunch of variations, and also tried to read the code but sadly I am only a fledgling lisp wizard, and "this foe is beyond me."

abo-abo commented 5 years ago

Here you go:

(defun my-test ()
  (interactive)
  (let ((wnd (aw-select "Test")))
    (message "You selected: %S" wnd)))
TRSx80 commented 5 years ago

I'm sorry abo-abo, I have tried playing with it a bunch, but still cannot seem to figure it out. :(

If I define the function my-test and then try to execute something like (my-test 2) I am still getting wrong number of arguments.

If I try and put the number 2 instead of Test eg. (aw-select "2") and then execute (my-test) that doesn't work either.

I'm sorry but I can't seem to follow your code. :(

abo-abo commented 5 years ago

You can use M-x ielm to play around with this. (aw-select "Test") returns a window object, which you can later pass to select-window.

If you need more help with Elisp, read: https://www.gnu.org/software/emacs/manual/html_node/eintr/index.html.

jcs090218 commented 5 years ago

I just wrote this function, hope this would help!

(defun jcs-ace-select-window (win-id)
  "Use `ace-window' to select the window by using window index.
WIN-ID : Window index."
  (let ((wnd (nth win-id (aw-window-list))))
    (when wnd
      (select-window wnd)
      (select-frame-set-input-focus (selected-frame)))))

You can call it this way.

(jcs-ace-select-window 0)
abo-abo commented 5 years ago

OK, I see what you were going for. Closing the issue.