<!-- This file was generated by extract_docstrings.sh -->

# API Reference

---

## Introduction

> This page documents the Python functions available to Koi workflows and plugins.

Example usage:

```python

# This is the default scripts-file for Koi Editor

@command("Word count")
def word_count():
    import re
    
    text = selected_text()
    count = len(re.findall(r"\b[\w'-]+\b", text))
    
    message(f"Word count: {count:,} words")

@command("Insert UUID")
def insert_uuid():
    from uuid import uuid4
    insert_text(text=str(uuid4()))
    
@command("Markdown: Selection to link")
def insert_link():
    text = selected_text()
    insert_text(text=f"[{text}](https://{text})")

@command("Markdown: Insert unchecked box")
def insert_unchecked_box():
    insert_text(text="- [ ] ")

@command("Markdown: Wrap selection in fenced block")
def fenced_block():
    text = selected_text()
    insert_text(text=f"```\n{text}\n```")

@command("Markdown: Bold")
def make_bold():
    text = selected_text()
    insert_text(text=f"**{text}**")
```

## CodeEditor

### `insert_text`

```python
def insert_text(text: str = '')
```

Insert text at the current cursor position.

### `unselect_other_active_tabs`

```python
def unselect_other_active_tabs()
```

Unselect other active tabs.
Keep active editor as only selected tab.

### `format_csv_columns`

```python
def format_csv_columns()
```

Formats CSV columns to align them.

### `submit_prompt`

```python
def submit_prompt()
```

Submit the current line as a prompt.

### `toggle_word_wrap`

```python
def toggle_word_wrap()
```

Toggle word wrap mode.
If enabled, the editor will wrap lines at word boundaries.

### `auto_detect_lexer`

```python
def auto_detect_lexer()
```

Auto detect lexer based on file extension.

### `detach_lexer`

```python
def detach_lexer()
```

Detach the lexer.
Useful for very large files.

### `accept_first_completion_item`

```python
def accept_first_completion_item()
```

Accept the first item in the completion list.

### `accept_ghost_text`

```python
def accept_ghost_text()
```

Accept the ghost text in the editor.

### `toggle_read_only`

```python
def toggle_read_only()
```

Toggle read-only mode on the editor.

### `find_next`

```python
def find_next(needle, forward = True)
```

Find the next occurrence of 'needle' in the document.
Forward search is enabled by default.

### `move_to_next_word_match`

```python
def move_to_next_word_match()
```

Move the cursor to the next word match.

### `move_to_previous_word_match`

```python
def move_to_previous_word_match()
```

Move the cursor to the previous word match.

### `select_next_match`

```python
def select_next_match()
```

Multi-cursor editing.
Selects the next match of the current selection.

### `unselect_last_match`

```python
def unselect_last_match()
```

Multi-cursor editing.
Unselect the last match.

### `select_matches`

```python
def select_matches()
```

Multi-cursor editing.
Select all matches of the current word.

### `add_cursors_to_line_starts`

```python
def add_cursors_to_line_starts()
```

Replace the current selection with one cursor at the start of each
selected line, including empty lines.

### `get_token_at`

```python
def get_token_at(line, index)
```

Returns the token type and color at the given position in the specified line.

### `get_indent_level`

```python
def get_indent_level(line_text)
```

Returns the indentation level of the given line text.

### `replace_tabs_with_spaces`

```python
def replace_tabs_with_spaces()
```

Replace all tabs with spaces in the document.

### `read_file`

```python
def read_file(_file)
```

Read file into editor.
Replaces current text.

### `inline_command`

```python
def inline_command()
```

Execute inline command.

### `python_eval_line`

```python
def python_eval_line()
```

Evaluate the current line as Python code.

### `new_file`

```python
def new_file()
```

Open a new file.
Returns the new file buffer.

### `new_window`

```python
def new_window()
```

Open a new window.
Returns the new window object.

### `open_file_in_new_window`

```python
def open_file_in_new_window()
```

Open the current file in a new window.

### `reopen_last_closed_file`

```python
def reopen_last_closed_file()
```

Reopen the last closed file.

### `close_window`

```python
def close_window()
```

Close the current window.

### `close_file`

```python
def close_file()
```

Close the current file.

### `close_other_files`

```python
def close_other_files()
```

Close all files except the current one.

### `fold_line`

```python
def fold_line(line = None)
```

Fold the line at the given line number.
If no line number is given, the current line is used.

### `fold_all`

```python
def fold_all()
```

Fold all foldable lines.

### `open_config_file`

```python
def open_config_file()
```

Open the config file in the current window.

### `open_scripts_file`

```python
def open_scripts_file()
```

Open the scripts file in the current window.

### `move_up_to_empty_line`

```python
def move_up_to_empty_line()
```

Move the cursor up to the previous empty line.

### `move_up_to_empty_line_extend`

```python
def move_up_to_empty_line_extend()
```

Extend the selection up to the previous empty line.

### `move_down_to_empty_line`

```python
def move_down_to_empty_line()
```

Move the cursor down to the next empty line.

### `move_down_to_empty_line_extend`

```python
def move_down_to_empty_line_extend()
```

Extend the selection down to the next empty line.

### `open_file`

```python
def open_file()
```

Open a file in the current window.

### `save_file`

```python
def save_file()
```

Save the current file.

### `save_file_as`

```python
def save_file_as()
```

Save a the current file as a new file.

### `save_file_copy_as`

```python
def save_file_copy_as()
```

Save a copy of the current file as a new file.

### `reload_from_disk`

```python
def reload_from_disk()
```

Reload the current file from disk.

### `line_comment`

```python
def line_comment()
```

Toggle line comment for the current line or selection.

### `reset_zoom`

```python
def reset_zoom()
```

Reset the zoom level to 0.

### `replace_all_eol`

```python
def replace_all_eol()
```

Replace all EOLs with the current buffer EOL mode.

### `eol_mode_lf`

```python
def eol_mode_lf()
```

Set EOL mode to LF for the current buffer only.

### `eol_mode_crlf`

```python
def eol_mode_crlf()
```

Set EOL mode to CRLF for the current buffer only.

### `eol_mode_cr`

```python
def eol_mode_cr()
```

Set EOL mode to CR for the current buffer only.

### `toggle_eol_symbols`

```python
def toggle_eol_symbols()
```

Toggle visible EOL symbols for the current buffer only.
This is not persistent.

### `zoom_in`

```python
def zoom_in()
```

Zoom in by 1 point.
This is for current buffer only and not persistent on close.

### `zoom_out`

```python
def zoom_out()
```

Zoom out by 1 point.
This is for current buffer only and not persistent on close.

### `toggle_split_editor`

```python
def toggle_split_editor()
```

Toggle the split editor mode.

### `copy_path_to_file`

```python
def copy_path_to_file(file_with_path = None)
```

Copy the path to the file to the clipboard.

### `select_all`

```python
def select_all()
```

Selects all text in the editor.

### `undo`

```python
def undo()
```

Undo the last edit action.

### `redo`

```python
def redo()
```

Redo the last edit action.

### `copy`

```python
def copy()
```

Copy the selected text to the clipboard.

### `cut`

```python
def cut()
```

Cut selected text to the clipboard.

### `paste`

```python
def paste()
```

Paste the text from the clipboard.

### `lowercase`

```python
def lowercase()
```

Convert the selected text to lowercase.

### `uppercase`

```python
def uppercase()
```

Convert the selected text to uppercase.

### `cancel`

```python
def cancel()
```

Cancel the current operation.

### `newline`

```python
def newline()
```

Insert a newline while preserving indentation.

### `insert_line_above`

```python
def insert_line_above()
```

Insert a line above the current line.
This collapses multiple selections to single selection.

### `insert_line_below`

```python
def insert_line_below()
```

Insert a line below the current line.
This collapses multiple selections to single selection.

### `tab`

```python
def tab()
```

Insert a tab character.

### `selected_text`

```python
def selected_text()
```

Returns the selected text as a string.

### `backtab`

```python
def backtab()
```

Remove one indentation level from the current line or selected lines.
Alias for line_unindent().

### `center_on_cursor`

```python
def center_on_cursor()
```

Center the view on the cursor.

### `line_indent`

```python
def line_indent()
```

Indent selected lines.

### `line_unindent`

```python
def line_unindent()
```

Unindent selected lines.

### `selection_duplicate`

```python
def selection_duplicate()
```

Duplicate the selection.

### `move_line_up`

```python
def move_line_up()
```

Move the current line up.

### `move_line_down`

```python
def move_line_down()
```

Move the current line down.

### `document_start`

```python
def document_start()
```

Move the cursor to the start of the document.
This collapses multiple selections to single selection.

### `document_start_extend`

```python
def document_start_extend()
```

Move the cursor to the start of the document and extend the selection.
This collapses overlapping selections into single selection.

### `document_end`

```python
def document_end()
```

Move the cursor to the end of the document.
This collapses multiple selections to single selection.

### `document_end_extend`

```python
def document_end_extend()
```

Move the cursor to the end of the document and extend the selection.
This collapses overlapping selections into single selection.

### `home`

```python
def home()
```

Move the cursor to the start of the line.
This collapses multiple selections to single selection.

### `home_extend`

```python
def home_extend()
```

Move the cursor to the start of the line and extend the selection.
This collapses overlapping selections into single selection.

### `line_up`

```python
def line_up()
```

Move the cursor up one line.
This collapses multiple selections to single selection.

### `line_up_start`

```python
def line_up_start()
```

Move the cursor up one line and to the start of the line.
This collapses multiple selections to single selection.

### `line_up_start_extend`

```python
def line_up_start_extend()
```

Move the cursor up one line and to the start of the line and extend the selection.
This collapses overlapping selections into single selection.

### `line_down_end`

```python
def line_down_end()
```

Move the cursor down one line and to the end of the line.
This collapses multiple selections to single selection.

### `line_down_end_extend`

```python
def line_down_end_extend()
```

Move the cursor down one line and to the end of the line and extend the selection.
This collapses overlapping selections into single selection.

### `line_up_extend`

```python
def line_up_extend()
```

Move the cursor up one line and extend the selection.
This collapses overlapping selections into single selection.

### `line_down`

```python
def line_down()
```

Move the cursor down one line.
This collapses multiple selections to single selection.

### `line_down_extend`

```python
def line_down_extend()
```

Move the cursor down one line and extend the selection.
This collapses overlapping selections into single selection.

### `line_scroll_up`

```python
def line_scroll_up()
```

Scroll the view up one line.

### `line_scroll_down`

```python
def line_scroll_down()
```

Scroll the view down one line.

### `line_add_caret_up`

```python
def line_add_caret_up()
```

Multi-cursor editing.
Add a cursor above the current cursor.

### `line_add_caret_down`

```python
def line_add_caret_down()
```

Multi-cursor editing.
Add a cursor below the current cursor.

### `duplicate_line`

```python
def duplicate_line()
```

Duplicate the current line.
This collapses multiple selections to single selection.

### `sort_selected_lines_reverse`

```python
def sort_selected_lines_reverse()
```

Sort selected lines alphabetically, reversed.
Expands the selection to whole lines.

### `sort_selected_lines`

```python
def sort_selected_lines(reverse = False, case_sensitive = False)
```

Sort selected lines alphabetically.
Expands the selection to whole lines.

### `move_caret_paragraph_above`

```python
def move_caret_paragraph_above()
```

Move caret to the start of the current paragraph.
Or paragraph above if caret at the start of the current paragraph.
This collapses multiple selections to single selection.

### `move_caret_paragraph_below`

```python
def move_caret_paragraph_below()
```

Move caret to the start of the paragraph below.
This collapses multiple selections to single selection.

### `extend_selection_paragraph_above`

```python
def extend_selection_paragraph_above()
```

Extend selection to the start of the current paragraph.
Or paragraph above if caret at the start of the current paragraph.
This collapses multiple selections to single selection.

### `extend_selection_paragraph_below`

```python
def extend_selection_paragraph_below()
```

Extend selection to the start of the paragraph below.
This collapses multiple selections to single selection.

### `move_caret_to_fold_above`

```python
def move_caret_to_fold_above()
```

Move the caret to the nearest fold header above.
This collapses multiple selections to single selection.

### `move_caret_to_fold_below`

```python
def move_caret_to_fold_below()
```

Move the caret to the nearest fold header below.
This collapses multiple selections to single selection.

### `extend_selection_to_fold_above`

```python
def extend_selection_to_fold_above()
```

Extend the selection to the nearest fold header above.
This collapses multiple selections to single selection.

### `extend_selection_to_fold_below`

```python
def extend_selection_to_fold_below()
```

Extend the selection to the nearest fold header below.
This collapses multiple selections to single selection.

### `move_caret_back`

```python
def move_caret_back()
```

Move caret back one character.

### `extend_selection_back`

```python
def extend_selection_back()
```

Extend selection back one character.

### `move_caret_forward`

```python
def move_caret_forward()
```

Move caret forward one character.

### `extend_selection_forward`

```python
def extend_selection_forward()
```

Extend selection forward one character.

### `move_caret_back_word`

```python
def move_caret_back_word()
```

Move caret back one word.

### `move_caret_forward_word`

```python
def move_caret_forward_word()
```

Move caret forward one word.
Start of word.

### `extend_selection_back_word`

```python
def extend_selection_back_word()
```

Extend selection back one word.

### `extend_selection_forward_word`

```python
def extend_selection_forward_word()
```

Extend selection forward one word.

### `move_caret_back_word_end`

```python
def move_caret_back_word_end()
```

Move caret back one word.
End of word.

### `move_caret_forward_word_end`

```python
def move_caret_forward_word_end()
```

Move caret forward one word.
End of word.

### `extend_selection_back_word_end`

```python
def extend_selection_back_word_end()
```

Extend selection back one word.
End of word.

### `extend_selection_forward_word_end`

```python
def extend_selection_forward_word_end()
```

Extend selection forward one word.
End of word.

### `move_caret_back_word_part`

```python
def move_caret_back_word_part()
```

Move caret back one word part.

### `extend_selection_back_word_part`

```python
def extend_selection_back_word_part()
```

Extend selection back one word part.

### `move_caret_forward_word_part`

```python
def move_caret_forward_word_part()
```

Move caret forward one word part.

### `extend_selection_forward_word_part`

```python
def extend_selection_forward_word_part()
```

Extend selection forward one word part.

### `move_caret_line_start`

```python
def move_caret_line_start()
```

Move caret to the start of the line.

### `move_caret_line_end`

```python
def move_caret_line_end()
```

Move caret to the end of the line.

### `extend_selection_line_start`

```python
def extend_selection_line_start()
```

Extend selection to the start of the line.

First jump goes to visual/home indentation.
Second jump goes to absolute line start.

### `extend_selection_line_end`

```python
def extend_selection_line_end()
```

Extend selection to the end of the line.

### `page_up`

```python
def page_up()
```

Move caret up one page.

### `page_down`

```python
def page_down()
```

Move caret down one page.

### `page_up_stuttered`

```python
def page_up_stuttered()
```

Move caret up one page, stuttered.

### `page_down_stuttered`

```python
def page_down_stuttered()
```

Move caret down one page, stuttered.

### `delete_back`

```python
def delete_back()
```

Delete the character to the left of the caret.
In leading indentation, delete back to the previous tab stop.

### `delete_back_not_newline`

```python
def delete_back_not_newline()
```

Delete the character to the left of the caret without joining lines.

### `delete_forward`

```python
def delete_forward()
```

Delete the character to the right of the caret.

### `delete_back_word`

```python
def delete_back_word()
```

Delete the word to the left of the caret.

### `delete_forward_word`

```python
def delete_forward_word()
```

Delete the word to the right of the caret.

### `delete_line`

```python
def delete_line()
```

Delete the current line.

### `delete_to_line_start`

```python
def delete_to_line_start()
```

Delete from the caret to the start of the line.

### `delete_to_line_end`

```python
def delete_to_line_end()
```

Delete from the caret to the end of the line.

### `previous_tab`

```python
def previous_tab(extend = False)
```

Switch to the previous tab.

### `previous_tab_extend`

```python
def previous_tab_extend()
```

Extend active tabs to the previous tab.

### `next_tab`

```python
def next_tab(extend = False)
```

Switch to the next tab.

### `next_tab_extend`

```python
def next_tab_extend()
```

Extend active tabs to the next tab.

### `reset_window_position`

```python
def reset_window_position()
```

Reset the window position.

### `reset_file_explorer`

```python
def reset_file_explorer()
```

Reset the root folder for file explorer.

### `reload_file_explorer`

```python
def reload_file_explorer()
```

Reload the root folder for file explorer.

### `detect_tab_width`

```python
def detect_tab_width()
```

Detect indentation width from the current buffer and apply it.
This is for the current buffer only and is not persistent.

### `tab_width_2_spaces`

```python
def tab_width_2_spaces()
```

Set the tab width to 2 spaces.
This is for current buffer only and not persistent on close.

### `tab_width_4_spaces`

```python
def tab_width_4_spaces()
```

Set the tab width to 4 spaces.
This is for current buffer only and not persistent on close.

### `tab_width_8_spaces`

```python
def tab_width_8_spaces()
```

Set the tab width to 4 spaces.
This is for current buffer only and not persistent on close.

### `indent_with_tabs`

```python
def indent_with_tabs()
```

Set the indentation to use tabs.
This is for current buffer only and not persistent on close.

### `indent_with_spaces`

```python
def indent_with_spaces()
```

Set the indentation to use spaces.
This is for current buffer only and not persistent on close.

### `open_diff_from_buffers`

```python
def open_diff_from_buffers()
```

Open a diff between the first two active buffers in a new tab.

### `open_diff_from_git`

```python
def open_diff_from_git()
```

Open the Git diff for the current file in a new buffer.

## EditorWindow

### `open_folder`

```python
def open_folder(path_to_folder)
```

Open a folder in the default file manager.

### `show_message`

```python
def show_message(title = None, text = None)
```

Show a message box with the given title and text.
The default title is "System Message".

### `drop_to_open_file`

```python
def drop_to_open_file(file_with_path, line_number = None, text_to_highlight = None, line = None, index = None)
```

Open a file or folder in the current editor window.

## App

### `system_message`

```python
def system_message(title = None, text = None)
```

No description provided.

