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