Update Claude and theme configuration.

Configure claude-code/claudemacs runtime settings, switch theme setup to ewal-doom-one, and remove obsolete GPTEL setup docs.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-03-05 21:16:11 +08:00
parent 298a9913b5
commit c021bc8452
7 changed files with 72 additions and 289 deletions
+1
View File
@@ -17,3 +17,4 @@ tramp/
-259
View File
@@ -1,259 +0,0 @@
# gptel Configuration Guide
## 🎉 What Was Configured
Your Doom Emacs now has a comprehensive gptel setup with:
### ✅ Installed Packages
1. **gptel** - Main LLM client
2. **gptel-quick** - Quick lookups in popup
3. **gptel-extensions** - Extra utility functions
4. **gptel-autocomplete** - Inline code completion
### ✅ Configured Features
- ✨ OpenRouter backend with multiple models (Gemini, Claude)
- 📝 Org-mode as default (better for saving conversations)
- ⌨️ Comprehensive keybindings under `SPC a` prefix
- 🎨 5 task-specific presets (coder, explain, refactor, quick, docs)
- 🤖 Auto-completion in programming modes
- 🛠️ Custom helper functions for quick explanations and proofreading
---
## 🔐 IMPORTANT: Secure Your API Key
**⚠️ WARNING**: Your OpenRouter API key is currently hardcoded in `ai.el`. This is a security risk!
### Recommended Setup: Use auth-source
1. **Create encrypted credentials file:**
```bash
touch ~/.authinfo.gpg
chmod 600 ~/.authinfo.gpg
```
2. **Add your API key to `~/.authinfo.gpg`:**
```
machine openrouter.ai login apikey password sk-or-v1-YOUR_KEY_HERE
```
Emacs will prompt for a password to encrypt this file.
3. **Update `~/.config/doom/ai.el`:**
Replace the `:key` line in the `gptel-make-openai` section:
```elisp
;; BEFORE (insecure):
:key "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"
;; AFTER (secure):
:key (auth-source-pick-first-password :host "openrouter.ai")
```
4. **Reload Doom:**
```bash
doom sync
```
---
## ⌨️ Keybindings Reference
All gptel commands are under `SPC A` (uppercase A - AI prefix):
| Keybinding | Command | Description |
|------------|---------|-------------|
| `SPC A g` | `gptel` | Open gptel chat buffer |
| `SPC A s` | `gptel-send` | Send prompt to LLM |
| `SPC A m` | `gptel-menu` | Open transient menu (change model, backend, etc) |
| `SPC A r` | `gptel-rewrite` | Rewrite selected region with AI |
| `SPC A c` | `gptel-add` | Add region/buffer to context |
| `SPC A f` | `gptel-add-file` | Add file to context |
| `SPC A q` | `gptel-quick` | Quick lookup in popup (word/region) |
| `SPC A l` | Load buffer into session | Send whole buffer as context |
| `SPC A b` | Send whole buffer | Send entire buffer to AI |
| `SPC A R` | Refactor region | Refactor selected code |
| `SPC A e` | Quick explain | Explain selected code quickly |
| `SPC A p` | Proofread text | Fix grammar/spelling in selection |
| `SPC A C` | Complete at point | Trigger AI code completion |
| `SPC A a` | Accept completion | Accept displayed ghost text completion |
### In gptel buffer:
- `C-c RET` - Send message
- `C-c C-c` - Open menu
- `C-c C-k` - Abort request
### Auto-completion (in programming modes):
- `M-TAB` or `C-c TAB` - Trigger completion (`gptel-complete`)
- `C-c C-a` - Accept completion (`gptel-accept-completion`)
---
## 🎨 Using Presets
Presets let you switch AI behavior for specific tasks:
1. Open gptel menu: `SPC A m` or `C-c C-c`
2. Select "Preset" option
3. Choose from:
- **coder** - Expert coding assistant (uses Claude Sonnet 4.5)
- **explain** - Explain code to beginners
- **refactor** - Code refactoring expert
- **quick** - Quick, concise answers (uses fast Gemini Flash)
- **docs** - Documentation writer
Or use `C-u SPC A s` to adjust settings on-the-fly!
---
## 🚀 Quick Start Workflows
### 1. Chat with AI
```
SPC A g → Opens gptel buffer
Type question → Write your prompt
C-c RET → Send (or SPC A s)
```
### 2. Rewrite Code
```
1. Select code region (visual mode)
2. SPC A r
3. Type instruction: "Add error handling"
4. Review changes and accept
```
### 3. Add Context (Multi-file awareness)
```
1. Open reference file
2. SPC A c (adds buffer to context)
3. Open gptel: SPC A g
4. Now AI knows about the reference file!
```
### 4. Quick Explanations
```
1. Hover over word or select code
2. SPC A q
3. See explanation in popup!
```
### 5. Code Completion
```
Start typing code...
M-TAB or SPC A C → Request AI completion (shows as ghost text)
C-c C-a or SPC A a → Accept the completion
```
---
## 🏠 Local Models with Ollama (Optional)
Want to run AI locally for privacy?
1. **Install Ollama:**
```bash
# Linux
curl -fsSL https://ollama.com/install.sh | sh
# Start Ollama
ollama serve
```
2. **Pull models:**
```bash
ollama pull qwen2.5-coder:latest
ollama pull mistral:latest
```
3. **Uncomment Ollama config in `ai.el`:**
Look for the "Optional: Add Ollama" section around line 126 and uncomment:
```elisp
(after! gptel
(gptel-make-ollama "Ollama"
:host "localhost:11434"
:stream t
:models '(qwen2.5-coder:latest
mistral:latest
llama3.2:latest)))
```
4. **To make Ollama default**, uncomment lines 136-141 as well
5. **Reload:** `doom sync`
6. **Switch backends:** `SPC a m` → Select "Backend" → Choose "Ollama"
---
## 🎯 Pro Tips
1. **Save conversations**: gptel uses org-mode by default, so just save the buffer!
2. **Switch models on-the-fly**: `C-u SPC A s` before sending
3. **Context management**:
- Add files in Dired: Mark files → `SPC A c`
- Remove context: `SPC A m` → Manage context
4. **Org-mode features**:
- Each heading can be a separate conversation branch
- Set properties: `M-x gptel-org-set-properties`
- Set topic: `M-x gptel-org-set-topic`
5. **Custom instructions**: Use `SPC A r` on selected code and give specific instructions
6. **Programmatic use**: See helper functions at bottom of `ai.el` for examples
---
## 📚 Next Steps
1. **Secure your API key** (see section above)
2. **Run:** `doom sync` to install packages
3. **Restart Emacs**
4. **Try:** `SPC A g` to start chatting!
5. **Watch:** "Every LLM in Emacs, with gptel" video (17 min)
---
## 🐛 Troubleshooting
### Packages not loading?
```bash
doom sync
doom build
```
### Transient version error?
```elisp
;; Add to ai.el before gptel config:
(setq package-install-upgrade-built-in t)
```
Then: `M-x package-install RET transient RET`
### API key not working?
- Check `~/.authinfo.gpg` format
- Ensure proper encryption password
- Test: `(auth-source-pick-first-password :host "openrouter.ai")`
### Autocomplete not working?
- Trigger manually: `M-x gptel-complete` or `M-TAB`
- Accept completion: `M-x gptel-accept-completion` or `C-c C-a`
- Note: There's no auto-mode - you trigger completions on-demand
- Check gptel is configured and working first (`SPC A g`)
- Adjust context size if needed (see `gptel-autocomplete-*-context-lines` variables)
---
## 📖 Resources
- [gptel GitHub](https://github.com/karthink/gptel)
- [gptel Manual](https://gptel.org/manual.html)
- [OpenRouter Docs](https://openrouter.ai/docs)
- [Ollama Models](https://ollama.com/library)
---
**Enjoy your AI-powered Emacs! 🎉**
+45 -18
View File
@@ -48,32 +48,32 @@
(after! gptel
;; Coding assistant preset
(gptel-make-preset 'coder
:description "Expert coding assistant"
:backend "OpenRouter"
:model 'anthropic/claude-sonnet-4.5
:system "You are an expert coding assistant. Provide high-quality code solutions, refactorings, and explanations. Be concise but thorough. Include error handling and follow best practices.")
:description "Expert coding assistant"
:backend "OpenRouter"
:model 'anthropic/claude-sonnet-4.5
:system "You are an expert coding assistant. Provide high-quality code solutions, refactorings, and explanations. Be concise but thorough. Include error handling and follow best practices.")
;; Code explainer preset
(gptel-make-preset 'explain
:description "Explain code to beginners"
:system "Explain this code to a novice programmer. Use simple language and break down complex concepts.")
:description "Explain code to beginners"
:system "Explain this code to a novice programmer. Use simple language and break down complex concepts.")
;; Refactoring preset
(gptel-make-preset 'refactor
:description "Code refactoring expert"
:model 'anthropic/claude-sonnet-4.5
:system "You are a code refactoring expert. Improve code quality, readability, and performance while maintaining functionality. Explain your changes.")
:description "Code refactoring expert"
:model 'anthropic/claude-sonnet-4.5
:system "You are a code refactoring expert. Improve code quality, readability, and performance while maintaining functionality. Explain your changes.")
;; Quick answers preset
(gptel-make-preset 'quick
:description "Quick, concise answers"
:model 'google/gemini-2.5-flash
:system "Provide quick, concise answers. Be direct and to the point.")
:description "Quick, concise answers"
:model 'google/gemini-2.5-flash
:system "Provide quick, concise answers. Be direct and to the point.")
;; Documentation writer preset
(gptel-make-preset 'docs
:description "Documentation writer"
:system "Write clear, comprehensive documentation. Include examples and explain edge cases."))
:description "Documentation writer"
:system "Write clear, comprehensive documentation. Include examples and explain edge cases."))
;;; ============================================================================
;;; gptel-quick - Quick lookups and explanations
@@ -161,9 +161,9 @@
(when (use-region-p)
(let ((code (buffer-substring-no-properties (region-beginning) (region-end))))
(gptel-request code
:system "Explain this code concisely in 2-3 sentences."
:callback (lambda (response info)
(message "Explanation: %s" response))))))
:system "Explain this code concisely in 2-3 sentences."
:callback (lambda (response info)
(message "Explanation: %s" response))))))
(defun my/gptel-proofread-region ()
"Proofread and improve selected text."
@@ -183,8 +183,11 @@
(use-package! claude-code
:defer t
:config
(setq claude-code-program "ccr"
claude-code-program-switches '("code" "--dangerously-skip-permissions"))
;; Use vterm backend
(setq claude-code-terminal-backend 'vterm)
(setq claude-code-terminal-backend 'eat)
;; Enable global mode
(claude-code-mode 1)
@@ -233,3 +236,27 @@
(lambda ()
(when (eq claude-code-terminal-backend 'vterm)
(setq-local vterm-max-scrollback 100000)))))
(use-package! claudemacs
:defer t
:commands (claudemacs claudemacs-transient-menu)
:init
(setq claudemacs-program "ccr"
claudemacs-program-switches '("code" "--dangerously-skip-permissions")
claudemacs-default-tool 'claude
claudemacs-prefer-projectile-root t)
:config
(map! :map prog-mode-map
"C-c C-e" #'claudemacs-transient-menu)
(map! :map emacs-lisp-mode-map
"C-c C-e" #'claudemacs-transient-menu)
(map! :map text-mode-map
"C-c C-e" #'claudemacs-transient-menu)
(after! python
(map! :map python-base-mode-map
"C-c C-e" #'claudemacs-transient-menu))
(after! eat
(setq eat-term-scrollback-size 400000))
(map! :leader
(:prefix ("C" . "claude-code")
:desc "Claudemacs menu" "E" #'claudemacs-transient-menu)))
+2 -3
View File
@@ -5,9 +5,8 @@
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(custom-safe-themes
'("d481904809c509641a1a1f1b1eb80b94c58c210145effc2631c1a7f2e4a2fdf4"
"039112154ee5166278a7b65790c665fe17fd21c84356b7ad4b90c29ffe0ad606"
"b58b5aa5664a927866daa481ae5f0795423ed3982ce5f64e56c4106261dbd13e" default)))
'("0325a6b5eea7e5febae709dab35ec8648908af12cf2d2b569bedc8da0a3a81c1"
"8a379e7ac3a57e64de672dd744d4730b3bdb88ae328e8106f95cd81cbd44e0b6" default)))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
+1
View File
@@ -30,3 +30,4 @@
+6
View File
@@ -51,9 +51,15 @@
:recipe (:host github :repo "stevemolitor/claude-code.el" :branch "main" :depth 1
:files ("*.el" (:exclude "images/*"))))
(package! claudemacs
:recipe (:host github :repo "cpoile/claudemacs"))
;; Usage metrics and key tracking
(package! keyfreq)
(package! command-log-mode)
;; Theme
(package! base16-theme)
(package! ewal)
(package! ewal-doom-themes
:recipe (:host github :repo "cyruseuros/ewal" :files ("doom-themes/*.el")))
+17 -9
View File
@@ -1,13 +1,21 @@
;;; theme.el -*- lexical-binding: t; -*-
;; Configure base16-theme
;; https://github.com/tinted-theming/base16-emacs
;; Configure ewal
(use-package! ewal
:init
(setq ewal-use-built-in-always-p nil
ewal-use-built-in-on-failure-p t
ewal-built-in-palette "sexy-material"))
;; Set customization variables before loading the theme
;; (Optional: adjust these as needed)
(setq base16-distinct-fringe-background t
base16-highlight-mode-line 'box)
(use-package! ewal-doom-themes
:config
(load-theme 'ewal-doom-one t)
(enable-theme 'ewal-doom-one))
;; Set the theme to base16-default-dark
;; This overrides any theme set in core.el
(setq doom-theme 'base16-default-dark)
;; Set the theme to ewal-doom-one
(setq doom-theme 'ewal-doom-one)
;; Previous base16 config (commented out)
;; (setq base16-distinct-fringe-background t
;; base16-highlight-mode-line 'box)
;; (setq doom-theme 'base16-default-dark)