wex  v21.04.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/macros.h>

Public Types

enum  key_t { KEY_ALT , KEY_CONTROL , KEY_NORMAL }
 Type of macro key used for key_map. More...
 
typedef std::map< int, std::string > keys_map_t
 Maps key to command.

 

Public Member Functions

 macros ()
 Default constructor.
 
bool erase ()
 Erases current macro from the vector and cleans it. More...
 
const std::vector< std::string > 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 std::vector< std::string > get () const
 Returns all macro names as a vector of strings. More...
 
const auto & get_abbreviations () const
 Returns abbreviations.
 
const path get_filename () const
 Returns the filename with xml document.
 
const keys_map_tget_keys_map (key_t type=KEY_NORMAL) const
 Returns keys map.
 
const std::vector< std::string > 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 std::vector< std::string > get_registers () const
 Returns all registers (with content) as a vector of strings. More...
 
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. More...
 
bool load_document ()
 Loads all macros (and variables) from xml document. More...
 
auto & mode ()
 Returns the mode we are in.

 
const auto & mode () const
 Returns the mode we are in.

 
bool record (const std::string &text, bool new_command=true)
 Records text to current macro (or register) as a new command. More...
 
bool save_document (bool only_if_modified=true)
 Saves all macros (and variables) to xml document. More...
 
void 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_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). More...
 
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.

Member Enumeration Documentation

◆ key_t

Type of macro key used for key_map.

Enumerator
KEY_ALT 

alt key

KEY_CONTROL 

control key

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 std::vector< std::string > wex::macros::get ( ) const

Returns all macro names as a vector of strings.

Does not include registers.

◆ get_registers()

const std::vector< std::string > 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.

◆ 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.