2010-01-17 6 views
83

Muchas de las funciones de Emacs dividen automáticamente la pantalla. Sin embargo, todos lo hacen verticalmente (es decir, hacen dos ventanas, una encima de la otra). ¿Hay alguna manera de hacer que todos se dividan horizontalmente (uno al lado del otro) de forma predeterminada? ManualConfiguración de Emacs Dividir en Horizontal

+12

Yo cambiaría el uso de horizontal y vertical en esta pregunta - Yo diría que el comportamiento predeterminado es dividir horizontalmente (la división es una línea horizontal en la pantalla). – Skilldrick

+21

C-x 3 ejecuta el comando split-window-horizontally, para el comando que da ventanas una al lado de la otra, así que estoy usando la misma. – Nikwin

+0

@Skilldrick "Vertical" y "horizontal" son ambiguos y podrían interpretarse de manera diferente; podrían describir cómo está orientado el divisor o cómo están orientadas las particiones. Mi inclinación normal es estar de acuerdo con la redacción de la pregunta original (es decir, normalmente interpretaría "dividir verticalmente" como "dividir el espacio vertical"). – jamesdlin

Respuesta

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

GNU Emacs Lisp Referencia: Choosing Window Options

+7

Tenga en cuenta que esto funciona debido a cómo afectan a split-window-preferred-function y la función de ventana dividida sensible que se establece en - si lee los documentos para eso, puede descubrir cómo afectan estas variables. Para aquellos de nosotros que preferimos la división vertical por defecto, podemos simplemente usar (setq split-width-threshold nil) que no permite que el sistema divida las ventanas horizontalmente. –

+5

Después de leer los documentos y jugar un poco, he establecido el umbral de altura dividida en cero y el umbral de ancho dividido en 80 para que primero vea si puede dividirse horizontalmente y solo luego intentarlo verticalmente. Tenerlo dividido verticalmente a menudo simplemente se pone feo cuando las ventanas se vuelven estrechas. – Nikwin

+0

Esto suena muy plausible. Sin embargo, esto no funciona para la integración de GDB/GUD en emacs. Si tengo una sola ventana, inicie el depurador, emacs siempre se divide verticalmente. ¿Hay alguna configuración específica de GUD/GDB para eso? – mefiX

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

es lo que tenía que utilizar para obtener el comportamiento deseado (sin división horizontal)

1

la respuesta sencilla de configurar 2 variables a cero y 0 no funcionó para mí, así que escribí 2 funciones simples: una simplemente divide la ventana en búferes verticales NX y abre archivos llamados (por ejemplo) archivo.1 archivo.2 ... archivo.NX en cada uno y en otro piensa lo mismo, excepto que lo hace en 2D (filas NY por columnas NX f o abriendo archivos f.1 f.2 ... f. [NX * NY]). Para instalar, agregue este código a .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) 
     ) 
     ) 
    ) 

y después de usar el vertical, voy a cero * * (C-x b *scratch* RET, C-x 1), el tipo de (grid-files-h 3 20 "file.") continuación C-x C-e, o si usted quiere poner a prueba la plaza qrid uno, C-x 1, el tipo de (grid-files-sq 2 15 3 20 "f.") y luego C-x C-e y debería ver algo como 2x3 grid

Esto probablemente se puede hacer mejor/más eficiente, pero es un comienzo y lo hace lo que necesito que haga (pantalla un grupo de pequeños archivos secuencialmente nombrados). Siéntase libre de mejorar o reutilizar.

4

Dos soluciones aquí, utilice cualquiera te gusta:

A: verticalmente (izquierda/derecha) por defecto:

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

B: ventana dividida verticalmente automáticamente (izquierda/derecha) si la ventana actual es amplia lo suficientemente

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

poner uno en cualquier archivo que .emacs/init.el. Puede cambiar el "100" al valor que desee, dependiendo de su pantalla.

Si usted tiene dos ventanas en un marco, y desea cambiar el diseño de vertical a verso horizontal o vicio, aquí es una solución:

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

ponerlo en su archivo .emacs/init.el, el uso C-x 4 t a alternar el diseño de sus ventanas.

1

Uso varios marcos (ventanas OSX) en emacs regularmente para diferentes proyectos. Así es como configuré algunos fotogramas inicialmente divididos en una ventana izquierda y derecha.

(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") 
Cuestiones relacionadas