将窗口“弹出”到框架中


13

通常,我的窗口会自动拆分,直到我任意决定当前帧没有足够的房地产。发生这种情况时,我手动删除一个窗口,创建一个框架,然后切换到该删除的窗口。如何编写实现此目的的elisp函数?

我试过了:

(defun pop-window-into-frame ()
  (interactive)
  (delete-window)
  (make-frame-command)
  (switch-to-prev-buffer))

但是由于某种原因,这并没有达到我的预期。

Answers:


15

尝试以下方法:

(defun my-turn-current-window-into-frame ()
  (interactive)
  (let ((buffer (current-buffer)))
    (unless (one-window-p)
      (delete-window))
    (display-buffer-pop-up-frame buffer nil)))

1
直到有人写了我才知道我不想要的另一件事。凉。
glucas 2015年

真好!+1是为了简洁。
PythonNut

就(最小的)性能影响而言,如果换成let和not形式,会有所不同吗?
Matthias

@Matthias我不确定这时反转是否有意义,我绑定当前缓冲区的原因是因为删除窗口可能会更改当前缓冲区的概念。我所看到的唯一方法是通过检查是否只有一个窗口来使代码更加复杂,如果是,则让我们绑定当前缓冲区,删除并弹出它,如果不行,则仅在新帧中显示当前缓冲区。对于微小的性能更改恕我直言,失去清晰度是不值得的。
wasamasa 2015年

@wasamasa对不起您不准确。我已经记过了(除非(one-window-p)(让...
Matthias

4
;; Inspired from `mouse-tear-off-window'.
(defun tear-off-window ()
  "Create a new frame displaying buffer of selected window.
    If window is not the only one in frame, then delete it.
    Otherwise, this command effectively clones the frame and window."
  (interactive)
  (let ((owin  (selected-window))
        (buf   (window-buffer))
        (fr    (make-frame)))
    (select-frame fr)
    (switch-to-buffer buf)
    (save-window-excursion 
      (select-window owin)
      (unless (one-window-p) (delete-window owin)))))

库中提供了此命令以及以下命令(如果所选窗口单独位于其框架中,则不执行任何操作)frame-cmds.el

(defun tear-off-window-if-not-alone ()
  "Move selected window to a new frame, unless it is alone in its frame.
If it is alone, do nothing.  Otherwise, delete it and create a new
frame showing the same buffer."
  (interactive)
  (if (one-window-p 'NOMINI)
      (message "Sole window in frame")
    (tear-off-window)))

这并没有将重点放在这里的新框架(gnome3.28)。最后添加(select-frame-set-input-focus fr)有效。
olejorgenb

@olejorgenb:是的,一个新创建的框架是否获得输入焦点取决于您的窗口管理器。所以是的,您可能需要添加select-frame-set-input-focus。例如,在MS Windows中,它确实获得了焦点,因此不需要这样做。另外,命令描述并没有说框架变得聚焦。如果需要,可以创建一个不同的命令来调用它,然后聚焦框架。
提请
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.