Linked Questions

Popular Questions

The function detach defined here copies the buffer in the current window to a new frame, eliminating all windows displaying the buffer in the old frame.

But the file (e.g. agama.log) still shows up it the Buffers Menu of the OLD FRAME. How can I remove the file from the Buffers Menu List in the OLD FRAME as well. And keep only the buffer in the NEW FRAME.

(defun detach ()
  "Tear off window and delete others showing buffer.
Delete all windows from selected frame that show buffer of
selected window, and show the buffer in a new frame."
  (let ((buf  (window-buffer (selected-window)))
    ;; If all windows in selected frame show BUF, then handle error
    ;; "Attempt to delete minibuffer or sole ordinary window", by
    ;; replacing BUF with`other-buffer` in the last window showing BUF.
    (condition-case nil
        (while (setq win  (get-buffer-window buf)) (delete-window win))
      (error (switch-to-buffer (other-buffer buf))))
    (switch-to-buffer-other-frame buf)))

Related Questions