如何在Emacs中正确配置Ctrl-Tab

Use*_*er1 7 emacs

在我的大部分开发中,我从Visual Studio转换为Emacs(主要是由于切换编程语言).但是,我真正想念Visual Studio有一个很酷的功能: Ctrl- Tab在"缓冲区"之间.

ctrl- tab在Visual Studio是不一样的C- x b在Emacs.所以,这不仅仅是键盘映射问题.以下是我理想的特点Ctrl- Tab:

  1. 按住ctrl命中选项卡,在放开之前,您会看到下一个缓冲区ctrl.
  2. 没有必要输入.
  3. 如果这不是您想要的缓冲区,请再次按Tab键,直到看到所需的缓冲区.
  4. ctrl释放的那一刻,缓冲环会更新.环中的下一个缓冲区是您第一次按下的缓冲区ctrl.

我见过一些试图模拟这种行为的Emacs插件,但#4是最困难的.似乎Emacs无法检测ctrl密钥何时被释放.相反,代码等待用户在缓冲区中一段时间​​或等待缓冲区更改..然后缓冲区被添加到环中.这足以不同,真正阻挠我,只是从来没有用我心爱的ctrl- tab一次.现在我只是处理C- x b.偶像模式使C- x b更容忍,但我仍然梦想有一天我可以ctrl- tab在emacs.

有没有人找到一种方法来配置Ctrl- Tab在Emacs中工作像Visual Studio?

小智 5

我正在搜索你描述的行为,并遇到了iflipb包:http://www.emacswiki.org/emacs/iflipb 并将其绑定到C- tab,C- S- tab.

不幸的是,在释放ctrl密钥后它不会重新启动循环,所以在这方面与上面答案中的my-switch-buffer相同.任何有关此问题的新见解都受到高度赞赏.


Tre*_*son 2

我认为这很接近你想要的。正如您所提到的,Emacs 不会接收控制键的事件,因此您无法完全获得所需的功能。但是,这不会记录缓冲区切换,直到您执行除按下之外的其他操作C-tab(即滚动、键入内容、单击鼠标、使用命令M-x ...):

(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)))))))
Run Code Online (Sandbox Code Playgroud)