diff --git a/fish.cpp b/fish.cpp index f1c5b898a..35b641ee0 100644 --- a/fish.cpp +++ b/fish.cpp @@ -227,7 +227,9 @@ static void source_config_in_directory(const wcstring &dir) const wcstring escaped_dir = escape_string(dir, ESCAPE_ALL); const wcstring cmd = L"builtin source " + escaped_dir + L"/config.fish 2>/dev/null"; parser_t &parser = parser_t::principal_parser(); + parser.set_is_within_fish_initialization(true); parser.eval(cmd, io_chain_t(), TOP); + parser.set_is_within_fish_initialization(false); } /** diff --git a/parser.cpp b/parser.cpp index 4f4a050e5..625a0678b 100644 --- a/parser.cpp +++ b/parser.cpp @@ -299,6 +299,7 @@ parser_t::parser_t(enum parser_type_t type, bool errors) : error_code(0), err_pos(0), cancellation_requested(false), + is_within_fish_initialization(false), current_tokenizer(NULL), current_tokenizer_pos(0), job_start_pos(0), @@ -322,6 +323,11 @@ parser_t &parser_t::principal_parser(void) return parser; } +void parser_t::set_is_within_fish_initialization(bool flag) +{ + is_within_fish_initialization = flag; +} + void parser_t::skip_all_blocks(void) { /* Tell all blocks to skip */ @@ -858,10 +864,13 @@ void parser_t::stack_trace(size_t block_idx, wcstring &buff) const b->src_lineno, user_presentable_path(file).c_str()); } + else if (is_within_fish_initialization) + { + append_format(buff, _(L"\tcalled during startup\n")); + } else { - append_format(buff, - _(L"\tcalled on standard input\n")); + append_format(buff, _(L"\tcalled on standard input\n")); } if (b->type() == FUNCTION_CALL) @@ -1064,15 +1073,17 @@ const wchar_t *parser_t::current_line() { int prev_width = my_wcswidth(lineinfo.c_str()); if (file) - append_format(lineinfo, - _(L"%ls (line %d): "), - file, - lineno); + { + append_format(lineinfo, _(L"%ls (line %d): "), file, lineno); + } + else if (is_within_fish_initialization) + { + append_format(lineinfo, L"%ls: ", _(L"Startup"), lineno); + } else - append_format(lineinfo, - L"%ls: ", - _(L"Standard input"), - lineno); + { + append_format(lineinfo, L"%ls: ", _(L"Standard input"), lineno); + } offset = my_wcswidth(lineinfo.c_str()) - prev_width; } else diff --git a/parser.h b/parser.h index 491e569f5..f4dfcac25 100644 --- a/parser.h +++ b/parser.h @@ -283,6 +283,9 @@ class parser_t /** Indication that we should skip all blocks */ bool cancellation_requested; + + /** Indicates that we are within the process of initializing fish */ + bool is_within_fish_initialization; /** Stack of execution contexts. We own these pointers and must delete them */ std::vector execution_contexts; @@ -447,6 +450,9 @@ class parser_t { return my_job_list; } + + /* Hackish. In order to correctly report the origin of code with no associated file, we need to know whether it's run during initialization or not. */ + void set_is_within_fish_initialization(bool flag); /** Pushes the block. pop_block will call delete on it. */ void push_block(block_t *newv);