很多Emacs功能会自动拆分屏幕.然而,它们都这样做,使得窗户是一个在另一个之上.是否有任何方法可以将它们分开,以便默认情况下它们是并排的?
off*_*by1 90
(setq split-height-threshold nil)
(setq split-width-threshold 0)
Run Code Online (Sandbox Code Playgroud)
GNU Emacs Lisp参考手册:选择窗口选项
这里有两个解决方案,使用你喜欢的任何一个
答:默认情况下垂直(左/右):
(setq split-height-threshold nil)
(setq split-width-threshold 0)
Run Code Online (Sandbox Code Playgroud)
B:如果当前窗口足够宽,则自动垂直(左/右)分割窗口
(defun display-new-buffer (buffer force-other-window)
"If BUFFER is visible, select it.
If it's not visible and there's only one window, split the
current window and select BUFFER in the new window. If the
current window (before the split) is more than 100 columns wide,
split horizontally(left/right), else split vertically(up/down).
If the current buffer contains more than one window, select
BUFFER in the least recently used window.
This function returns the window which holds BUFFER.
FORCE-OTHER-WINDOW is ignored."
(or (get-buffer-window buffer)
(if (one-window-p)
(let ((new-win
(if (> (window-width) 100)
(split-window-horizontally)
(split-window-vertically))))
(set-window-buffer new-win buffer)
new-win)
(let ((new-win (get-lru-window)))
(set-window-buffer new-win buffer)
new-win))))
;; use display-buffer-alist instead of display-buffer-function if the following line won't work
(setq display-buffer-function 'display-new-buffer)
Run Code Online (Sandbox Code Playgroud)
把任何一个放在你的.emacs/init.el文件中.您可以将"100"更改为您喜欢的值,具体取决于您的屏幕.
如果您在一个框架中有两个窗口,并且您想要将布局从垂直更改为水平或反之,那么这是一个解决方案:
(defun toggle-window-split ()
(interactive)
(if (= (count-windows) 2)
(let* ((this-win-buffer (window-buffer))
(next-win-buffer (window-buffer (next-window)))
(this-win-edges (window-edges (selected-window)))
(next-win-edges (window-edges (next-window)))
(this-win-2nd
(not (and (<= (car this-win-edges)
(car next-win-edges))
(<= (cadr this-win-edges)
(cadr next-win-edges)))))
(splitter
(if (= (car this-win-edges)
(car (window-edges (next-window))))
'split-window-horizontally
'split-window-vertically)))
(delete-other-windows)
(let ((first-win (selected-window)))
(funcall splitter)
(if this-win-2nd (other-window 1))
(set-window-buffer (selected-window) this-win-buffer)
(set-window-buffer (next-window) next-win-buffer)
(select-window first-win)
(if this-win-2nd (other-window 1))))))
;; C-x 4 t 'toggle-window-split
(define-key ctl-x-4-map "t" 'toggle-window-split)
Run Code Online (Sandbox Code Playgroud)
将它放在您的.emacs/init.el文件中,C-x 4 t用于切换窗口的布局.