In a variety of situations, in particular when in the middle of going full UTF-8 for a project, one has to switch back and forth between coding systems a lot. Here is how to do it easily.
This method is described in InternationalSetup, it’s the easiest but most cumbersome: type `C-x <RETURN> c’, choose a coding system, type next command (typically
Of course this is not always possible in a non-ambiguous fashion (e.g. all ASCII files are both valid latin-1 and valid UTF-8); but some kinds of file (e.g. XML) have extra markup in them that indicate precisely the coding system they are in. In order to take advantage of that in Emacs, one needs to customize the
The variable to customize is
auto-coding-alist. Similar to AutoModeAlist, you can use that to assign coding systems to whole directories, certain file suffixes or any regexp. For example, to view ASCII art
.nfo files, which traditionally are encoded the
‘cp437-dos’ encoding, add this to your DotEmacs file.
; Associate nfo file suffix with IBM codepage 437 encoding (setq auto-coding-alist (cons '("\\.nfo\\'" . cp437-dos) auto-coding-alist))
The ProjectSettings page offers ways to customize the behavior of Emacs in a given directory. This is of course useful not just for coding style issues (e.g. tab width), but alas it does not work for setting the coding system of a bunch of text files. Sorry about that…