Possible layout-outlines - ECB - the Emacs Code Browser
Description: ECB - the Emacs Code Browser

Next: The layout-engine API, Previous: Programming special windows, Up: The layout-engine

#### 11.5.3 The wide range of possible layout-outlines

In the two previous sections Programming a new layout and Programming special windows we have explained in detail how to program new layouts and how to program new special windows/buffers and adding them to a new layout.

The intention of this section is to be a summary what are the real restrictions for a new layout-outline programmed with `ecb-layout-define`. This is necessary because until now we just programmed “obvious” layouts, means layout which are in principle very similar to the standard ones which means one big edit-window and some special windows “around” this edit-window. This section will show you that a layout can have also very different outlines.

OK, here are the real restrictions and conditions for a layout programmed with `ecb-layout-define`:

1. It must have exactly one edit-window regardless of its size. The user of this layout can later split this edit-window in as many edit-windows as he like.
2. All other windows created within the CREATE-CODE body of `ecb-layout-define` (see Programming a new layout) must be dedicated to their buffers.
3. All the dedicated windows must (exclusive!) either reside on the left, right, top or left-and-right side of the edit-window. This will be defined with the TYPE-argument of `ecb-layout-define` (see Programming a new layout).

You see, there are only three restrictions/conditions. These and only these must be fulfilled at layout-programming.

Demonstrating what this really means and how flexible the layout-engine of ECB really is, can be done best with some “pathological” layout-outlines. All the following are correct layouts (working code is added below each layout):

The following is a top layout with three vertical layered special windows.

       ------------------------------------------------------------------
       |                                                                |
       |                 Upper special window (a tree-buffer)           |
       |                                                                |
       |----------------------------------------------------------------|
       |                                                                |
       |                 Middle special window (no tree-buffer)         |
       |                                                                |
       |----------------------------------------------------------------|
       |                                                                |
       |                 Lower special window (a tree-buffer)           |
       |                                                                |
       |================================================================|
       |                                                                |
       |                         Edit-area                              |
       |      (can be splitted by the user in several edit-windows)     |
       ------------------------------------------------------------------
       |                                                                |
       |                 Compilation-window (optional)                  |
       |                                                                |
       ------------------------------------------------------------------

Here is the code for that top layout (all buffers are dummy-buffers):

       ;; The "window dedicator to buffer" functions:

       (defecb-window-dedicator-to-ecb-buffer ecb-set-usw-buffer
          upper-special-window-buffer-name t
         (switch-to-buffer (get-buffer-create "Upper special window")))

       (defecb-window-dedicator-to-ecb-buffer ecb-set-msw-buffer
          middle-special-window-buffer-name nil
         (switch-to-buffer (get-buffer-create "Middle special window")))

       (defecb-window-dedicator-to-ecb-buffer ecb-set-lsw-buffer
          lower-special-window-buffer-name t
         (switch-to-buffer (get-buffer-create "Lower special window")))

       ;; The layout itself:

       (ecb-layout-define "example-layout3" top
         nil

         ;; here we have an edit-window and above one top window which we can
         ;; now split in several other windows. Dependent on the value of
         ;; `ecb-compile-window-height' we have also a compile-window at the
         ;; bottom.

         (ecb-set-usw-buffer)
         (ecb-split-ver 0.33)
         (ecb-set-msw-buffer)
         (ecb-split-ver 0.5)
         (ecb-set-lsw-buffer)

         ;; select the edit-window.
         (select-window (next-window)))

The following is a left-right layout which has six special windows in the left-”column” and one big special window in the right-”column”. For left-right layouts the left-”column” and the right-”column” have always the same width.

       ------------------------------------------------------------------
       |             |       |                   |                      |
       | Left1       | Left5 |                   |                      |
       |             |       |                   |                      |
       |-------------|       |                   |                      |
       |      |      |       |                   |                      |
       |      |      |       |                   |                      |
       |      |      |       |                   |                      |
       | Left2| Left3|-------|     Edit-area     |   Right1             |
       |      |      |       | (can be splitted  |                      |
       |      |      |       |  in several edit- |                      |
       |      |      |       |      windows)     |                      |
       |-------------|       |                   |                      |
       |             |       |                   |                      |
       | Left4       | Left6 |                   |                      |
       |             |       |                   |                      |
       ------------------------------------------------------------------
       |                                                                |
       |                 Compilation-window (optional)                  |
       |                                                                |
       ------------------------------------------------------------------

Here is the code for that left-right layout, again with dummy-buffers (depending to your screen-resolution you will need a quite big value for `ecb-windows-width`, e.g. 0.4):

Here is one of the “window dedicator for buffer”-functions1:

       (defvar buffer-name-left1 "left1")

       ;; Note that the third argument muts be not nil if the ecb-window should
       ;; display an ecb-buffer of type tree-buffer!
       (defecb-window-dedicator-to-ecb-buffer ecb-set-left1-buffer buffer-name-left1 nil
         (switch-to-buffer (get-buffer-create "Left1")))

Here is the layout-definition itself:

       (ecb-layout-define "example-layout2" left-right
         nil

         ;; here we have an edit-window and left and right two windows each
         ;; with width `ecb-windows-width'. Dependent to the value of
         ;; `ecb-compile-window-height' we have also a compile-window at the
         ;; bottom.

         (ecb-set-left1-buffer)
         (ecb-split-hor 0.66 t)
         (ecb-split-ver 0.75)
         (ecb-set-left4-buffer)
         (select-window (previous-window (selected-window) 0))
         (ecb-split-ver 0.25 nil t)
         (ecb-set-left2-buffer)
         (ecb-split-hor 0.5)
         (ecb-set-left3-buffer)
         (select-window (next-window (next-window)))
         (ecb-set-left5-buffer)
         (ecb-split-ver 0.5)
         (ecb-set-left6-buffer)
         (select-window (next-window (next-window)))
         (ecb-set-right1-buffer))

         ;; select the edit-window
         (select-window (previous-window (selected-window) 0)))

Especially the last example should demonstrate that even very complicated layouts are easy to program with `ecb-layout-define`. If such layouts are senseful is another topic ;-)

#### Footnotes

[1] The “window dedicators” for all these ecb-windows/buffers are not explicitly described - they look all like `ecb-set-left1-buffer` - of course with different buffer-names!