Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've been writing some fortran code using emacs, and found that I needed emacs to recognise that the code I'm working on is fortran code (if for example your filename doesn't end in .f or .f90) so that the appropiate syntax highlighting is used. I found out that this can be done by including this comment at the beginning of the code:

! -*- mode: F90 -*-

I was wondering if there was something similar I could put at the beginning of the code which would cause the emacs frame to resize? It would be useful because I have a small input file which I open regularly for my simulations, and everytime I open it I need to resize its frame to something smaller so that it fits snugly without wasting screen space. I still want the default frame size for other source code I'm working on.

share|improve this question
up vote 3 down vote accepted

Use eval:

! -*- eval: (set-frame-size (selected-frame) 40 25) -*-

Or the more general form:

! Local Variables: 
! eval: (set-frame-size (selected-frame) 40 25) 
! end: 

Here is a description:

Emacs asks you, if the code should be executed. Executing foreign code is a security problem. You can customize the behavior:


See the documentation here:

share|improve this answer
Thanks, that worked. One small question though. I tried setting enable-local-variables it to t, so that it would only ask me once, but it asks me everytime I open that file. So instead I've set enable-local-variable to :all so it doesn't ask me at all. Have I misunderstood how setting enable-local-variable to t works? – Eddy Jun 4 '11 at 10:13
True sets only safe variables. But eval is not safe. If you set the option to :all you are in trouble, if you open evil files. Keep it t and answer the question with ! to tell Emacs, that the use of set-frame-size is safe. – ceving Jun 4 '11 at 17:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .