Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set the size of Emacs' window?

Tags:

emacs

elisp

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.

like image 390
Tom Dunham Avatar asked Sep 18 '08 14:09

Tom Dunham


People also ask

How do I adjust window size in Emacs?

Type C-c + to enlarge the window. Then hit + or - repeatedly to enlarge/shrink the window. Any other key ends the resize operation.

Which function is used for setting the size of frame?

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.

How do I change frames in Emacs?

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.

What is an Emacs frame?

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.


1 Answers

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.

like image 149
Bryan Oakley Avatar answered Oct 03 '22 01:10

Bryan Oakley