更清晰的删除窗口的替代方法? [英] A smarter alternative to delete-window?
问题描述
有时我会为同一个缓冲区打开多个窗口(或类似的窗口),我必须区分窗口中的缓冲区是否与另一个缓冲区相同,然后再决定是否将其删除或删除窗口。 p>
只有缓冲存在于另一个窗体中,emacs中是否只能简单地删除一个窗口?理想情况下,我希望同样的功能也可以杀死缓冲区和窗口,如果它是窗口中缓冲区的唯一实例。
这是我正在寻找的行为。感谢您帮助基本功能介绍和逻辑。 Elisp仍然非常混乱,我很欣赏通过粗糙点的帮助。
查看解释行为的代码somment。您也应该能够直接从来源了解。
我已经对您以前的答案进行了投票,其中包含了我使用的大部分代码。 >
;;;删除所选择的窗口,而不会在缓冲区打开时杀死缓冲区
;;;在另一个;否则关闭窗口及其缓冲区。如果调用
;;;最后一个可见的窗口,然后缓冲区将被简单地杀死并替换为
;;;下一个可用缓冲区。
(defun delete-window-maybe-kill-buffer()
删除所选窗口
如果没有其他窗口显示其缓冲区,也可以杀死缓冲区。
(interactive )
(let *((selwin(selected-window))
(buf(window-buffer selwin)))
(if(& ))
(delete-window selwin)
(除非(get-buffer-window buf'visible)(kill-buffer buf))
(kill-buffer buf)))
Sometimes I get multiple windows open for the same buffer (or a similar one) and I have to differentiate whether or not the buffer in the window is the same as another before deciding to either kill it or delete the window.
Is there a way in emacs to simply delete a window only if the buffer exists already in another? Ideally I would like the same function to also kill the buffer and the window if it is the only instance of the buffer in a window.
This is the behavior I was looking for. Thank you for helping with the basic function layour and logic. Elisp is still very confusing to work with and I appreciate help with getting through the rough spots.
See the code somment which explains the behavior. You should also be able to understand it directly from the source.
I've up-voted your previous answer which includes the bulk of the code I used.
;;; Delete the selected window without killing the buffer if the buffer is open
;;; in another; otherwise close the window and its buffer. If called on the
;;; last visible window then the buffer will simply be killed and replaced by
;;; the next available buffer.
(defun delete-window-maybe-kill-buffer ()
"Delete selected window.
If no other window shows its buffer, kill the buffer too."
(interactive)
(let* ((selwin (selected-window))
(buf (window-buffer selwin)))
(if (> (length (window-list)) 1)
(delete-window selwin)
(unless (get-buffer-window buf 'visible) (kill-buffer buf))
(kill-buffer buf))))
这篇关于更清晰的删除窗口的替代方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!