An Emacs package that integrates Fabric prompts with gptel for powerful LLM interactions.
- Use Fabric patterns (prompts) directly within Emacs
- No Fabric binary required - works entirely through gptel
- Support for both standard and custom Fabric patterns
- Interactive pattern selection with completion
- Create custom shortcuts for frequently used patterns
- Pattern caching for fast access
- History of recently used patterns
- Emacs 27.1 or later
- gptel 0.8.0 or later
- Fabric patterns installed (typically in
~/.config/fabric/)
(use-package gptel-fabric
:ensure t
:after gptel
:config
(gptel-fabric-setup))- Install and configure gptel
- Have Fabric patterns installed in
~/.config/fabric/(or configure custom location)
;; Clone this repository, then add to your init file:
(add-to-list 'load-path "/path/to/gptel-fabric")
(require 'gptel-fabric)
;; Optional: Setup with default configuration
(gptel-fabric-setup)(use-package gptel-fabric
:load-path "/path/to/gptel-fabric"
:after gptel
:config
(gptel-fabric-setup)
;; Optional: Set default pattern
(setq gptel-fabric-default-pattern "summarize"));; Set Fabric config directory (default: ~/.config/fabric/)
(setq gptel-fabric-config-dir "~/my-fabric-config/")
;; Set custom patterns directory explicitly
(setq gptel-fabric-custom-patterns-dir "~/my-patterns/")
;; Set default pattern
(setq gptel-fabric-default-pattern "summarize")
;; Set history length
(setq gptel-fabric-history-length 30)gptel-fabric-select-pattern- Select a pattern interactivelygptel-fabric-send-with-pattern- Send region/buffer with selected pattern- Without prefix: Opens result in new buffer
- With prefix (C-u): Inserts result at point
gptel-fabric-replace-with-pattern- Replace region/buffer with LLM output- Replaces region if active, otherwise entire buffer
gptel-fabric-proofread- Quick proofreading with replacementgptel-fabric-query-with-pattern- Send a query with selected patterngptel-fabric-list-patterns- List all available patternsgptel-fabric-describe-pattern- Show details of a specific patterngptel-fabric-refresh-cache- Refresh the patterns cache
You can create dedicated commands for frequently used patterns:
;; Create a command for the 'summarize' pattern
(gptel-fabric-create-pattern-command "summarize")
;; This creates: gptel-fabric-run-summarize
;; Create a replace command for proofreading
(gptel-fabric-create-replace-command "proofreader")
;; This creates: gptel-fabric-replace-proofreader
;; Bind to keys
(global-set-key (kbd "C-c g s") 'gptel-fabric-run-summarize)
(global-set-key (kbd "C-c g p") 'gptel-fabric-replace-proofreader)
;; Or use the built-in proofreading function
(global-set-key (kbd "C-c g P") 'gptel-fabric-proofread)-
Summarize text:
;; Select text in buffer M-x gptel-fabric-send-with-pattern RET summarize RET -
Proofread and replace text:
;; Select text or use whole buffer M-x gptel-fabric-proofread RET ;; Or with any pattern: M-x gptel-fabric-replace-with-pattern RET improve_writing RET
-
Quick query with pattern:
M-x gptel-fabric-query-with-pattern RET explain_code RET ;; Type your code or question -
Using with keybindings:
;; Add to your config (define-key gptel-mode-map (kbd "C-c f") 'gptel-fabric-send-with-pattern) (define-key gptel-mode-map (kbd "C-c F") 'gptel-fabric-select-pattern) (define-key gptel-mode-map (kbd "C-c r") 'gptel-fabric-replace-with-pattern)
Fabric patterns are expected to have the following structure:
~/.config/fabric/
├── patterns/
│ ├── summarize/
│ │ ├── system.md
│ │ └── user.md
│ └── explain_code/
│ ├── system.md
│ └── user.md
└── patterns-custom/
└── my-pattern/
├── system.md
└── user.md
system.md- Contains the system prompt for the LLMuser.md- Contains user prompt template (optional)
- Pattern Discovery: Use
gptel-fabric-list-patternsto see all available patterns - Pattern Details: Use
gptel-fabric-describe-patternto view pattern prompts - Custom Patterns: Custom patterns are marked with
[CUSTOM]in listings - Performance: Patterns are cached on first use; refresh with
gptel-fabric-refresh-cache
# With gptel installed (full test suite)
make test
# Or specify gptel location
GPTEL_DIR=/path/to/gptel make test
# Standalone tests (without gptel)
make test-standalonemake compilemake lint
make package-lint # Requires package-lintmake check # Runs lint and testsThis program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
See LICENSE for details.
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Before submitting, please ensure:
- All tests pass (
make test) - Code is properly formatted
- Documentation is updated if needed
Alex Olkhovskiy gtptel-fabric@monoinbox.co.uk