unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* mac/dos/unix newline conversion without specify from
@ 2007-12-02 18:14 Xah Lee
  2007-12-04 14:18 ` David Reitter
  0 siblings, 1 reply; 17+ messages in thread
From: Xah Lee @ 2007-12-02 18:14 UTC (permalink / raw)
  To: help-gnu-emacs

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
\xAD\xF4 http://xahlee.org/

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2007-12-09  1:23 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-12-02 18:14 mac/dos/unix newline conversion without specify from Xah Lee
2007-12-04 14:18 ` David Reitter
2007-12-05 14:37   ` Xah Lee
2007-12-05 15:05     ` David Kastrup
2007-12-05 16:16       ` Xah Lee
2007-12-05 16:25         ` David Kastrup
2007-12-05 16:51           ` Xah Lee
2007-12-05 17:05             ` David Kastrup
2007-12-07 18:03               ` Xah Lee
2007-12-07 22:35                 ` Stefan Monnier
2007-12-07 16:27         ` Stefan Monnier
2007-12-07 18:04           ` Xah Lee
2007-12-07 22:30             ` Stefan Monnier
2007-12-08  0:38               ` Xah Lee
2007-12-08 11:47                 ` Eli Zaretskii
     [not found]                 ` <mailman.4757.1197114470.18990.help-gnu-emacs@gnu.org>
2007-12-08 17:12                   ` Xah Lee
2007-12-09  1:23                     ` David Kastrup

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).