Emacs personal configuration
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

78 lines
2.1KB

  1. ;;; capnp-mode.el --- major mode for editing Capn' Proto Files
  2. ;; This is free and unencumbered software released into the public domain.
  3. ;; Author: Brian Taylor <el.wubo@gmail.com>
  4. ;; Version: 1.0.0
  5. ;;; Commentary:
  6. ;; Provides basic syntax highlighting for capnp files.
  7. ;;
  8. ;; To use:
  9. ;;
  10. ;; Add something like this to your .emacs file:
  11. ;;
  12. ;; (add-to-list 'load-path "~/src/capnproto/highlighting/emacs")
  13. ;; (require 'capnp-mode)
  14. ;; (add-to-list 'auto-mode-alist '("\\.capnp\\'" . capnp-mode))
  15. ;;
  16. (add-to-list 'auto-mode-alist '("\\.capnp\\'" . capnp-mode))
  17. ;;; Code:
  18. ;; command to comment/uncomment text
  19. (defun capnp-comment-dwim (arg)
  20. "Comment or uncomment current line or region in a smart way.
  21. For detail, see `comment-dwim'."
  22. (interactive "*P")
  23. (require 'newcomment)
  24. (let (
  25. (comment-start "#") (comment-end "")
  26. )
  27. (comment-dwim arg)))
  28. (defvar capnp--syntax-table
  29. (let ((syn-table (make-syntax-table)))
  30. ;; bash style comment: “# …”
  31. (modify-syntax-entry ?# "< b" syn-table)
  32. (modify-syntax-entry ?\n "> b" syn-table)
  33. syn-table)
  34. "Syntax table for `capnp-mode'.")
  35. (defvar capnp--keywords
  36. '("struct" "enum" "interface" "union" "import"
  37. "using" "const" "annotation" "extends" "in"
  38. "of" "on" "as" "with" "from" "fixed")
  39. "Keywords in `capnp-mode'.")
  40. (defvar capnp--types
  41. '("union" "group" "Void" "Bool" "Int8" "Int16"
  42. "Int32" "Int64" "UInt8" "UInt16" "UInt32"
  43. "UInt64" "Float32" "Float64" "Text" "Data"
  44. "AnyPointer" "AnyStruct" "Capability" "List")
  45. "Types in `capnp-mode'.")
  46. (defvar capnp--font-lock-keywords
  47. `(
  48. (,(regexp-opt capnp--keywords 'words) . font-lock-keyword-face)
  49. (,(regexp-opt capnp--types 'words) . font-lock-type-face)
  50. ("@\\w+" . font-lock-constant-face))
  51. "Font lock definitions in `capnp-mode'.")
  52. ;;;###autoload
  53. (define-derived-mode capnp-mode prog-mode
  54. "capn-mode is a major mode for editing capnp protocol files"
  55. :syntax-table capnp--syntax-table
  56. (setq font-lock-defaults '((capnp--font-lock-keywords)))
  57. (setq mode-name "capnp")
  58. (define-key capnp-mode-map [remap comment-dwim] 'capnp-comment-dwim))
  59. (provide 'capnp-mode)