views:

65

answers:

3

I use the same .emacs across multiple machines, operating systems and platforms. I would like the default frame size of Emacs upon invocation to be relative to the available screen size (e.g. 96 lines work very well on a 1600x1200 desktop screen, but on an 1280x800 laptop I need to specify no more than 68 lines).

Is there an emacs-lisp expression that returns the width & height of the system's screen?

Update: I just found a similar question, but for some reason neither (x-display-pixel-width) nor (display-pixel-width) can be found in my GNU Emacs 23.2 on Windows XP system. Continuing to research...

+1  A: 

I'm running Gnu Emacs 23.2.1 on XP Pro, and the functions (x-display-pixel-width) and (x-display-pixel-height)

are both working just fine. They are a part of the c source, and should be present.

You CAN run emacs outside of a terminal it trust?

Here's the documentation from my current emacs:

x-display-pixel-height is a built-in function in `C source code'.

(x-display-pixel-height &optional TERMINAL)

Return the height in pixels of the X display TERMINAL. The optional argument TERMINAL specifies which display to ask about. TERMINAL should be a terminal object, a frame or a display name (a string). If omitted or nil, that stands for the selected frame's display.

Also, I have a entire library of convenience functions to help with sizing and moving the emacs frame, if you interested.

  • Chris
Chris McMahan
Chris, thank you. How do I invoke these functions? I tried M-x x-display-pixel-height from the minibuffer but Emacs can't find it. How do you invoke it in your system?BTW, "About Emacs" in my system displays: GNU Emacs 23.2.1 (i386-mingw-nt5.1.2600) of 2010-05-08 on G41R2F1
Android Eve
They aren't interactive functions. You can invoke them with M-: (x-display-pixel-height) RET
scottfrazer
Scott, your comment was exactly what I needed. Alt+Shift+':' on my Windows XP keyboard, invoked the 'Eval:' prompt. I then typed (x-display-pixel-height), hit the Enter key and, sure enough, the correct result was displayed: 1200. Thanks!
Android Eve
A: 

Thanks to the answer and comments by Chris and Scott, I managed to come up with the following working line in my .emacs:

(set-frame-size  (selected-frame)  96 (/ (* (x-display-pixel-height) 46) 600) ) 

It works well when I do eval-buffer on the .emacs, but when I double-click Windows XP's Emacs shortcut, this statement is ignored completely.

I know that (selected-frame) is not the (initial-frame) so I tried this too:

(setq initial-frame-alist
    '((top . 1) (left . 288) (width . 96) (height . (/ (* (x-display-pixel-height) 46) 600))))

But it works only when I do eval-buffer on the read .emacs. It doesn't work when Emacs is started (either from the command line or by double-clicking its shortcut). Weird.

Android Eve
There is no `selected-frame` at startup on Emacs 23, due to the addition of daemon mode, multi terminal support and the like. So you need to set initial-frame-alist or default-frame-alist.
JSON
Try`(setq initial-frame-alist '((top . 1) (left . 288) (width . 96))) (add-to-list 'initial-frame-alist (cons 'height (/ (* (x-display-pixel-height)))))`The reason your current version is not working is that the height calculation is inside the quoted list, so will not be evaluated.
JSON
Eve, I'm using 22.3.1 on my work machine.
John R. Strohm
Also: using setq means you lose anything that was added to initial-frame-alist before your code ran. I think I ran into an issue like that with default-frame-alist, and that's why I used add-to-list.
John R. Strohm
+1  A: 

I'm doing it a poor way, for a somewhat-older version.

(tool-bar-mode nil)

(mapc (lambda (x) (add-to-list 'default-frame-alist x))
   (list
          (cons 'top 0) (cons 'left 0)
          (cons 'font "-outline-Courier New-normal-r-normal-normal-11-82-96-96-c-*-iso10646-1")
          (cons 'height 67) (cons 'width 176)
))

The default frame is built after .emacs runs, from the default-frame-alist. I've never heard of the initial-frame-alist.

John R. Strohm
John, your way is essentially equivalent (except for default vs. initial) but it doesn't work on Emacs 23.2. Which Emacs version are you using?
Android Eve
`initial-frame-alist` only affects the first frame. `default-frame-alist` affects all frames created thereafter.
JSON