1

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.

liwp
  • 6,746
  • 1
  • 27
  • 39
George Host
  • 980
  • 1
  • 12
  • 26
  • As ataylor indicated, killing `*Messages*` isn't a good idea. How is it causing you problems? – phils Mar 02 '12 at 16:50
  • I just want to reduce the clutter in the buffers list i find it annoying when a few things happen, when I do a dired it doesn't close the buffer as I finish with it, when I do a completion it leaves that buffer open as soon as its done, when I am in a current frame and want to switch buffers more buffers to run through are required – George Host Mar 06 '12 at 15:52
  • Consider adding a global key binding for `M-x bury-buffer`. Be aware that `q` buries the buffer in many major modes (dired, help, info, customize, etc, etc...). Rebind `C-x C-b` to `ibuffer` instead of the default `list-buffers`, and then learn how you can filter and group the listing to keep unwanted buffers out of the way. For dired you can use `a` to remove the dired buffer when opening files or directories. (edit: in fact, I have a previous answer which goes into more detail on exactly these suggestions: http://stackoverflow.com/a/3145824/324105 ) – phils Mar 06 '12 at 21:46

3 Answers3

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.

ataylor
  • 64,891
  • 24
  • 161
  • 189
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\*"))
liwp
  • 6,746
  • 1
  • 27
  • 39
  • "and everyone should be using it" Ido is better than the default completion mechanism. But Anything is far ans away better than ido when you have to select amongst a big list long strings (i.e. buffer names). – event_jr Mar 03 '12 at 01:43
  • I tried using Anything a while back, and found it too weird / intrusive / in your face IIRC. I'm a heavy QuickSilver user on OS X, so maybe I should give Anything another try... – liwp Mar 03 '12 at 08:58
  • "^\*Messages\*" do we have to use the regex in this case ? – George Host Mar 06 '12 at 15:54
0

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

sabof
  • 8,062
  • 4
  • 28
  • 52