`

nXhtml: tame your rhtml files

阅读更多

I personally use Emacs as an IDE to develop rails project. Equipped with emacs-rails, it becomes a powerful IDE for rails developing.

However, you may noticed, it doesn’t have full support for rhtml files. You can use html-mode to edit rhtml files, it is already good enough. But is is of course not as good as other wonderful modes(e.g. ruby-mode) Emacs supplied.

Other choices is mmm-mode, two-mode-mode or some similar things. But it is a little complicated to config while the results is not very impressing.

There’s also a custom-made mode for rhtml files in Rinari: rhtml-mode. It might be good. Bug I guess there’s something wrong with the code. Emacs may become slow when I turn on this mode: a latency can be felt even to move the cursor up and down.

I still use the plain old html-mode to edit those rhtml files, until I finally find the godsends nXhtml package. It has a nxhtml-mode which can recognize plenty of embedded fragment including javascript, php and, of course, ruby, etc.

It is really an amazing package! And the installation is very simple. Just download the latest nXhtml zip package. Unzip it and load the autostart.el file in your Emacs.

However, as an Emacs geek, I always want to configure it to my own style. So here comes my configuration for nXhtml to edit rhtml files:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
(load "~/emacs/packages/nxml/autostart.el")
(add-to-list 'auto-mode-alist
             '("\\.rhtml$" . kid-rhtml-mode))
;; only special background in submode
(setq mumamo-chunk-coloring 'submode-colored)
(setq nxhtml-skip-welcome t)
 
;; do not turn on rng-validate-mode automatically, I don't like
;; the anoying red underlines
(setq rng-nxml-auto-validate-flag nil)
 
;; force to load another css-mode, the css-mode in nxml package
;; seems failed to load under my Emacs 23
(let ((load-path (cons "~/emacs/extension/"
                       load-path)))
  (require 'css-mode))
 
(defun kid-rhtml-mode ()
  (nxhtml-mode)
  ;; I don't use cua-mode, but nxhtml always complains. So, OK, let's
  ;; define this dummy variable
  (make-local-variable 'cua-inhibit-cua-keys)
  (setq mumamo-current-chunk-family '("eRuby nXhtml Family" nxhtml-mode
                                      (mumamo-chunk-eruby
                                       mumamo-chunk-inlined-style
                                       mumamo-chunk-inlined-script
                                       mumamo-chunk-style=
                                       mumamo-chunk-onjs=)))
  (mumamo-mode)
  (rails-minor-mode t)
  (auto-fill-mode -1)
  (setq tab-width 2)
  (setq indent-tab-mode nil))

You can see in the screenshot the nxhtml-mode recognize both ERB fragment and javascript fragment. It can also handle css fragment if you have proper css-mode installed(nxml comes with a css-mode, but it refuses to load with my Emacs 23). Wonderful! :D

分享到:
评论

相关推荐

    tame your game with as3

    标题与描述:“tame your game with as3” 在IT领域,特别是游戏开发和动画设计行业中,“tame your game with as3”是一个具有深刻含义的短语。它指向的是使用Adobe Flash CS3及其内置的ActionScript 3(简称AS3)...

    Pragmatic Guide to Sass 3

    ### Pragmatic Guide to Sass 3:掌握现代样式表 #### 概述 《Pragmatic Guide to Sass 3》是一本由Hampton Lintorn Catlin与Michael Lintorn Catlin共同编写的关于Sass(Syntactically Awesome Style Sheets)的...

    tame-oauth::locked_with_key:遵循sans-io方法的小型OAuth板条箱:crab:

    :locked_with_key: tame-oauth tame-oauth是遵循方法的小型oauth板条箱。 为什么? 您想控制如何实际发出oauth HTTP请求 为什么不? 当前唯一实现的身份验证流是GCP的服务帐户流。 可以添加其他流程,但是现在这...

    tame-gcs-具有少量Google Cloud Storage操作的小型图书馆-Rust开发

    tame-gcs tame-gcs是一箱带有sans-io方法的有限的Google Cloud Storage(GCS)操作集的板条箱。 为什么? 您想控制:open_file_folder:tame-gcs tame-gcs是一箱带有遵循sans-io方法的有限的Google Cloud Storage(GCS...

    TAME-开源

    【TAME-开源】项目是一个致力于构建全面且功能强大的即时通讯(IM)客户端的开源工程。这个项目的主要目标是提供一个跨平台的解决方案,让用户能够使用AOL Instant Messenger(AIM)服务进行通信。值得注意的是,...

    New programmer's survival manual 程序员新人生存手册

    Tame Complexity Tip 4. Fail Gracefully excerpt Tip 5. Be Stylish Tip 6. Improve Legacy Code Tip 7. Review Your Code Get Your Tools in Order Tip 8. Optimize Your Environment Tip 9. Speak Your ...

    前端开源库-tame-search

    **前端开源库-tame-search** 是一款专为前端开发者设计的高效、强大的搜索工具库,其核心目标是帮助开发者构建出灵活且精确的搜索功能。它具有高度可定制性,支持严格的通配符索引和搜索,使得在大量数据中进行高效...

    Android代码-Parrot

    then provides you a simple function to tame all your needs: ImageView.load This function has the following parameters: url, optional string with current remote image url placeholder, optional bitmap ...

    云计算-关于Q(√39)的Tame核的一些计算.pdf

    在本文中,主要探讨了关于虚二次域Q(√39)中Tame核的一些计算。Tame核是代数数论中的一个重要概念,特别是在研究类域论时扮演着核心角色。虚二次域Q(√39)是一个具有负判别式的数域,其结构在数学上具有独特的性质。...

    大学英语期末备考资料——四级高频词汇及例句(全面整合版,有大量补充!).doc

    - 例句:Tame elephants are different from wild elephants in many aspects, including their tempers. - 用法:in many aspects 在许多方面 6. approach (接近;方法) - 例句:What’s the biggest fear of ...

    Cucumber Recipes

    Powerful filters will tame tables full of test data, transforming them into the format your application needs. Custom output formatters will generate reports for any occasion. Continuous Integration ...

    Moving to Responsive Web Design(Apress,2016)

    can be daunting, but with this book and the right tools you can tame the scope of the project from the start and find the time for you and your team to work on making your site enjoyable on any ...

    TameImpalaQuiz

    **驯服黑斑羚乐队(Tame Impala)测验** 在音乐的世界里,Tame Impala是一个备受瞩目的名字,以其独特的迷幻流行音乐风格赢得了全球乐迷的喜爱。这个名为“Tame Impala Quiz”的测验旨在挑战你对这个澳大利亚独立...

    Tame Impala New Tab Theme-crx插件

    在每个新标签页上都包含Austrailian Psychadelic摇滚乐队Tame Impala的高清图片! 对于摇滚乐迷。 在每个新标签页上都包含Austrailian Psychadelic摇滚乐队Tame Impala的高清图片! 对于摇滚乐迷。 请给我们评分! ...

    [CrackBerry True Tales of BlackBerry Use and Abuse][part.1]

    How to tame and get the most out of your BlackBerry device BlackBerry etiquette guidelines This book offers a comprehensive 12 Step Plan for BlackBerry users and abusers. It’s a must have if you own...

    [CrackBerry True Tales of BlackBerry Use and Abuse][part.2]

    How to tame and get the most out of your BlackBerry device BlackBerry etiquette guidelines This book offers a comprehensive 12 Step Plan for BlackBerry users and abusers. It’s a must have if you own...

    吉他谱_The Less I Know The Better - Tame Impala.pdf

    初级入门吉他谱 guitar tab

    [Mac.Hacks(2013.3)].Chris.Seibold.文字版

    14. Hack14: 驯服你的浏览器(Tame Your Browsers) - 浏览器是大多数用户上网的主要工具,这个技巧可能包括提高浏览器安全性和隐私保护的措施,以及如何通过插件或扩展提高浏览器的效率和功能。 15. Hack15: 使用...

    Addison.Wesley.-.Imperfect.C++.Practical.Solutions.for.Real-Life.Programming.chm

    He shows you how to tame C++'s complexity, cut through its vast array of paradigms, take back control over your code--and get far better results. If you're a long-time C++ developer, this book will ...

Global site tag (gtag.js) - Google Analytics