简体   繁体   English

为杂乱的Rails文件启用ruby模式

[英]Enabling ruby-mode for sundry Rails files

I am in the process of learning both RoR and Emacs, a process that I happily expect to take up the rest of my lifetime, and my basic strategy is to start with a simple set of tools and then fill up my tool chest as I go along. 我正在学习RoR和Emacs,这是我很乐意占去我余生的过程,而我的基本策略是从使用一组简单的工具开始,然后随着我的前进填补工具箱沿。

To that end, I don't want to install Rinari or nXhtml just yet, but I would like at least basic syntax highlighting and indentation in the various Rails files. 为此,我现在还不想安装Rinari或nXhtml,但是我希望至少在各种Rails文件中突出显示基本语法和缩进。 I also don't want to use a emacs.d "starter kit" since another goal of mine is to understand every line of my Emacs configuration, and keep in nice and clean and free of cruft. 我也不想使用emacs.d“入门工具包”,因为我的另一个目标是了解我的Emacs配置的每一行,并保持整洁,干净而无毛病。

Problem is that it seems that many files in rails, like Gemfile use ruby syntax, but don't use the .rb suffix, eg, Gemfile, so I have to turn on ruby-mode for each file that I encounter. 问题在于,似乎轨道中的许多文件(例如Gemfile)都使用ruby语法,但没有使用.rb后缀(例如Gemfile),因此我必须为遇到的每个文件都打开ruby模式。 This doesn't seem like the Emacs way. 这似乎不像Emacs那样。

I was thinking that there must be a map out there of Rails files and the modes they use out there that I can easily plop into my config, but I can't seem to find it. 我当时在想,那里必须有一个Rails文件及其使用的模式的映射,我可以轻松地将它们放入我的配置中,但是我似乎找不到它。 Does anyone have any suggestions? 有没有人有什么建议?

Ruby-mode file associations: Ruby模式文件关联:

(add-to-list 'auto-mode-alist '("\\.\\(rb\\|ru\\|builder\\|rake\\|thor\\|gemspec\\)\\'" . ruby-mode))
(add-to-list 'auto-mode-alist '("\\(rake\\|thor\\|guard\\|gem\\|cap\\|vagrant\\)file\\'" . ruby-mode))

Editing modes for other types of files: 其他类型文件的编辑模式:

erb templates - rhtml-mode erb模板-rhtml-mode

haml templates - haml-mode haml模板-haml模式

slim templates - slim-mode 超薄模板- 超薄模式

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

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