Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using Aquamacs, a distro of GNU Emacs

I'm looking at some source files written with some comments in Greek, and they are encoded in CP1253.

And, I can either revert with the proper encoding or I can add a file local variable:

/* -*- mode: c-mode; tab-width: 4; coding: cp1253-unix; -*- */

So I can get them to open properly, and I could certainly tack on file variables to each file.

But I'd like to set the coding for the whole directory. Rather than editing .dir-locals.el by hand, I thought I'd simply:

M-x copy-file-locals-to-dir-locals

From the file that opened correctly. And that generates:

;;; Directory Local Variables
;;; See Info node `(emacs) Directory Variables' for more information.

  (tab-width . 4)
  (coding . cp1253-unix)))

No dice. Yet it clearly recognizes the new tab-width, so it's reading the file.

Any ideas why? And is there any log as emacs is processing the a-list?

share|improve this question

migrated from Aug 19 '11 at 11:25

This question came from our site for system and network administrators.

With emacs24, if I try to set coding in .dir-locals.el, I get a warning when opening a new file: Warning (:warning): Coding cannot be specified by dir-locals – ggll Aug 31 '15 at 11:34

Unfortunately, it appears that the coding header, by design, does not propagate from Emacs dir-locals; I struggled with your setup, and replicated the issue as well.

Later I came across this source that seems to verify what you found:

I'm not sure if there is a log for processing the a-list, but in case you aren't familiar with this variable, you can verify your encoding after visiting a file with:

C-h v buffer-file-coding-system RET


M-x describe-variable RET buffer-file-coding-system RET

Personally, I think your best bet would be what you already have working - file local variables.

Alternatives I can think of (first is untested) would be to take a look at some of the elisp functions:

(set-coding-system-priority &rest coding-systems)

OR second: (assuming your directory structure is /something/blah/greekcode/file.c)

(add-to-list 'auto-coding-alist 
     '("/greekcode/[^/]+.c\\'" . cp1253-unix))

This takes precedence even over file local variables. Modify the regexp as you need, and experiment by evaluating:

(find-auto-coding "/home/brian/greekcode/garbage.c" 1) <= C-x C-e


(cp1253-unix . auto-coding-alist)

Hopefully this helps! Would love to hear what other emacs users propose as solutions.

share|improve this answer

You must log in to answer this question.