How to configure GNU Emacs to write UNIX or DOS formatted files by default?
NickName:Greg Mattes Ask DateTime:2009-11-04T23:20:36

How to configure GNU Emacs to write UNIX or DOS formatted files by default?

I've had these functions in my .emacs.el file for years:

(defun dos2unix ()
  "Convert a DOS formatted text buffer to UNIX format"
  (interactive)
  (set-buffer-file-coding-system 'undecided-unix nil))

(defun unix2dos ()
  "Convert a UNIX formatted text buffer to DOS format"
  (interactive)
  (set-buffer-file-coding-system 'undecided-dos nil))

These functions allow me to easily switch between formats, but I'm not sure how to configure Emacs to write in one particular format by default regardless of which platform I'm using. As it is now, when I run on Windows, Emacs saves in Windows format; when I run in UNIX/Linux, Emacs saves in UNIX format.

I'd like to instruct Emacs to write in UNIX format regardless of the platform on which I'm running. How do I do this?

Should I perhaps add some text mode hook that calls one of these functions? For example, if I'm on Windows, then call dos2unix when I find a text file?

Copyright Notice:Content Author:「Greg Mattes」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/1674481/how-to-configure-gnu-emacs-to-write-unix-or-dos-formatted-files-by-default

Answers
user181548 2009-11-04T15:27:39

I've got a bunch of these in my .emacs:\n\n(setq-default buffer-file-coding-system 'utf-8-unix)\n(setq-default default-buffer-file-coding-system 'utf-8-unix)\n(set-default-coding-systems 'utf-8-unix)\n(prefer-coding-system 'utf-8-unix)\n\n\nI don't know which is right, I am just superstitious.",


More about “How to configure GNU Emacs to write UNIX or DOS formatted files by default?” related questions

How to configure GNU Emacs to write UNIX or DOS formatted files by default?

I've had these functions in my .emacs.el file for years: (defun dos2unix () "Convert a DOS formatted text buffer to UNIX format" (interactive) (set-buffer-file-coding-system 'undecided-unix ...

Show Detail

How to set the default line terminator for new files in emacs?

Is there a something I can put in my .emacs config file to set the default line-ending style for newly created files? I'm using GNU emacs for windows, but would like newly created files to use unix-

Show Detail

Checking for DOS files on UNIX

I want to check whether any DOS files exist in any specific directory. Is there any way to distinguish DOS files from UNIX apart from the ^M chars ? I tried using file, but it gives the same outpu...

Show Detail

How to convert some files from dos format to unix

I know how to change file format from dos to unix by use dos2unix, but how can I change ALL the files will under a directory tree. Can dos2unix change files recursively? for example, I have some ...

Show Detail

How to set umask and dos2unix when checking out on Linux?

How can I configure my svn client (/bin/svn) to check out files under a default permission setting (e.g. umask 0022 or chmod 755) as well as to instantly convert them from DOS file format? Currentl...

Show Detail

Do I need to know Emacs Lisp in order to use GNU/Emacs

Recently, I began studying GNU/Emacs. Was very easy to use program. Studied its structure. Tuned nice color for me. Configure it to class on C programming. Everything seemed normal. But now the que...

Show Detail

Java code to create or write files in UTF-8, DOS and UNIX formats

I want to create files using Java in the formats specified in question, ie. UTF-8 for the chartset, and either DOS or UNIX format for the end of lines. I tried lot of things and checked in Context

Show Detail

Ruby / CSV - Convert Dos to Unix

I currently use: http://emacswiki.org/emacs/DosToUnix to manually convert DOS CSVs to UNIX. Just wondering if there's a ruby function for the CSV library that I'm missing? And / or if it's possible...

Show Detail

How to run dos2unix for all the files in subfolders in bash?

I am using dos2unix *.sh to convert all the .sh files in the current directory. So how to convert all the .sh files in the subfolders as well? I tried this but it does not work for bash: How to ...

Show Detail

Is it possible to write custom primitives for GNU Emacs with C?

GNU Emacs is easily extended with Emacs Lisp. In some cases you may hit a performance wall even after byte compiling. In this situation it would be useful to be able to write C functions that you c...

Show Detail