[ < ] [ > ]   [ << ] [Plus haut] [ >> ]         [Top] [Table des matières] [Index] [ ? ]

28.2 Splitting Windows

The functions described here are the primitives used to split a window into two windows. Two higher level functions sometimes split a window, but not always: pop-to-buffer and display-buffer (voir la section Displaying Buffers in Windows).

The functions described here do not accept a buffer as an argument. The two “halves” of the split window initially display the same buffer previously visible in the window that was split.

Command: split-window &optional window size horizontal

This function splits a new window out of window's screen area. It returns the new window.

If horizontal is non-nil, then window splits into two side by side windows. The original window window keeps the leftmost size columns, and gives the rest of the columns to the new window. Otherwise, it splits into windows one above the other, and window keeps the upper size lines and gives the rest of the lines to the new window. The original window is therefore the left-hand or upper of the two, and the new window is the right-hand or lower.

If window is omitted or nil, that stands for the selected window. When you split the selected window, it remains selected.

If size is omitted or nil, then window is divided evenly into two parts. (If there is an odd line, it is allocated to the new window.) When split-window is called interactively, all its arguments are nil.

If splitting would result in making a window that is smaller than window-min-height or window-min-width, the function signals an error and does not split the window at all.

The following example starts with one window on a screen that is 50 lines high by 80 columns wide; then it splits the window.

 
(setq w (selected-window))
     ⇒ #<window 8 on windows.texi>
(window-edges)          ; Edges in order:
     ⇒ (0 0 80 50)     ;   left--top--right--bottom

;; Returns window created
(setq w2 (split-window w 15))
     ⇒ #<window 28 on windows.texi>
(window-edges w2)
     ⇒ (0 15 80 50)    ; Bottom window;
                        ;   top is line 15
(window-edges w)
     ⇒ (0 0 80 15)     ; Top window

The screen looks like this:

 
         __________
        |          |  line 0
        |    w     |
        |__________|
        |          |  line 15
        |    w2    |
        |__________|
                      line 50
 column 0   column 80

Next, split the top window horizontally:

 
(setq w3 (split-window w 35 t))
     ⇒ #<window 32 on windows.texi>
(window-edges w3)
     ⇒ (35 0 80 15)  ; Left edge at column 35
(window-edges w)
     ⇒ (0 0 35 15)   ; Right edge at column 35
(window-edges w2)
     ⇒ (0 15 80 50)  ; Bottom window unchanged

Now the screen looks like this:

 
     column 35
         __________
        |   |      |  line 0
        | w |  w3  |
        |___|______|
        |          |  line 15
        |    w2    |
        |__________|
                      line 50
 column 0   column 80

Normally, Emacs indicates the border between two side-by-side windows with a scroll bar (voir la section Scroll Bars) or ‘|’ characters. The display table can specify alternative border characters; see Display Tables.

Command: split-window-vertically &optional size

This function splits the selected window into two windows, one above the other, leaving the upper of the two windows selected, with size lines. (If size is negative, then the lower of the two windows gets - size lines and the upper window gets the rest, but the upper window is still the one selected.) However, if split-window-keep-point (see below) is nil, then either window can be selected.

In other respects, this function is similar to split-window. In particular, the upper window is the original one and the return value is the new, lower window.

User Option: split-window-keep-point

If this variable is non-nil (the default), then split-window-vertically behaves as described above.

If it is nil, then split-window-vertically adjusts point in each of the two windows to avoid scrolling. (This is useful on slow terminals.) It selects whichever window contains the screen line that point was previously on.

This variable only affects the behavior of split-window-vertically. It has no effect on the other functions described here.

Command: split-window-horizontally &optional size

This function splits the selected window into two windows side-by-side, leaving the selected window on the left with size columns. If size is negative, the rightmost window gets - size columns, but the leftmost window still remains selected.

This function is basically an interface to split-window. You could define a simplified version of the function like this:

 
(defun split-window-horizontally (&optional arg)
  "Split selected window into two windows, side by side..."
  (interactive "P")
  (let ((size (and arg (prefix-numeric-value arg))))
    (and size (< size 0)
	 (setq size (+ (window-width) size)))
    (split-window nil size t)))
Function: one-window-p &optional no-mini all-frames

This function returns non-nil if there is only one window. The argument no-mini, if non-nil, means don't count the minibuffer even if it is active; otherwise, the minibuffer window is counted when it is active.

The argument all-frames specifies which frames to consider. Here are the possible values and their meanings:

nil

Count the windows in the selected frame, plus the minibuffer used by that frame even if it lies in some other frame.

t

Count all windows in all existing frames.

visible

Count all windows in all visible frames.

0

Count all windows in all visible or iconified frames.

anything else

Count precisely the windows in the selected frame, and no others.


[ < ] [ > ]   [ << ] [Plus haut] [ >> ]         [Top] [Table des matières] [Index] [ ? ]

Ce document a été généré par Eric Reinbold le 13 Octobre 2007 en utilisant texi2html 1.78.