Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 101 additions & 31 deletions packages/emacs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,103 @@

Provides a major mode for editing Dotprompt (`.prompt`) files with syntax highlighting and LSP support.

## Features

- **Syntax Highlighting**: Handlebars helpers, partials, Dotprompt markers
- **LSP Integration**: Diagnostics, formatting, hover via eglot or lsp-mode
- **Format Buffer**: `C-c C-f` or `M-x dotprompt-format-buffer`
- **Format on Save**: Optional automatic formatting

## Installation

### Manual
### use-package (Recommended)

```elisp
(use-package dotprompt-mode
:load-path "path/to/dotprompt/packages/emacs"
:mode "\\.prompt\\'"
:custom
(dotprompt-promptly-path "promptly")
(dotprompt-format-on-save t))
```

1. Copy `dotprompt-mode.el` to your load path (e.g., `~/.emacs.d/lisp/`).
2. Add the following to your init file:
### straight.el

```elisp
(add-to-list 'load-path "~/.emacs.d/lisp/")
(require 'dotprompt-mode)
(straight-use-package
'(dotprompt-mode :type git
:host github
:repo "google/dotprompt"
:files ("packages/emacs/*.el")))

(use-package dotprompt-mode
:mode "\\.prompt\\'"
:custom
(dotprompt-format-on-save t))
```

### Doom Emacs

Add to `packages.el`:

```elisp
(package! dotprompt-mode
:recipe (:host github
:repo "google/dotprompt"
:files ("packages/emacs/*.el")))
```

Add to `config.el`:

```elisp
(use-package! dotprompt-mode
:mode "\\.prompt\\'"
:config
(setq dotprompt-format-on-save t)
(add-hook 'dotprompt-mode-hook #'eglot-ensure))
```

### use-package
### Spacemacs

Add to your `dotspacemacs/user-config`:

```elisp
(use-package dotprompt-mode
:load-path "path/to/dotprompt/packages/emacs"
:mode "\\.prompt\\'")
:mode "\\.prompt\\'"
:init
(spacemacs/set-leader-keys-for-major-mode 'dotprompt-mode
"f" 'dotprompt-format-buffer))
```

## Features
### Manual

- **Syntax highlighting** for:
- Dotprompt markers (`<<<dotprompt:...>>>`)
- Handlebars helpers (`if`, `unless`, `each`)
- Dotprompt custom helpers (`json`, `role`, `history`)
- Partials (`{{> ... }}`)
- **Auto-detection** of `.prompt` files
- **LSP integration** via eglot or lsp-mode
1. Copy `dotprompt-mode.el` to your load path (e.g., `~/.emacs.d/lisp/`)
2. Add to your init file:

## LSP Support
```elisp
(add-to-list 'load-path "~/.emacs.d/lisp/")
(require 'dotprompt-mode)
```

For diagnostics, formatting, and hover documentation, install `promptly`:
## Install promptly for LSP Features

```bash
cargo install --path rs/promptly
# or
cargo build --release -p promptly
```

## LSP Support

### Using Eglot (Emacs 29+, built-in)

Eglot integration is automatic. Just enable eglot in your dotprompt buffers:
Eglot integration is automatic. Enable in your dotprompt buffers:

```elisp
(add-hook 'dotprompt-mode-hook 'eglot-ensure)
```

If `promptly` is not in your PATH, customize the path:

```elisp
(setq dotprompt-promptly-path "/path/to/promptly")
```

### Using lsp-mode

lsp-mode integration is also automatic:
Expand All @@ -64,15 +107,42 @@ lsp-mode integration is also automatic:
(add-hook 'dotprompt-mode-hook 'lsp-deferred)
```

### LSP Features

With LSP enabled, you get:
- **Diagnostics**: Real-time error detection for YAML and Handlebars syntax
- **Formatting**: Format buffer with `M-x lsp-format-buffer` or `M-x eglot-format-buffer`
- **Hover**: Documentation for Handlebars helpers and frontmatter fields (`M-x eldoc` or hover)

## Configuration

| Variable | Default | Description |
|----------|---------|-------------|
| `dotprompt-promptly-path` | `"promptly"` | Path to the promptly executable |
| `dotprompt-format-on-save` | `nil` | Format buffer before saving |

### Custom promptly path

```elisp
(setq dotprompt-promptly-path "/path/to/promptly")
```

### Enable format on save

```elisp
(setq dotprompt-format-on-save t)
```

## Keybindings

| Key | Command | Description |
|-----|---------|-------------|
| `C-c C-f` | `dotprompt-format-buffer` | Format the current buffer |

## LSP Features

With LSP enabled (eglot or lsp-mode), you get:

| Feature | Description |
|---------|-------------|
| **Diagnostics** | Real-time error detection for YAML and Handlebars syntax |
| **Formatting** | Format with `M-x eglot-format-buffer` or `M-x lsp-format-buffer` |
| **Hover** | Documentation with `M-x eldoc` or mouse hover |
| **Go to Definition** | Jump to partial files with `M-.` |

## Commands

- `dotprompt-format-buffer` - Format the current buffer using LSP or promptly directly
60 changes: 57 additions & 3 deletions packages/emacs/dotprompt-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
;; limitations under the License.

;; Author: Google
;; Version: 0.2.0
;; Version: 0.3.0
;; Keywords: languages, dotprompt
;; URL: https://github.com/google/dotprompt
;; Package-Requires: ((emacs "27.1"))

;;; Commentary:

Expand All @@ -26,6 +27,12 @@
;; Includes LSP integration via eglot or lsp-mode for diagnostics,
;; formatting, and hover documentation when `promptly` is installed.
;;
;; Features:
;; - Syntax highlighting for Handlebars templates
;; - LSP integration via eglot (Emacs 29+) or lsp-mode
;; - Format buffer command
;; - Format on save (optional)
;;
;; For best results with frontmatter, consider using polymode or mmm-mode.

;;; Code:
Expand All @@ -40,6 +47,11 @@
:type 'string
:group 'dotprompt)

(defcustom dotprompt-format-on-save nil
"When non-nil, format the buffer before saving."
:type 'boolean
:group 'dotprompt)

(defvar dotprompt-mode-hook nil
"Hook run after entering `dotprompt-mode'.")

Expand All @@ -66,6 +78,12 @@
)
"Minimal highlighting for Dotprompt.")

(defvar dotprompt-mode-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "C-c C-f") #'dotprompt-format-buffer)
map)
"Keymap for `dotprompt-mode'.")

;;;###autoload
(define-derived-mode dotprompt-mode prog-mode "Dotprompt"
"Major mode for editing Dotprompt files."
Expand All @@ -79,11 +97,48 @@
(setq-local tab-width 2)

;; Font lock
(setq-local font-lock-defaults '(dotprompt-font-lock-keywords)))
(setq-local font-lock-defaults '(dotprompt-font-lock-keywords))

;; Format on save hook
(when dotprompt-format-on-save
(add-hook 'before-save-hook #'dotprompt-format-buffer nil t)))

;;;###autoload
(add-to-list 'auto-mode-alist '("\\.prompt\\'" . dotprompt-mode))

;;; Format Command

(defun dotprompt-format-buffer ()
"Format the current buffer using promptly or LSP.
If an LSP client is connected, use LSP formatting.
Otherwise, call promptly fmt directly."
(interactive)
(cond
;; Try eglot first (Emacs 29+)
((and (fboundp 'eglot-managed-p) (eglot-managed-p))
(eglot-format-buffer))
;; Try lsp-mode
((and (fboundp 'lsp-workspaces) (lsp-workspaces))
(lsp-format-buffer))
;; Fall back to direct promptly call
(t
(dotprompt--format-with-promptly))))

(defun dotprompt--format-with-promptly ()
"Format the current buffer using promptly fmt."
(let ((temp-file (make-temp-file "dotprompt-format" nil ".prompt"))
(original-point (point)))
(unwind-protect
(progn
(write-region (point-min) (point-max) temp-file nil 'silent)
(let ((exit-code (call-process dotprompt-promptly-path nil nil nil
"fmt" temp-file)))
(when (zerop exit-code)
(erase-buffer)
(insert-file-contents temp-file)
(goto-char (min original-point (point-max))))))
(delete-file temp-file))))

;;; LSP Integration

;; Eglot integration (built-in to Emacs 29+)
Expand All @@ -106,4 +161,3 @@
(provide 'dotprompt-mode)

;;; dotprompt-mode.el ends here

43 changes: 40 additions & 3 deletions packages/jetbrains/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ Language support for Dotprompt (`.prompt`) files in JetBrains IDEs (IntelliJ IDE

- **Syntax Highlighting**: YAML frontmatter, Handlebars templates, Dotprompt markers
- **LSP Integration**: Real-time diagnostics, formatting, and hover documentation (via LSP4IJ)
- **Live Templates**: Type `role`, `if`, `each`, `json` + Tab for quick insertions
- **Code Comments**: Block comment support using `{{! ... }}`
- **Settings UI**: Configure promptly path and format on save

## Requirements

Expand Down Expand Up @@ -35,7 +37,7 @@ Language support for Dotprompt (`.prompt`) files in JetBrains IDEs (IntelliJ IDE

3. **Install**:
- Go to **Settings/Preferences** → **Plugins** → **⚙️** → **Install Plugin from Disk...**
- Select `build/distributions/dotprompt-intellij-0.1.0.zip`
- Select `build/distributions/dotprompt-intellij-0.2.0.zip`

### From Source (Bazel)

Expand Down Expand Up @@ -72,6 +74,30 @@ cargo build --release -p promptly
./gradlew test
```

## Live Templates

Type these abbreviations and press Tab to expand:

| Abbreviation | Expands To |
|--------------|------------|
| `role` | Role block with customizable role name |
| `system` | System role block |
| `user` | User role block |
| `model` | Model role block |
| `if` | Handlebars if block |
| `ifelse` | Handlebars if-else block |
| `unless` | Handlebars unless block |
| `each` | Handlebars each loop |
| `with` | Handlebars with block |
| `json` | JSON serialization helper |
| `media` | Media embedding helper |
| `history` | History insertion |
| `section` | Named section block |
| `partial` | Partial template inclusion |
| `comment` | Handlebars comment |
| `prompt` | Complete prompt template |
| `frontmatter` | YAML frontmatter |

## LSP Features

When `promptly` is installed and in your PATH, you get:
Expand All @@ -84,9 +110,20 @@ When `promptly` is installed and in your PATH, you get:

## Configuration

### Settings UI

Go to **Settings/Preferences** → **Languages & Frameworks** → **Dotprompt**:

- **Promptly path**: Custom path to the promptly executable
- **Enable LSP features**: Toggle diagnostics, formatting, hover
- **Format on save**: Automatically format when saving

### Auto-Detection

The plugin automatically finds `promptly` in:
1. System PATH
2. `~/.cargo/bin/promptly`
1. User-configured path (Settings)
2. System PATH
3. `~/.cargo/bin/promptly`

## Architecture

Expand Down
Loading
Loading