refac: Automatically edit text.
The workflow:
- Select some text.
- Run the command, write instructions on what you want changed.
- Never edit text directly again.
This tool calls the openai api edits endpoint. You'll need your own api key to use it.
Use refac login to enter your api key. It will be saved in your home directory
for future use.
This tool uses your openai account so usage is not exactly free. I've paid a total of $0.04 today while developing this tool.
Setup
# This tool can be installed using cargo.
# Enter your api key it will be saved to your drive for future use.
Try it out
> refac
> refac
Using Refac From Your Favorite Text Editor
First, make sure you have:
- installed refac
- entered your api key using
refac login
Emacs
After installing and logging in add this chunk of flim-flam to your init.el:
(defun refac (start end)
(interactive "r")
(let* ((selected-text
(buffer-substring-no-properties
start
end))
(transform (read-string "Enter transformation instruction: "))
(refac-executable (executable-find "refac")))
(if refac-executable (progn (let (result exit-status)
(with-temp-buffer
(setq exit-status (call-process refac-executable nil t nil "tor" selected-text
transform))
(setq result (buffer-string)))
(if (zerop exit-status)
(progn (delete-region start end)
(insert result))
(message "refac returned a non-zero exit status: %d. Error: %s" exit-status
result))))
(error
"refac executable not found"))))
And bind the function to a key if you like that sort of thing.
(global-set-key (kbd "C-c r") 'refac)
Not Emacs
Your contrubutions are welcome!
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.