简体   繁体   English

emacs:重新缩进然后换行和缩进后的ruby模式

[英]emacs: ruby mode after reindent-then-newline-and-indent

i am using emacs 23.2 and reference configurations from purcell https://github.com/purcell/emacs.d i met a problem when i am edit ruby file and rails file, see below 我正在使用emacs 23.2和来自purcell的参考配置https://github.com/purcell/emacs.d我在编辑ruby文件和rails文件时遇到问题,请参见下文 在此处输入图片说明

steps: 脚步:
1. move the cursor to somewhere 1.将光标移到某处
2. hit "RET" key to add more new line, then move the cursor to somewhere 2.按“ RET”键添加更多新行,然后将光标移至某处
3. the red space happened at the last new line. 3.红色空间发生在最后一行新行中。

do you know how to turn this mark off? 您知道如何关闭此标记吗?

What's your problem with this feature? 您对此功能有什么疑问? The red space goes away as soon as you start typing doesn't it? 开始输入后,红色空格消失了,不是吗?

The feature is show-trailing-whitespace , and it's meant to help you see spurious space at EOL. 该功能是show-trailing-whitespace ,它旨在帮助您在EOL上看到虚假的空间。 Which is very helpful for team development environment, as checking in such code will annoy your teammates. 这对于团队开发环境非常有帮助,因为签入此类代码会使您的队友烦恼。

What you should do is add a before-save-hook that removes spurious whitespace see: 您应该做的是添加一个before-save-hook ,以除去虚假的空格,请参见:

http://www.emacswiki.org/emacs/DeletingWhitespace#toc3 http://www.emacswiki.org/emacs/DeletingWhitespace#toc3

code: 码:

(add-hook 'before-save-hook 'delete-trailing-whitespace)

If you want to disable show-trailing-whitespace as well: 如果还要禁用show-trailing-whitespace ,请执行以下操作:

(add-hook 'ruby-mode-hook (lambda ()
                            (setq show-trailing-whitespace nil)))

You might like to look at the ws-trim.el library, which removes trailing whitespace from lines which you edit, but by default does not remove them from other lines*. 您可能想看看ws-trim.el库,该库从您编辑的行中删除尾随空格,但默认情况下不会从其他行中删除它们*。

I find this best for version-control (compared to deleting all trailing whitespace upon saving), as you do not introduce changes in other people's work if you edit the same file. 对于版本控制,我发现这是最好的选择(与保存时删除所有尾随空白相比),因为如果您编辑同一文件,则不会在其他人的工作中引入更改。

(*) although it is also nicely configurable if you want it to do more than that. (*),但如果您希望它做得更多,它也可以很好地配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM