---
title: "emacs下rails模式中的错误代码的颜色修改"
author: "kiol"
date: "2008-07-02T22:01:11Z"
tags: []
slug: "emacs-rails"
draft: false
lastmod: "2008-07-02T22:01:11Z"
id: 210793
url: "https://kiol.iteye.com/blog/210793"
---

联系使用emacs做rails开发,并使用color-theme做了色彩调整,我用的是(color-theme-calm-forest),但是在代码出错后,背景色变得和前景色极为相近,非常难辩认.修改color-theme不起作用,后来发现所有色彩主题都是同样的颜色,后又猜是ruby-mode搞得,看了一遍也没找到原因.最后终于找到,可以使用

"Set point on a comment and hit \`M-x describe-face'.  You can also use  
\`M-x customize-face' to modify it."

然后看了一下,原来flyMake搞的鬼,应该rails带的,以前到没注意这个,有空看看除了实时提醒代码错误外,还能干嘛.

最后加了一行代码解决:

(custom-set-faces '(flymake-errline ((((class color)) (:background "DarkRed")))))

全部.emacs文件如下:

(desktop-save-mode 1)

(setq default-major-mode 'text-mode)  
(add-hook 'text-mode-hook 'turn-on-auto-fill)

;;(global-font-lock-mode)  
(transient-mark-mode t)

(fset 'yes-or-no-p 'y-or-n-p)  
(display-time)  
(show-paren-mode t)  
(tool-bar-mode -1)  
(menu-bar-mode -1)  
(scroll-bar-mode -1)  
(setq-default make-backup-files nil)  
(setq default-directory "E:/NBProjects/")

(global-set-key \[(meta g)] 'goto-line)  
(global-set-key \[(meta left)] 'backward-sexp)  
(global-set-key \[(meta right)] 'forward-sexp)  
(global-set-key "\\C-x\\C-m" 'execute-extended-command)  
(global-set-key "\\C-c\\C-m" 'execute-extended-command)  
(global-set-key "\\C-w" 'backward-kill-word)  
(global-set-key "\\C-x\\C-k" 'kill-region)  
(global-set-key "\\C-c\\C-k" 'kill-region)  
(global-set-key \[f5] 'call-last-kbd-macro)

;; Taken from the comment section in inf-ruby.el  
;; (setq ruby-program-name "/usr/local/bin/ruby")  
(add-to-list 'load-path (expand-file-name "D:/ruby/src/ruby-1.8.6-p111/misc"))  
(autoload 'ruby-mode "ruby-mode" "Mode for editing ruby source files")  
(add-to-list 'auto-mode-alist '("\\\\.rb$" . ruby-mode))  
(add-to-list 'interpreter-mode-alist '("ruby" . ruby-mode))  
(autoload 'run-ruby "inf-ruby" "Run an inferior Ruby process")  
(autoload 'inf-ruby-keys "inf-ruby" "Set local key defs for inf-ruby in ruby-mode")  
(add-hook 'ruby-mode-hook '(lambda () (inf-ruby-keys)  
                 (require 'ruby-electric)  
                 (ruby-electric-mode t)))

;; disable backup  
(setq make-backup-files nil)  
;; abbrev mode  
(setq-default abbrev-mode t)  
(read-abbrev-file "~/.emacs.d/abbrev\_defs")  
(setq save-abbrevs t)

(add-to-list 'load-path "~/site-lisp")  
(add-to-list 'load-path "~/site-lisp/rails")  
(add-to-list 'load-path "~/site-lisp/cedet/common")  
(add-to-list 'load-path "~/site-lisp/ecb")

(add-hook 'nxml-mode-hook  
          (lambda ()  
            (setq local-abbrev-table nxml-mode-abbrev-table)))  
(defun try-complete-abbrev (old)  
  (if (expand-abbrev) t nil))

(setq hippie-expand-try-functions-list  
      '(try-complete-abbrev  
        try-complete-file-name  
        try-expand-dabbrev))

(require 'psvn)  
(require 'snippet)  
(require 'cedet)  
(require 'rails)  
;; associate ruby-mode with .rb files  
(add-to-list 'auto-mode-alist '("\\.rb$" . ruby-mode))  
(setq auto-mode-alist  (cons '("\\\\.rjs$" . ruby-mode) auto-mode-alist))  
(setq auto-mode-alist  (cons '("\\\\.rake$" . ruby-mode) auto-mode-alist))  
(setq auto-mode-alist  (cons '("\\\\.rhtml$" . nxml-mode) auto-mode-alist))  
(setq auto-mode-alist  (cons '("\\\\.erb$" . nxml-mode) auto-mode-alist))

(modify-coding-system-alist 'file "\\\\.rhtml$" 'utf-8)  
(modify-coding-system-alist 'file "\\\\.erb$" 'utf-8)  
(modify-coding-system-alist 'file "\\\\.rb$" 'utf-8)  
(modify-coding-system-alist 'file "\\\\.rjs$" 'utf-8)  
(modify-coding-system-alist 'file "\\\\.yml$" 'utf-8)

(add-to-list 'load-path "~/site-lisp/yasnippet")  
(require 'yasnippet)  
(add-to-list 'yas/extra-mode-hooks  
             'ruby-mode-hook)  
(yas/initialize)  
(yas/load-directory "~/site-lisp/yasnippet/snippets")  
(setq yas/root-directory "~/snippets")  
(yas/load-directory yas/root-directory)  
(make-variable-buffer-local 'yas/trigger-key)  
(add-hook 'ruby-mode-hook ; or rails-minor-mode-hook ?  
          '(lambda ()  
             (setq yas/trigger-key  
                   (kbd "&lt;tab&gt;"))))  
(semantic-load-enable-code-helpers)  
(require 'ecb-autoloads)  
(mouse-avoidance-mode 'animate)   
   
(load "~/site-lisp/nxml/autostart.el")

(add-to-list 'auto-mode-alist '("\\\\.css$" . css-mode)) 

(add-to-list 'load-path "~/site-lisp/color-theme")  
(require 'color-theme)   
(color-theme-initialize)   
;;(color-theme-gnome2)   
(color-theme-calm-forest)  
(custom-set-faces '(flymake-errline ((((class color)) (:background "DarkRed")))))

;;在html和css模式下将#XXXXXX按所代表的颜色着色  
(defvar hexcolour-keywords  
   '(("#\[abcdef\[:digit:]]\\\\{6\\\\}"  
      (0 (put-text-property (match-beginning 0)  
                            (match-end 0)  
                            'face (list :background  
                                        (match-string-no-properties 0)))))))  
 (defun hexcolour-add-to-font-lock ()  
   (font-lock-add-keywords nil hexcolour-keywords))  
 (add-hook 'nxml-mode-hook 'hexcolour-add-to-font-lock)  
 (add-hook 'css-mode-hook 'hexcolour-add-to-font-lock)  
   
;; for yaml   
    
(require 'yaml-mode)   
   
(add-to-list 'auto-mode-alist '("\\\\.yml$" . yaml-mode))   
(add-hook 'yaml-mode-hook   
          '(lambda ()   
             (define-key yaml-mode-map "\\C-m" 'newline-and-indent)))   
   
;; for javascript 

;;启动emacsclient服务，然后用emacsclientw.exe打开文件就不用新开一个emacs了  
(server-start)  
   
(autoload 'javascript-mode "javascript" nil t)   
(add-to-list 'auto-mode-alist '( "\\\\.js\\\\'" . javascript-mode))   
(custom-set-variables  
  ;; custom-set-variables was added by Custom.  
  ;; If you edit it by hand, you could mess it up, so be careful.  
  ;; Your init file should contain only one such instance.  
  ;; If there is more than one, they won't work right.  
 '(ecb-options-version "2.33beta2"))

(ido-mode t)