How do I find the display size of my system in Emacs?
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 1280开发者_如何学Cx800 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...
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.
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.
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.
Update: I ended up setting the initial size in the invocation command in the shortcut's Target field:
C:\emacs-23.2\bin\runemacs.exe -geometry 96x78+240+0
An ugly solution, I know, but currently that's the only solution that does the trick.
精彩评论