Emacs Lisp: 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:

?xmlversion1.0” encoding “utf-8”」〕
〔feedxmlnshttp://www.w3.org/2005/Atom” xml:base “http://xahlee.org/emacs/”」

  〔title Xah's Emacs Blog〕
  〔subtitle Emacs, Emacs, Emacs〕
  〔linkrelself” href “http://xahlee.org/emacs/blog.xml”」〕
  〔linkrelalternate” href “http://xahlee.org/emacs/blog.html”」〕
  〔updated 2010-09-19T14:53:08-07:00〕
  〔author
name Xah Lee〕
   〔uri http://xahlee.org/〕
  〕

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

  〔entry
title Emacs: Abbrev Mode Tutorial〕
   〔id tag:xahlee.org,2010-09-19:215308〕
   〔updated 2010-09-19T14:53:08-07:00〕
   〔summary tutorial〕
   〔linkrelalternate” href “http://xahlee.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

;;; HISTORY
;; 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 Emacs Lisp: Regex Tutorial

Writing Major Mode Topics

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

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

Syntax Table

  1. Emacs Lisp: Syntax Table Tutorial
  2. Emacs Lisp: How to Find Syntax of a Character?
  3. Emacs Lisp: How to Modify Syntax Table Temporarily
  4. Emacs Lisp: How to Determine If Cursor is Inside String or Comment
  5. Emacs Lisp: Find Matching Bracket Character
Like it? Buy Xah Emacs Tutorial. Thanks.