Elisp: html6-mode

By Xah Lee. Date: . Last updated: .

This page shows a very simple example of writing a major mode for emacs.

Suppose you are designing HTML6, and it looks like this:

?xml 「version “1.0” encoding “utf-8”」〕
〔feed 「xmlns “http://www.w3.org/2005/Atom” xml:base “http://ergoemacs.org/emacs/”」

  〔title Xah's Emacs Blog〕
  〔subtitle Emacs, Emacs, Emacs〕
  〔link 「rel “self” href “http://ergoemacs.org/emacs/blog.xml”」〕
  〔link 「rel “alternate” href “http://ergoemacs.org/emacs/blog.html”」〕
  〔updated 2017-12-21T11:14:52-08:00〕
name Xah Lee〕
   〔uri http://xahlee.info/〕

  〔id http://ergoemacs.org/emacs/blog.html〕
  〔icon http://xahlee.org/ics/sum.png〕
  〔rights © 2009 to 2017, Xah Lee〕

title Emacs: Abbrev Mode Tutorial〕
   〔id tag:xahlee.org,2010-09-19:215308〕
   〔updated 2010-09-19T14:53:08-07:00〕
   〔summary tutorial〕
   〔link 「rel “alternate” href “http://ergoemacs.org/emacs/emacs_abbrev_mode.html”」〕

You want to write a emacs major mode to syntax color it.

Here's the code.

;;; xah-html6-mode.el --- Major mode for editing html6. -*- coding: utf-8 -*-

;; http://xahlee.info/comp/html6.html

;; version 0.3, 2016-09-08
;; version 0.1, 2010-12-17

(defvar xah-html6-font-lock-defaults nil "Value for font-lock-defaults.")

(setq xah-html6-font-lock-defaults
      '(("〔\\([^ ]+?\\) " . (1 font-lock-function-name-face))
        ("“\\([^ ]+?\\)”" . (1 font-lock-string-face))
        ("「\\([^」]+\\)」" . (1 font-lock-variable-name-face))
        ) )

(define-derived-mode xah-html6-mode fundamental-mode "HTML6"
  "sample simple mode for html6"
  (setq font-lock-defaults '(xah-html6-font-lock-defaults)))

(provide 'xah-html6)

For a detailed tutorial, see: How to Write a Emacs Major Mode for Syntax Coloring.

[see Elisp: Regex Tutorial]

Writing Major Mode

  1. How to Write a Emacs Major Mode for Syntax Coloring
  2. Elisp: Font Lock Mode Basics
  3. Elisp: How to Define Face
  4. Elisp: How to Color Comment in Major Mode
  5. Elisp: How to Write Comment Command in Major Mode
  6. Elisp: How to Write Your Own Comment Command from Scratch
  7. Elisp: How to Write Keyword Completion Command
  8. Elisp: How to Create Keymap for Major Mode
  9. Elisp: Abbrev, Template, for Major Mode
  10. Elisp: Text Properties
  11. Elisp: Overlay Highlighting
  12. Emacs: Lookup Google, Dictionary, Documentation
  13. Elisp: Syntax Table Tutorial

  1. Elisp: How to Name Your Major Mode
  2. Elisp: What's “feature”?
  3. Elisp: require, load, load-file, autoload, feature

Syntax Table

  1. Elisp: Syntax Table Tutorial
  2. Elisp: How to Find Syntax of a Character?
  3. Elisp: How to Modify Syntax Table Temporarily
  4. Elisp: How to Determine If Cursor is Inside String or Comment
  5. Elisp: Regex Patterns and Syntax Table
  6. Elisp: Find Matching Bracket Character
Patreon me $5 patreon

Or Buy Xah Emacs Tutorial

Or buy a nice keyboard: Best Keyboard for Emacs

If you have a question, put $5 at patreon and message me.