Emacs 选项卡全局配置
我正在尝试从 Vim 切换到 Emacs,但我正在绞尽脑汁地尝试将其配置为按照我希望的方式处理选项卡。我要求:
- 插入“制表符”以扩展为两个空格。无论我做什么,Emacs 都顽固地坚持八个。
- 制表符(即真正的
\t
字符)在屏幕上由两个 空格表示。 - 按 TAB 应该在光标处插入制表符,而不是缩进整行。目前,我在任何地方按 TAB 键,Emacs 都会销毁行开头的所有空格;这是迄今为止最令人气愤的事情。
我当前的 ~/.emacs
读取,
(setq standard-indent 2)
(setq-default indent-tabs-mode nil)
但我已经尝试了无数来自网络的建议配置,但没有一个达到他们所说的效果。 (API 会不断变化吗?显然,我正在使用 GNU Emacs 23.1.1
。)
I'm attempting to switch from Vim to Emacs, but I'm tearing my hair out trying to configure it to treat tabs how I wish. I require:
- Inserted "tabs" to be expanded into two spaces. Emacs stubbornly sticks to eight, no matter what I do.
- Tabs (i.e. real
\t
characters) to be represented on screen by two spaces. - Pressing TAB should insert a tab at the cursor rather than indent the entire line. Currently, I press TAB anywhere and Emacs destroys all whitespace at the start of the line; this is the most infuriating thing so far.
My current ~/.emacs
reads
(setq standard-indent 2)
(setq-default indent-tabs-mode nil)
but I have tried no end of suggested configurations from the web, none of which have done what they said they would. (Does the API constantly change? I'm using GNU Emacs 23.1.1
, apparently.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Emacs 对处理缩进有极其灵活的支持。通常,您所处的模式决定了它们的工作方式 - 因此,如果您正在处理 C 文件,那么按 Tab 的工作方式将与处理 Python 文件时不同。
因此,这确实取决于您所使用的工作模式,这将限制您获得的答案。在大多数情况下,我建议您不要反对它 - 对我来说,缩进行为是 emacs 最好的功能之一。但是,您确实需要花时间为自己定制它。
要更改制表符的显示方式,您需要将制表符宽度设置为 2。如果您正在编辑 Java 或 C 样式代码,那么听起来您想通过将这些设置为 NIL 来关闭所有良好的缩进功能:
我建议您通过自定义界面设置这些。如果您使用“Mxcustomize-group RET C”,那么您可以看到C模式的各种设置。
如果您编辑不同类型的文件,则说明会有所不同。
也许 emacs 的文件模式不正确。您可以尝试执行“Mx basic-mode”,看看您是否喜欢那里的行为。
Emacs has extremely flexible support for handling indentation. Generally the mode that you are in dictates how they work - so if you're working on a C file then the way that pressing tab works will be different than if you're working on a Python file.
So it does depend which mode you're working in, which will limit the answers you get. In most cases I would recommend that you don't fight against it - for me the indentation behaviour is one of the best features of emacs. However, you do need to spend the time to customize it for yourself.
To change the way that tabs are displayed you need to set tab-width to 2. If you're editing Java or C style code then it sounds like you want to turn off all the nice indentation features by these to NIL:
I suggest you set these through the customization interface. If you use "M-x customize-group RET C" then you can see the various settings for C mode.
If you're editting different types of files then the instructions will be different.
Perhaps emacs is in the wrong mode for your file. You could try doing "M-x fundamental-mode" to see if you prefer the behaviour there.
这应该能让你得到你想要的大部分东西。您可能需要自定义一些常用的其他编程模式。
This should get you most of what you want. You'll probably have to customize some other programming modes you commonly use.