wex v24.10.0
Public Types | Public Member Functions | List of all members
wex::macros Class Reference

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_tmacros_map_t
 Maps macro (register) to vector of command.
 
typedef std::unordered_map< std::string, variablevariables_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_tget_keys_map (key_t type=key_t::NORMAL) const
 Returns keys map.
 
const commands_t get_macro_commands (const std::string &macro) 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 &macro) const
 Is macro or variable recorded.
 
bool is_recorded_macro (const std::string &macro) 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 &macro)
 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.
 

Detailed Description

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.

dot_inline_dotgraph_3.png

Member Enumeration Documentation

◆ key_t

enum class wex::macros::key_t
strong

Type of macro key used for key_map.

Enumerator
ALT 

alt key

CONTROL 

control key

NORMAL 

normal key (default)

Member Function Documentation

◆ erase()

bool wex::macros::erase ( )

Erases current macro from the vector and cleans it.

Returns true if macro was erased.

◆ get()

const commands_t wex::macros::get ( ) const

Returns all macro names as a vector of strings.

Does not include registers.

◆ get_registers()

const commands_t wex::macros::get_registers ( ) const

Returns all registers (with content) as a vector of strings.

Does not include macros.

◆ is_recorded_macro()

bool wex::macros::is_recorded_macro ( const std::string & macro) const

Is macro recorded.

Does not check for variables.

◆ load_document()

bool wex::macros::load_document ( )

Loads all macros (and variables) from xml document.

Returns true if document is loaded (macros still can be empty).

◆ record()

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.

Parameters
texttext to record
new_commandnormally each record is a new command, if not, the text is appended after the last command

◆ save_document()

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.

◆ save_macro()

bool wex::macros::save_macro ( const std::string & macro)

Saves macro (and calls save_document).

Returns false if macro does not exist.

◆ set_register()

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.