7

So I generally have 3 buffers open in Emacs.

  1. One buffer for the actual code I am writing.
  2. One buffer for the unit test for said code.
  3. A third buffer that displays the results of the unit test. This buffer comes into being below the two other buffers when I run my unit test C-x SPACE.

How do I disable this third buffer such that when I press C-x o I am only switching between buffer 1 and buffer 2? Currently, I switch between buffer 1, then buffer 2, then buffer 3, then buffer 1, etc. To be specific, I want C-x o to only switch between buffer 1 and 2.

Thank you.

Stephen Cagle
  • 14,124
  • 16
  • 55
  • 86
  • Not an answer but a workaround that might help you: http://stackoverflow.com/questions/91071/emacs-switch-active-window – Gerald Senarclens de Grancy Oct 15 '09 at 20:58
  • It sounds like you're asking to skip a *window* when it contains a particular buffer you don't want to switch into. Correct? – Trey Jackson Oct 15 '09 at 21:26
  • Stephen, may I suggest you update the title and question to put window instead of buffer ? buffer/window/frame have a specific meaning in emacs: Frame is the equivalent of what a windows manager calls a window (the enclosure you can generally move around). window is what you're referring to: a subset of the frame that shows some text. a buffer is what represents the actual content shown. It's generally identified by a name, that shows in the modeline. You can show the same buffer on 2 windows, e.g. – Bahbar Oct 16 '09 at 07:16
  • 1
    window-number-mode is good for this. – jrockway Oct 17 '09 at 01:00
  • Using smarter movement commands is also a good strategy; see http://github.com/jrockway/elisp/blob/master/_local/term-extras.el for example. – jrockway Oct 17 '09 at 01:03
  • Ok, I will switch it to buffer. – Stephen Cagle Oct 18 '09 at 06:42

2 Answers2

7

A general solution to this (can look) something like the following:

(defvar ignore-windows-containing-buffers-matching-res '("\\*Help")
      "List of regular expressions specifying windows to skip (if window contains buffer that matches, skip)")

(defadvice other-window (before other-window-ignore-windows-containing activate)
  "skip over windows containing buffers which match regular expressions in 'ignore-windows-containing-buffers-matching-res"
  (if (and (= 1 (ad-get-arg 0)) (interactive-p))
      (let* ((win (next-window))
             (bname (buffer-name (window-buffer win))))
        (when (some 'identity (mapcar '(lambda (re)
                                        (string-match re bname))
                                     ignore-windows-containing-buffers-matching-res))
          (ad-set-arg 0 2)))))

Customize the variable to be a regular expression matching the buffer names you want to skip.

Trey Jackson
  • 73,529
  • 11
  • 197
  • 229
  • I copied this into my .emacs file. I then just replaced "*Help" with "*Ruby-Test*" (which was the name of the buffer that the ruby test were being run within). Now when I switch buffers, it only switches between buffer 1 and 2. Seems like a good solution. Thanks. – Stephen Cagle Oct 18 '09 at 06:46
5

Trey's answer will do exactly what you want (at least it looks like it will; I haven't tried it). A more generic solution would be to use swbuff with either swbuff-x or my own swbuff-advice. Info about all three can be found on the Emacs Wiki swbuff page.

Joe Casadonte
  • 15,888
  • 11
  • 45
  • 57