mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-06 00:41:15 -03:00
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`.
This commit is contained in:
16
function.h
16
function.h
@@ -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;
|
||||
@@ -48,6 +50,11 @@ struct function_data_t
|
||||
List of all named arguments for this function
|
||||
*/
|
||||
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 @@ class function_info_t
|
||||
/** 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;
|
||||
|
||||
@@ -162,6 +172,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.
|
||||
|
||||
Reference in New Issue
Block a user