<feed xmlns='http://www.w3.org/2005/Atom'>
<title>dotemacs/modules/ai-rewrite.el, branch load-graph-classify-end</title>
<subtitle>My Emacs configuration
</subtitle>
<id>https://git.cjennings.net/dotemacs/atom?h=load-graph-classify-end</id>
<link rel='self' href='https://git.cjennings.net/dotemacs/atom?h=load-graph-classify-end'/>
<link rel='alternate' type='text/html' href='https://git.cjennings.net/dotemacs/'/>
<updated>2026-05-16T06:55:16+00:00</updated>
<entry>
<title>feat(ai-rewrite): add directive-picker wrappers around gptel-rewrite</title>
<updated>2026-05-16T06:55:16+00:00</updated>
<author>
<name>Craig Jennings</name>
<email>c@cjennings.net</email>
</author>
<published>2026-05-16T06:55:16+00:00</published>
<link rel='alternate' type='text/html' href='https://git.cjennings.net/dotemacs/commit/?id=6ee37e0a68d31909861cf59684d3601bf40f5abe'/>
<id>urn:sha1:6ee37e0a68d31909861cf59684d3601bf40f5abe</id>
<content type='text'>
`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.
</content>
</entry>
</feed>
