버퍼를 나란히 분할하도록 Emacs 설정


92

많은 Emacs 기능이 자동으로 화면을 분할합니다. 그러나 그들은 모두 창문이 다른 창문 위에 놓 이도록 그렇게합니다. 대신 기본적으로 나란히 배치되도록 분할하는 방법이 있습니까?


12
이 질문에서 가로 및 세로 사용을 바꿉니다. 기본 동작은 가로로 분할하는 것입니다 (분할은 화면을 가로 지르는 가로선입니다).
Skilldrick

22
Cx 3은 나란히 창을 제공하는 명령에 대해 split-window-horizontally 명령을 실행하므로 동일한 명령을 사용하고 있습니다.
Nikwin

@Skilldrick "Vertical"및 "horizontal"은 모호하며 다르게 해석 될 수 있습니다. 그들은 디바이더의 방향 또는 파티션의 방향을 설명 할 수 있습니다. 나의 일반적인 경향은 원래 질문의 표현에 동의하는 것입니다 (즉, 일반적으로 "수직으로 분할"을 "수직 공간 분할"로 해석합니다).
jamesdlin

답변:


94
(setq split-height-threshold nil)
(setq split-width-threshold 0)

GNU Emacs Lisp 참조 매뉴얼 : 창 옵션 선택


8
이러한 기능은 분할 창 우선 함수에 영향을 미치는 방식과로 설정된 분할 창 인식 기능에 영향을 미치기 때문에 작동합니다. 문서를 읽으면 이러한 변수가 설정되는 방식을 알 수 있습니다. 기본적으로 수직 분할을 선호하는 사람들을 위해 시스템이 창을 수평으로 분할하는 것을 허용하지 않는 (setq split-width-threshold nil)을 사용할 수 있습니다.
Kendall Helmstetter Gelner

5
문서를 읽고 약간 놀아 본 후 split-height-threshold를 nil로 설정하고 split-width-threshold를 80으로 설정하여 먼저 수평으로 분할 할 수 있는지 확인한 다음 수직으로 만 시도합니다. 창문이 좁아지면 수직으로 만 분할되는 경우가 종종 있습니다.
Nikwin

이것은 매우 그럴듯하게 들립니다. 그러나 이것은 emacs의 GDB / GUD 통합에서는 작동하지 않습니다. 하나의 창을 가지고 디버거를 시작하면 emacs는 항상 수직으로 분할됩니다. 이를위한 GUD / GDB 관련 설정이 있습니까?
mefiX 2010

@Nikwin : 제 경우에이 솔루션은 "Cx 4 b"를 두 개의 80 열 창을 나란히 놓은 두 개로 제한합니다 (현재 화면 영역은 그 정도만 맞을 수 있음). "Cx 4 b"를 두 번 호출해도 수직으로 분할 된 새로운 "기타"창이 열리지 않습니다. 대신 현재 사용 가능한 "기타"창에서 버퍼를 엽니 다. 설명하신대로 어떻게 동작하도록 만들 수 있습니까 (가로로 시도한 다음 세로로 시도)?
avendael

이것은 내가 아는 익숙한 Cx 형식이 아닙니다. 이 명령을 어떻게 실행합니까?
user1552512

8

여기에 두 가지 솔루션, 원하는 것을 사용하십시오.

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에서 버퍼를 단정하게하지 않습니다
알퍼

4
(setq split-height-threshold 0) (setq split-width-threshold 0)

원하는 동작을 얻기 위해 사용해야하는 것입니다 (수평 분할 없음).



1

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과 같은 내용을 볼 수 있습니다. 2x3 그리드

이것은 아마도 더 잘 / 더 효율적으로 수행 될 수 있지만 시작이며 필요한 작업을 수행합니다 (순차적으로 명명 된 작은 파일 묶음 표시). 개선하거나 재사용하십시오.


1

여러 프로젝트를 위해 정기적으로 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")
당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.