简体   繁体   English

如何使Emacs的other-window命令忽略终端窗口?

[英]How do I make Emacs' other-window command ignore terminal windows?

Emacs does an okay job of being a window manager. Emacs作为窗口管理器做得不错。 I've been splitting up my Emacs frame like this: 我一直在像这样拆分我的Emacs框架:

+---------------------------+
|             |             |
|             |             |
|             |      B      |
|      A      |             |
|             |             |
|             |             |
|             |-------------|
|             |      C      |
+---------------------------+

C is usually a terminal with some kind of long-running process, like a web server or daemon. C通常是具有某种长时间运行过程的终端,例如Web服务器或守护程序。 Occasionally I'll move the point there to restart the daemon, but most of the time I'd like to swap only between A and B . 有时,我会将点移到那里以重新启动守护程序,但是大多数时候我只想在AB之间交换。 How can I make this convenient? 我该如何方便呢?

There's nothing built-in to do what you want. 没有内置功能可以执行您想要的操作。 You can use the following code to do what you want (just customize the regular expression to match the name of the buffer(s) you want to avoid). 您可以使用以下代码执行所需的操作(只需自定义正则表达式以匹配要避免的缓冲区的名称)。

Note: the my-other-window doesn't implement all the features other-window does, that is left as an exercise for the reader. 注: my-other-window没有实现所有功能, other-window呢,那就是作为一个练习留给读者。

my-other-window will try to switch to a window whose buffer doesn't match the avoid-window-regexp . my-other-window将尝试切换到其缓冲区与avoid-window-regexp不匹配的avoid-window-regexp If there's no such window available, then it just switches to the next one. 如果没有可用的窗口,那么它将切换到下一个窗口。

(require 'cl)
(defvar avoid-window-regexp "^[0-9]$")
(defun my-other-window ()
  "Similar to 'other-window, only try to avoid windows whose buffers match avoid-window-regexp"
  (interactive)
  (let* ((window-list (delq (selected-window) (window-list)))
         (filtered-window-list (remove-if
                                (lambda (w)
                                  (string-match-p avoid-window-regexp (buffer-name (window-buffer w))))
                                window-list)))
    (if filtered-window-list
        (select-window (car filtered-window-list))
      (and window-list
           (select-window (car window-list))))))

And bind it appropriately: 并适当地绑定它:

(global-set-key (kbd "C-x o") 'my-other-window)

This works for eshell: 这适用于eshell:

(add-hook 'eshell-mode-hook (lambda () (set-window-parameter (first (window-list)) 'no-other-window t)))

Setting no-other-window to non-nil makes the standard other-window function skip this. 将no-other-window设置为non-nil会使标准other-window函数跳过此设置。 See other-window docs with Ch Cf other-window 查看带有Ch Cf other-window窗口文档

There might be a better way to get the current window, but I don't know it yet. 可能会有更好的方法来获取当前窗口,但是我还不知道。

Not the exact answer but I use windmove-mode for that which allow you to use the arrow to visually move between windows and then doing Control-Left or Control-Right to move only between A and B. 不是确切的答案,但我使用windmove模式 ,该模式允许您使用箭头在窗口之间可视地移动,然后进行Control-Left或Control-Right仅在A和B之间移动。

Other than that you probably can redefine other-buffer function with something that take buffer-list ignoring some patters when switch-to-buffer to it but I didn't write the code handy. 除此之外,您可能还可以重新定义其他缓冲区函数,该函数在切换到缓冲区时将缓冲区列表忽略了某些模式,但是我没有编写任何方便的代码。

For the lazy, I use something like this in my .emacs 对于懒惰的人,我在.emacs中使用了类似的内容

(fset 'doublejump
      "\C-u2\C-xo")
(global-set-key (kbd "C-c o") 'doublejump)

and alternate between using single and double buffer switches. 并在使用单缓冲开关和双缓冲开关之间切换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM