From 48d534260115ad29146b0f660e754b6eb50439f9 Mon Sep 17 00:00:00 2001 From: Kurtis Rader Date: Mon, 1 May 2017 21:44:30 -0700 Subject: [PATCH] style cleanups Time for another `make style-all`. --- src/autoload.cpp | 7 +++-- src/builtin.cpp | 8 +++--- src/builtin_test.cpp | 2 +- src/env.cpp | 3 +- src/event.h | 4 +-- src/fish_tests.cpp | 1 - src/highlight.cpp | 39 ++++++++++++++----------- src/io.cpp | 6 ++-- src/output.cpp | 7 +++-- src/parse_execution.cpp | 15 +++++----- src/parse_productions.h | 2 +- src/parser.cpp | 4 +-- src/path.cpp | 3 +- src/postfork.cpp | 2 +- src/proc.cpp | 6 ++-- src/reader.cpp | 13 +++++---- src/screen.cpp | 63 ++++++++++++++++++++++------------------- 17 files changed, 99 insertions(+), 86 deletions(-) diff --git a/src/autoload.cpp b/src/autoload.cpp index 8e063c7a1..ae3a7aafc 100644 --- a/src/autoload.cpp +++ b/src/autoload.cpp @@ -97,9 +97,10 @@ int autoload_t::load(const wcstring &cmd, bool reload) { // on the main thread. if (!inserted) { // We failed to insert. - debug(0, _(L"Could not autoload item '%ls', it is already being autoloaded. " - L"This is a circular dependency in the autoloading scripts, please remove it."), - cmd.c_str()); + const wchar_t *fmt = + _(L"Could not autoload item '%ls', it is already being autoloaded. " + L"This is a circular dependency in the autoloading scripts, please remove it."); + debug(0, fmt, cmd.c_str()); return 1; } // Try loading it. diff --git a/src/builtin.cpp b/src/builtin.cpp index d4199ae9c..b48cba8a4 100644 --- a/src/builtin.cpp +++ b/src/builtin.cpp @@ -3045,10 +3045,10 @@ static int disown_job(parser_t &parser, io_streams_t &streams, job_t *j) { // Stopped disowned jobs must be manually signalled; explain how to do so if (job_is_stopped(j)) { - killpg(j->pgid, SIGCONT); - streams.err.append_format( - _(L"%ls: job %d ('%ls') was stopped and has been signalled to continue.\n"), - L"disown", j->job_id, j->command_wcstr()); + killpg(j->pgid, SIGCONT); + const wchar_t *fmt = + _(L"%ls: job %d ('%ls') was stopped and has been signalled to continue.\n"); + streams.err.append_format(fmt, L"disown", j->job_id, j->command_wcstr()); } if (parser.job_remove(j)) { diff --git a/src/builtin_test.cpp b/src/builtin_test.cpp index eaeb59365..b114f46e7 100644 --- a/src/builtin_test.cpp +++ b/src/builtin_test.cpp @@ -730,7 +730,7 @@ static bool unary_primary_evaluate(test_expressions::token_t token, const wcstri } } } -}; +}; // namespace test_expressions /// Evaluate a conditional expression given the arguments. If fromtest is set, the caller is the /// test or [ builtin; with the pointer giving the name of the command. for POSIX conformance this diff --git a/src/env.cpp b/src/env.cpp index 77a274249..5bf60d470 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -807,7 +807,8 @@ void env_init(const struct config_paths_t *paths /* or NULL */) { // Some `su`s keep $USER when changing to root. // This leads to issues later on (and e.g. in prompts), // so we work around it by resetting $USER. - // TODO: Figure out if that su actually checks if username == "root"(as the man page says) or UID == 0. + // TODO: Figure out if that su actually checks if username == "root"(as the man page says) or + // UID == 0. uid_t uid = getuid(); setup_user(uid == 0); diff --git a/src/event.h b/src/event.h index f549ce0ec..c08f9866e 100644 --- a/src/event.h +++ b/src/event.h @@ -53,8 +53,8 @@ struct event_t { /// The type-specific parameter. The int types are one of the following: /// /// signal: Signal number for signal-type events.Use EVENT_ANY_SIGNAL to match any signal - /// pid: Process id for process-type events. Use EVENT_ANY_PID to match any pid. (Negative values are used for PGIDs). - /// job_id: Job id for EVENT_JOB_ID type events + /// pid: Process id for process-type events. Use EVENT_ANY_PID to match any pid. (Negative + /// values are used for PGIDs). job_id: Job id for EVENT_JOB_ID type events union { int signal; int job_id; diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index 3be5eac68..c04ef520d 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -2134,7 +2134,6 @@ static void test_complete(void) { complete(L"echo \\$Foo", &completions, COMPLETION_REQUEST_DEFAULT, vars); do_test(completions.empty()); - // File completions. completions.clear(); complete(L"cat test/complete_test/te", &completions, COMPLETION_REQUEST_DEFAULT, vars); diff --git a/src/highlight.cpp b/src/highlight.cpp index 9e828f738..8722bf7ad 100644 --- a/src/highlight.cpp +++ b/src/highlight.cpp @@ -41,16 +41,25 @@ /// The environment variables used to specify the color of different tokens. This matches the order /// in highlight_spec_t. -static const wchar_t *const highlight_var[] = { - L"fish_color_normal", L"fish_color_error", L"fish_color_command", L"fish_color_end", - L"fish_color_param", L"fish_color_comment", L"fish_color_match", L"fish_color_search_match", - L"fish_color_operator", L"fish_color_escape", L"fish_color_quote", L"fish_color_redirection", - L"fish_color_autosuggestion", L"fish_color_selection", - - L"fish_pager_color_prefix", L"fish_pager_color_completion", L"fish_pager_color_description", - L"fish_pager_color_progress", L"fish_pager_color_secondary" - -}; +static const wchar_t *const highlight_var[] = {L"fish_color_normal", + L"fish_color_error", + L"fish_color_command", + L"fish_color_end", + L"fish_color_param", + L"fish_color_comment", + L"fish_color_match", + L"fish_color_search_match", + L"fish_color_operator", + L"fish_color_escape", + L"fish_color_quote", + L"fish_color_redirection", + L"fish_color_autosuggestion", + L"fish_color_selection", + L"fish_pager_color_prefix", + L"fish_pager_color_completion", + L"fish_pager_color_description", + L"fish_pager_color_progress", + L"fish_pager_color_secondary"}; /// Determine if the filesystem containing the given fd is case insensitive for lookups regardless /// of whether it preserves the case when saving a pathname. @@ -843,9 +852,8 @@ void highlighter_t::color_redirection(const parse_node_t &redirection_node) { this->parse_tree.type_for_redirection(redirection_node, this->buff, NULL, &target); // We may get a TOK_NONE redirection type, e.g. if the redirection is invalid. - this->color_node( - *redirection_primitive, - redirect_type == TOK_NONE ? highlight_spec_error : highlight_spec_redirection); + auto hl = redirect_type == TOK_NONE ? highlight_spec_error : highlight_spec_redirection; + this->color_node(*redirection_primitive, hl); // Check if the argument contains a command substitution. If so, highlight it as a param // even though it's a command redirection, and don't try to do any other validation. @@ -942,9 +950,8 @@ void highlighter_t::color_redirection(const parse_node_t &redirection_node) { } if (redirection_target != NULL) { - this->color_node( - *redirection_target, - target_is_valid ? highlight_spec_redirection : highlight_spec_error); + auto hl = target_is_valid ? highlight_spec_redirection : highlight_spec_error; + this->color_node(*redirection_target, hl); } } } diff --git a/src/io.cpp b/src/io.cpp index 0dfb1f75f..f5b315430 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -53,9 +53,9 @@ void io_buffer_t::read() { // never block. But a broken pipe seems to cause some flags to reset, causing the // EOF flag to not be set. Therefore, EAGAIN is ignored and we exit anyway. if (errno != EAGAIN) { - debug(1, _(L"An error occured while reading output from code block on file " - L"descriptor %d"), - pipe_fd[0]); + const wchar_t *fmt = + _(L"An error occured while reading output from code block on fd %d"); + debug(1, fmt, pipe_fd[0]); wperror(L"io_buffer_t::read"); } diff --git a/src/output.cpp b/src/output.cpp index cb7a0aa46..8814b5fc1 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -555,8 +555,9 @@ void writembs_check(char *mbs, const char *mbs_name, const char *file, long line tputs(mbs, 1, &writeb); } else { env_var_t term = env_get_string(L"TERM"); - debug(0, _(L"Tried to use terminfo string %s on line %ld of %s, which is undefined in " - L"terminal of type \"%ls\". Please report this error to %s"), - mbs_name, line, file, term.c_str(), PACKAGE_BUGREPORT); + const wchar_t *fmt = + _(L"Tried to use terminfo string %s on line %ld of %s, which is " + L"undefined in terminal of type \"%ls\". Please report this error to %s"); + debug(0, fmt, mbs_name, line, file, term.c_str(), PACKAGE_BUGREPORT); } } diff --git a/src/parse_execution.cpp b/src/parse_execution.cpp index 24aaa80a1..7708d4a30 100644 --- a/src/parse_execution.cpp +++ b/src/parse_execution.cpp @@ -767,10 +767,11 @@ parse_execution_result_t parse_execution_context_t::handle_command_not_found( } } else if (wcschr(cmd, L'$') || wcschr(cmd, VARIABLE_EXPAND_SINGLE) || wcschr(cmd, VARIABLE_EXPAND)) { + const wchar_t *msg = + _(L"Variables may not be used as commands. In fish, " + L"please define a function or use 'eval %ls'."); wcstring eval_cmd = reconstruct_orig_str(cmd_str); - this->report_error(statement_node, _(L"Variables may not be used as commands. In fish, " - L"please define a function or use 'eval %ls'."), - eval_cmd.c_str()); + this->report_error(statement_node, msg, eval_cmd.c_str()); } else if (err_code != ENOENT) { this->report_error(statement_node, _(L"The file '%ls' is not executable by this user"), cmd ? cmd : L"UNKNOWN"); @@ -998,10 +999,10 @@ bool parse_execution_context_t::determine_io_chain(const parse_node_t &statement } else { int old_fd = fish_wcstoi(target.c_str()); if (errno || old_fd < 0) { - errored = - report_error(redirect_node, _(L"Requested redirection to '%ls', which " - L"is not a valid file descriptor"), - target.c_str()); + const wchar_t *fmt = + _(L"Requested redirection to '%ls', " + L"which is not a valid file descriptor"); + errored = report_error(redirect_node, fmt, target.c_str()); } else { new_io.reset(new io_fd_t(source_fd, old_fd, true)); } diff --git a/src/parse_productions.h b/src/parse_productions.h index ce1589ebb..74f2d7a97 100644 --- a/src/parse_productions.h +++ b/src/parse_productions.h @@ -44,6 +44,6 @@ inline bool production_element_is_valid(production_element_t elem) { const production_element_t *production_for_token(parse_token_type_t node_type, const parse_token_t &input1, const parse_token_t &input2, uint8_t *out_tag); -} +} // namespace parse_productions #endif diff --git a/src/parser.cpp b/src/parser.cpp index 3750eec60..f3ba54206 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -440,9 +440,7 @@ const wchar_t *parser_t::is_function() const { return result; } -const wchar_t *parser_t::get_function_name() { - return this->is_function(); -} +const wchar_t *parser_t::get_function_name() { return this->is_function(); } int parser_t::get_lineno() const { int lineno = -1; diff --git a/src/path.cpp b/src/path.cpp index 51d79f840..6241f2622 100644 --- a/src/path.cpp +++ b/src/path.cpp @@ -233,8 +233,7 @@ static void maybe_issue_path_warning(const wcstring &which_dir, const wcstring & debug(0, custom_error_msg.c_str()); if (path.empty()) { debug(0, _(L"Unable to locate the %ls directory."), which_dir.c_str()); - debug(0, _(L"Please set the %ls or HOME environment variable " - L"before starting fish."), + debug(0, _(L"Please set the %ls or HOME environment variable before starting fish."), xdg_var.c_str()); } else { const wchar_t *env_var = using_xdg ? xdg_var.c_str() : L"HOME"; diff --git a/src/postfork.cpp b/src/postfork.cpp index da9d2f26a..9f29963b0 100644 --- a/src/postfork.cpp +++ b/src/postfork.cpp @@ -326,7 +326,7 @@ bool fork_actions_make_spawn_properties(posix_spawnattr_t *attr, // set_child_group puts each job into its own process group // do the same here if there is no PGID yet (i.e. PGID == -2) desired_process_group_id = j->pgid; - if (desired_process_group_id == -2 ) { + if (desired_process_group_id == -2) { desired_process_group_id = 0; } } diff --git a/src/proc.cpp b/src/proc.cpp index 25c37e9ad..df9f17c45 100644 --- a/src/proc.cpp +++ b/src/proc.cpp @@ -597,9 +597,9 @@ int job_reap(bool allow_interactive) { } else { const wcstring job_number_desc = (job_count == 1) ? wcstring() : format_string(L"from job %d, ", j->job_id); - fwprintf(stdout, _(L"%ls: Process %d, \'%ls\' %ls\'%ls\' " - L"terminated by signal %ls (%ls)"), - program_name, p->pid, p->argv0(), job_number_desc.c_str(), + const wchar_t *fmt = + _(L"%ls: Process %d, \'%ls\' %ls\'%ls\' terminated by signal %ls (%ls)"); + fwprintf(stdout, fmt, program_name, p->pid, p->argv0(), job_number_desc.c_str(), truncate_command(j->command()).c_str(), sig2wcs(WTERMSIG(p->status)), signal_get_desc(WTERMSIG(p->status))); } diff --git a/src/reader.cpp b/src/reader.cpp index 9e47aef25..23edd6f5c 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -447,9 +447,9 @@ static void reader_repaint() { bool focused_on_pager = data->active_edit_line() == &data->pager.search_field_line; size_t cursor_position = focused_on_pager ? data->pager.cursor_position() : cmd_line->position; - s_write(&data->screen, data->left_prompt_buff, data->right_prompt_buff, full_line, cmd_line->size(), - &colors[0], &indents[0], cursor_position, data->current_page_rendering, - focused_on_pager); + s_write(&data->screen, data->left_prompt_buff, data->right_prompt_buff, full_line, + cmd_line->size(), &colors[0], &indents[0], cursor_position, + data->current_page_rendering, focused_on_pager); data->repaint_needed = false; } @@ -1603,9 +1603,10 @@ static void reader_interactive_init() { } else { if (check_for_orphaned_process(loop_count, shell_pgid)) { // We're orphaned, so we just die. Another sad statistic. - debug(1, _(L"I appear to be an orphaned process, so I am quitting politely. My " - L"pid is %d."), - (int)getpid()); + const wchar_t *fmt = + _(L"I appear to be an orphaned process, so I am quitting politely. " + L"My pid is %d."); + debug(1, fmt, (int)getpid()); exit_without_destructors(1); } diff --git a/src/screen.cpp b/src/screen.cpp index ff37d27be..0d0d3cc1d 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -1020,44 +1020,52 @@ static screen_layout_t compute_layout(screen_t *s, size_t screen_width, // the right prompt? The issue is resizing: if you resize the window smaller, then the right // prompt will wrap to the next line. This means that we can't go back to the line that we were // on, and things turn to chaos very quickly. + size_t calculated_width; bool done = false; // Case 1 - if (!done && - left_prompt_width + right_prompt_width + first_command_line_width + - autosuggest_total_width < - screen_width) { - result.left_prompt = left_prompt; - result.left_prompt_space = left_prompt_width; - result.right_prompt = right_prompt; - result.autosuggestion = autosuggestion; - done = true; + if (!done) { + calculated_width = left_prompt_width + right_prompt_width + first_command_line_width + + autosuggest_total_width; + if (calculated_width < screen_width) { + result.left_prompt = left_prompt; + result.left_prompt_space = left_prompt_width; + result.right_prompt = right_prompt; + result.autosuggestion = autosuggestion; + done = true; + } } // Case 2. Note that we require strict inequality so that there's always at least one space // between the left edge and the rprompt. - if (!done && left_prompt_width + right_prompt_width + first_command_line_width < screen_width) { - result.left_prompt = left_prompt; - result.left_prompt_space = left_prompt_width; - result.right_prompt = right_prompt; + if (!done) { + calculated_width = left_prompt_width + right_prompt_width + first_command_line_width; + if (calculated_width < screen_width) { + result.left_prompt = left_prompt; + result.left_prompt_space = left_prompt_width; + result.right_prompt = right_prompt; - // Need at least two characters to show an autosuggestion. - size_t available_autosuggest_space = - screen_width - (left_prompt_width + right_prompt_width + first_command_line_width); - if (autosuggest_total_width > 0 && available_autosuggest_space > 2) { - size_t truncation_offset = truncation_offset_for_width(autosuggest_truncated_widths, - available_autosuggest_space - 2); - result.autosuggestion = wcstring(autosuggestion, truncation_offset); - result.autosuggestion.push_back(ellipsis_char); + // Need at least two characters to show an autosuggestion. + size_t available_autosuggest_space = + screen_width - (left_prompt_width + right_prompt_width + first_command_line_width); + if (autosuggest_total_width > 0 && available_autosuggest_space > 2) { + size_t truncation_offset = truncation_offset_for_width( + autosuggest_truncated_widths, available_autosuggest_space - 2); + result.autosuggestion = wcstring(autosuggestion, truncation_offset); + result.autosuggestion.push_back(ellipsis_char); + } + done = true; } - done = true; } // Case 3 - if (!done && left_prompt_width + first_command_line_width < screen_width) { - result.left_prompt = left_prompt; - result.left_prompt_space = left_prompt_width; - done = true; + if (!done) { + calculated_width = left_prompt_width + first_command_line_width; + if (calculated_width < screen_width) { + result.left_prompt = left_prompt; + result.left_prompt_space = left_prompt_width; + done = true; + } } // Case 4 @@ -1072,11 +1080,8 @@ static screen_layout_t compute_layout(screen_t *s, size_t screen_width, prompt_percent_width > 33) { result.prompts_get_own_line = true; } - - done = true; } - assert(done); return result; }