# Engine

The engine for scripting the editor. To access the engine for scripting a particular Guppy instance, say called `"guppy1"`, do `Guppy("guppy1").engine`.

At that point, you can, for example, move that editor's cursor one spot to the left with `Guppy("guppy1").engine.left()`.

## Constructor

#### new Engine()

Source:
  - engine.js, line 19

### Methods

#### add_symbol(name, symbol, templateopt)

Source:
  - engine.js, line 148

Add a symbol to this instance of the editor.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`name` | string |  | param
`symbol` | Object |  | If `template` is present, this is the template arguments. Otherwise, it is a complete specification of the symbol, the format for which can be found in the documentation for Guppy.add_global_symbol.
`template` | string | <optional> | The name of the template to use.

#### backspace()

Source:
  - engine.js, line 1116

Simulate the "backspace" key press

#### delete_key()

Source:
  - engine.js, line 1131

Simulate the "delete" key press

#### done()

Source:
  - engine.js, line 1291

Execute the "done" callback

#### down()

Source:
  - engine.js, line 1199

Simulate a down arrow key press

#### end()

Source:
  - engine.js, line 1228

Move the cursor to the end of the document

#### get_content(t)

Source:
  - engine.js, line 76

Get the content of the editor

##### Parameters:

Name | Type | Description
--- | --- | ---
`t` | string | The type of content to render ("latex", "text", or "xml").

#### home()

Source:
  - engine.js, line 1219

Move the cursor to the beginning of the document

#### insert_doc(doc)

Source:
  - engine.js, line 532

Insert a copy of the given document into the editor at the current cursor position.

##### Parameters:

Name | Type | Description
--- | --- | ---
`doc` | Doc | The document to insert.

#### insert_string(s)

Source:
  - engine.js, line 510

Insert a string into the document at the current cursor position.

##### Parameters:

Name | Type | Description
--- | --- | ---
`s` | string | The string to insert.

#### insert_symbol(sym_name)

Source:
  - engine.js, line 362

Insert a symbol into the document at the current cursor position.

##### Parameters:

Name | Type | Description
--- | --- | ---
`sym_name` | string | The name of the symbol to insert. Should match one of the keys in the symbols JSON object

#### left()

Source:
  - engine.js, line 1007

Simulate the left arrow key press

#### list_extend(direction, copy)

Source:
  - engine.js, line 809

Add an element to a list (or row/column to a matrix) in the specified direction. Can optionally copy the current element/row/column to the new one.

##### Parameters:

Name | Type | Description
--- | --- | ---
`direction` | string | One of `"up"`, `"down"`, `"left"`, or `"right"`.
`copy` | boolean | Whether or not to copy the current element/row/column into the new one.

#### list_remove()

Source:
  - engine.js, line 949

Remove the current element from a list (or column from a matrix)

#### list_remove_col()

Source:
  - engine.js, line 880

Remove the current column from a matrix

#### list_remove_row()

Source:
  - engine.js, line 923

Remove the current row from a matrix

#### list_vertical_move(down)

Source:
  - engine.js, line 775

Move the cursor by one row up or down in a matrix.

##### Parameters:

Name | Type | Description
--- | --- | ---
`down` | boolean | If `true`, move down in the matrix; otherwise, up.

#### redo()

Source:
  - engine.js, line 1277

Redo the last undone action

#### remove_symbol(name)

Source:
  - engine.js, line 134

Remove a symbol from this instance of the editor.

##### Parameters:

Name | Type | Description
--- | --- | ---
`name` | string | The name of the symbol to remove.

#### right()

Source:
  - engine.js, line 977

Simulate the right arrow key press

#### sel_all()

Source:
  - engine.js, line 683

Select the entire contents of the editor.

#### sel_clear()

Source:
  - engine.js, line 643

Clear the current selection, leaving the document unchanged and nothing selected.

#### sel_copy()

Source:
  - engine.js, line 541

Copy the current selection, leaving the document unchanged but placing the contents of the current selection on the clipboard.

#### sel_cut()

Source:
  - engine.js, line 583

Cut the current selection, removing it from the document and placing it in the clipboard.

#### sel_delete()

Source:
  - engine.js, line 653

Delete the current selection.

#### sel_left()

Source:
  - engine.js, line 735

Move the cursor to the left, adjusting the selection along with the cursor.

#### sel_paste()

Source:
  - engine.js, line 629

Paste the current contents of the clipboard.

#### sel_right(name)

Source:
  - engine.js, line 697

function

##### Parameters:

Name | Type | Description
--- | --- | ---
`name` | string | param

#### set_content(xml_data)

Source:
  - engine.js, line 85

Set the XML content of the editor

##### Parameters:

Name | Type | Description
--- | --- | ---
`xml_data` | string | An XML string of the content to place in the editor

#### set_doc(doc)

Source:
  - engine.js, line 94

Set the document of the editor

##### Parameters:

Name | Type | Description
--- | --- | ---
`doc` | Doc | The Doc that will be the editor's source

#### spacebar()

Source:
  - engine.js, line 998

Simulate the spacebar key press

#### tab()

Source:
  - engine.js, line 1151

Simulate a tab key press

#### undo()

Source:
  - engine.js, line 1263

Undo the last action

#### up()

Source:
  - engine.js, line 1179

Simulate an up arrow key press