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

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?


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.

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.