https://github.com/rec/editor
🖋 Open the default text editor 🖋
https://github.com/rec/editor
editor python text-editor
Last synced: about 1 year ago
JSON representation
🖋 Open the default text editor 🖋
- Host: GitHub
- URL: https://github.com/rec/editor
- Owner: rec
- License: mit
- Created: 2020-07-22T09:35:03.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2024-03-20T18:25:21.000Z (over 2 years ago)
- Last Synced: 2025-03-24T04:04:06.122Z (over 1 year ago)
- Topics: editor, python, text-editor
- Language: Python
- Homepage: https://rec.github.io/editor/
- Size: 635 KB
- Stars: 8
- Watchers: 2
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG
- Funding: FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# 🖋 editor - Open a text editor 🖋
`editor` opens the default text editor or your favorite editor to edit an existing file,
a new file, or a tempfile, blocks while the user edits text, then returns the contents
of the file.
You can pass a parameter `editor=` to specify an editor or leave it empty, in which
case the editor is:
* The contents of the environment variable `VISUAL`, if it's set, otherwise:
* The the contents of the environment variable `EDITOR`, if it's set, otherwise:
* The string `'Notepad'`, if the code is running on Windows, otherwise:
* The string `'vim'`
### Example 1: Using a temporary file
If no filename is provided, a temporary file gets edited, and its contents
returned.
import editor
comments = editor.editor(text='Comments here\n\n')
# Pop up the default editor with a tempfile containing "Comments here",
# then return the contents and delete the tempfile.
### Example 2: Using a named file
If a filename is provided, then that file gets edited.
import os
FILE = 'file.txt'
assert not os.path.exists(FILE)
comments = editor.editor(text=MESSAGE, filename=FILE)
# Pop up an editor for a new FILE containing MESSAGE, user edits
# This file is saved when the user exits the editor.
assert os.path.exists(FILE)
# You can edit an existing file too, and select your own editor.
comments2 = editor.editor(filename=FILE, editor='emacs -nw')
### [API Documentation](https://rec.github.io/editor#editor--api-documentation)