0

Is there any command like other-frame which behaves like windows's Alt-TAB? And how to create this command?

To clarify this behavior, I wrote python code which virtually emulate this behavior. Each elements of frame_lst are frames. The first element of the frame_lst is the currently selected frame. With Alt being pressed, pressing TAB N times move the index which shows which frame will be selected, and after releasing TAB and Alt the frame of index'th element of frame_lst is selected and focused, then change the order of the elements of frame_lst to make recently selected frame become first element of the frame_lst.

  • Emulation Program (virtual_alt_tab.py)

    def init_environment():
        global frame_lst, index
        index = 0
        frame_lst = ['f1', 'f2', 'f3', 'f4']
    
    def on_alt_tab_pressed():
        global frame_lst, index
        index += 1
        index = index%len(frame_lst)
    
    def on_alt_tab_released():
            global frame_lst, index
            frame_lst.insert(0, frame_lst.pop(index))
            index = 0
    
    def hit_alt_tab_n_times(n):
        global frame_lst
        print('==== Before hitting Alt-TAB ====')
        print(frame_lst)
        for _ in range(n):
            on_alt_tab_pressed()
        on_alt_tab_released()
        print('==== After hitting alt-TAB consecutively %d times ===='%n)
        print(frame_lst)
    
    # test 1
    print('\n================ test 1 ================')
    init_environment()
    hit_alt_tab_n_times(1)
    
    # test 2
    print('\n================ test 2 ================')
    init_environment()
    hit_alt_tab_n_times(2)
    
    # test 3
    print('\n================ test 3 ================')
    init_environment()
    hit_alt_tab_n_times(3)
    
  • Output

    ================ test 1 ================
    ==== Before hitting Alt-TAB ====
    ['f1', 'f2', 'f3', 'f4']
    ==== After hitting alt-TAB consecutively 1 times ====
    ['f2', 'f1', 'f3', 'f4']
    
    ================ test 2 ================
    ==== Before hitting Alt-TAB ====
    ['f1', 'f2', 'f3', 'f4']
    ==== After hitting alt-TAB consecutively 2 times ====
    ['f3', 'f1', 'f2', 'f4']
    
    ================ test 3 ================
    ==== Before hitting Alt-TAB ====
    ['f1', 'f2', 'f3', 'f4']
    ==== After hitting alt-TAB consecutively 3 times ====
    ['f4', 'f1', 'f2', 'f3']
    

I found related article.

https://www.emacswiki.org/emacs/ControlTABbufferCycling

According to this article Emacs can't detect the release event of the Alt key. So I need another mechanics which complement this. I think pressing C-g will complement this, but I don't know how to detect C-g after Alt-TAB pressed repeatedly.

  • Please specify the behavior you're looking for, instead of just saying "like window's ALT-TAB". Some of those who might be able to help might not know just what that behavior is or which part(s) of it you're looking for. – Drew Apr 4 at 16:51
  • Maybe use (frame-list) to get the list of existing frames, and exclude (selected-frame) from that, then increment a pointer into that list (as a ring). Use ring-convert-sequence-to-ring to convert a list to a ring, then ring-next etc. – Drew Apr 4 at 16:58
  • @Drew: I added the program which virtually emulate the behavior. But Converting this program to lisp and implement C-g detection(see bottom of my question) is long way for me. I almost gave up. – Kei Minagawa Apr 5 at 11:01
  • Sorry, I meant only to please describe MS Windows's ALT-TAB behavior in this context, for people unfamiliar with it. I didn't mean that you needed to show code (e.g. Python) for it. – Drew Apr 5 at 14:57
  • @Drew: It is just writing code is more faster and precise than writing in English in my case. I just write this code in my iPhone while eating my launch. So No need for sorry :) – Kei Minagawa Apr 5 at 15:14
2

The function other-frame, bound to C-x 5 o by default, moves you to the next frame, and calling it repeatedly will cycle you through all available frames. As I recall, that's what Alt-tab does?

ace-window might also be useful for you. See this answer: https://emacs.stackexchange.com/a/46587/262

  • Yes, Alt-TAB cycles frames. I'm currently using Mac and has familiar function(Command-TAB). To clarify the behavior I added the program which virtually emulate it. But I almost gave up. – Kei Minagawa Apr 5 at 11:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.