cannam@48: ;;; capnp-mode.el --- major mode for editing Capn' Proto Files cannam@48: cannam@48: ;; This is free and unencumbered software released into the public domain. cannam@48: cannam@48: ;; Author: Brian Taylor cannam@48: ;; Version: 1.0.0 cannam@48: cannam@48: ;;; Commentary: cannam@48: cannam@48: ;; Provides basic syntax highlighting for capnp files. cannam@48: ;; cannam@48: ;; To use: cannam@48: ;; cannam@48: ;; Add something like this to your .emacs file: cannam@48: ;; cannam@48: ;; (add-to-list 'load-path "~/src/capnproto/highlighting/emacs") cannam@48: ;; (require 'capnp-mode) cannam@48: ;; (add-to-list 'auto-mode-alist '("\\.capnp\\'" . capnp-mode)) cannam@48: ;; cannam@48: cannam@48: ;;; Code: cannam@48: cannam@48: ;; command to comment/uncomment text cannam@48: (defun capnp-comment-dwim (arg) cannam@48: "Comment or uncomment current line or region in a smart way. cannam@48: For detail, see `comment-dwim'." cannam@48: (interactive "*P") cannam@48: (require 'newcomment) cannam@48: (let ( cannam@48: (comment-start "#") (comment-end "") cannam@48: ) cannam@48: (comment-dwim arg))) cannam@48: cannam@48: (defvar capnp--syntax-table cannam@48: (let ((syn-table (make-syntax-table))) cannam@48: cannam@48: ;; bash style comment: “# …” cannam@48: (modify-syntax-entry ?# "< b" syn-table) cannam@48: (modify-syntax-entry ?\n "> b" syn-table) cannam@48: cannam@48: syn-table) cannam@48: "Syntax table for `capnp-mode'.") cannam@48: cannam@48: (defvar capnp--keywords cannam@48: '("struct" "enum" "interface" "union" "import" cannam@48: "using" "const" "annotation" "extends" "in" cannam@48: "of" "on" "as" "with" "from" "fixed") cannam@48: "Keywords in `capnp-mode'.") cannam@48: cannam@48: (defvar capnp--types cannam@48: '("union" "group" "Void" "Bool" "Int8" "Int16" cannam@48: "Int32" "Int64" "UInt8" "UInt16" "UInt32" cannam@48: "UInt64" "Float32" "Float64" "Text" "Data" cannam@48: "AnyPointer" "AnyStruct" "Capability" "List") cannam@48: "Types in `capnp-mode'.") cannam@48: cannam@48: (defvar capnp--font-lock-keywords cannam@48: `( cannam@48: (,(regexp-opt capnp--keywords 'words) . font-lock-keyword-face) cannam@48: (,(regexp-opt capnp--types 'words) . font-lock-type-face) cannam@48: ("@\\w+" . font-lock-constant-face)) cannam@48: "Font lock definitions in `capnp-mode'.") cannam@48: cannam@48: ;;;###autoload cannam@48: (define-derived-mode capnp-mode prog-mode cannam@48: "capn-mode is a major mode for editing capnp protocol files" cannam@48: :syntax-table capnp--syntax-table cannam@48: cannam@48: (setq font-lock-defaults '((capnp--font-lock-keywords))) cannam@48: cannam@48: cannam@48: (setq mode-name "capnp") cannam@48: (define-key capnp-mode-map [remap comment-dwim] 'capnp-comment-dwim)) cannam@48: cannam@48: (provide 'capnp-mode)