Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I close an automatically opened window in Emacs?

Tags:

emacs

This is probably a very naive Emacs question - I'm new to it.

When I'm evaluating a lisp expression, if there's an error the debugger automatically comes up in another window. If I have *scratch* and *info* open (the former for trying out lisp and the latter for reading about it), then the debugger opens up in the window that *info* was in. At the moment, I have to switch to that window, then change it back to *info*, before returning to *scratch*. (The same thing happens if I do C-x C-b for a list of buffers.) I'm guessing there has to be a way to just close that window without this long sequence of commands. Can anyone enlighten me?

like image 775
Skilldrick Avatar asked Jul 31 '09 13:07

Skilldrick


People also ask

How do I close one window in Emacs?

Likewise in emacs, window can be split horizontally by C-x 2 , and vertically by C-x 3 . And close all other window by C-x 1 .

How do I close a frame in Emacs?

Typing C-x C-c closes all the frames on the current display, and ends the Emacs session if it has no frames open on any other displays (see Exiting Emacs). To close just the selected frame, type C-x 5 0 (that is zero, not o ).

What is a window in Emacs?

A window is an area of the screen that can be used to display a buffer (see Buffers). Windows are grouped into frames (see Frames). Each frame contains at least one window; the user can subdivide a frame into multiple, non-overlapping windows to view several buffers at once.


2 Answers

At least here on my emacs (22.3), when the debugger pops up, its window becomes the active one. There, pressing q just quits the debugger, if that's what you want. At that point, it also gets out of recursive editing.

like image 84
Bahbar Avatar answered Sep 21 '22 15:09

Bahbar


From what I understand, you want to close the buffer in the other window without moving your cursor from the current window.

I don't any existing function does that, so I rolled my own.

(defun other-window-kill-buffer ()
  "Kill the buffer in the other window"
  (interactive)
  ;; Window selection is used because point goes to a different window
  ;; if more than 2 windows are present
  (let ((win-curr (selected-window))
        (win-other (next-window)))
    (select-window win-other)
    (kill-this-buffer)
    (select-window win-curr)))

You can bind it to something like "C-x K" or some other somewhat difficult-to-press key so you won't press it by mistake.

(global-set-key (kbd "C-x K") 'other-window-kill-buffer)

I use this a LOT! (for Help buffers, Compilation buffers, Grep buffers, and just plain old buffers I want to close now, without moving the point)

like image 44
spk Avatar answered Sep 18 '22 15:09

spk