|
| 1 | +;;; dotprompt-mode.el --- Major mode for Dotprompt files -*- lexical-binding: t; -*- |
| 2 | + |
| 3 | +;; Copyright 2026 Google LLC |
| 4 | +;; |
| 5 | +;; Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +;; you may not use this file except in compliance with the License. |
| 7 | +;; You may obtain a copy of the License at |
| 8 | +;; |
| 9 | +;; http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +;; |
| 11 | +;; Unless required by applicable law or agreed to in writing, software |
| 12 | +;; distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +;; See the License for the specific language governing permissions and |
| 15 | +;; limitations under the License. |
| 16 | + |
| 17 | +;; Author: Google |
| 18 | +;; Version: 0.1.0 |
| 19 | +;; Keywords: languages, dotprompt |
| 20 | +;; URL: https://github.com/google/dotprompt |
| 21 | + |
| 22 | +;;; Commentary: |
| 23 | + |
| 24 | +;; Major mode for editing Dotprompt files (.prompt). |
| 25 | +;; Provides minimal syntax highlighting for markers, helpers, and partials. |
| 26 | +;; For best results with frontmatter, consider using polymode or mmm-mode. |
| 27 | + |
| 28 | +;;; Code: |
| 29 | + |
| 30 | +(defgroup dotprompt nil |
| 31 | + "Major mode for editing Dotprompt files." |
| 32 | + :prefix "dotprompt-" |
| 33 | + :group 'languages) |
| 34 | + |
| 35 | +(defvar dotprompt-mode-hook nil |
| 36 | + "Hook run after entering `dotprompt-mode'.") |
| 37 | + |
| 38 | +(defvar dotprompt-font-lock-keywords |
| 39 | + (list |
| 40 | + ;; Markers <<<dotprompt:role:system>>> |
| 41 | + '("<<<dotprompt:[^>]+>>>" . font-lock-preprocessor-face) |
| 42 | + |
| 43 | + ;; Partials {{> partialName}} |
| 44 | + '("{{>\\s-*[a-zA-Z0-9_.-]+\\s-*\\(.*?\\)}}" . font-lock-builtin-face) |
| 45 | + |
| 46 | + ;; Handlebars Control Flow {{#if}} {{/if}} |
| 47 | + '("{{[#/]\\(if\\|unless\\|each\\|with\\|log\\|lookup\\|else\\)" 1 font-lock-keyword-face) |
| 48 | + |
| 49 | + ;; Dotprompt Helpers (distinct color) |
| 50 | + '("\\<\\(json\\|role\\|history\\|section\\|media\\|ifEquals\\|unlessEquals\\)\\>" . font-lock-function-name-face) |
| 51 | + |
| 52 | + ;; General tags |
| 53 | + '("{{" . font-lock-delimiter-face) |
| 54 | + '("}}" . font-lock-delimiter-face) |
| 55 | + ) |
| 56 | + "Minimal highlighting for Dotprompt.") |
| 57 | + |
| 58 | +;;;###autoload |
| 59 | +(define-derived-mode dotprompt-mode prog-mode "Dotprompt" |
| 60 | + "Major mode for editing Dotprompt files." |
| 61 | + |
| 62 | + ;; Comments |
| 63 | + (setq-local comment-start "{{! ") |
| 64 | + (setq-local comment-end " }}") |
| 65 | + |
| 66 | + ;; Font lock |
| 67 | + (setq-local font-lock-defaults '(dotprompt-font-lock-keywords))) |
| 68 | + |
| 69 | +;;;###autoload |
| 70 | +(add-to-list 'auto-mode-alist '("\\.prompt\\'" . dotprompt-mode)) |
| 71 | + |
| 72 | +(provide 'dotprompt-mode) |
| 73 | + |
| 74 | +;;; dotprompt-mode.el ends here |
0 commit comments