From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Xah Lee Newsgroups: gmane.emacs.help Subject: mac/dos/unix newline conversion without specify from Date: Sun, 2 Dec 2007 10:14:44 -0800 (PST) Organization: http://groups.google.com Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1196620877 15639 80.91.229.12 (2 Dec 2007 18:41:17 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 2 Dec 2007 18:41:17 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Dec 02 19:41:24 2007 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Iytkj-0002sb-Hb for geh-help-gnu-emacs@m.gmane.org; Sun, 02 Dec 2007 19:41:17 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IytkT-00014a-G9 for geh-help-gnu-emacs@m.gmane.org; Sun, 02 Dec 2007 13:41:01 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!postnews.google.com!s36g2000prg.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 47 Original-NNTP-Posting-Host: 69.236.127.3 Original-X-Trace: posting.google.com 1196619284 14398 127.0.0.1 (2 Dec 2007 18:14:44 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Sun, 2 Dec 2007 18:14:44 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: s36g2000prg.googlegroups.com; posting-host=69.236.127.3; posting-account=qPxGtQkAAADb6PWdLGiWVucht1ZDR6fn User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/523.12 (KHTML, like Gecko) Version/3.0.4 Safari/523.12, gzip(gfe), gzip(gfe) Content-Disposition: inline Original-Xref: shelby.stanford.edu gnu.emacs.help:154349 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:49778 Archived-At: i was surprised today, to find that Carbon Emacs 22 and also Aquamacs, does not open a file with classic Mac OS line endings properly? (i.e. EOL shows up as ^M) i realized this when trying to write a elisp program to do the conversion given a file name. originally, i thought set-buffer-file-coding-system does it. But not so if the file opened is a classic mac os file with CR as newline. After some elisp doc reading, i find that i have to call (coding- system-for-read 'mac) first. But then, it is not better if i actually just do the newline replacement myself like this: ; code untested (defun xx () "temp... Convert list of files to unix/mac/dos's newline char." (interactive) (let (fpath mybuffer) (setq fpath "~/web/emacs/x2/x1mac") (setq mybuffer (find-file fpath)) ; note: Mac here denote Mac OS up to 9. ; In Mac OS X, both unix newline and old mac newline are accepted, but unix newline is recommended. (replace-string "\n" "\r" nil 1 (1+ (buffer-size))) ; unix to mac (replace-string "\n" "\r\n" nil 1 (1+ (buffer-size))) ; unix to dos (replace-string "\r" "\n" nil 1 (1+ (buffer-size))) ; mac to unix (replace-string "\r" "\r\n" nil 1 (1+ (buffer-size))) ; mac to dos (replace-string "\r\n" "\n" nil 1 (1+ (buffer-size))) ; dos to unix (replace-string "\r\n" "\r" nil 1 (1+ (buffer-size))) ; dos to mac ; (set-buffer-file-coding-system 'unix) ; or 'mac or 'dos (save-buffer) (kill-buffer mybuffer) ) ) Basically, i was trying to avoid having both to specify the from and to. I was hoping to just specifiy the to. any suggestions? Thanks. Xah xah@xahlee.org $B-t(B http://xahlee.org/