1

My use-case: So, I have two windows in a frame. Each window has a different buffer rendering in it. Out of them one was previously displayed using the function display-buffer.

Now, I want that buffer to get hidden (or out of sight) programmatically so that only one buffer is visible in the frame. What is the relevant Emacs API for that ?

2

It's important not to get confused between buffers, windows, and frames in Emacs.

Frames are the Emacs terminology for what are known as "windows" in the operating system (also, if you're running Emacs in a terminal, the entire display of Emacs in that terminal is also considered a frame). A single frame can contain one or more Emacs windows (which divide the frame horizontally or vertically). Each Emacs window can and must contain a view on to one single buffer at a time (though you can choose which buffer an Emacs window shows, and multiple windows can have views on to the same buffer).

It sounds like you have two buffers displayed in two different Emacs windows. It's not clear from your description whether both of those windows are in the same frame or not.

If both windows are in the same frame and point is in the window you wish to keep, you can delete the other window using the delete-other-windows command. If point is in the window you wish to delete, you can delete it using the delete-window command.

If the two windows are on separate frames and point is in the frame you wish to keep, you can delete the other frame using the delete-other-frames command. If point is in the frame you wish to delete, you can delete it using the delete-frame command.

If you don't actually want to delete a window (or a frame) and would rather simply replace one of the buffers in one of the windows with another buffer, you can move point to the window containing that buffer and then use the switch-to-buffer command (this command will also create a new buffer if it doesn't already exist).

Note that deleting a window (or a frame) will not delete any buffer. The buffers that they showed will remain open in Emacs, and you can show them inside an existing window by using switch-to-buffer or display-buffer.

  • So, I have two windows with two different buffers in it. The problem with switch-to-buffer is that it doesn't hide that window. My object is to hide one window from the frame. – Sibi Sep 29 '17 at 7:44
  • Also, I have edited the question to make it more clear. – Sibi Sep 29 '17 at 7:47
  • If point is in the window you wish to delete, you can delete it using the delete-window command. – izkon Sep 29 '17 at 7:51
  • Don't want to delete it, just want to hide it from the current view. – Sibi Sep 29 '17 at 7:52
  • 1
    delete-window doesn't actually delete the buffer that's displayed in the window, it only deletes the window (ie. the rectangular part of the frame that shows a view in to your buffer). The buffer remains open in Emacs, and you can return to it using switch-to-buffer or display-buffer. You can also open a new window if you want using the split-window command. – izkon Sep 29 '17 at 7:56
1

I think the "undisplay-buffer" function you want is called either bury-buffer or quit-window. I suggest you M-x report-emacs-bug asking for this to be clarified in the documentation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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