Emacs Lisp Buffer out of focus function?

2019-03-02 16:06发布

问题:

Is there an emacs lisp function that will allow me to tell if a buffer is out of focus?

I am trying to write a hook that will get rid of the semantics *possible completion's* buffer right after it is out of focus.

Also is it possible to get rid of the *Messages* Buffer as well? I haven't found a function that would kill it.

回答1:

Related to your second question, Also is it possible to get rid of the Messages Buffer as well. If you're using ido-mode (and everyone should be using it!), you can hide the *Messages* buffer from the buffer listing with the following elisp:

(require 'ido)
(setq ido-ignore-buffers '("^\*Messages\*"))


回答2:

You can test if a buffer is the buffer that currently has focus with current-buffer. For example, to test if *scratch* has the focus,

(eq 
 (current-buffer) 
 (get-buffer "*scratch*"))

The *Messages* buffer is an important part of emacs. It's the implicit target of the message function that is used to log various bits of information from all over. You can kill *Messages* like any other buffer, but it will just get recreated the next time something calls message. You could probably silence it by redefining the message function, but I'd question the point of doing so.



回答3:

You can try PopWin, It lets you specify buffers that will open in a special window. This window closes when the frame gets out of focus or when you press C-g