wex v24.10.0
|
Offers the macro collection, and allows recording and playback to vi (ex) component. More...
#include <wex/ex/macros.h>
Public Types | |
enum class | key_t { ALT , CONTROL , NORMAL } |
Type of macro key used for key_map. More... | |
typedef std::unordered_map< int, std::string > | keys_map_t |
Maps key to command. | |
typedef std::vector< std::string > | commands_t |
Type for commands. | |
typedef std::unordered_map< std::string, std::string > | strings_map_t |
Maps string to command. | |
typedef std::unordered_map< std::string, commands_t > | macros_map_t |
Maps macro (register) to vector of command. | |
typedef std::unordered_map< std::string, variable > | variables_map_t |
Maps string to variable. | |
Public Member Functions | |
macros () | |
Default constructor. | |
bool | erase () |
Erases current macro from the vector and cleans it. | |
const commands_t | find (const std::string &name) const |
Finds macro in macros or variables, and returns contents as a vector of strings, or empty vector if not found. | |
const commands_t | get () const |
Returns all macro names as a vector of strings. | |
const auto & | get_abbreviations () const |
Returns abbreviations. | |
const keys_map_t & | get_keys_map (key_t type=key_t::NORMAL) const |
Returns keys map. | |
const commands_t | get_macro_commands (const std::string ¯o) const |
Returns commands for specified macro. | |
const auto & | get_map () const |
Returns (string) map. | |
const std::string | get_register (char name) const |
Returns content of register. | |
const commands_t | get_registers () const |
Returns all registers (with content) as a vector of strings. | |
const auto & | get_variables () const |
Returns variables. | |
bool | is_modified () const |
Returns true if xml structure has been modified without being saved. | |
bool | is_recorded (const std::string ¯o) const |
Is macro or variable recorded. | |
bool | is_recorded_macro (const std::string ¯o) const |
Is macro recorded. | |
bool | load_document () |
Loads all macros (and variables) from xml document. | |
auto & | mode () |
Returns the mode we are in. | |
const auto & | mode () const |
Returns the mode we are in. | |
const wex::path | path () const |
Returns the path with xml document. | |
bool | record (const std::string &text, bool new_command=true) |
Records text to current macro (or register) as a new command. | |
bool | save_document (bool only_if_modified=true) |
Saves all macros (and variables) to xml document. | |
bool | save_macro (const std::string ¯o) |
Saves macro (and calls save_document). | |
void | set_abbreviation (const std::string &name, const std::string &value) |
Sets abbreviation (overwrites existing abbreviation). | |
void | set_key_map (const std::string &name, const std::string &value, key_t type=key_t::NORMAL) |
Sets key map (overwrites existing map). | |
void | set_map (const std::string &name, const std::string &value) |
Sets map (overwrites existing map). | |
bool | set_register (char name, const std::string &value) |
Sets register (overwrites existing register). | |
auto | size () const |
Returns number of macros and variables available. | |
bool | starts_with (const std::string_view &text) |
Does a recorded macro or variable starts with text. | |
Offers the macro collection, and allows recording and playback to vi (ex) component.
You can also use variables inside a macro (or in vi), these are expanded while playing back.
|
strong |
bool wex::macros::erase | ( | ) |
Erases current macro from the vector and cleans it.
Returns true if macro was erased.
const commands_t wex::macros::get | ( | ) | const |
Returns all macro names as a vector of strings.
Does not include registers.
const commands_t wex::macros::get_registers | ( | ) | const |
Returns all registers (with content) as a vector of strings.
Does not include macros.
bool wex::macros::is_recorded_macro | ( | const std::string & | macro | ) | const |
Is macro recorded.
Does not check for variables.
bool wex::macros::load_document | ( | ) |
Loads all macros (and variables) from xml document.
Returns true if document is loaded (macros still can be empty).
bool wex::macros::record | ( | const std::string & | text, |
bool | new_command = true ) |
Records text to current macro (or register) as a new command.
The text to be recorded should be valid ex command, though it is not checked here. If you playback this macro the text is sent to the ex component to execute it, and then should be a valid command. Returns false if text is not recorded.
text | text to record |
new_command | normally each record is a new command, if not, the text is appended after the last command |
bool wex::macros::save_document | ( | bool | only_if_modified = true | ) |
Saves all macros (and variables) to xml document.
If you specify only_if_modified, then document is only saved if it was modified (if macros have been recorded since last save). Returns true if document is saved.
bool wex::macros::save_macro | ( | const std::string & | macro | ) |
Saves macro (and calls save_document).
Returns false if macro does not exist.
bool wex::macros::set_register | ( | char | name, |
const std::string & | value ) |
Sets register (overwrites existing register).
The name should be a one letter register. Returns false if name is not appropriate.