web-dev-qa-db-fra.com

Définition d'Emacs pour diviser les tampons côte à côte

De nombreuses fonctions Emacs divisent automatiquement l'écran. Cependant, ils le font tous de telle sorte que les fenêtres sont superposées. Existe-t-il un moyen de les diviser de sorte qu'ils soient côte à côte par défaut à la place?

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

Manuel de référence GNU Emacs LISP: Choix des options de fenêtre

90
offby1

Deux solutions ici, utilisez celle que vous aimez:

A: verticalement (gauche/droite) par défaut:

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

B: Fractionner automatiquement la fenêtre verticalement (gauche/droite) si la fenêtre actuelle est suffisamment large

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

Mettez quelqu'un en vous .emacs/init.el fichier. Vous pouvez changer le "100" à la valeur que vous aimez, selon votre écran.

Si vous avez deux fenêtres dans un cadre et que vous souhaitez modifier la disposition de vertical à horizontal ou vice versa, voici une solution:

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

Mettez-le dans votre .emacs/init.el fichier, utilisez C-x 4 t pour changer la disposition de vos fenêtres.

5
CodyChan
(setq split-height-threshold 0) (setq split-width-threshold 0)

est ce que j'ai dû utiliser pour obtenir le comportement souhaité (pas de division horizontale)

4
eoj

Parfois, nous devons changer entre horizontal et vertical en fonction de l'affichage actuel et de nos besoins (plus de lignes ou plus de colonnes).

Je recommande le grand ToggleWindowSplit , et je lie la clé à "C-c y"

http://www.emacswiki.org/emacs/ToggleWindowSplit

4
whunmr

la réponse simple consistant à définir 2 variables sur nil et 0 n'a pas fonctionné pour moi, j'ai donc écrit 2 fonctions simples: l'une divise simplement la fenêtre en tampons verticaux NX et ouvre les fichiers nommés (par exemple) file.1 file.2 .. . file.NX dans chacun et un autre fait la même chose, sauf qu'il le fait en 2D (lignes NY par colonnes NX pour ouvrir les fichiers f.1 f.2 ... f. [NX * NY]). Pour installer, ajoutez ce code à .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)
          )
        )
      )

puis pour utiliser le vertical, je vais * gratter * (C-x b *scratch* RET, C-x 1), tapez (grid-files-h 3 20 "file.") puis C-x C-e, ou si vous voulez tester le carré qrid, C-x 1, tapez (grid-files-sq 2 15 3 20 "f.") puis C-x C-e et vous devriez voir quelque chose comme 2x3 grid

Cela peut probablement être fait mieux/plus efficacement, mais c'est un début et il fait ce dont j'ai besoin (afficher un tas de petits fichiers nommés séquentiellement). N'hésitez pas à améliorer ou réutiliser.

1
alexey

J'utilise régulièrement plusieurs cadres (fenêtres OSX) dans emacs pour différents projets. Voici comment configurer quelques images initialement divisées en une fenêtre gauche et droite.

  (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")
1
Jason