From: Dirk Traulsen Date: 2007-10-23T20:21:29+09:00 Subject: Re: Encoding::primary_encoding Am 23 Oct 2007 um 4:26 hat David Flanagan geschrieben: > Wolfgang N�dasi-Donner wrote: > > > > Are there other possible values for magic comments? - I didn't find > > anything in the sources. > > Yes, there are. > > Here's a section from chapter 2 of my forthcoming book. (..) > > More generally, however, you can identify the encoding of a > Ruby file by placing a special comment on the first (or > second: see below) line of the Ruby file. The comment must be > written entirely in ASCII, and must include the string > "coding" So the vim modeline # vim: fenc=utf-8 will not be recognized? > followed by colon or equals sign and the name of the > desired encoding (which cannot include spaces or punctuation > other than hyphen and underscore). Whitespace is allowed on > either side of the colon or equals sign, and the string > "coding" may have any prefix, such as "en" to spell > "encoding". The entire comment, including "coding" and the > encoding name is case-insensitive and can be written with > uppercase or lowercase letters. > > > > Encoding comments are usually written so that they also inform > a text editor of the file encoding. (...) > > And vi users might write: > > > # vim: set fileencoding=utf-8 > ]]> Two comments: 1. You speak of vi users and used vim: in the modeline. This is not necessary in vim. Vim recognizes equally 'vi:', 'vim:' and even 'ex:'. For your readers it might be more consistent to use only vi or vim, IF Ruby will recognize both or ignore them completely, which I don't know. 2. You're modeline example is no valid modeline in vim. There are two forms of modelines in vim: a. One with implicit, but not mentioned command 'set' and b. one with the command 'set' spelled out. In case a. it reads the complete line, so nothing else is allowed there. In case b. which you used, there MUST be a colon ending the command, which also allowes to add comments after the command: # vi: set fileencoding=utf-8: #This sets the encoding for Ruby also! (or in c: /* vi: set fileencoding=utf-8 : */ ) > > An encoding comment like that shown above is usually only > valid on the first line of the file. It may appear on the > second line, however, if the first line is a "shebang" comment Modelines are by default recognized by vim in the first and last 5 lines of a file. Do you know whether this is true for Ruby also? Does Ruby recognize modelines at least in the last line too, where they are mostly? Dirk