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