Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm using Aquamacs, a distro of GNU Emacs 23.3.50.1.

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.

((c-mode
  (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 serverfault.com Aug 19 '11 at 11:25

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

1 Answer 1

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: http://www.emacsmirror.org/package/dir-locals.html

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

or

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:

(coding-system-priority-list)
(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

returns:

(cp1253-unix . auto-coding-alist)

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.