+(require 'cl)
 (require 'dash)
 (require 'dash-functional)
 

            (setq available-windows
                  (-difference available-windows window-list))))))

    ;; Filter dead windows
    (setq available-windows
          (-remove (-not #'window-live-p) available-windows))

    ;; Pick among the remaining windows
    (when available-windows
      (let ((selected-window))
        ;; TODO: Look for an active one
        (setq selected-window (car available-windows))
        (window--display-buffer buffer
                                selected-window
                                'reuse
                                alist)))))

(defadvice display-buffer (around jail-window-hook activate)
  "Handles jailing the window"
  (if (jail-windows/active-p)
      (let ((display-buffer-overriding-action
                    '((jail-windows--display-buffer-override))))
               ad-do-it)
    (progn ad-do-it)))

;; TODO: (defadvice display-buffer-other-frame ...)?


;;; Layout Activation

(defun jail-windows--space-available-check (available-space
                                            minimum-space
                                            size
                                            ratio)
  "[Internal]"
  (if size
      (<= minimum-space
          (- available-space
             size))
    (when ratio
      (<= minimum-space
          (* (/ available-space
                ratio)
             (- 1.0 ratio))))))

(defun jail-windows--add-to-groups (window groups)
  "[Internal]"
  (when groups
