# Editor

The Editor function allows to invoke the FAR internal editor.

    int WINAPI Editor(
      const char *FileName,
      const char *Title,
      int X1,
      int Y1,
      int X2,
      int Y2,
      DWORD Flags,
      int StartLine,
      int StartChar
    );

### Parameters

FileName
Name of the file to edit. Unless EF_CREATENEW is set in the Flags parameter, must specify an existing file.
Title
Null-terminated text string that will be shown in the top line of the editor window. If this parameter is `NULL`, the file name will be used.
X1, Y1, X2, Y2
Editor window coordinates. If X2 or Y2 is -1, they will be replaced with the screen width or height. If X1 or Y1 are less than zero, then their are taken as zero.
Flags
Editor flags. Can be a combination of the following values (EDITOR_FLAGS enum):

Flag | Description
--- | ---
EF_NONMODAL | Creates a non-modal editor window. If this flag is present, the user will be able to switch to other FAR windows. The plugin will regain control only after the editor is closed, or after the user switches to a different window (e.g. by pressing `Ctrl+Tab`). If you need to regain control immediately after the editor has been opened, use the EF_IMMEDIATERETURN flag.
EF_IMMEDIATERETURN | If this flag is set, the Editor function returns immediately after the editor has been opened. The newly opened editor becomes the active window. This flag can be used only with EF_NONMODAL.
EF_DELETEONCLOSE | Instructs FAR to delete the file being edited after the editor is closed. If the directory with the edited file contains no other files, it will also be deleted. If only the file needs to be deleted use the EF_DELETEONLYFILEONCLOSE flag. The file will not be deleted: if the user switched to the viewer by pressing `F6`, or if the file is open in other viewer or editor windows. if the user has saved the file.
EF_DELETEONLYFILEONCLOSE | Similar to EF_DELETEONCLOSE, but only the file will be deleted. The directory will not be deleted even if it is empty. This flag has a lower priority than EF_DELETEONCLOSE.
EF_CREATENEW | Opens a new (non-existing) file in the editor, similar to pressing `Shift-F4` in FAR.
EF_ENABLE_F6 | Enables switching from the editor to the viewer by pressing `F6`.
EF_DISABLEHISTORY | Disables adding the file name to the view/edit history (`Alt-F11`). If this flag is not specified, the name is added to the history.

StartLine
Number of the line to which the cursor is positioned (0-based).
StartChar
Initial cursor position in the line (1-based).

### Return value

This function can return one of the following values (EDITOR_EXITCODE enum):

Returned value | Description
--- | ---
EEC_OPEN_ERROR | File open error, occurs in the following cases: FAR could not allocate enough memory while creating the editor (as an object); if FileName is an empty line; if FileName is a path to an existing folder; if the file to be opend is read-only and the user refused to continue editing this file in the corresponding dialog.
EEC_MODIFIED | Successful return. File was modified. This value is also returned if the EF_NONMODAL flag was used.
EEC_NOT_MODIFIED | Successful return. File was not modified.
EEC_LOADING_INTERRUPTED | File loading was stopped by user.

### Remarks

If StartLine and StartChar are both equal to -1 and the option "Save file position" is enabled, the previously saved file position will be restored.
See also:
Viewer