[OS X Emacs] Re: opening old mac files (CR end of line char)

xah lee xah at xahlee.org
Wed Dec 5 14:27:00 EST 2007


Bill Rising wrote:

> When the ^M's show up:
> 1. Make a text file with the default unix eols.
> 2. Change eols using M-x replace-string
> C-q C-j RET C-q C-m RET.
> 3. Save the file.
> 4. Open the file.
> Result: Instead of the file being opened as a Mac file, it is opened
> with encoding nil and shows ^Ms.


On Dec 5, 2007, at 9:46 AM, Edward O'Connor wrote:
> What do you have `require-final-newline' set to? If it's non-null, at
> step 3 a ^J might be inserted at the end of the file, thus throwing  
> off
> Emacs' EOL detection in step 4.

------------------------------

Good point.

thru newsgroup discussion at emacs.help, David Reitter has also  
confirmed the problem and pointed out the cause. That is, the files i  
work on are html files, and html-mode automatically sets require- 
final-newline to t. This means after i work on the file and save it,  
and when opening it again, there's a LF at the end, which causes  
emacs to be confused and thinks that this is a unix file and shows  
newlines as ^M.

Thanks for finding the problem.

Anyhow, for what's worth, i think this is still something emacs (in  
particular Mac versions) should fixup. Basically, the scenario is  
that a user opens mac classic html files, work on it, save it, then  
next time he opens the files shows ^M. (this actually happens to me a  
lot since i work on a server with non-professional coders and they  
use BBEdit that is still set to CR as newline) In contrast, i open  
the same file (with CR as eol but a LF at the end) in Xcode,  
TextWrangler, TextEdit, all opens correctly and indicate as Mac files.

• perhaps require-final-newline should insert the right EOL char  
based on the encoding.

• perhaps emacs file opening routine should be more smart. (i.e. not  
using the last EOL, or check more lines, to determine the EOL char)

   Xah
   xah at xahlee.orghttp://xahlee.org/


More information about the MacOSX-Emacs mailing list