많은 Emacs 기능이 자동으로 화면을 분할합니다. 그러나 그들은 모두 창문이 다른 창문 위에 놓 이도록 그렇게합니다. 대신 기본적으로 나란히 배치되도록 분할하는 방법이 있습니까?
많은 Emacs 기능이 자동으로 화면을 분할합니다. 그러나 그들은 모두 창문이 다른 창문 위에 놓 이도록 그렇게합니다. 대신 기본적으로 나란히 배치되도록 분할하는 방법이 있습니까?
답변:
(setq split-height-threshold nil)
(setq split-width-threshold 0)
GNU Emacs Lisp 참조 매뉴얼 : 창 옵션 선택
여기에 두 가지 솔루션, 원하는 것을 사용하십시오.
A : 기본적으로 세로 (왼쪽 / 오른쪽) :
(setq split-height-threshold nil)
(setq split-width-threshold 0)
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)
.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)
당신에 넣어 .emacs/init.el파일을 사용 C-x 4 t하여 Windows의 레이아웃을 전환합니다.
undo-tree누르기 를 사용했을 때 솔루션보기 q에서 버퍼를 단정하게하지 않습니다
때때로 우리는 현재 디스플레이와 요구 사항 (더 많은 라인 또는 더 많은 열)에 따라 수평과 수직 사이를 변경해야합니다.
나는 위대한 ToggleWindowSplit을 추천 하고 키를 "Cc y"에 바인딩합니다.
2 개의 변수를 nil로 설정하고 0으로 설정하는 간단한 대답은 저에게 효과가 없었기 때문에 2 개의 간단한 함수를 작성했습니다. 하나는 창을 NX 수직 버퍼로 분할하고 file.1 file.2라는 이름의 파일을 엽니 다. . file.NX는 2D (파일 f.1 f.2 ... f. [NX * NY])를 여는 NX 열의 NY 행을 제외하고는 동일한 생각을합니다. 설치하려면 다음 코드를 .emacs에 추가하십시오.
(defun grid-files-h (nx wx pfx)
"Using dotimes, split the window into NX side-by-side buffers of width WX and load files starting with prefix PFX and ending in numbers 1 through NX"
(let (ox fn k) ; ox is not used, but fn is used to store the filename, and k to store the index string
(dotimes (x (- nx 1) ox) ; go through buffers, x goes from 0 to nx-2 and ox is not used here
; (print x)
(setq k (number-to-string (+ x 1) ) ) ; k is a string that goes from "1" to "nx-1"
; (print k)
(setq fn (concat pfx k) ) ; fn is filename - concatenate prefix with k
; (print fn)
(find-file fn) ; open the filename in current buffer
(split-window-horizontally wx) ; split window (current buffer gets wx-columns)
(other-window 1) ; switch to the next (right) buffer
)
(setq k (number-to-string nx )) ; last (rightmost) buffer gets the "nx" file
(setq fn (concat pfx k) ) ; fn = "pfx"+"nx"
(find-file fn ) ; open fn
(other-window 1) ; go back to the first buffer
)
)
(defun grid-files-sq (ny wy nx wx pfx)
"Using dotimes, split the window into NX columns of width WX and NY rows of height WY and load files starting with prefix PFX and ending in numbers 1 through NX*NY"
(let (oy ox fn k)
(dotimes (y ny oy) ; go through rows, y goes from 0 to ny-1 and oy is not used here
(split-window-vertically wy) ; create this row
(dotimes (x (- nx 1) ox) ; go through columns, x goes from 0 to nx-2 and ox is not used here
(setq k (number-to-string (+ 1 (+ x (* y nx) ) ) ) ) ; k must convert 2 indecies (x,y) into one linear one (like sub2ind in matlab)
(setq fn (concat pfx k) ) ; filename
(find-file fn ) ; open
(split-window-horizontally wx) ; create this column in this row (this "cell")
(other-window 1) ; go to the next buffer on the right
)
(setq k (number-to-string (+ nx (* y nx) ) ) ) ; rightmost buffer in this row needs a file too
(setq fn (concat pfx k) ) ; filename
(find-file fn ) ; open
(other-window 1) ; go to next row (one buffer down)
)
)
)
그런 다음 세로 형을 사용하려면 * scratch * ( C-x b *scratch* RET, C-x 1) 로 이동하여 (grid-files-h 3 20 "file.")then을 입력 C-x C-e하거나 사각형 qrid를 테스트하려면을 C-x 1입력 (grid-files-sq 2 15 3 20 "f.")한 다음 다음 C-x C-e과 같은 내용을 볼 수 있습니다.

이것은 아마도 더 잘 / 더 효율적으로 수행 될 수 있지만 시작이며 필요한 작업을 수행합니다 (순차적으로 명명 된 작은 파일 묶음 표시). 개선하거나 재사용하십시오.
여러 프로젝트를 위해 정기적으로 emacs에서 여러 프레임 (OSX 창)을 사용합니다. 처음에 왼쪽 및 오른쪽 창으로 분할 된 몇 개의 프레임을 설정하는 방법은 다음과 같습니다.
(defun make-maximized-split-frame (name)
(let (( f (make-frame (list (cons 'name name))) ))
(maximize-frame f)
(split-window (frame-root-window f) nil t)
))
(make-maximized-split-frame "DocRaptor")
(make-maximized-split-frame "Gauges")
(make-maximized-split-frame "Instrumental")