open-interpreter icon indicating copy to clipboard operation
open-interpreter copied to clipboard

Added an edit magic command

Open Eliaskhal opened this issue 1 year ago • 4 comments

Added %edit to allow the user to edit the last code submitted by OI. The code is saved in a temp file with its extension matching the language. When the user is done editing it, the code gets saved in interpreter.messages.

Pre-Submission Checklist :

  • [ ] I have included relevant documentation updates (stored in /docs)
  • [x] I have read docs/CONTRIBUTING.md
  • [x] I have read docs/ROADMAP.md

OS Tests :

  • [x] Tested on Windows
  • [ ] Tested on MacOS
  • [ ] Tested on Linux

Eliaskhal avatar Jan 18 '24 12:01 Eliaskhal

@KillianLucas Can you please give an update on this.

Eliaskhal avatar Jan 20 '24 12:01 Eliaskhal

Hi @Eliaskhal! Thanks for updating the PR, I think a magic command is a fantastic addition to OI.

From first glance I'm not sure if this would work, it looks like it appends the new code block to interpreter.messages. I think the edit command will need to:

  1. Retrieve the file extension from self.computer.terminal.get_language("language").file_extension — instead of a custom map at the top. This makes it work with custom languages too.
  2. Insert the code into the code block that it's editing, not append it as a new code block.
  3. Display the code to the user and prompt if they want to run it (y/n).
  4. Use self.computer.run("language", "code") to run the code.

I'm happy to merge once this becomes a higher priority, then make those changes. If you can make those changes @Eliaskhal, I can credit you fully for the %edit command and get it into the update coming out this weekend! Great work either way, this is seriously such an awesome feature.

KillianLucas avatar Jan 25 '24 20:01 KillianLucas

Hey @KillianLucas, thank you for your reply. I will work on adding the features you mentioned. Thank you

Eliaskhal avatar Jan 26 '24 10:01 Eliaskhal

Hey @Eliaskhal! Let me know if you want to move make those changes, otherwise I'm happy to take a crack at it. Great work again.

KillianLucas avatar Mar 28 '24 02:03 KillianLucas