comparison contrib/hg-test-mode.el @ 22081:ed426b011612

contrib: add emacs mode for *.t files
author Matt Mackall <mpm@selenic.com>
date Fri, 08 Aug 2014 17:45:36 -0500
parents
children 6e5ff8e26af6
comparison
equal deleted inserted replaced
22080:37f46575d9c2 22081:ed426b011612
1 ;; hg-test-mode.el - Major mode for editing Mercurial tests
2 ;;
3 ;; Copyright 2014 Matt Mackall <mpm@selenic.com>
4 ;; "I have no idea what I'm doing"
5 ;;
6 ;; This software may be used and distributed according to the terms of the
7 ;; GNU General Public License version 2 or any later version.
8 ;;
9 ;; To enable, add something like the following to your .emacs:
10 ;;
11 ;; (if (file-exists-p "~/hg/contrib/hg-test-mode.el")
12 ;; (load "~/hg/contrib/hg-test-mode.el"))
13
14 (defvar hg-test-mode-hook nil)
15
16 (defvar hg-test-mode-map
17 (let ((map (make-keymap)))
18 (define-key map "\C-j" 'newline-and-indent)
19 map)
20 "Keymap for hg test major mode")
21
22 (add-to-list 'auto-mode-alist '("\\.t\\'" . hg-test-mode))
23
24 (defconst hg-test-font-lock-keywords-1
25 (list
26 '("^ \\(\\$\\|>>>\\) " 1 font-lock-builtin-face)
27 '("^ \\(>\\|\\.\\.\\.\\) " 1 font-lock-constant-face)
28 '("^ \\([[][0-9]+[]]\\)$" 1 font-lock-warning-face)
29 '("^ \\(.*?\\)\\(\\( [(][-a-z]+[)]\\)+\\)$" 2 font-lock-type-face)
30 '("^ \\(.*?\\)\\(\\( [(][-a-z]+[)]\\)*\\)$" 1 font-lock-string-face)
31 '("^#.*" . font-lock-preprocessor-face)
32 '("^\\([^ ].*\\)$" 1 font-lock-comment-face)
33 )
34 "Minimal highlighting expressions for hg-test mode")
35
36 (defvar hg-test-font-lock-keywords hg-test-font-lock-keywords-1
37 "Default highlighting expressions for hg-test mode")
38
39 (defvar hg-test-mode-syntax-table
40 (let ((st (make-syntax-table)))
41 (modify-syntax-entry ?\" "w" st) ;; disable standard quoting
42 st)
43 "Syntax table for hg-test mode")
44
45 (defun hg-test-mode ()
46 (interactive)
47 (kill-all-local-variables)
48 (use-local-map hg-test-mode-map)
49 (set-syntax-table hg-test-mode-syntax-table)
50 (set (make-local-variable 'font-lock-defaults) '(hg-test-font-lock-keywords))
51 (setq major-mode 'hg-test-mode)
52 (setq mode-name "hg-test")
53 (run-hooks 'hg-test-mode-hook))
54
55 (provide 'hg-test-mode)