How to properly configure Ctrl-Tab in Emacs

I converted from Visual Studio to Emacs for most of my development (mainly due to switching programming languages). However, there is one interesting feature of Visual Studio that I really missed: Ctrl - Tab between the "buffers".

Ctrl - Tab , which in Visual Studio does not match C - x b in Emacs. Thus, this is not just a keyboard display issue. Here are my ideals Ctrl - Tab :

  • Holding the Ctrl hit tab, you will see the following buffer before you release Ctrl .
  • No need to enter input.
  • If this is not the buffer you want, click the tab again until you see the buffer you want.
  • When Ctrl is released, the buffer ring is updated. The next buffer in the ring is the buffer that you first pressed Ctrl .

I saw some Emacs plugins that try to mimic this behavior, but # 4 is the most complicated. It seems that Emacs cannot detect when the Ctrl key is released. Instead, the code expects the user to be in the buffer for a certain time, or waiting for the buffer to change ... and then the buffer is added to the ring. It's different enough to really upset me and just never ever use my favorite Ctrl - Tab again. At the moment, I only deal with C - x b . ido-mode makes C - x b more bearable, but I'm still dreaming of a day when I can Ctrl - Tab in emacs.

Has anyone found a way to configure Ctrl - Tab in Emacs to work like Visual Studio?

+6
emacs
source share
5 answers

I looked for exactly the behavior that you described and came across the iflipb package: http://www.emacswiki.org/emacs/iflipb and attached it to the C - tab , C - S - tab .

Unfortunately, it does not restart the loop after releasing the ctrl key, therefore it is the same in this respect as in my buffer response in the answer above. Any new ideas in this matter are highly appreciated.

+4
source share

If you are using GNU Emacs 22.1 or later, \Cx<Right> fires Mx next-buffer and \Cx<Left> fires Mx previous-buffer . This EmacsWiki page has a link to C-TAB Windows-style buffer cyclicity. The page also talks about how to bring this behavior to older versions of Emacsen.

This question yesterday looks very similar to what you want to achieve, except that this question is about Notepad ++ instead of Visual Studio.

+3
source share

I think this is close to what you want. As you mentioned, Emacs does not receive events for the control key, so you cannot get the necessary functionality. However, this will not write the buffer switch until you do something other than pressing C-tab (i.e., scroll, enter something, click, use the Mx ... command):

 (global-set-key (kbd "<C-tab>") 'my-switch-buffer) (defun my-switch-buffer () "Switch buffers, but don't record the change until the last one." (interactive) (let ((blist (copy-sequence (buffer-list))) current (key-for-this (this-command-keys)) (key-for-this-string (format-kbd-macro (this-command-keys))) done) (while (not done) (setq current (car blist)) (setq blist (append (cdr blist) (list current))) (when (and (not (get-buffer-window current)) (not (minibufferp current))) (switch-to-buffer current t) (message "Type %s to continue cycling" key-for-this-string) (when (setq done (not (equal key-for-this (make-vector 1 (read-event))))) (switch-to-buffer current) (clear-this-command-keys t) (setq unread-command-events (list last-input-event))))))) 
+2
source share

I like the cycling and switching behavior of iflipb, it is very similar to the behavior of Windows Alt-Tab. However, as stated earlier, Emacs does not make it easy to notice when you release the control key. This makes it impossible to switch between the two upper buffers: if you press C-Tab (and release) and then C-Tab (and release), you will not switch between the two upper buffers. Instead, iflipb just goes further down the buffer list. But if you execute any other Emacs command between two C-Tab events, iflipb recognizes that it starts in the buffer march, so it switches.

On Windows, AutoHotKey can come to the rescue and send Emacs a keystroke when releasing a control key. Here is my script:

 #if WinActive("ahk_class Emacs") ^Tab:: Send {Blind}^{Tab} SetTimer, WaitForCtrlUp, 10 return WaitForCtrlUp: if(!GetKeyState("LControl", "P") and !GetKeyState("RControl","P")) { if WinActive("ahk_class Emacs") Send ^c: SetTimer, WaitForCtrlUp, Off } return 

Whenever a C-Tab is pressed in emacs, the script starts polling the state of the control key. When the key is released, it sends Emacs the Cc : key sequence. I have a key associated with the "null" command, which is enough to get iflipb to notice what is happening.

Here's the corresponding excerpt .emacs:

 ; see http://www.emacswiki.org/emacs/iflipb (require 'iflipb) (global-set-key (kbd "<C-tab>") 'iflipb-next-buffer) (global-set-key (if (featurep 'xemacs) (kbd "<C-iso-left-tab>") (kbd "<CS-tab>")) 'iflipb-previous-buffer) (defun null-command () "Do nothing (other than standard command processing such as remembering this was the last command executed)" (interactive)) (global-set-key "\Cc:" 'null-command) 

So this is kind of hacks, but it really works. Thanks to the posters at http://www.autohotkey.com/board/topic/72433-controltab/ , which tried to solve a similar problem.

+1
source share

Add the following to the .emacs file:

 (global-set-key (kbd "<C-tab>") 'next-buffer) 
0
source share

All Articles