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

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

Re: [h-e-w] emacs geometry


From: Chris McMahan
Subject: Re: [h-e-w] emacs geometry
Date: Thu, 1 Aug 2002 11:50:45 -0400

Sarir A Khamsi writes:
>
> I am interested...in fact, I was about to ask if there was a way to get the
> screen size and set it to the max so that my .emacs file would work across
> different screen resolutions.
>
> Sarir

> Chris McMahan <address@hidden>
>> While we're on the topic of geometry...
>> 
>> I have some functions that set the initial height of the emacs screen
>> based on the selected font and the screen resolution, to maximize the
>> usable area of emacs. I can post them if there's interest.
>> 
>>  - Chris

Sorry for the length of the message...

I have my emacs set up into several files. The .emacs sets some user
preferences then calls the other files as appropriate. That's why you
see the references to the DEFCONST here.

Here you go:

First is the initial setup, then some other functions to readjust as
necessary. (I'm not an elisp programmer by any stretch... so comments
and suggestions are more than welcome!)


.emacs code

;;;===================================================
;;; Set the default font and frame size for all frames
;;;===================================================

(defconst MY_FONT "-*-Lucida Console-normal-r-*-*-11-*-*-*-c-*-iso8859-15")

;;; Set the initial window height based on the current screen resolution.
;;; Need to set the default font first to return the appropriate
;;; character height for the initial height calculation
(set-frame-font MY_FONT)

;;; initial window position settings, height and vertical position are
;;; automatically calculated.
;;; The top left corner is 0 0, the bottom right is -1 -1
(defconst MY_INITIAL_WIDTH  120)
(defconst MY_INITIAL_LEFT   -15)

;; use the screen resolution to calculate the height and center
;; the frame
(defconst MY_INITIAL_HEIGHT
  (- (/ (x-display-pixel-height)
                (frame-char-height) ) 8))

;;; set the height of the frame so the top can then be calculated to
;;; center it
(set-frame-height (selected-frame) MY_INITIAL_HEIGHT)

;;; calculate the top to center the frame
(defconst MY_INITIAL_TOP
  (- (/ (- (x-display-pixel-height)
                   (frame-pixel-height)) 5) 2))

;;; now that the initial frame info is known, set the size and
;;; position for subsequent windows
(defconst MY_DEFAULT_HEIGHT (- MY_INITIAL_HEIGHT 15))
(defconst MY_DEFAULT_TOP    (+ MY_INITIAL_TOP 45))
(defconst MY_DEFAULT_LEFT   (- MY_INITIAL_LEFT 150))
(defconst MY_DEFAULT_WIDTH   MY_INITIAL_WIDTH)


;;;======================================================================
;;; set the frame sizes and fonts for the initial and subsequent frames
;;;======================================================================
;;; this is done already in the .emacs. Here for convience and
;;; reference
;;;(set-frame-font MY_FONT)

(if (not window-system)
    (set-background-color "lightgray")
  ;;; Set the font and frame size for the initial frame.
  (progn
    (setq initial-frame-alist
          `(
            (top . ,MY_INITIAL_TOP)
            (left . ,MY_INITIAL_LEFT)
            (width . ,MY_INITIAL_WIDTH)
            (height . ,MY_INITIAL_HEIGHT)
            (internal-border-width . 1)
            (menu-bar-lines . 1)
            (cursor-type . t)
            (font . ,MY_FONT)
            )
          )

  ;;; Set the default font and frame size
    (setq default-frame-alist
          `(
            (top . ,MY_DEFAULT_TOP)
            (left . ,MY_DEFAULT_LEFT)
            (width . ,MY_DEFAULT_WIDTH)
            (height . ,MY_DEFAULT_HEIGHT)
            (internal-border-width . 1)
            (menu-bar-lines . 1)
            (cursor-type . t)
            (font . ,MY_FONT)
            )
          )
    ))



;------------------------------------------------------------
;I also have a couple of convience functions to reset to the default
;and to readjust the height (good when selecting different fonts)
;------------------------------------------------------------

;;;======================================================================
;;; frame sizing functions
;;;======================================================================
;;; Note: these functions rely on the consts defined in the .emacs file

(defun enlarge-frame ()
  "Enlarge the selected frame to fill a sizeable portion of the screen,
based on the current screen resolution"
  (interactive)
  (set-frame-size
    (selected-frame)
      (- (/ (x-display-pixel-width)
                        (frame-char-width)) 10)
      (- (/ (x-display-pixel-height)
            (frame-char-height) ) 8))
  (set-frame-position
    (selected-frame)
        MY_INITIAL_LEFT
        ;center the screen horizontally
    ; need to account for the title bar and menu when centering
        ; vertically
    (- (/ (- (x-display-pixel-height)
          (frame-pixel-height)) 5) 2))
)


(defun adjust-frame ()
  "Adjust the selected frame based to the user's initial width, but
  adjust the height based on the current screen resolution"

  (interactive)
  (set-frame-size
    (selected-frame)
        MY_INITIAL_WIDTH
        (- (/ (x-display-pixel-height)
                  (frame-char-height) ) 8))
  (set-frame-position
    (selected-frame)
    MY_INITIAL_LEFT
        ;; need to account for the title bar and menu when centering
        ;; vertically
        (- (/ (- (x-display-pixel-height)
                         (frame-pixel-height)) 5) 2))
)

(defun fix-frame ()
  "Restore the frame back to the initial height, width and position as
set up in the .emacs

uses the global variables:
   MY_INITIAL_WIDTH
   MY_INITIAL_HEIGHT
   MY_INITIAL_LEFT
   MY_INITIAL_RIGHT

defined in the .emacs file"
  (interactive)
  (set-frame-size (selected-frame) MY_INITIAL_WIDTH MY_INITIAL_HEIGHT)
  (set-frame-position (selected-frame) MY_INITIAL_LEFT MY_INITIAL_TOP)
)


-- 
    ================================
    Chris McMahan | address@hidden
    ================================




reply via email to

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