1

I am just starting to set up a perl environment in emacs but the problem is that I already program with prolog and both languages use the .pl file extension. I have two directory ~/src/prolog and ~/src/perl where I store code for the respective languages. Currently I only have this line in my init:

(setq auto-mode-alist (append '(("\\.pl$" . prolog-mode))
                               auto-mode-alist))

How can I tell emacs that .pl files in the ~/src/prolog directory should use prolog-mode while the .pl files in ~/src/perl should use cperl-mode?

2

You're lucky that the files for the different languages are segregated by directory like that.

You can define directory-local values for variable auto-mode-alist.

See the Elisp manual, node Directory Local Variables.

As the intro text of that node says:

This is useful when the files in the directory belong to some “project” and therefore share the same local variables.

1
  • Won't that shadow all other entries on the list, though?
    – SamB
    Aug 29 at 16:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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