使emacs下一个缓冲区跳过*消息*缓冲区 [英] Make emacs next-buffer skip *Messages* buffer

查看:117
本文介绍了使emacs下一个缓冲区跳过*消息*缓冲区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对Emacs进行简单的更改,以便 next-buffer previous-buffer 命令(我已经绑定到 Cx< RIGHT> Cx 将跳过 *消息* 缓冲区。

I'd like to make a simple change to Emacs so that the next-buffer and previous-buffer commands (which I have bound to C-x <RIGHT> and C-x <LEFT> will skip over the *Messages* buffer.

我正在使用Emacs 24和 Emacs入门工具包

I'm using Emacs 24 and the Emacs Starter Kit.

我已经阅读了以下相关问题和答案,但他们不是我想要的:

I've read the following related questions and answers, but they are not what I want:

  • Buffer cycling in Emacs: avoiding scratch and Messages buffer
  • Emacs disable *Messages* buffer
  • Emacs Lisp Buffer out of focus function?

以下是他们无法工作的一些原因:

Here are some of the reasons why they don't work:


  • 我想保持尽可能简单。

  • 我不想杀死或阻止 *消息*

  • (add-to-list'ido-ignore-buffers^ \ * Messages\ *帮助我的 Cx b ido-switch-buffer ),但不会更改 next-buffer previous-buffer behave。

  • I'd like to keep it as simple as possible. Fewer configuration changes are better.
  • I don't want to kill or prevent *Messages* altogether.
  • (add-to-list 'ido-ignore-buffers "^\*Messages\*" helps with my C-x b (ido-switch-buffer) but does not change how next-buffer and previous-buffer behave.

推荐答案

最简单的我可以想到的是为两个函数定义一个建议,这里是 next-buffer ,同样的是 previous-buffer 。您还可以定义一个配置变量来启用/禁用该行为(或激活/停用该建议):

The simplest I can think of is defining an advice for both functions. Here it is for next-buffer. Similarly would be for previous-buffer. You can also define a configuration variable to enable/disable the behavior (or activating/deactivating the advice):

(defadvice next-buffer (after avoid-messages-buffer-in-next-buffer)
  "Advice around `next-buffer' to avoid going into the *Messages* buffer."
  (when (string= "*Messages*" (buffer-name))
    (next-buffer)))

;; activate the advice
(ad-activate 'next-buffer)

也许你可以用其他方式比较缓冲区而不是它的字符串名称,但这将工作。前一个缓冲区的代码几乎相同。我不知道是否有一种调用原始函数的方式,而不会在建议本身内部触发建议,但是再次,即使稍后测试缓冲区的名称,代码也会工作(如果您刚刚有一个缓冲区,它是消息缓冲区;一些代码可以检查是否只有一个缓冲区,不要再次调用 next-buffer

Maybe you can compare buffers in some other way instead of its string name, but that will work. The code for previous buffer is almost the same. I don't know either if there is a way of calling the original function without triggering the advice once inside the advice itself, but again, the code will work even if the name of the buffer is tested afterwards (will fail if you just have one buffer, and it is the messages buffer; some code can check if there is just one buffer and don't call next-buffer again).

如果您想使用独立的功能执行相同的操作:

If you want to use a standalone function that does the same thing:

(defun my-next-buffer ()
  "next-buffer, only skip *Messages*"
  (interactive)
  (next-buffer)
  (when (string= "*Messages*" (buffer-name))
      (next-buffer)))

(global-set-key [remap next-buffer] 'my-next-buffer)
(global-set-key [remap previous-buffer] 'my-next-buffer)

这篇关于使emacs下一个缓冲区跳过*消息*缓冲区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆