Basically that. I need a function that would do this when I open a buffer in a frame with many other windows. Maybe Emacs has one by default.
2 Answers
What about
(defun switch-buffer-delete-other-windows ()
(interactive)
(call-interactively 'switch-to-buffer)
(delete-other-windows))
(defun find-file-delete-other-windows ()
(interactive)
(call-interactively 'find-file)
(delete-other-windows))
and so on…?
C-x 5 2
does what you request: it opens the current buffer in a separate frame. But it does not delete the original window showing the buffer in the original frame.
Command tear-off-window
does both: opens the buffer in a separate frame and deletes its window from the original frame.
Personally, I bind tear-off-window
to C-x 5 1
. (I don't use that key's original binding of delete-other-frames
.)
-
Thanks, when I do tear-off-window (in a split vertically window), it opens a new frame with my buffer, but inside two windows. What I need is a one window, in one frame solution :) Commented Feb 5, 2021 at 19:57
-
Sorry; I don't understand. A frame inside two windows? Maybe you're reversing the meanings of "frame" and "window"? No idea what you're saying now.– DrewCommented Feb 5, 2021 at 21:15
-
My apologies. I meant: "when I do tear-off-window (in a split vertically window), it opens a new frame with my buffer, but inside THERE ARE two windows. What I need is a one window, in one frame solution :)" Commented Feb 6, 2021 at 20:58
-
Do you see that if you start Emacs with
emacs -Q
(no init file). I don't. I don't see that with either a vertically split window (C-x 3
) or a horizontally split window (C-x 2
). If you don't see that withemacs -Q
then bisect your init file to find the culprit.– DrewCommented Feb 6, 2021 at 23:03 -
(delete-other-windows)
after the target window has acquired focus. The answer in the linked thread targets the largest window in the frame, but that is a custom function and can be changed to do anything under the sun.