* Creating a bottom window? @ 2010-07-22 13:35 Elena 2010-07-22 20:15 ` Pascal J. Bourguignon 2010-07-23 14:18 ` TheFlyingDutchman 0 siblings, 2 replies; 6+ messages in thread From: Elena @ 2010-07-22 13:35 UTC (permalink / raw) To: help-gnu-emacs 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. Thanks. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Creating a bottom window? 2010-07-22 13:35 Creating a bottom window? Elena @ 2010-07-22 20:15 ` Pascal J. Bourguignon 2010-07-23 14:18 ` TheFlyingDutchman 1 sibling, 0 replies; 6+ messages in thread From: Pascal J. Bourguignon @ 2010-07-22 20:15 UTC (permalink / raw) To: help-gnu-emacs Elena <egarrulo@gmail.com> writes: > 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. If you just want to reproduce the windows show in that picture: C-x 1 C-x 2 C-x 3 If you want to have automatically a specific windows at the bottom, even when you type C-x 1, or C-x 3 in that bottom window, I would suggest to add code in the window-configuration-change-hook to check the windows and re-arrange them or re-create the bottom window everytime it's needed. (See the function window-tree and window-parameters). Otherwise, you may explore (in emacs sources) the mini-buffer, which stays at the bottom. -- __Pascal Bourguignon__ http://www.informatimago.com/ ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Creating a bottom window? 2010-07-22 13:35 Creating a bottom window? Elena 2010-07-22 20:15 ` Pascal J. Bourguignon @ 2010-07-23 14:18 ` TheFlyingDutchman 2010-07-23 14:25 ` TheFlyingDutchman 2010-07-23 16:39 ` Pascal J. Bourguignon 1 sibling, 2 replies; 6+ messages in thread From: TheFlyingDutchman @ 2010-07-23 14:18 UTC (permalink / raw) To: help-gnu-emacs 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) ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Creating a bottom window? 2010-07-23 14:18 ` TheFlyingDutchman @ 2010-07-23 14:25 ` TheFlyingDutchman 2010-07-23 15:20 ` TheFlyingDutchman 2010-07-23 16:39 ` Pascal J. Bourguignon 1 sibling, 1 reply; 6+ messages in thread From: TheFlyingDutchman @ 2010-07-23 14:25 UTC (permalink / raw) To: help-gnu-emacs should have been: (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") ) ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Creating a bottom window? 2010-07-23 14:25 ` TheFlyingDutchman @ 2010-07-23 15:20 ` TheFlyingDutchman 0 siblings, 0 replies; 6+ messages in thread From: TheFlyingDutchman @ 2010-07-23 15:20 UTC (permalink / raw) To: help-gnu-emacs There was an inadvertent "1" in this function. (defun BottomWithTwoVerticalWindows () (unless topWindowActive (other-window 1) ) (shrink-window (round (/ bottom_window_lines 2))) (other-window 1) (split-window-vertically (- (window-height) bottom_window_lines)) (when bottom_window_buffer (set-window-buffer (next-window) bottom_window_buffer) ) (if topWindowActive (other-window -1) ) ) ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Creating a bottom window? 2010-07-23 14:18 ` TheFlyingDutchman 2010-07-23 14:25 ` TheFlyingDutchman @ 2010-07-23 16:39 ` Pascal J. Bourguignon 1 sibling, 0 replies; 6+ messages in thread From: Pascal J. Bourguignon @ 2010-07-23 16:39 UTC (permalink / raw) To: help-gnu-emacs TheFlyingDutchman <zzbbaadd@aol.com> writes: > 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. Here is how I would do it. The following code gets the window-tree, and walks it to build a lisp expression that will delete and re-split windows so that a new window is created at the bottom. It would need to be completed with the saving and restoring of more window parameters, and to be more precise. For example, I note a shift in the position of the vertical splits which must be due to the difference between window-width and what split-window takes as size argument in this case. Also, before deleting and spliting windows, the size should be checked, and windows resized to accomodate the new one. ;;;; -*- mode:emacs-lisp;coding:utf-8 -*- ;;;;************************************************************************** ;;;;FILE: window-pane.el ;;;;LANGUAGE: emacs lisp ;;;;SYSTEM: POSIX ;;;;USER-INTERFACE: NONE ;;;;DESCRIPTION ;;;; ;;;; A sketch for split-bottom. ;;;; ;;;;AUTHORS ;;;; <PJB> Pascal J. Bourguignon <pjb@informatimago.com> ;;;;MODIFICATIONS ;;;; 2010-07-23 <PJB> Created. ;;;;BUGS ;;;;LEGAL ;;;; GPL ;;;; ;;;; Copyright Pascal J. Bourguignon 2010 - 2010 ;;;; ;;;; This program is free software; you can redistribute it and/or ;;;; modify it under the terms of the GNU General Public License ;;;; as published by the Free Software Foundation; either version ;;;; 2 of the License, or (at your option) any later version. ;;;; ;;;; This program is distributed in the hope that it will be ;;;; useful, but WITHOUT ANY WARRANTY; without even the implied ;;;; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ;;;; PURPOSE. See the GNU General Public License for more details. ;;;; ;;;; You should have received a copy of the GNU General Public ;;;; License along with this program; if not, write to the Free ;;;; Software Foundation, Inc., 59 Temple Place, Suite 330, ;;;; Boston, MA 02111-1307 USA ;;;;************************************************************************** (require 'cl) (require 'eieio) (defclass pane () ((left :initform nil :initarg :left :accessor pane-left) (top :initform nil :initarg :top :accessor pane-top) (width :initform nil :initarg :width :accessor pane-width) (height :initform nil :initarg :height :accessor pane-height))) (defclass emacs-window (pane) ((window :initarg :window :accessor emacs-window-window))) (defclass horizontal-splits (pane) ((subpanes :initarg :subpanes :accessor pane-subpanes)) (:documentation "Subpanes are one above the other, the first topmost.")) (defclass frame-pane (horizontal-splits) () ;; TODO: what about frames without a mini-buffer? (:documentation "Contains only the main pane and the mini-buffer")) (defclass vertical-splits (pane) ((subpanes :initarg :subpanes :accessor pane-subpanes)) (:documentation "Subpanes are side by side, the first leftmost.")) (defun window-tree-to-pane (tree) "Convert a window tree into a pane tree." (if (windowp tree) (make-instance 'emacs-window :width (window-width tree) :height (window-height tree) :window tree) (destructuring-bind (horizontalp (left top width height) &rest subpanes) tree (make-instance (if horizontalp 'horizontal-splits 'vertical-splits) :left left :top top :width width :height height :subpanes (mapcar (function window-tree-to-pane) subpanes))))) (defun window-pane (&optional frame) (let* ((frame (or frame (selected-frame))) (tree (window-tree frame))) ;; TODO: see what window-tree returns for frames without a mini-buffer. (make-instance 'frame-pane :width (frame-width frame) :height (frame-height frame) :subpanes (list (window-tree-to-pane (first tree)) (window-tree-to-pane (second tree)))))) (defmethod split-bottom ((self frame-pane) size) "SIZE is the size of the bottom frame to be created." (split-bottom (first (pane-subpanes self)) size)) (defmethod split-bottom ((self horizontal-splits) size) (eval (split-bottom-command self size))) (defmethod split-bottom ((self vertical-splits) size) (eval (split-bottom-command self size))) (defmethod split-bottom ((self emacs-window) size) (eval (split-bottom-command self size))) (defmethod split-bottom-command ((self horizontal-splits) size) (split-bottom-command (first (last (pane-subpanes self))) size)) (defmethod split-bottom-command ((self vertical-splits) size) (let ((deletes (delete-subpane-command self))) `(progn ,@(cddr deletes) (split-window ,(second (second deletes)) ,(- (pane-height self) size) nil) ,(recreate-subpane-command self)))) (defmethod split-bottom-command ((self emacs-window) size) `(split-window ,(emacs-window-window self) ,(- (pane-height self) size) nil)) (defmethod delete-subpane-command ((self horizontal-splits)) `(progn ,@(mapcar (function delete-subpane-command) (pane-subpanes self)))) (defmethod delete-subpane-command ((self vertical-splits)) `(progn ,@(mapcar (function delete-subpane-command) (pane-subpanes self)))) (defmethod delete-subpane-command ((self emacs-window)) `(delete-window ,(emacs-window-window self))) (defmethod recreate-subpane-command ((self horizontal-splits)) (let ((height (reduce (function +) (pane-subpanes self) :key (function pane-height)))) `(progn ,@(mapcar (lambda (pane) `(progn ,@(when (plusp (decf height (pane-height pane))) `((split-window nil ,(pane-height pane) nil))) ,(recreate-subpane-command pane) (other-window 1))) (pane-subpanes self))))) (defmethod recreate-subpane-command ((self vertical-splits)) (let ((width (reduce (function +) (pane-subpanes self) :key (function pane-width)))) `(progn ,@(mapcar (lambda (pane) `(progn ,@(when (plusp (decf width (pane-width pane))) `((split-window nil ,(pane-width pane) t))) ,(recreate-subpane-command pane) (other-window 1))) (pane-subpanes self))))) (defmethod recreate-subpane-command ((self emacs-window)) `(progn (switch-to-buffer ,(window-buffer (emacs-window-window self))) ;; TODO: set other window parameters from the old window. )) ;; (split-bottom (window-pane) 10) ; makes a window 10 lines high at the bottom. ;; You may use C-x r w a to store the current window configuration in register 'a' ;; and C-x r j a to restore the saved window configuration. -- __Pascal Bourguignon__ http://www.informatimago.com/ ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2010-07-23 16:39 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2010-07-22 13:35 Creating a bottom window? Elena 2010-07-22 20:15 ` Pascal J. Bourguignon 2010-07-23 14:18 ` TheFlyingDutchman 2010-07-23 14:25 ` TheFlyingDutchman 2010-07-23 15:20 ` TheFlyingDutchman 2010-07-23 16:39 ` Pascal J. Bourguignon
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).