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