From owner-ntemacs-users@trout Sat Apr 26 09:10:21 1997 X-VM-v5-Data: ([nil nil nil nil nil nil nil nil nil] [nil "Sat" "26" "April" "1997" "11:26:31" "-0400" "Chris Weikart" "weikart@crl.dec.com" nil "84" "Re: ^M problem in copying from NT4.0 to SUN" "^From:" nil nil "4" nil nil nil nil] nil) Received: from joker.cs.washington.edu (joker.cs.washington.edu [128.95.1.42]) by june.cs.washington.edu (8.8.5+CS/7.2ju) with SMTP id JAA02892 for ; Sat, 26 Apr 1997 09:10:20 -0700 Received: from trout.cs.washington.edu (trout.cs.washington.edu [128.95.1.178]) by joker.cs.washington.edu (8.6.12/7.2ws+) with ESMTP id JAA30872 for ; Sat, 26 Apr 1997 09:10:19 -0700 Received: from june.cs.washington.edu (june.cs.washington.edu [128.95.1.4]) by trout.cs.washington.edu (8.8.5+CS/7.2ws+) with ESMTP id IAA15410 for ; Sat, 26 Apr 1997 08:30:42 -0700 (PDT) Received: from crl.dec.com (crl.dec.com [192.58.206.2]) by june.cs.washington.edu (8.8.5+CS/7.2ju) with SMTP id IAA01732 for ; Sat, 26 Apr 1997 08:30:41 -0700 Received: by crl.dec.com; id AA14276; Sat, 26 Apr 97 11:26:35 -0400 Received: by quabbin.crl.dec.com; id AA09368; Sat, 26 Apr 1997 11:26:34 -0400 Message-Id: <3.0.32.19970426112629.0073dfc4@pop-server.crl.dec.com> X-Sender: weikart@pop-server.crl.dec.com X-Mailer: Windows Eudora Pro Version 3.0 (32) Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" From: Chris Weikart To: "Murugappa Krishnan (Murgie)" , "NT-Emacs Email List." Subject: Re: ^M problem in copying from NT4.0 to SUN Date: Sat, 26 Apr 1997 11:26:31 -0400 > I use Emacs on NT4.0, and sometimes save a text file to a >SUN/UNIX machine (Samba connection) whose drive can be seen by our NT >4.0. Later when I read it in Emacs on the UNIX, there are ^M's all over. This is the CR/LF translation problem. There is a section in http://www.cs.washington.edu/homes/voelker/ntemacs.html about this entitled "How can I control CR/LF translation (e.g., to access UNIX files via NFS)?". But it does not contain the latest wisdom on the subject. May I suggest the following? It was cobbled together from various posts to the mailing list. 'check-buffer-file-type' puts a buffer into text-mode or not according to the contents of the file being loaded. 'toggle-buffer-file-type' allows you to change the mode by hand. Both of these work like a charm for me. It would be great if Geoff would put them in the FAQ. -Chris ;; Associate the universal match regexp "" with the ;; function check-buffer-file-type, so any file will be ;; examined to automatically select the appropriate mode. ;; Add this check only after known filename patterns are ;; treated the way they should be. (That's why we append ;; to the list, instead of replacing it). You might want ;; to use more more restrictive pattern(s) for doing this ;; check. (setq file-name-buffer-file-type-alist (append file-name-buffer-file-type-alist '(("" . check-buffer-file-type)))) (defun check-buffer-file-type (filename) "Examines the actual contents of the loaded file to see if it should use text mode or binary." (if (and (looking-at ".*\r\n") ;; has CR-LF sequence (not (re-search-forward "[^\r]\n]" nil t))) ;; and no LF w/o CR nil ;; so use text mode t)) ;; else binary mode (defun toggle-buffer-file-type (arg) "Alternate value of buffer-file-type. If you have loaded a file as binary that actually has the ^M's in it, then switching to text mode will remove them in the buffer. Of course now that it's in text mode, it will save with the ^M's inserted. Switching to binary mode does NOT have a reverse effect. If you want to disable that change on entering text mode, then use a negative prefix argument, as described below. A prefix argument will force the mode change in a particular direction. A positive prefix argument forces it to binary. A zero prefix argument forces text mode allowing the removal of ^M's (only preceding ^J's). A negative prefix argument forces text mode disallowing the removal of ^M's. When the mode is changed the state of modification of the buffer is preserved, even if the ^M's are removed." (interactive "P") (let ((old buffer-file-type) (mod (buffer-modified-p)) (buffer-read-only nil)) (setq buffer-file-type (if arg (>= arg 1) (not buffer-file-type))) (if (and old (not buffer-file-type) (or (not arg) (> arg -2))) (save-excursion (beginning-of-buffer) (while (search-forward "\r\n" nil t) (replace-match "\n" nil t)) (set-buffer-modified-p mod)))) (force-mode-line-update)) _______________________________________________________________________ Chris Weikart Digital Equipment Corporation Speech Interaction Group (Web Apps) Cambridge Research Laboratory tel: (617) 692-7649, (DTN) 259-7649 One Kendall Square Bldg. 700 fax: (617) 692-7650, (DTN) 259-7650 Cambridge MA 02139-1562 USA http://www.research.digital.com/CRL/personal/weikart/