help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Creating a bottom window?


From: TheFlyingDutchman
Subject: Re: Creating a bottom window?
Date: Wed, 08 Dec 2010 15:20:22 -0000
User-agent: G2/1.0

On Jul 22, 6:35 am, Elena <egarr...@gmail.com> wrote:
> Hello,
>
> how do you create a window as wide as its frame and positioned at the
> bottom, no matter how many windows are there at the moment? I mean, a
> window positioned like the `shrink-fit.el' in this 
> picture:http://www.emacswiki.org/emacs/DrewsEmacsWindowCallouts
>
> I've checked the ELisp reference about windows, but it seems you can
> just split existing windows.
>

I also don't see any other way to create a new window besides
splitting windows.

This code doesn't satisfy "no matter how many windows are there" - it
only handles 1 or 2 windows, and also assumes equal sized windows, so
may not be of any value. It does allow the number of bottom window
lines and bottom window buffer to be spacified.


; window lines seems to include the mode line
(setq bottom_window_lines 8)
(setq bottom_window_buffer "*scratch*")


(defun MakeBottomWindow ()
  (interactive)
  (let ( (num_windows (length (window-list nil 0 nil))) )
    (cond
     ( (= num_windows 1)
        (split-window-vertically (- (window-height)
                                    bottom_window_lines))
        (when (get-buffer bottom_window_buffer)
          (set-window-buffer (next-window)
                             bottom_window_buffer)  )
      )
    ( (= num_windows 2)
       (if (FrameHasTwoHorizontalWindows)
         (BottomWithTwoHorizontalWindows)
         (BottomWithTwoVerticalWindows)  )
    )
    ( (> num_windows 2)
      (message "MakeBottomWindow can't handle more than two windows")
      (beep)
    )
   )
  )
)

(defun BottomWithTwoHorizontalWindows ()
   (get-buffer-create " work")
   (delete-other-windows)
   (switch-to-buffer " work")
   (split-window-vertically (- (window-height)
                            bottom_window_lines))
   (split-window-horizontally)

   (set-window-buffer nil leftWindowBuffer)
   (other-window 1)
   (set-window-buffer nil rightWindowBuffer)
   (other-window 1)
   (when bottom_window_buffer
       (set-window-buffer nil
                        bottom_window_buffer)
   (other-window 1)  )
   (when rightWindowActive
     (other-window 1)  )
   (kill-buffer " work")
)

(defun BottomWithTwoVerticalWindows ()
   (unless topWindowActive
     (other-window 1)   )
   (shrink-window (round (/ bottom_window_lines 2)))
   (other-window 1)
   (split-window-vertically (- (window-height)1
                               bottom_window_lines))
   (when bottom_window_buffer
       (set-window-buffer (next-window)
                        bottom_window_buffer)  )
   (if topWindowActive
     (other-window -1)   )
)

(defun FrameHasTwoHorizontalWindows ()
"are there two side by side windows - from window-split-horizontally"
  (interactive)
  (setq currentWindow (next-window) )
  (setq windowList (window-list nil 0 nil))
  (setq window1Coords (window-edges (car windowList)))
  (setq window2Coords (window-edges (car (cdr windowList))))
  (if (/= (length windowList) 2)
     nil
     (if (= (car window1Coords) (car window2Coords))
          (progn
            (if (< (nth 1 window1Coords)
                   (nth 1 window2Coords) )
               (progn
                 (setq topWindow (car windowList) )
                 (setq bottomWindow (nth 1 windowList) )
               )
               (setq bottomWindow (car windowList) )
               (setq topWindow (nth 1 windowList) )
            )
            (if (eq (next-window) topWindow)
               (setq topWindowActive nil)
               (setq topWindowActive t)
            )
            nil
          )
          (if (< (car window1Coords) (car window2Coords) )
              (progn
                (setq leftWindow (car windowList) )
                (setq rightWindow (car (cdr windowList) ) )
              )
              (setq leftWindow (car (cdr windowList) ) )
              (setq rightWindow (car windowList) )
          )
          (setq leftWindowBuffer (window-buffer leftWindow) )
          (setq rightWindowBuffer (window-buffer rightWindow) )
          (if (eq (next-window) leftWindow)
               (setq rightWindowActive t)
               (setq rightWindowActive nil)
          )
          t
     )
  )
)


(global-set-key (kbd "<f8>") 'MakeBottomWindow)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]