将 emacs ruby 模式缩进更改为 4 个空格
在上一篇文章中,我在 emacs 中使用了 Ruby 模式。这很好用。
我们公司使用缩进有 4 个空格,而不是默认的 2 个。我很难让它工作。
这是我的 .emacs 文件
(添加到列表'加载路径“~/rdoc-mode.el”)
(需要“ruby 模式”)
(setq 缩进制表符模式 nil) ;始终用空格替换制表符
(setq-默认制表符宽度 4) ;将所有缓冲区的制表符宽度设置为 4
有人看到我做错了什么吗?
谢谢!
From a previous post I got Ruby mode working in emacs. This is working great.
Setting up .emacs file for mac ruby development
Our company uses 4 spaces for indents though instead of the default 2. I am having difficulty getting this to work.
Here is my .emacs file
(add-to-list 'load-path "~/rdoc-mode.el")
(require 'ruby-mode)
(setq indent-tabs-mode nil) ; always replace tabs with spaces
(setq-default tab-width 4) ; set tab width to 4 for all buffers
Does anyone see what I am doing wrong?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
tab-width
设置仅控制制表符的宽度,即制表符在缓冲区中显示时相当于多少个空格。它不会影响用于缩进代码的空格(或制表符)数量。对于 Ruby 代码,缩进由 ruby-indent-level 变量控制:
The
tab-width
setting only controls the width of a tab character, i.e. how many spaces a tab character is equivalent to when displayed in your buffer. It does not affect the number of spaces (or tabs) used for indenting your code.For Ruby code, the indentation is controlled by the
ruby-indent-level
variable:其他发帖者已经提供了正确答案,所以我在这里提到如何找出此类问题的答案。
首先,由于您正确地假设缩进宽度是可配置的,因此要尝试的第一件事是:
果然,自定义选项之一是“Ruby Indent Level”。您可以设置它并保存更改。完毕!
或者,您可以查看 ruby-mode 本身:
然后搜索(使用 Cs)“缩进”。在那里你会找到一个变量定义:
当你找到这样的变量时,你可以使用 setq 在 .emacs(或 ~/.emacs.d/init.el)中设置它:
你还可以使用 apropos 发现该变量:
这就是为什么 emacs 被描述为“自文档化”!
The other posters have provided the correct answer, so I'll mention here how to figure out the answer to this kind of question.
First of all, since you correctly assumed that the indent width would be configurable, the first thing to try is:
And sure enough, one of the customization options there is "Ruby Indent Level". You can set it and save the changes. Done!
Alternatively, you can look at ruby-mode itself:
Then search (with C-s) for 'indent'. There you'll find a variable definition:
When you find a variable like that, you can set it in your .emacs (or ~/.emacs.d/init.el) with setq:
You could also discover that variable using apropos:
That's why emacs is described as "self-documenting"!
有一种方法可以在不接触 .emacs 的情况下做到这一点。您可以在每个设置 "文件变量" 特定于该文件。任何 emacs 或 xemacs 编辑该文件都将使用模式、选项卡设置和等等在评论区。
作为示例,以下是我们用于 Ruby 开发的“文件变量”块:
There's a way to do it without touching .emacs. You can put a special comment block at the end of every Ruby file that sets "file variables" specific to that file. Any emacs or xemacs editing that file will use the mode, tab settings, & etc in that comment block.
As an example, here is the "file variables" block we use for Ruby development: