Skip to content
Boris Lovosevic edited this page Jan 26, 2019 · 4 revisions

pye module



Original source: Micropython-Editor.


Description

A small text editor written in Python, allowing to edit files locally.

The editor assumes a VT100 terminal. It works in Insert mode. The following list shows most of the commands:

Key(s) Function
Up Down Left Right Cursor movement by one line or char
Shift-Up Shift-Down Mark current line or extend mark
PgUp & PgDd Page up/down
Home Toggle the position between the start-of-code and the start of line
End Toggle the position between the end-of-the-code and end-of-line
Enter Enter a line break at the cursor position. Auto-indent is supported
Backspace Delete char left to the cursor (The key must be set to ASCII-Del)
Del Delete the char under the cursor. At the end of the line join the next line. If autoindent is enabled, delete also the leading spaces of the joined line. If lines are marked, delete the marked area
Tab & Backtab Insert or remove spaces up to the next tab position. If lines are marked, indent or unindent (opt)
Ctrl-O Open a new file. If the file name is left empty, an empty buffer is opened
Ctrl-W Toggle to the next file buffer
Ctrl-Q or Alt-Q Close a file buffer or end line-edit
Ctrl-S Save to file with the option to change the file name
Ctrl-W Switch to the next file buffer
Ctrl-F Find
Ctrl-N Repeat last find
Ctrl-H or Ctrl-R Find and Replace (opt)
Ctrl-G Go to a line
Ctrl-T Go to the first line (opt)
Ctrl-B Go to the last line (opt)
Ctrl-K Goto the bracket matching the one under the cursor (opt)
Ctrl-L or Ctrl-Space Mark/Unmark the current line. The mark can then be extended by moving the cursor
Ctrl-X or Ctrl-Y Cut the marked lines
Ctrl-C or Ctrl-D Copy the marked lines
Ctrl-V Insert the copied/cut lines. In the line edit mode paste the item under the cursor of the active window
Ctrl-Z Undo the last change(s)
Ctrl-P Comment/Uncomment a line or marked area
Ctrl-A Change settings for tab size, search case sensitivity, auto-indent, comment string and writing tabs (opt)
Ctrl-E Redraw the screen. On WiPy and PyBord it shows the amount of free memory

Start pye from the REPL prompt, e.g. with

from pye import pye  
res = pye(object_1, object_2, ..[, tabsize=n][, undo=n])  

If object_n is a string, it's considered as the name of a file to be edited or a directory to be opened. If it’s a file, the content will be loaded, and the name of the file will be returned when pye is closed. If the file does not exist, an error is displayed, but the edit window is given that name. If it’s a directory, the list of file names will be loaded to the edit window. If object_n is a list of strings, these will be edited, and the edited list will be returned. If no object is named, pye() will give you an empty screen, creating a list of strings, unless you save to a file. In that case, the file name will be returned. If object_n is neither a string nor a list of strings, an empty buffer is opened. It is always the last buffer closed, which determines the return value of pye().
Optional named parameters:

tabsize=n Tab step (integer). The default is 4
undo=n Size of the undo stack (integer). A value of 0 or False disables undo.

More details can be found in the Pyboard Editor.pdf.
On reading files, tab characters are expanded to spaces with a tab size of 8, and trailing white space on a line will be discarded. Optionally, tabs can be written when saving the file, replacing spaces with tabs when possible. However, the original state of tabs will NOT be restored when the file is written. The screen size is determined, when the editor is started, when the Redraw-key (Ctrl-E) is hit or on any file window change (Ctrl-W).

Clone this wiki locally