2

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?

1
  • 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, 2015 at 11:34

1 Answer 1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .