capnp-mode.el (2197B)
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 ;; URL: https://github.com/capnproto/capnproto 8 9 ;;; Commentary: 10 11 ;; Provides basic syntax highlighting for capnp files. 12 ;; 13 ;; To use: 14 ;; 15 ;; Add something like this to your .emacs file: 16 ;; 17 ;; (add-to-list 'load-path "~/src/capnproto/highlighting/emacs") 18 ;; (require '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' for ARG explanation." 27 (interactive "*P") 28 (require 'newcomment) 29 (let ( 30 (comment-start "#") (comment-end "")) 31 (comment-dwim arg))) 32 33 (defvar capnp--syntax-table 34 (let ((syn-table (make-syntax-table))) 35 36 ;; bash style comment: “# …” 37 (modify-syntax-entry ?# "< b" syn-table) 38 (modify-syntax-entry ?\n "> b" syn-table) 39 40 syn-table) 41 "Syntax table for `capnp-mode'.") 42 43 (defvar capnp--keywords 44 '("struct" "enum" "interface" "union" "import" 45 "using" "const" "annotation" "extends" "in" 46 "of" "on" "as" "with" "from" "fixed") 47 "Keywords in `capnp-mode'.") 48 49 (defvar capnp--types 50 '("union" "group" "Void" "Bool" "Int8" "Int16" 51 "Int32" "Int64" "UInt8" "UInt16" "UInt32" 52 "UInt64" "Float32" "Float64" "Text" "Data" 53 "AnyPointer" "AnyStruct" "Capability" "List") 54 "Types in `capnp-mode'.") 55 56 (defvar capnp--font-lock-keywords 57 `( 58 (,(regexp-opt capnp--keywords 'words) . font-lock-keyword-face) 59 (,(regexp-opt capnp--types 'words) . font-lock-type-face) 60 ("@\\w+" . font-lock-constant-face)) 61 "Font lock definitions in `capnp-mode'.") 62 63 ;;;###autoload 64 (define-derived-mode capnp-mode prog-mode 65 "capn-mode is a major mode for editing capnp protocol files" 66 :syntax-table capnp--syntax-table 67 68 (setq font-lock-defaults '((capnp--font-lock-keywords))) 69 70 71 (setq mode-name "capnp") 72 (define-key capnp-mode-map [remap comment-dwim] 'capnp-comment-dwim)) 73 74 ;;;###autoload 75 (add-to-list 'auto-mode-alist '("\\.capnp\\'" . capnp-mode)) 76 77 (provide 'capnp-mode) 78 ;;; capnp-mode.el ends here 79