2010-01-17 32 views
83

Birçok Emacs işlevi ekranı otomatik olarak böler. Bununla birlikte, hepsi dikey olarak yaparlar, (yani, biri diğerinin üstünde iki pencere yaparlar). Onları varsayılan olarak tamamen yatay olarak (yan yana) yapmak için herhangi bir yolu var mı?Emacs'i Yatay Olarak Ayarlama

+12

Bu soru yatay ve dikey kullanımını takas olur - varsayılan davranışı (bölünmüş ekran boyunca yatay bir çizgidir) yatay bölmek olduğunu söyleyebilirim. – Skilldrick

+21

C-x 3, yan yana pencereleri veren komut için bölme-pencere-yatay olarak komutu çalıştırır, ben de aynı şeyi kullanıyorum. – Nikwin

+0

@Skilldrick "Dikey" ve "yatay" belirsizdir ve farklı şekilde yorumlanabilir; Bölenin nasıl yönlendirildiğini veya bölümlerin nasıl yönlendirildiğini açıklayabilirler. Normal eğilimim, orijinal sorunun metnini kabul etmektir (yani, dikey olarak "dikey uzayı bölme" olarak yorumluyorum). – jamesdlin

cevap

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

GNU Emacs Lisp Referans Manuel: Choosing Window Options

+7

Not: Bu işlevin, bölünmüş pencere tercihli işlevini ve ayarlanan bölünmüş pencere duyarlı işlevini nasıl etkilediklerinden ötürü unutmayın - bunun için dokümanı okuyorsanız, bu değişkenlerin ayarlanan şeyleri nasıl etkilediğini öğrenebilirsiniz. Varsayılan olarak dikey bölmeyi tercih edenler için, sistemin pencereleri yatay olarak bölmesine izin vermeyen (setq split-width-threshold nil) kullanabiliriz. –

+5

Dokümanları okuduktan ve bir parça çevirdikten sonra, bölünmüş yükseklik eşiğini sıfır olarak ayarladım ve bölünmüş genişlik eşiğini 80'e getirdim, böylece ilk önce yatay olarak bölünüp bölünmeyeceğini ve sadece dikey olarak deneyip denemeyeceğini görecek. Sadece dikey olarak bölünmesi, pencerelerin daralmasıyla sıklıkla çirkinleşir. – Nikwin

+0

Bu çok mantıklı geliyor. Ancak, bu emacs GDB/GUD entegrasyonu için çalışmıyor. Tek bir pencerem varsa, hata ayıklayıcısını başlatın, emacs her zaman dikey olarak böler. Bunun için GUD/GDB'ye özgü bir ayar var mı? – mefiX

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

i (hayır yatay yarma)

1

nil 2 değişkenleri ayarlayarak basit cevabı istenilen davranışı elde etmek kullanmak zorunda budur ve 0 benim için işe yaramadı, bu yüzden 2 basit fonksiyon yazdım: biri sadece pencereyi NX dikey arabelleklere böler ve (örneğin) dosya.1 dosya.2 dosya.NX (her biri diğeride) adlı dosyaları açar aynı düşüncenin dışında, 2 boyutlu (NX sütunlar f ile NY satırları hariç) veya dosya açma f.1 f.2 ... f. [NX * NY]). yüklemek için, .emacs bu kodu ekleyin: dikey birini kullanmak sonra

(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) 
     ) 
     ) 
    ) 

ve ben * sıfırdan * (C-x b *scratch* RET, C-x 1) daha sonra (grid-files-h 3 20 "file.")C-x C-e yılında, tip veya istediğiniz olmadığını test etmek gitmek tek bir kare, C-x 1, tip (grid-files-sq 2 15 3 20 "f.") ve daha sonra C-x C-e qrid ve 2x3 grid

Bu muhtemelen yapılabilir daha iyi/daha verimli, ama bu bir başlangıç ​​ve bunu yapmak gerekir yapar (ekran gibi bir şey göreceksiniz sıralı küçük dosyalar olarak adlandırılan bir demet). İyileştirmek veya yeniden kullanmakta özgürsünüz.

4

İki çözümleri burada "Cc y" anahtarı bağlamak, istediğiniz herhangi birini kullanın:

A: Dikey (sol/sağ)

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

B: varsayılan olarak otomatik bölünmüş pencerede dikey (sol/sağ) geçerli pencere genişliğinde ise Yeterince

(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) 

Eğer .emacs/init.el dosyada herhangi birini koyun. Ekranınıza bağlı olarak "100" değerini istediğiniz değere değiştirebilirsiniz.

(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) 

, sizin .emacs/init.el dosyada koy için C-x 4 t kullanın: bir çerçevedeki iki pencere var ve siz yatay veya yardımcısı ayet dikey iken düzenini değiştirmek isterseniz

, burada bir çözümdür pencerelerinizin düzenini değiştirmek.

1

Farklı projeler için düzenli olarak birkaç çerçeveyi (OSX pencereleri) emacs'te kullanıyorum. İşte başlangıçta sol ve sağ bir pencereye bölünmüş birkaç kare kuruyorum.

(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") 
İlgili konular