如何配置 GNU Emacs 默认写入 UNIX 或 DOS 格式的文件? [英] How to configure GNU Emacs to write UNIX or DOS formatted files by default?

查看:24
本文介绍了如何配置 GNU Emacs 默认写入 UNIX 或 DOS 格式的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 .emacs.el 文件中已经有这些函数多年了:

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))

这些功能让我可以轻松地在格式之间切换,但我不确定如何将 Emacs 配置为默认情况下以一种特定格式编写,而不管我使用的是哪个平台.就像现在一样,当我在 Windows 上运行时,Emacs 以 Windows 格式保存;当我在 UNIX/Linux 中运行时,Emacs 以 UNIX 格式保存.

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.

我想指示 Emacs 以 UNIX 格式编写,而不管我在哪个平台上运行.我该怎么做?

我是否应该添加一些调用这些函数之一的文本模式挂钩?例如,如果我在 Windows 上,那么当我找到一个文本文件时调用 dos2unix 吗?

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?

推荐答案

我的 .emacs 中有很多这样的:

I've got a bunch of these in my .emacs:

(setq-default buffer-file-coding-system 'utf-8-unix)
(setq-default default-buffer-file-coding-system 'utf-8-unix)
(set-default-coding-systems 'utf-8-unix)
(prefer-coding-system 'utf-8-unix)

我不知道哪个是对的,我只是迷信.

I don't know which is right, I am just superstitious.

这篇关于如何配置 GNU Emacs 默认写入 UNIX 或 DOS 格式的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆