add /editor command

Opens an editor for constructing a user prompt, using the currently defined chat mode.

The editor is determined as follows:

Look for the following environment variables, in order:

1. AIDER_EDITOR
2. VISUAL
3. EDITOR

If none of these are defined, use the following defaults:

Windows: notepad
OS X: vim
*nix: vi

If an editor is not found, a RuntimeError is raised.

Any arguments passed after the /editor command are inserted as content.

The temporary file used for editing has an .md extension, which can be leveraged for syntax highlighting.

NOTE: The editor used MUST block the process until the editor is closed -- the default editors all do this.
This commit is contained in:
Chad Phillips 2024-11-03 20:17:23 -05:00
parent 0022c1a67e
commit d8e9da35d6
3 changed files with 162 additions and 6 deletions

View file

@ -1357,6 +1357,13 @@ class Commands:
report_github_issue(issue_text, title=title, confirm=False)
def cmd_editor(self, initial_content=""):
"Open an editor to write a prompt"
from aider.editor import pipe_editor
user_input = pipe_editor(initial_content, suffix="md")
self.io.display_user_input(user_input)
self._generic_chat_command(user_input, self.coder.edit_format)
def expand_subdir(file_path):
if file_path.is_file():