diff options
author | Kevin Ballard <kevin@sb.org> | 2014-10-02 15:59:24 -0700 |
---|---|---|
committer | Kevin Ballard <kevin@sb.org> | 2014-10-02 18:41:39 -0700 |
commit | cfc06203e7ad7707acadd160292d47b25d6daba6 (patch) | |
tree | 387a4aa8149477309f9c545dfb9c6ccf1ea24ac1 /function.h | |
parent | 6d7a7b00d77098c93aa2b6c0deba4c18029b5a32 (diff) |
Add new `functions` flag -V/--inherit-variable
--inherit-variable takes a variable name and snapshots its current
value. When the function is executed, it will have a local variable with
this value already defined. Printing the function source will include
synthesized `set -l` lines for the values.
This is primarily useful for functions that are created on the fly, such
as in `psub`.
Diffstat (limited to 'function.h')
-rw-r--r-- | function.h | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -11,10 +11,12 @@ #define FISH_FUNCTION_H #include <wchar.h> +#include <map> #include "util.h" #include "common.h" #include "event.h" +#include "env.h" class parser_t; class env_vars_snapshot_t; @@ -49,6 +51,11 @@ struct function_data_t */ wcstring_list_t named_arguments; /** + List of all variables that are inherited from the function definition scope. + The variable values are snapshotted when function_add() is called. + */ + wcstring_list_t inherit_vars; + /** Set to non-zero if invoking this function shadows the variables of the underlying function. */ @@ -79,6 +86,9 @@ public: /** List of all named arguments for this function */ const wcstring_list_t named_arguments; + /** Mapping of all variables that were inherited from the function definition scope to their values */ + const std::map<wcstring,env_var_t> inherit_vars; + /** Flag for specifying that this function was automatically loaded */ const bool is_autoload; @@ -163,6 +173,12 @@ int function_get_definition_offset(const wcstring &name); wcstring_list_t function_get_named_arguments(const wcstring &name); /** + Returns a mapping of all variables of the specified function that were inherited + from the scope of the function definition to their values. + */ +std::map<wcstring,env_var_t> function_get_inherit_vars(const wcstring &name); + +/** Creates a new function using the same definition as the specified function. Returns true if copy is successful. */ |