<commit_before># Advanced

## Command Entry

Access to the Lua state is available through the command entry. Press `Ctrl+E`
(`⌘E` on Mac OSX) to access it. It is useful for debugging, inspecting, and
entering buffer or view commands. If you try to cause instability in Textadept's
Lua state, you might very well succeed so be careful. For more information, see
the [scripting](11_Scripting.html) page.

Abbreviated commands for the `buffer`, `view` and `gui` are available. So
`buffer:append_text('foo')` can be shortened to `append_text('foo')`. `print()`
redirects to  [`gui.print()`](../modules/gui.html#print). Use `_G.print()` for
Lua's `print()`.

![Command Entry](images/commandentry.png)

#### Tab Completion

Tab-completion for functions, variables, tables, etc. is available. Press the
`Tab` (`⇥`) key to display a list of available completions. Use the arrow keys
to make a selection and press `Enter` (`↩`) to insert it.

![Command Completion](images/commandentrycompletion.png)

#### Extending

You can extend the command entry to do more than enter Lua commands. An
example of this is [incremental
search](../modules/gui.find.html#find_incremental). See
`modules/textadept/find.lua` for the implementation.

## Shell Commands and Filtering Text

Sometimes it is easier to use an existing shell command to manipulate text
instead of using the command entry. An example would be sorting all text in a
buffer (or a selection). You could do the following from the command entry:

    ls={}; for l in buffer:get_text():gmatch('[^\n]+') do ls[#ls+1]=l end;
    table.sort(ls); buffer:set_text(table.concat(ls, '\n'))

A simpler way would be to press `Ctrl+|` (`⌘|` on Mac OSX), enter the shell
command `sort`, and hit `Enter` (`↩`).

The standard input (stdin) for shell commands is determined as follows:

* If text is selected and spans multiple lines, all text on the lines containing
  the selection is used. However, if the end of the selection is at the
  beginning of a line, only the EOL (end of line) characters from the previous
  line are included as input. The rest of the line is excluded.
* If text is selected and spans a single line, only the selected text is used.
* If no text is selected, the entire buffer is used.

The input text is replaced with the standard output (stdout) of the command.<commit_msg>Added manual documentation for select_command(); doc/manual/10_Advanced.md<commit_after># Advanced

## Command Entry

Access to the Lua state is available through the command entry. Press `Ctrl+E`
(`⌘E` on Mac OSX) to access it. It is useful for debugging, inspecting, and
entering buffer or view commands. If you try to cause instability in Textadept's
Lua state, you might very well succeed so be careful. For more information, see
the [scripting](11_Scripting.html) page.

Abbreviated commands for the `buffer`, `view` and `gui` are available. So
`buffer:append_text('foo')` can be shortened to `append_text('foo')`. `print()`
redirects to  [`gui.print()`](../modules/gui.html#print). Use `_G.print()` for
Lua's `print()`.

![Command Entry](images/commandentry.png)

#### Tab Completion

Tab-completion for functions, variables, tables, etc. is available. Press the
`Tab` (`⇥`) key to display a list of available completions. Use the arrow keys
to make a selection and press `Enter` (`↩`) to insert it.

![Command Completion](images/commandentrycompletion.png)

#### Extending

You can extend the command entry to do more than enter Lua commands. An
example of this is [incremental
search](../modules/gui.find.html#find_incremental). See
`modules/textadept/find.lua` for the implementation.

## Command Selection

If you did not disable the menu in your [preferences](9_Preferences.html), then
pressing `Ctrl+Shift+E` (`⌘⇧E` on Mac OSX) brings up the command selection
dialog. Typing part of any command filters the list with spaces being wildcards.
This is an easy way to run commands without navigating the menus, using the
mouse, or remembering key commands. It is also useful for looking up particular
key commands quickly.

## Shell Commands and Filtering Text

Sometimes it is easier to use an existing shell command to manipulate text
instead of using the command entry. An example would be sorting all text in a
buffer (or a selection). You could do the following from the command entry:

    ls={}; for l in buffer:get_text():gmatch('[^\n]+') do ls[#ls+1]=l end;
    table.sort(ls); buffer:set_text(table.concat(ls, '\n'))

A simpler way would be to press `Ctrl+|` (`⌘|` on Mac OSX), enter the shell
command `sort`, and hit `Enter` (`↩`).

The standard input (stdin) for shell commands is determined as follows:

* If text is selected and spans multiple lines, all text on the lines containing
  the selection is used. However, if the end of the selection is at the
  beginning of a line, only the EOL (end of line) characters from the previous
  line are included as input. The rest of the line is excluded.
* If text is selected and spans a single line, only the selected text is used.
* If no text is selected, the entire buffer is used.

The input text is replaced with the standard output (stdout) of the command.
{'fraction_non_alphanumeric': 0.09569934134056567, 'fraction_numerical': 0.001743510267338241, 'mean_word_length': 4.551612903225807, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3187519', 'n_tokens_mistral': 1497, 'n_tokens_neox': 1439, 'n_words': 741}