annotate src/capnproto-0.6.0/highlighting/emacs/capnp-mode.el @ 147:45360b968bf4

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