annotate src/capnproto-git-20161025/highlighting/emacs/capnp-mode.el @ 157:570d27da3fb5

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