Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

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: http://www.gnu.org/software/libtool/manual/emacs/Specifying-File-Variables.html#Specifying-File-Variables

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

M-xcustomize-optionReturnenable-local-variablesReturn

See the documentation here: http://www.gnu.org/software/emacs/elisp/html_node/File-Local-Variables.html#File-Local-Variables

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
1  
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.