comparison src/capnproto-git-20161025/highlighting/emacs/capnp-mode.el @ 133:1ac99bfc383d

Add Cap'n Proto source
author Chris Cannam <cannam@all-day-breakfast.com>
date Tue, 25 Oct 2016 11:17:01 +0100
parents
children
comparison
equal deleted inserted replaced
132:42a73082be24 133:1ac99bfc383d
1 ;;; capnp-mode.el --- major mode for editing Capn' Proto Files
2
3 ;; This is free and unencumbered software released into the public domain.
4
5 ;; Author: Brian Taylor <el.wubo@gmail.com>
6 ;; Version: 1.0.0
7
8 ;;; Commentary:
9
10 ;; Provides basic syntax highlighting for capnp files.
11 ;;
12 ;; To use:
13 ;;
14 ;; Add something like this to your .emacs file:
15 ;;
16 ;; (add-to-list 'load-path "~/src/capnproto/highlighting/emacs")
17 ;; (require 'capnp-mode)
18 ;; (add-to-list 'auto-mode-alist '("\\.capnp\\'" . capnp-mode))
19 ;;
20
21 ;;; Code:
22
23 ;; command to comment/uncomment text
24 (defun capnp-comment-dwim (arg)
25 "Comment or uncomment current line or region in a smart way.
26 For detail, see `comment-dwim'."
27 (interactive "*P")
28 (require 'newcomment)
29 (let (
30 (comment-start "#") (comment-end "")
31 )
32 (comment-dwim arg)))
33
34 (defvar capnp--syntax-table
35 (let ((syn-table (make-syntax-table)))
36
37 ;; bash style comment: “# …”
38 (modify-syntax-entry ?# "< b" syn-table)
39 (modify-syntax-entry ?\n "> b" syn-table)
40
41 syn-table)
42 "Syntax table for `capnp-mode'.")
43
44 (defvar capnp--keywords
45 '("struct" "enum" "interface" "union" "import"
46 "using" "const" "annotation" "extends" "in"
47 "of" "on" "as" "with" "from" "fixed")
48 "Keywords in `capnp-mode'.")
49
50 (defvar capnp--types
51 '("union" "group" "Void" "Bool" "Int8" "Int16"
52 "Int32" "Int64" "UInt8" "UInt16" "UInt32"
53 "UInt64" "Float32" "Float64" "Text" "Data"
54 "AnyPointer" "AnyStruct" "Capability" "List")
55 "Types in `capnp-mode'.")
56
57 (defvar capnp--font-lock-keywords
58 `(
59 (,(regexp-opt capnp--keywords 'words) . font-lock-keyword-face)
60 (,(regexp-opt capnp--types 'words) . font-lock-type-face)
61 ("@\\w+" . font-lock-constant-face))
62 "Font lock definitions in `capnp-mode'.")
63
64 ;;;###autoload
65 (define-derived-mode capnp-mode prog-mode
66 "capn-mode is a major mode for editing capnp protocol files"
67 :syntax-table capnp--syntax-table
68
69 (setq font-lock-defaults '((capnp--font-lock-keywords)))
70
71
72 (setq mode-name "capnp")
73 (define-key capnp-mode-map [remap comment-dwim] 'capnp-comment-dwim))
74
75 (provide 'capnp-mode)