shell

Setting variables in emacs at file header

When editing LaTeX files, I usually call the master file of a project 00father.ltx for historical reasons. Moreover, the following line is part of my .emacs:

(setq-default TeX-master "00father.ltx")

because most of the time I am editing multifile projects.

However, from time to time I need to write a single-file document and in this case, naming it 00father.ltx is not that useful, and I do not want to have to set the master-file variable each time I load the file.

There is an easy way to get this done. Just include a line at the top of the file -as a comment in the appropriate language- setting the variables. The syntax is as follows (in C, for example):

/* -*- variable1: value1; variable2: value2; -*- */

I am giving two examples. The first one in C again. Assume this is the header of a file called trial.c

/* -*- tab-width: 8; column-number-mode: 1; fill-column: 80; -*- */

The line tells emacs to set the length of a tab to 8 spaces (usual in BSD), to show the column number in the information line and to wrap lines (if wrapping -fill-mode- is set) at 80 characters.

For my LaTeX issue, the first line of a single-file document letter_to_my_friend.ltx goes as follows (notice the difference in the comment syntax):

% -*- TeX-master: "letter_to_my_friend.ltx"; -*-

I have checked and if your file is a shell script, which usually begins with

#!/bin/sh

(or some similar line), you can place the variable-setting line just afterwards.

2 Comments

  • On 07.28.12 m said:

    *-* should be -*-

  • On 07.31.12 rafacas said:

    Thanks, I have corrected it.

speak up

Add your comment below, or trackback from your own site.

Subscribe to these comments.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*Required Fields