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

时间:2010-11-10 16:22:35

标签: emacs

在我的大部分开发中,我从Visual Studio转换为Emacs(主要是由于切换编程语言)。但是,我真的错过了Visual Studio的一个很酷的功能: Ctrl - Tab 在“buffers”之间。

Visual Studio中的 ctrl - 选项卡 C - x 不同b 在Emacs中。所以,这不仅仅是键盘映射问题。以下是我理想的 Ctrl - Tab 的功能:

  1. 按住 ctrl 点击标签,在放开 ctrl 之前,您会看到下一个缓冲区。
  2. 没有必要按回车。
  3. 如果这不是您想要的缓冲区,请再次按Tab键,直到看到所需的缓冲区为止。
  4. 释放 ctrl 的那一刻,缓冲环被更新。环中的下一个缓冲区是第一次按 ctrl 的缓冲区。
  5. 我见过一些试图模拟这种行为的Emacs插件,但#4是最难的。似乎Emacs无法检测何时释放 ctrl 键。相反,代码等待用户在缓冲区中一段时间​​或等待缓冲区更改..然后缓冲区被添加到环中。它的不同之处真的让我感到沮丧,再也不会再使用我心爱的 ctrl - 标签了。现在我只处理 C - x b 。 ido-mode让 C - x b 更容忍,但我仍然梦想有一天我可以 ctrl - emacs中的标签

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

5 个答案:

答案 0 :(得分:5)

我正在搜索您描述和遇到的行为 iflipb包:http://www.emacswiki.org/emacs/iflipb并将其绑定到 C - tab C - S - < KBD>标签

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

答案 1 :(得分:4)

如果您使用的是GNU Emacs 22.1或更新版本,则\C-x<Right>会触发M-x next-buffer\C-x<Left>触发M-x previous-bufferEmacsWiki上的此页面包含指向C-TAB Windows样式缓冲区循环的链接。该页面还讨论了如何在旧版本的Emacsen上引入此行为。

昨天的

This question看起来非常类似于你想要实现的目标,除了问题是关于Notepad ++而不是Visual Studio。

答案 2 :(得分:2)

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

(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)))))))

答案 3 :(得分:1)

我也喜欢iflipb的循环和切换行为,它非常像Windows Alt-Tab行为。但是,如前所述,当您释放控制键时,Emacs并不容易注意到。这使得在前两个缓冲区之间切换不完美:如果按C-Tab(和释放)然后按C-Tab(和释放),则您没有在前两个之间切换。相反,iflipb只是进一步向下进入缓冲区列表。但是如果你在两个C-Tab事件之间执行任何其他Emacs命令,那么iflipb会识别它在缓冲区游行中重新开始,所以它会进行切换。

在Windows上,当您释放控制键时,AutoHotKey可以解救并向Emacs发送击键。这是我的剧本:

#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

每当在emacs中按下C-Tab时,脚本开始轮询控制键的状态。释放密钥后,它会向Emacs发送C-c :密钥序列。我将该键绑定到“null”命令,这足以让iflipb注意到正在发生的事情。

以下是相关的.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 "<C-S-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 "\C-c:" 'null-command)

所以,它有点像hacky,但确实有效。感谢http://www.autohotkey.com/board/topic/72433-controltab/的海报,他们试图解决类似的问题。

答案 4 :(得分:1)

将以下内容添加到 .emacs 文件中:

(global-set-key (kbd "<C-tab>") 'next-buffer)
相关问题