I'm trying to detect the size of the screen I'm starting emacs on, and adjust the size and position the window it is starting in (I guess that's the frame in emacs-speak) accordingly. I'm trying to set up my .emacs so that I always get a "reasonably-big" window with it's top-left corner near the top-left of my screen.
I guess this is a big ask for the general case, so to narrow things down a bit I'm most interested in GNU Emacs 22 on Windows and (Debian) Linux.
Type C-c + to enlarge the window. Then hit + or - repeatedly to enlarge/shrink the window. Any other key ends the resize operation.
Using setSize() you can give the size of frame you want but if you use pack() , it will automatically change the size of the frames according to the size of components in it.
Emacs opens a new frame on dickens . If you type C-x b to move to another buffer, the name at the top of the frame changes to the new buffer's name (and on Linux, it shows the path as well). To move to a buffer and put it in a new frame, type C-x 5 b.
A frame is a screen object that contains one or more Emacs windows (see Windows). It is the kind of object called a “window” in the terminology of graphical environments; but we can't call it a “window” here, because Emacs uses that word in a different way.
If you want to change the size according to resolution you can do something like this (adjusting the preferred width and resolutions according to your specific needs):
(defun set-frame-size-according-to-resolution () (interactive) (if window-system (progn ;; use 120 char wide window for largeish displays ;; and smaller 80 column windows for smaller displays ;; pick whatever numbers make sense for you (if (> (x-display-pixel-width) 1280) (add-to-list 'default-frame-alist (cons 'width 120)) (add-to-list 'default-frame-alist (cons 'width 80))) ;; for the height, subtract a couple hundred pixels ;; from the screen height (for panels, menubars and ;; whatnot), then divide by the height of a char to ;; get the height we want (add-to-list 'default-frame-alist (cons 'height (/ (- (x-display-pixel-height) 200) (frame-char-height))))))) (set-frame-size-according-to-resolution)
Note that window-system is deprecated in newer versions of emacs. A suitable replacement is (display-graphic-p)
. See this answer to the question How to detect that emacs is in terminal-mode? for a little more background.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With