719016
719016

Reputation: 10451

defining perl indentation for emacs in source code file?

Is it possible to put a comment at the top of a source Perl file to have Emacs abide by a 4-space indentation rule in that same file, regardless of the default indentation rule defined in .emacs?

I am finding myself editing Perl files with different indentations, some 2-spaced, some 4-spaced, and I would like Emacs to automatically follow the indentation rule described in the file itself, other than having to change the configuration every time.

All this is using cperl-mode for Perl editing (http://www.emacswiki.org/emacs/CPerlMode).

I tried adding the comments below at the end of this example perl script:

#!/usr/bin/perl

my @a = (1,2,3,4,5,6);
for my $e (@a) {
  print "$e\n";
}

# Local variables:
# perl-indent-level: 4
# End:

But it still uses indent level 2. Maybe the reason is because it's not overriding the .emacs settings?

Upvotes: 0

Views: 299

Answers (2)

torbonde
torbonde

Reputation: 2459

How about adding (setq cperl-indent-level 4) to your .emacs file? Found at this page.

Upvotes: 1

Tarmil
Tarmil

Reputation: 11372

You should get it working by putting this at the end of the file:

# Local variables:
# perl-indent-level: 4
# End:

Upvotes: 5

Related Questions