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