[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
shrink-fit-all.el - automatically shrink all frames to fit windo
From: |
Drew Adams |
Subject: |
shrink-fit-all.el - automatically shrink all frames to fit window |
Date: |
Tue, 16 Jan 2001 21:35:20 -0500 |
;;; shrink-fit-all.el --- Automatically shrink all frames to fit window.
;;
;; Filename: shrink-fit-all.el
;; Description: Automatically shrink all frames to fit window.
;; Author: Drew Adams
;; Maintainer: Drew Adams
;; Copyright (C) 2000, 2001, Drew Adams, all rights reserved.
;; Created: Thu Dec 7 10:06:18 2000
;; Version: $Id: shrink-fit-all.el,v 1.3 2001/01/09 22:20:39 dadams Exp $
;; Last-Updated: Tue Jan 9 14:20:20 2001
;; By: dadams
;; Update #: 55
;; Keywords: internal, extensions, local
;; Compatibility: GNU Emacs 20.x
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Commentary:
;;
;; Automatically shrink all frames to fit their selected window.
;;
;; Functions and user options (variables) are provided here to
;; automatically shrink all frame to fit their selected window.
;; Standard Emacs primitive functions are redefined to do this. The
;; main user options defined here are `fit-frame-when-display-p',
;; `fit-frame-when-pop-to-p' and `fit-frame-when-switch-to-p'.
;;
;; This file loads the file `shrink-fit.el', which provides the main
;; functionality behind the automatic frame resizing. See it for
;; customizing sizes etc.; in particular, consult these user options:
;;
;; `create-empty-frame-height', `create-empty-frame-width',
;; `create-empty-special-display-frame-height',
;; `create-empty-special-display-frame-width',
;; `create-frame-max-height', `create-frame-max-height-percent',
;; `create-frame-max-width', `create-frame-max-width-percent',
;; `create-frame-min-height', `create-frame-min-width', and
;; `enable-shrink-frame-to-fit'.
;;
;; The reason for separating the code here from that in
;; `shrink-fit.el' is to let you load that code but not load the code
;; here, if you don't want to redefine Emacs primitives.
;;
;; You may want to put the following in your `~/.emacs' file, in
;; order to provide for automatic frame resizing of all frames:
;;
;; (require 'shrink-fit-all) ; load this file
;; (if (not (featurep 'shrink-fit)) nil
;; (add-hook 'after-make-frame-functions 'shrink-frame-to-fit)
;; (add-hook 'after-make-frame-functions 'making-frame-done-msg)
;; (add-hook 'before-make-frame-hook 'making-frame-msg))
;; (add-hook 'temp-buffer-show-hook 'fit-frame-if-one-window 'append)
;;
;;
;; Main new functions defined here:
;;
;; `fit-frame-if-one-window', `fit-frame-if-one-window-and-cond'.
;;
;; Main new user options (variables) defined here:
;;
;; `fit-frame-when-display-p', `fit-frame-when-pop-to-p', and
;; `fit-frame-when-switch-to-p'.
;;
;;
;; ***** NOTE: The following EMACS PRIMITIVES have been REDEFINED HERE:
;;
;; `display-buffer' -
;; 1) Uses `read-buffer' in interactive spec.
;; 2) `fit-frame-if-one-window' if `fit-frame-when-display-p'.
;; `pop-to-buffer' -
;; `fit-frame-if-one-window' if `fit-frame-when-pop-to-p'.
;; `switch-to-buffer' -
;; 1) Uses `read-buffer' in interactive spec.
;; 2) If current window is dedicated, then use another window.
;; 3) `fit-frame-if-one-window' if `fit-frame-when-switch-to-p'.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Change log:
;;
;; RCS $Log: shrink-fit-all.el,v $
;; RCS Revision 1.3 2001/01/09 22:20:39 dadams
;; RCS Adapted file header for Emacs Lisp Archive.
;; RCS
;; RCS Revision 1.2 2001/01/03 01:14:21 dadams
;; RCS *** empty log message ***
;; RCS
;; RCS Revision 1.1 2000/12/07 19:54:47 dadams
;; RCS Initial revision
;; RCS
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Code:
(require 'cl) ;; when
(eval-when-compile (require 'strings)) ;; read-buffer
(require 'shrink-fit) ;; shrink-frame-to-fit
(provide 'shrink-fit-all)
;;;;;;;;;;;;;;;;;;;;;;;
;;; User options ---------------------------------------------------
;;;###autoload
(defvar fit-frame-when-pop-to-p t
"*Non-nil => `pop-to-buffer' does `fit-frame-if-one-window'.")
;;;###autoload
(defvar fit-frame-when-display-p t
"*Non-nil => `display-buffer' does `fit-frame-if-one-window'.")
;;;###autoload
(defvar fit-frame-when-switch-to-p t
"*Non-nil => `switch-to-buffer' does `fit-frame-if-one-window'.")
;;; Non-interactive functions ---------------------------------
;;;###autoload
(defun fit-frame-if-one-window ()
"`shrink-frame-to-fit' if `one-window-p'.
Usable in `temp-buffer-show-hook'."
(and (one-window-p t)
(fboundp 'shrink-frame-to-fit)
(shrink-frame-to-fit)))
;;;###autoload
(defun fit-frame-if-one-window-and-cond (condition-p)
"`shrink-frame-to-fit' if `one-window-p' and CONDITION-P."
(and (one-window-p t)
condition-p
(fboundp 'shrink-frame-to-fit)
(shrink-frame-to-fit)))
(or (fboundp 'old-pop-to-buffer)
(fset 'old-pop-to-buffer (symbol-function 'pop-to-buffer)))
;; REPLACES ORIGINAL (built-in):
;; `fit-frame-if-one-window' if `fit-frame-when-pop-to-p'.
;;;###autoload
(defun pop-to-buffer (bufname &optional other-window)
"Select buffer BUFFER in some window, preferably a different one.
If BUFFER is nil, then some other buffer is chosen.
If `pop-up-windows' is non-nil, windows can be split to do this.
If optional second arg OTHER-WINDOW is non-nil, insist on finding another
window even if BUFFER is already visible in the selected window."
(old-pop-to-buffer bufname other-window)
(fit-frame-if-one-window-and-cond fit-frame-when-pop-to-p))
;;; Commands ---------------------------------------------------
(or (fboundp 'old-display-buffer)
(fset 'old-display-buffer (symbol-function 'display-buffer)))
;; REPLACES ORIGINAL (built-in):
;; 1) Uses `read-buffer' in interactive spec.
;; 2) `fit-frame-if-one-window' if `fit-frame-when-display-p'.
;;;###autoload
(defun display-buffer (buffer &optional not-this-window frame)
"Make BUFFER appear in some window but don't select it.
BUFFER can be a buffer or a buffer name.
If BUFFER is shown already in some window, just use that one,
unless the window is the selected window and the optional second
argument NOT-THIS-WINDOW is non-nil (interactively, with prefix arg).
If `pop-up-frames' is non-nil, make a new frame if no window shows BUFFER.
Returns the window displaying BUFFER.
The variables `special-display-buffer-names', `special-display-regexps',
`same-window-buffer-names', and `same-window-regexps' customize how certain
buffer names are handled.
If optional argument FRAME is `visible', search all visible frames.
If FRAME is 0, search all visible and iconified frames.
If FRAME is t, search all frames.
If FRAME is a frame, search only that frame.
If FRAME is nil, search only the selected frame
(actually the last nonminibuffer frame),
unless `pop-up-frames' is non-nil,
which means search visible and iconified frames.
`fit-frame-if-one-window' if `fit-frame-when-display-p'."
(interactive
(list (read-buffer "Display buffer: " (current-buffer) 'existing)
current-prefix-arg))
(let ((win (old-display-buffer buffer not-this-window frame)))
(when (window-live-p win)
(save-selected-window
(select-window win)
(fit-frame-if-one-window-and-cond fit-frame-when-display-p)))
win)) ; Return the window
(or (fboundp 'old-switch-to-buffer)
(fset 'old-switch-to-buffer (symbol-function 'switch-to-buffer)))
;; REPLACES ORIGINAL (built-in):
;; 1) Uses `read-buffer' in interactive spec.
;; 2) If current window is dedicated, then use another window.
;; NOTE: Versions >= 19.34 signal an error if dedicated window,
;; instead of using another one. Don't know what the 19.28 version
did.
;; Don't know if this is needed any more.
;; 3) `fit-frame-if-one-window' if `fit-frame-when-switch-to-p'.
;;;###autoload
(defun switch-to-buffer (buffer &optional norecord)
"Select buffer BUFFER in current window, unless the window is dedicated.
If current window is dedicated (`window-dedicated-p'), then another window
is used. BUFFER may be a buffer or its name.
Optional second arg NORECORD non-nil =>
Do not put BUFFER at front of list of recently selected buffers.
*WARNING*: This is NOT the way to work on another buffer temporarily
within a Lisp program! Use `set-buffer' instead, to avoid messing
with window-buffer correspondences.
`fit-frame-if-one-window' if `fit-frame-when-switch-to-p'."
(interactive
(list (read-buffer "Switch to buffer: " nil 'existing)))
(if (window-dedicated-p (selected-window))
(switch-to-buffer-other-window buffer)
(old-switch-to-buffer buffer norecord))
(fit-frame-if-one-window-and-cond fit-frame-when-switch-to-p))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; `shrink-fit-all.el' ends here
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- shrink-fit-all.el - automatically shrink all frames to fit window,
Drew Adams <=