General set of functions to programmatically interact with HEdit.
Members
-
static, readonly mode :string
-
The name of the mode the editor is currently in.
-
static, readonly view :string
-
The name of the currently active view.
Methods
-
static command(cmd) → {boolean}
-
Executes a command.
Parameters:
Name Type Description cmdstring Command to execute.
Returns:
boolean -Returns
trueif the command executed successfully,falseotherwise.Example
hedit.command('q!'); // Exits the editor -
static emitKeys(keys)
-
Emits the given keys as if the user actually typed them.
Parameters:
Name Type Description keysstring Keys to emit.
Example
hedit.emitKeys('<Escape>:w<Enter>i'); -
static get(name) → {*}
-
Retrives the value of an option.
Parameters:
Name Type Description namestring Option name.
Throws:
Throws if the option name is invalid.
Returns:
* -The current value of the option.
Example
log.info('Current colwidth:', hedit.get('colwidth')); -
static map(mode, from, to, forceopt)
-
Registers a new key mapping.
Parameters:
Name Type Attributes Default Description modestring Mode the new mapping is valid in.
fromstring Key to map.
tostring The key sequence that the
fromkey will be expanded to.forceboolean <optional>
false Skip the check for an existing mapping for the same key.
Throws:
Throws if the mapping registration fails.
- See:
-
emitKeys for more information about the format of the keys.
Example
hedit.map('insert', '<C-j>', 'cafebabe'); -
static registerCommand(name, handler)
-
Registers a new command, whose implementation is up to the user.
Parameters:
Name Type Description namestring Command name.
handlerCommandCallback Function implementing the command.
Throws:
Throws if the command registration fails.
Example
hedit.registerCommand('special', n => { log.info('The argument is', parseInt(n, 10) % 2 == 0 ? 'even' : 'odd'); }); -
static registerOption(name, defaultValue, handler)
-
Registers a new option, whose implementation is up to the user.
Parameters:
Name Type Description namestring Name of the option.
defaultValuestring Default option value.
handlerOptionCallback Function to be called when the value of the option changes.
Example
hedit.registerOption('cool', false, newValue => { if (newValue === 'true') { log.info('The coolness is now on!'); return true; } else if (newValue === 'false') { log.info('So sad :('); return true; } else { // Invalid value return false; } }); -
static set(name, value)
-
Sets the value of an option.
Parameters:
Name Type Description namestring Option name.
valuestring | number Value of the option.
Throws:
Throws if there's an error setting the option.
Example
hedit.set('colwidth', 8); -
static setTheme(t)
-
Sets the current theme.
A theme determines the colors used by the editor to render itself. Different parts of the UI can be drawn with different pens, which contains the actual style information. For example, to draw the line offsets bold green and text blue, we can use:
{ linenos: { fg: '00ff00', bold: true }, text: '0000ff' // Shortcut for `{ fg: '0000ff' }` }The following parts of the UI can be themed:
textlinenoserrorblock_cursorsoft_cursorstatusbarcommandbarlog_debuglog_infolog_warnlog_errorlog_fatal
Each of these parts can be themed with a pen, which has 4 properties:
fgbgboldunder
Colors can be specified either using standard ANSI number or hex RGB values, which will be rounded to the closest color supported by the terminal.
If any of the previous properties is missing, the default value will be used.
For an example of the usage of
setTheme, see A colorful statusbar.Parameters:
Name Type Description tobject Theme description.
Throws:
Throws if an invalid theme description is passed.
- See:
-
- Usage example: A colorful statusbar.
-
static switchMode(name)
-
Switches the editor to the given mode.
Parameters:
Name Type Description namestring Name of the mode to switch to.
Example
hedit.switchMode('insert');
Type Definitions
-
CommandCallback(…args)
-
Handler of a custom command.
Parameters:
Name Type Attributes Description argsstring <repeatable>
All the commands supplied by the user at the moment of the invocation of the command.
-
OptionCallback(newValue) → {boolean}
-
Handler of a custom option.
Parameters:
Name Type Description newValuestring New value of the option.
Returns:
boolean -Returns
trueif the change is accepted,falseotherwise.
Events
-
file/change
-
Event raised when the contents of the file change.
Parameters:
Name Type Description offsetinteger Offset of the change.
leninteger Length of the change.
-
file/close
-
Event raised when the open file is closed.
-
file/open
-
Event raised when a new file is opened by the user.
-
file/write
-
Event raised when the file has been successfully written to disk.
-
load
-
Event raised only once when the editor is fully loaded and ready.
-
mode-switch
-
Event raised when the user switches mode.
Parameters:
Name Type Description modestring New mode set.
-
quit
-
Event raised only once when the editor is going to close.
-
view-switch
-
Event raised when the user switches view.
Parameters:
Name Type Description viewstring New active view.