do not edit — generated by btf.
git.druid.rocksindexdruid520radiumradium-lang-btf.el

radium-lang-btf.el


;;; radium-lang-btf.el, minimal major mode for btf/.btft/.btfs -*- lexical-binding: t; -*-
;;
;; no package on elpa/melpa covers btf (druid520/btf.git) - written
;; from scratch, same reasoning as radium-lang-kona.el. .btft (pages)
;; and .btfs (stylesheets, compiled to real css by btf.pm's own
;; compile_css) are one grammar, not two: a tag is `[name attr="val"
;; ...]`, closed by the one universal `[e]` (never a per-tag closer
;; like html's `</name>`) - `[rule sel="..."]`/`[prop n="..."]` in a
;; .btfs are just ordinary tags under that same grammar, not a
;; separate syntax, so one mode genuinely covers both extensions.
;;
;; grammar taken directly from btf.pm's own tokenizer (`tok`), not
;; guessed from example files: a tag name is [a-z][a-z0-9-]*, an
;; attribute is name="value" (double-quoted only), `\` escapes exactly
;; the next character (`\[` for a literal bracket, `\\` for a literal
;; backslash), and an unrecognized `[...]` (no closing `]`, or content
;; that isn't `e`, `/nav` or a name-then-attrs shape) degrades to a
;; literal `[` rather than eating the rest of the line - btf.pm's own
;; comment here on why: real bracket-shaped prose text (not markup)
;; should still show itself. `[comment]...[e]` is a real tag, not
;; special syntax - btf2html/btf2man give it skip-the-content meaning,
;; the tokenizer doesn't - so it's highlighted like any other tag name
;; here rather than as a real multiline comment region; comment-start/
;; -end are still wired to it for M-; anyway, cheap and correct even
;; without the fontification to match.
 
(define-derived-mode btf-mode text-mode "btf"
  "major mode for .btft/.btfs: fontification and comment-dwim for
btf's `[name attr=\"val\"]...[e]' markup."
  (setq-local indent-tabs-mode t)
  (setq-local tab-width 8)
  (setq-local comment-start "[comment]")
  (setq-local comment-end "[e]")
  (setq-local comment-start-skip "\\[comment\\]\\s-*")
  (setq-local font-lock-defaults '(radium-btf-font-lock-keywords)))
 
(defvar radium-btf-font-lock-keywords
  '(;; the one universal close, and the one special-named close -
    ;; matched before the general tag-name rule below so `[e]' itself
    ;; doesn't also get painted as if "e" were an ordinary tag name.
    ("\\[e\\]\\|\\[/nav\\]" . font-lock-builtin-face)
    ;; an opening tag's name only (not its attributes, not the
    ;; brackets) - [a-z][a-z0-9-]*, right after `[`.
    ("\\[\\([a-z][a-z0-9-]*\\)" 1 font-lock-function-name-face)
    ;; attr="value" pairs: only ever appear inside a tag per the
    ;; grammar above, so matching them anywhere (not anchored to a
    ;; specific enclosing tag) is correct and much simpler than an
    ;; anchored sub-match for a variable-length attribute list.
    ("\\([a-z][a-z0-9-]*\\)=\"\\([^\"]*\\)\"" (1 font-lock-variable-name-face) (2 font-lock-string-face))
    ;; `\[' / `\\' escapes - dim the backslash itself so the escaped
    ;; character reads as plain text, not markup.
    ("\\(\\\\\\)[\\[]" 1 font-lock-warning-face))
  "fontification for btf-mode: tag names, attributes, the universal
[e] close, and \\-escapes. no attempt at validating a document's
actual tag vocabulary - btf itself has none, any name is legal.")
 
(add-to-list 'auto-mode-alist '("\\.btft\\'" . btf-mode))
(add-to-list 'auto-mode-alist '("\\.btfs\\'" . btf-mode))
 
(provide 'radium-lang-btf)
powered by btf.