I like to work with a vertically split frame with code in both windows. When i call M-x compile the *compilation* buffer shows in the other window (wich is fine as M-g n would show problematic code in the current window while i can still see the error in the other), but, after reviewing code, i would like to kill the *compilation* buffer and show the code that was in that window before, without visiting that window (C-x o) and killing it (C-x k).

Is there a way to do that?

I've come up with something, altough, it does not work; it throws:

wrong-type-argument windowp (#<window 10 on *Backtrace*>))`
window-buffer((#<window 10 on *Backtrace*>))

I believe that window-buffer does take a window as an argument and return its buffer, but I don't know any Lisp.

The code:

(defun kill-other-window-buffer ()
  "Kill the buffer of the other window if there is two windows"
  ;; I thought it will be better this way, to avoid killing an unexpected buffer
  ;; when several windows are in the frame
  (if (= (length (window-list)) 2)
    (kill-buffer
      (window-buffer (last (window-list)))
  )))
  • 3
    Doesn't pressing C-x k prompt you to chose the buffer you want to kill from the buffers list ? You can just chose the buffer you want to kill and press enter to kill buffer. – Chakravarthy Raghunandan Sep 17 '16 at 16:47
  • What @ChakravarthyRaghunandan said. – Drew Sep 17 '16 at 19:14
  • Are you looking for something like this? – Nsukami _ Sep 17 '16 at 22:19
  • How about?: (kill-buffer "*compilation*") – lawlist Sep 18 '16 at 5:36

As suggested by Charkravarthy and Drew, using either vanilla Emacs, or together with Helm, Ido or Ivy one can kill / close the *Compilation* buffer using C-x k and selecting it when prompted to do so.

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.