Closed nordlow closed 1 week ago
the current behavior that outputs typically non-working code or English text the resulting in a syntactically incorrect code modification.
Perhaps this is the problem. You can ask it to output code and only code in the system message, and it will generally do so. One of the default gptel-directives
includes this, and you can set it for the buffer. That said, you'll probably want to write a system message with more instructions.
Emacs DWIM principle, meaning it should output the response into another buffer
I'm not seeing what's DWIM about this behavior. "What I Mean" can be anything here -- In a prog-mode
buffer, I might want
All of these (and more) seem like equally valid "DWIM" behaviors to me.
You can do the first and last using gptel's transient menu. To wrap text in a code comment in the prog-mode
buffer you can use the hook gptel-post-response-functions
. To rewrite/refactor the code you can use the "in-place output" option in the transient menu, or use the refactor interface (also in the transient menu).
I guess it all comes down to what instructions (system message) you feed it.
I guess it would be very useful to have gtpel insert code in the same language as that major-mode represents as real code and anything else as comments.
To me this is the most obvious generic DWIM behavior. IMO , a use never wants his prog-mode
buffer to contain non-code content unless it's in a comment.
I guess it would be very useful to have gtpel insert code in the same language as that major-mode represents as real code and anything else as comments.
It's rarely enough to specify that the response has to be code in language FOO. Typically you are looking to provide many more task-specific instructions. You can craft a system message with the requisite details and save it as an element of gptel-directives
. When using gptel you can switch the system message to this preset and send your request.
The "add directive" d
option in the transient menu can be used to add a one-time instruction on top of the more general system message.
M-x gptel-send
when mark is active in a code buffer should adhere to the Emacs DWIM principle, meaning it should output the response into another buffer instead of the current behavior that outputs typically non-working code or English text the resulting in a syntactically incorrect code modification.The solution could branch on the whether the current major-mode inherits from
prog-mode
and output the result in another buffer or directly in the minibuffer.