diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-16 01:55:16 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-16 01:55:16 -0500 |
| commit | 6ee37e0a68d31909861cf59684d3601bf40f5abe (patch) | |
| tree | d14726945d65853f183896a06532c1e88bbb81de /modules/ai-config.el | |
| parent | 670117cccdbae4706dfaa5e05144c256c3a657f0 (diff) | |
| download | dotemacs-6ee37e0a68d31909861cf59684d3601bf40f5abe.tar.gz dotemacs-6ee37e0a68d31909861cf59684d3601bf40f5abe.zip | |
feat(ai-rewrite): add directive-picker wrappers around gptel-rewrite
`gptel-rewrite` is the killer feature for the keep-gptel decision,
and it now lives behind two commands instead of the bare call:
- `cj/gptel-rewrite-with-directive` (`C-; a r`, replacing the
former bare `gptel-rewrite` binding): completing-read on a
directive name from `cj/gptel-rewrite-directives`, then rewrite
the active region.
- `cj/gptel-rewrite-redo-with-different-directive` (`C-; a R`):
replay the prior region with a different directive. The region
is preserved via markers stored buffer-local on the first call so
it survives accept/reject of the prior rewrite.
I picked the hook injection approach over an `:after`-advice +
state-capture pattern. `gptel-rewrite-directives-hook` is an
abnormal hook gptel-rewrite already consults for a per-call
system message. Wrapping the call in a one-shot `let`-binding on
that hook gives the directive exactly the lifetime of the rewrite
and leaves nothing to clean up. Mutating `gptel-directives`
globally would mean either restoring it afterward or living with
the change -- both worse than the hook.
Directives ship inline as a `defcustom` alist with the six names
called out in the task -- `terse`, `fix-grammar`,
`refactor-readability`, `add-docstring`, `explain-as-comment`,
`shorten`. Customization is a `customize-variable` or `setq`
away.
9 tests cover the defcustom shape (default names present, bodies
non-empty strings), the wrapper (normal path, no-region error,
unknown-directive error, last-state recording), and the redo
(replays the prior region, errors when no previous, excludes the
current directive from the re-pick prompt). `gptel-rewrite`
stubbed in tests so no rewrite UI fires.
Diffstat (limited to 'modules/ai-config.el')
| -rw-r--r-- | modules/ai-config.el | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/modules/ai-config.el b/modules/ai-config.el index 6eff1ba6..c7a14cae 100644 --- a/modules/ai-config.el +++ b/modules/ai-config.el @@ -35,6 +35,8 @@ (autoload 'cj/gptel-delete-conversation "ai-conversations" "Delete a saved AI conversation." t) (autoload 'cj/gptel-autosave-toggle "ai-conversations" "Toggle autosave in the current GPTel buffer." t) (autoload 'cj/gptel-quick-ask "ai-quick-ask" "One-shot quick-ask in a transient buffer." t) +(autoload 'cj/gptel-rewrite-with-directive "ai-rewrite" "Pick a directive and run gptel-rewrite on the region." t) +(autoload 'cj/gptel-rewrite-redo-with-different-directive "ai-rewrite" "Re-run the previous rewrite with a different directive." t) ;;; ------------------------- AI Config Helper Functions ------------------------ @@ -510,7 +512,8 @@ Works for any buffer, whether it's visiting a file or not." "m" #'cj/gptel-change-model ;; change the LLM model "p" #'gptel-system-prompt ;; change prompt "q" #'cj/gptel-quick-ask ;; one-shot quick ask - "r" #'gptel-rewrite ;; rewrite a region of code/text + "r" #'cj/gptel-rewrite-with-directive ;; rewrite region with a chosen directive + "R" #'cj/gptel-rewrite-redo-with-different-directive ;; redo last rewrite, new directive "c" #'cj/gptel-context-clear ;; clear all context "s" #'cj/gptel-save-conversation ;; save conversation "t" #'cj/toggle-gptel ;; toggles the ai-assistant window @@ -530,7 +533,8 @@ Works for any buffer, whether it's visiting a file or not." "C-; a m" "change model" "C-; a p" "change prompt" "C-; a q" "quick ask" - "C-; a r" "rewrite region" + "C-; a r" "rewrite region (directive)" + "C-; a R" "redo rewrite, new directive" "C-; a c" "clear context" "C-; a s" "save conversation" "C-; a t" "toggle window" |
