An acutally useful html-mode for emacs

If you've ever used html-mode for emacs, your reaction likely was similar to mine. "What the hell? Why does every time I type angle bracket it give me < Argggh!" So, I thought about it, and decided funamental mode was about the best for writing HTML.

I did want, however to be able to have pretty hilit19 colors (if you don't use emacs19, you're out of luck, sorry). So, I redefined html-mode to be the same as fundamental-mode, but with a different name, as follows:

(defun html-mode ()
  "Mkgray's html mode"
  (interactive)
  (setq major-mode 'html-mode)
  (setq mode-name "HTML")
  (run-hooks 'funamental-mode-hook))
And then enabled hilit19 stuff:
         (setq hilit-mode-enable-list  '(not text-mode)
               hilit-background-mode   'dark
               hilit-inhibit-hooks     nil
               hilit-inhibit-rebinding nil)
	 (require 'hilit19)
Then I added some pretty colors (the fun part). Specifically: Note, these colors are designed to work with an emacs with a dark color as a background. Here's the elisp:
; HTML stuff
         (hilit-add-pattern "&[^;]+;" "" 'green 'html-mode nil)
         (hilit-add-pattern "<[Ii][mM][Gg] *[^>]+>" "" 'yellow 'html-mode nil)
         (hilit-add-pattern "<[hH][1-6]>" "" 'red 'html-mode nil)
         (hilit-add-pattern "" "" 'hex-c44 'html-mode nil)
         (hilit-add-pattern "[hH][Rr][Ee][Ff] *= *\"[^\"]+\"" "" 'hex-28c 'html-mode nil)
         (hilit-add-pattern "<[aA] *[^>]+>" "" 'hex-55e 'html-mode nil)
         (hilit-add-pattern "" "" 'hex-33c 'html-mode nil)
         (hilit-add-pattern "]+>" "" 'hex-c7c 'html-mode nil)
         (hilit-add-pattern "<[^>]+>" "" 'hex-b3b 'html-mode nil)
Now, when I edit html, it looks nice in a way that is useful to me! My page about me now looks colorful in emacs [image].

Have fun.


Mkgray's homepage
About Mkgray