aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2014-03-31 10:01:39 -0700
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2014-03-31 10:01:39 -0700
commit0d3169ef70032559e201a500aff2197a2854aa72 (patch)
tree89971815f95f8826ad1eee19985147d0635ca2ea
parentfe3b439e31ce893d9345112e95a031aa5ec11183 (diff)
Run restyle.sh to enforce style rules.
-rw-r--r--autoload.cpp2
-rw-r--r--autoload.h2
-rw-r--r--builtin.cpp22
-rw-r--r--builtin_commandline.cpp14
-rw-r--r--builtin_complete.cpp10
-rw-r--r--common.h4
-rw-r--r--complete.cpp20
-rw-r--r--expand.cpp62
-rw-r--r--fish.cpp8
-rw-r--r--fish_tests.cpp12
-rw-r--r--highlight.cpp30
-rw-r--r--history.cpp34
-rw-r--r--history.h14
-rw-r--r--input.cpp94
-rw-r--r--input.h4
-rw-r--r--pager.cpp158
-rw-r--r--pager.h92
-rw-r--r--parse_constants.h6
-rw-r--r--parse_execution.cpp30
-rw-r--r--parse_execution.h20
-rw-r--r--parse_productions.cpp2
-rw-r--r--parse_tree.cpp9
-rw-r--r--parse_tree.h10
-rw-r--r--parse_util.cpp36
-rw-r--r--parser.cpp10
-rw-r--r--parser.h12
-rw-r--r--reader.cpp142
-rw-r--r--reader.h20
-rw-r--r--screen.cpp6
-rw-r--r--screen.h8
30 files changed, 450 insertions, 443 deletions
diff --git a/autoload.cpp b/autoload.cpp
index 5a72a5cd..5e93ac1a 100644
--- a/autoload.cpp
+++ b/autoload.cpp
@@ -94,7 +94,7 @@ int autoload_t::load(const wcstring &cmd, bool reload)
this->last_path = path_var;
this->last_path_tokenized.clear();
tokenize_variable_array(this->last_path, this->last_path_tokenized);
-
+
scoped_lock locker(lock);
this->evict_all_nodes();
}
diff --git a/autoload.h b/autoload.h
index 2f1e00d3..b4338538 100644
--- a/autoload.h
+++ b/autoload.h
@@ -64,7 +64,7 @@ private:
/** The path from which we most recently autoloaded */
wcstring last_path;
-
+
/** That path, tokenized (split on separators) */
wcstring_list_t last_path_tokenized;
diff --git a/builtin.cpp b/builtin.cpp
index 9fc55aa4..8a81648e 100644
--- a/builtin.cpp
+++ b/builtin.cpp
@@ -418,20 +418,20 @@ static void builtin_bind_list(const wchar_t *bind_mode)
{
continue;
}
-
+
if (bind_mode != NULL && bind_mode != mode)
{
- continue;
+ continue;
}
wcstring tname;
if (input_terminfo_get_name(seq, tname))
{
append_format(stdout_buffer, L"bind -k %ls -M %ls -m %ls", tname.c_str(), mode.c_str(), sets_mode.c_str());
- for(int i = 0; i < ecmds.size(); i++)
+ for (int i = 0; i < ecmds.size(); i++)
{
- wcstring ecmd = ecmds.at(i);
- append_format(stdout_buffer, L" %ls", escape(ecmd.c_str(), 1));
+ wcstring ecmd = ecmds.at(i);
+ append_format(stdout_buffer, L" %ls", escape(ecmd.c_str(), 1));
}
append_format(stdout_buffer, L"\n");
}
@@ -439,10 +439,10 @@ static void builtin_bind_list(const wchar_t *bind_mode)
{
const wcstring eseq = escape_string(seq, 1);
append_format(stdout_buffer, L"bind -k %ls -M %ls -m %ls", eseq.c_str(), mode.c_str(), sets_mode.c_str());
- for(int i = 0; i < ecmds.size(); i++)
+ for (int i = 0; i < ecmds.size(); i++)
{
- wcstring ecmd = ecmds.at(i);
- append_format(stdout_buffer, L" %ls", escape(ecmd.c_str(), 1));
+ wcstring ecmd = ecmds.at(i);
+ append_format(stdout_buffer, L" %ls", escape(ecmd.c_str(), 1));
}
append_format(stdout_buffer, L"\n");
}
@@ -672,11 +672,11 @@ static int builtin_bind(parser_t &parser, wchar_t **argv)
}
/*
- * if mode is given, but not new mode, default to new mode to mode
+ * if mode is given, but not new mode, default to new mode to mode
*/
- if(bind_mode_given && !sets_bind_mode_given)
+ if (bind_mode_given && !sets_bind_mode_given)
{
- sets_bind_mode = bind_mode;
+ sets_bind_mode = bind_mode;
}
switch (mode)
diff --git a/builtin_commandline.cpp b/builtin_commandline.cpp
index 36726b9f..88084c3b 100644
--- a/builtin_commandline.cpp
+++ b/builtin_commandline.cpp
@@ -357,7 +357,7 @@ static int builtin_commandline(parser_t &parser, wchar_t **argv)
case 's':
selection_mode = 1;
break;
-
+
case 'P':
paging_mode = 1;
break;
@@ -431,16 +431,16 @@ static int builtin_commandline(parser_t &parser, wchar_t **argv)
const wchar_t *buffer = reader_get_buffer();
if (reader_get_selection(&start, &len))
{
- wchar_t *selection = new wchar_t[len + 1];
- selection[len] = L'\0';
- selection = wcsncpy(selection, buffer + start, len);
+ wchar_t *selection = new wchar_t[len + 1];
+ selection[len] = L'\0';
+ selection = wcsncpy(selection, buffer + start, len);
- append_format(stdout_buffer, selection);
- delete selection;
+ append_format(stdout_buffer, selection);
+ delete selection;
}
else
{
- append_format(stdout_buffer, L"");
+ append_format(stdout_buffer, L"");
}
return 0;
}
diff --git a/builtin_complete.cpp b/builtin_complete.cpp
index c2fb6637..d029e83e 100644
--- a/builtin_complete.cpp
+++ b/builtin_complete.cpp
@@ -509,22 +509,22 @@ static int builtin_complete(parser_t &parser, wchar_t **argv)
for (size_t i=0; i< comp.size() ; i++)
{
const completion_t &next = comp.at(i);
-
+
/* Make a fake commandline, and then apply the completion to it. */
const wcstring faux_cmdline = token;
size_t tmp_cursor = faux_cmdline.size();
wcstring faux_cmdline_with_completion = completion_apply_to_command_line(next.completion, next.flags, faux_cmdline, &tmp_cursor, false);
-
+
/* completion_apply_to_command_line will append a space unless COMPLETE_NO_SPACE is set. We don't want to set COMPLETE_NO_SPACE because that won't close quotes. What we want is to close the quote, but not append the space. So we just look for the space and clear it. */
- if (! (next.flags & COMPLETE_NO_SPACE) && string_suffixes_string(L" ", faux_cmdline_with_completion))
+ if (!(next.flags & COMPLETE_NO_SPACE) && string_suffixes_string(L" ", faux_cmdline_with_completion))
{
faux_cmdline_with_completion.resize(faux_cmdline_with_completion.size() - 1);
}
-
+
/* The input data is meant to be something like you would have on the command line, e.g. includes backslashes. The output should be raw, i.e. unescaped. So we need to unescape the command line. See #1127 */
unescape_string_in_place(&faux_cmdline_with_completion, UNESCAPE_DEFAULT);
stdout_buffer.append(faux_cmdline_with_completion);
-
+
/* Append any description */
if (! next.description.empty())
{
diff --git a/common.h b/common.h
index 9b88e494..3c409e8f 100644
--- a/common.h
+++ b/common.h
@@ -95,11 +95,11 @@ enum selection_direction_t
direction_east,
direction_south,
direction_west,
-
+
/* logical directions */
direction_next,
direction_prev,
-
+
/* special value that means deselect */
direction_deselect
};
diff --git a/complete.cpp b/complete.cpp
index 7d7d7981..73d3182e 100644
--- a/complete.cpp
+++ b/complete.cpp
@@ -1716,10 +1716,10 @@ bool completer_t::try_complete_variable(const wcstring &str)
{
enum {e_unquoted, e_single_quoted, e_double_quoted} mode = e_unquoted;
const size_t len = str.size();
-
+
/* Get the position of the dollar heading a run of valid variable characters. -1 means none. */
size_t variable_start = -1;
-
+
for (size_t in_pos=0; in_pos<len; in_pos++)
{
wchar_t c = str.at(in_pos);
@@ -1728,20 +1728,20 @@ bool completer_t::try_complete_variable(const wcstring &str)
/* This character cannot be in a variable, reset the dollar */
variable_start = -1;
}
-
+
switch (c)
{
case L'\\':
in_pos++;
break;
-
+
case L'$':
if (mode == e_unquoted || mode == e_double_quoted)
{
variable_start = in_pos;
}
break;
-
+
case L'\'':
if (mode == e_single_quoted)
{
@@ -1752,7 +1752,7 @@ bool completer_t::try_complete_variable(const wcstring &str)
mode = e_single_quoted;
}
break;
-
+
case L'"':
if (mode == e_double_quoted)
{
@@ -1765,7 +1765,7 @@ bool completer_t::try_complete_variable(const wcstring &str)
break;
}
}
-
+
/* Now complete if we have a variable start that's also not the last character */
bool result = false;
if (variable_start != static_cast<size_t>(-1) && variable_start + 1 < len)
@@ -1860,7 +1860,7 @@ void complete(const wcstring &cmd_with_subcmds, std::vector<completion_t> &comps
bool use_function = 1;
bool use_builtin = 1;
- //debug( 1, L"Complete '%ls'", cmd.c_str() );
+ //debug( 1, L"Complete '%ls'", cmd.c_str() );
const wchar_t *cmd_cstr = cmd.c_str();
const wchar_t *tok_begin = NULL, *prev_begin = NULL, *prev_end = NULL;
@@ -1885,14 +1885,14 @@ void complete(const wcstring &cmd_with_subcmds, std::vector<completion_t> &comps
parse_node_tree_t tree;
parse_tree_from_string(cmd, parse_flag_continue_after_error | parse_flag_accept_incomplete_tokens, &tree, NULL);
-
+
/* Find any plain statement that contains the position. We have to backtrack past spaces (#1261). So this will be at either the last space character, or after the end of the string */
size_t adjusted_pos = pos;
while (adjusted_pos > 0 && cmd.at(adjusted_pos - 1) == L' ')
{
adjusted_pos--;
}
-
+
const parse_node_t *plain_statement = tree.find_node_matching_source_location(symbol_plain_statement, adjusted_pos, NULL);
if (plain_statement == NULL)
{
diff --git a/expand.cpp b/expand.cpp
index bae7bde1..f7812efa 100644
--- a/expand.cpp
+++ b/expand.cpp
@@ -902,20 +902,20 @@ void expand_variable_error(parser_t &parser, const wcstring &token, size_t token
if (is_var)
{
append_syntax_error(errors,
- error_pos,
- COMPLETE_VAR_BRACKET_DESC,
- cpy,
- name,
- post);
+ error_pos,
+ COMPLETE_VAR_BRACKET_DESC,
+ cpy,
+ name,
+ post);
}
else
{
append_syntax_error(errors,
- error_pos,
- COMPLETE_VAR_BRACKET_DESC,
- L"",
- L"VARIABLE",
- L"");
+ error_pos,
+ COMPLETE_VAR_BRACKET_DESC,
+ L"",
+ L"VARIABLE",
+ L"");
}
free(cpy);
@@ -925,16 +925,16 @@ void expand_variable_error(parser_t &parser, const wcstring &token, size_t token
case INTERNAL_SEPARATOR:
{
append_syntax_error(errors,
- error_pos,
- COMPLETE_VAR_PARAN_DESC);
+ error_pos,
+ COMPLETE_VAR_PARAN_DESC);
break;
}
case 0:
{
append_syntax_error(errors,
- error_pos,
- COMPLETE_VAR_NULL_DESC);
+ error_pos,
+ COMPLETE_VAR_NULL_DESC);
break;
}
@@ -948,9 +948,9 @@ void expand_variable_error(parser_t &parser, const wcstring &token, size_t token
token_stop_char = L'*';
append_syntax_error(errors,
- error_pos,
- (token_stop_char == L'?' ? COMPLETE_YOU_WANT_STATUS : COMPLETE_VAR_DESC),
- token_stop_char);
+ error_pos,
+ (token_stop_char == L'?' ? COMPLETE_YOU_WANT_STATUS : COMPLETE_VAR_DESC),
+ token_stop_char);
break;
}
}
@@ -999,7 +999,7 @@ static int parse_slice(const wchar_t *in, wchar_t **end_ptr, std::vector<long> &
pos+=2;
while (in[pos]==INTERNAL_SEPARATOR)
pos++;
-
+
const size_t number_start = pos;
long tmp1 = wcstol(&in[pos], &end, 10);
if ((errno) || (end == &in[pos]))
@@ -1068,10 +1068,10 @@ static int expand_variables_internal(parser_t &parser, wchar_t * const in, std::
int empty=0;
wcstring var_tmp;
-
+
// list of indexes
std::vector<long> var_idx_list;
-
+
// parallel array of source positions of each index in the variable list
std::vector<size_t> var_pos_list;
@@ -1123,7 +1123,7 @@ static int expand_variables_internal(parser_t &parser, wchar_t * const in, std::
if (is_ok)
{
tokenize_variable_array(var_val.c_str(), var_item_list);
-
+
const size_t slice_start = stop_pos;
if (in[slice_start] == L'[')
{
@@ -1133,8 +1133,8 @@ static int expand_variables_internal(parser_t &parser, wchar_t * const in, std::
if (parse_slice(in + slice_start, &slice_end, var_idx_list, var_pos_list, var_item_list.size()))
{
append_syntax_error(errors,
- stop_pos,
- L"Invalid index value");
+ stop_pos,
+ L"Invalid index value");
is_ok = 0;
break;
}
@@ -1153,8 +1153,8 @@ static int expand_variables_internal(parser_t &parser, wchar_t * const in, std::
{
/* The slice was parsed starting at stop_pos, so we have to add that to the error position */
append_syntax_error(errors,
- slice_start + var_src_pos,
- ARRAY_BOUNDS_ERR);
+ slice_start + var_src_pos,
+ ARRAY_BOUNDS_ERR);
is_ok=0;
var_idx_list.resize(j);
break;
@@ -1349,8 +1349,8 @@ static int expand_brackets(parser_t &parser, const wcstring &instr, int flags, s
if (syntax_error)
{
append_syntax_error(errors,
- SOURCE_LOCATION_UNKNOWN,
- _(L"Mismatched brackets"));
+ SOURCE_LOCATION_UNKNOWN,
+ _(L"Mismatched brackets"));
return 0;
}
@@ -1416,8 +1416,8 @@ static int expand_cmdsubst(parser_t &parser, const wcstring &input, std::vector<
{
case -1:
append_syntax_error(errors,
- SOURCE_LOCATION_UNKNOWN,
- L"Mismatched parenthesis");
+ SOURCE_LOCATION_UNKNOWN,
+ L"Mismatched parenthesis");
return 0;
case 0:
append_completion(out_list, input);
@@ -1457,8 +1457,8 @@ static int expand_cmdsubst(parser_t &parser, const wcstring &input, std::vector<
if (idx < 1 || (size_t)idx > sub_res.size())
{
append_syntax_error(errors,
- SOURCE_LOCATION_UNKNOWN,
- ARRAY_BOUNDS_ERR);
+ SOURCE_LOCATION_UNKNOWN,
+ ARRAY_BOUNDS_ERR);
return 0;
}
idx = idx-1;
diff --git a/fish.cpp b/fish.cpp
index 35b641ee..7a99ef38 100644
--- a/fish.cpp
+++ b/fish.cpp
@@ -185,12 +185,12 @@ static struct config_paths_t determine_config_directory_paths(const char *argv0)
{
wcstring base_path = str2wcstring(exec_path);
base_path.resize(base_path.size() - strlen(suffix));
-
+
paths.data = base_path + L"/share/fish";
paths.sysconf = base_path + L"/etc/fish";
paths.doc = base_path + L"/share/doc/fish";
paths.bin = base_path + L"/bin";
-
+
/* Check only that the data and sysconf directories exist. Handle the doc directories separately */
struct stat buf;
if (0 == wstat(paths.data, &buf) && 0 == wstat(paths.sysconf, &buf))
@@ -526,12 +526,12 @@ int main(int argc, char **argv)
restore_term_mode();
restore_term_foreground_process_group();
-
+
if (g_profiling_active)
{
parser.emit_profiling(s_profiling_output_filename);
}
-
+
history_destroy();
proc_destroy();
builtin_destroy();
diff --git a/fish_tests.cpp b/fish_tests.cpp
index 92bd0f71..dcc6814e 100644
--- a/fish_tests.cpp
+++ b/fish_tests.cpp
@@ -628,33 +628,33 @@ static void test_parser()
}
- if (! (detect_argument_errors(L"foo$$") & PARSER_TEST_ERROR))
+ if (!(detect_argument_errors(L"foo$$") & PARSER_TEST_ERROR))
{
err(L"Bad variable expansion not reported as error");
}
- if (! (detect_argument_errors(L"foo$@") & PARSER_TEST_ERROR))
+ if (!(detect_argument_errors(L"foo$@") & PARSER_TEST_ERROR))
{
err(L"Bad variable expansion not reported as error");
}
/* Within command substitutions, we should be able to detect everything that parse_util_detect_errors can detect */
- if (! (detect_argument_errors(L"foo(cat | or cat)") & PARSER_TEST_ERROR))
+ if (!(detect_argument_errors(L"foo(cat | or cat)") & PARSER_TEST_ERROR))
{
err(L"Bad command substitution not reported as error");
}
- if (! (detect_argument_errors(L"foo\\xFF9") & PARSER_TEST_ERROR))
+ if (!(detect_argument_errors(L"foo\\xFF9") & PARSER_TEST_ERROR))
{
err(L"Bad escape not reported as error");
}
- if (! (detect_argument_errors(L"foo(echo \\xFF9)") & PARSER_TEST_ERROR))
+ if (!(detect_argument_errors(L"foo(echo \\xFF9)") & PARSER_TEST_ERROR))
{
err(L"Bad escape in command substitution not reported as error");
}
- if (! (detect_argument_errors(L"foo(echo (echo (echo \\xFF9)))") & PARSER_TEST_ERROR))
+ if (!(detect_argument_errors(L"foo(echo (echo (echo \\xFF9)))") & PARSER_TEST_ERROR))
{
err(L"Bad escape in nested command substitution not reported as error");
}
diff --git a/highlight.cpp b/highlight.cpp
index 73b5f193..14672bf0 100644
--- a/highlight.cpp
+++ b/highlight.cpp
@@ -61,7 +61,7 @@ static const wchar_t * const highlight_var[] =
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",
@@ -360,10 +360,10 @@ bool plain_statement_get_expanded_command(const wcstring &src, const parse_node_
rgb_color_t highlight_get_color(highlight_spec_t highlight, bool is_background)
{
rgb_color_t result = rgb_color_t::normal();
-
+
/* If sloppy_background is set, then we look at the foreground color even if is_background is set */
- bool treat_as_background = is_background && ! (highlight & highlight_modifier_sloppy_background);
-
+ bool treat_as_background = is_background && !(highlight & highlight_modifier_sloppy_background);
+
/* Get the primary variable */
size_t idx = highlight_get_primary(highlight);
if (idx >= VAR_COUNT)
@@ -398,12 +398,12 @@ rgb_color_t highlight_get_color(highlight_spec_t highlight, bool is_background)
result.set_underline(true);
}
}
-
+
if (highlight & highlight_modifier_force_underline)
{
result.set_underline(true);
}
-
+
return result;
}
@@ -589,7 +589,7 @@ static size_t color_variable(const wchar_t *in, size_t in_len, std::vector<highl
{
assert(in_len > 0);
assert(in[0] == L'$');
-
+
// Handle an initial run of $s.
size_t idx = 0;
while (in[idx] == '$')
@@ -606,13 +606,13 @@ static size_t color_variable(const wchar_t *in, size_t in_len, std::vector<highl
}
idx++;
}
-
+
// Handle a sequence of variable characters
while (wcsvarchr(in[idx]))
{
colors[idx++] = highlight_spec_operator;
}
-
+
// Handle a slice. Note that we currently don't do any validation of the slice's contents, e.g. $foo[blah] will not show an error even though it's invalid.
if (in[idx] == L'[')
{
@@ -912,7 +912,7 @@ class highlighter_t
/* Environment variables. Again, a reference member variable! */
const env_vars_snapshot_t &vars;
-
+
/* Whether it's OK to do I/O */
const bool io_ok;
@@ -1325,7 +1325,7 @@ const highlighter_t::color_array_t & highlighter_t::highlight()
switch (node.type)
{
- // Color direct string descendants, e.g. 'for' and 'in'.
+ // Color direct string descendants, e.g. 'for' and 'in'.
case symbol_while_header:
case symbol_begin_header:
case symbol_function_header:
@@ -1339,7 +1339,7 @@ const highlighter_t::color_array_t & highlighter_t::highlight()
this->color_children(node, parse_token_type_string, highlight_spec_command);
}
break;
-
+
case symbol_switch_statement:
{
const parse_node_t *literal_switch = this->parse_tree.get_child(node, 0, parse_token_type_string);
@@ -1348,7 +1348,7 @@ const highlighter_t::color_array_t & highlighter_t::highlight()
this->color_node(*switch_arg, highlight_spec_param);
}
break;
-
+
case symbol_for_header:
{
// Color the 'for' and 'in' as commands
@@ -1356,7 +1356,7 @@ const highlighter_t::color_array_t & highlighter_t::highlight()
const parse_node_t *literal_in_node = this->parse_tree.get_child(node, 2, parse_token_type_string);
this->color_node(*literal_for_node, highlight_spec_command);
this->color_node(*literal_in_node, highlight_spec_command);
-
+
// Color the variable name as a parameter
const parse_node_t *var_name_node = this->parse_tree.get_child(node, 1, parse_token_type_string);
this->color_argument(*var_name_node);
@@ -1415,7 +1415,7 @@ const highlighter_t::color_array_t & highlighter_t::highlight()
}
}
break;
-
+
case symbol_end_command:
this->color_node(node, highlight_spec_command);
break;
diff --git a/history.cpp b/history.cpp
index de405699..d0933cb0 100644
--- a/history.cpp
+++ b/history.cpp
@@ -586,13 +586,13 @@ void history_t::save_internal_unless_disabled()
{
/* This must be called while locked */
ASSERT_IS_LOCKED(lock);
-
+
/* Respect disable_automatic_save_counter */
if (disable_automatic_save_counter > 0)
{
return;
}
-
+
/* We may or may not vacuum. We try to vacuum every kVacuumFrequency items, but start the countdown at a random number so that even if the user never runs more than 25 commands, we'll eventually vacuum. If countdown_to_vacuum is -1, it means we haven't yet picked a value for the counter. */
const int kVacuumFrequency = 25;
if (countdown_to_vacuum < 0)
@@ -601,7 +601,7 @@ void history_t::save_internal_unless_disabled()
/* Generate a number in the range [0, kVacuumFrequency) */
countdown_to_vacuum = rand_r(&seed) / (RAND_MAX / kVacuumFrequency + 1);
}
-
+
/* Determine if we're going to vacuum */
bool vacuum = false;
if (countdown_to_vacuum == 0)
@@ -609,11 +609,11 @@ void history_t::save_internal_unless_disabled()
countdown_to_vacuum = kVacuumFrequency;
vacuum = true;
}
-
+
/* This might be a good candidate for moving to a background thread */
time_profiler_t profiler(vacuum ? "save_internal vacuum" : "save_internal no vacuum");
this->save_internal(vacuum);
-
+
/* Update our countdown */
assert(countdown_to_vacuum > 0);
countdown_to_vacuum--;
@@ -660,9 +660,9 @@ void history_t::set_valid_file_paths(const wcstring_list_t &valid_file_paths, hi
{
return;
}
-
+
scoped_lock locker(lock);
-
+
/* Look for an item with the given identifier. It is likely to be at the end of new_items */
for (history_item_list_t::reverse_iterator iter = new_items.rbegin(); iter != new_items.rend(); iter++)
{
@@ -1768,10 +1768,10 @@ static int threaded_perform_file_detection(file_detection_context_t *ctx)
static void perform_file_detection_done(file_detection_context_t *ctx, int success)
{
ASSERT_IS_MAIN_THREAD();
-
+
/* Now that file detection is done, update the history item with the valid file paths */
ctx->history->set_valid_file_paths(ctx->valid_paths, ctx->history_item_identifier);
-
+
/* Allow saving again */
ctx->history->enable_automatic_saving();
@@ -1793,13 +1793,13 @@ void history_t::add_with_file_detection(const wcstring &str)
{
ASSERT_IS_MAIN_THREAD();
path_list_t potential_paths;
-
+
/* Find all arguments that look like they could be file paths */
bool impending_exit = false;
parse_node_tree_t tree;
parse_tree_from_string(str, parse_flag_none, &tree, NULL);
size_t count = tree.size();
-
+
for (size_t i=0; i < count; i++)
{
const parse_node_t &node = tree.at(i);
@@ -1807,7 +1807,7 @@ void history_t::add_with_file_detection(const wcstring &str)
{
continue;
}
-
+
if (node.type == symbol_argument)
{
wcstring potential_path = node.get_source(str);
@@ -1824,7 +1824,7 @@ void history_t::add_with_file_detection(const wcstring &str)
{
impending_exit = true;
}
-
+
wcstring command;
tree.command_for_plain_statement(node, str, &command);
unescape_string_in_place(&command, UNESCAPE_DEFAULT);
@@ -1842,21 +1842,21 @@ void history_t::add_with_file_detection(const wcstring &str)
/* Grab the next identifier */
static history_identifier_t sLastIdentifier = 0;
identifier = ++sLastIdentifier;
-
+
/* Create a new detection context */
file_detection_context_t *context = new file_detection_context_t(this, identifier);
context->potential_paths.swap(potential_paths);
-
+
/* Prevent saving until we're done, so we have time to get the paths */
this->disable_automatic_saving();
-
+
/* Kick it off. Even though we haven't added the item yet, it updates the item on the main thread, so we can't race */
iothread_perform(threaded_perform_file_detection, perform_file_detection_done, context);
}
/* Actually add the item to the history */
this->add(str, identifier);
-
+
/* If we think we're about to exit, save immediately, regardless of any disabling. This may cause us to lose file hinting for some commands, but it beats losing history items */
if (impending_exit)
{
diff --git a/history.h b/history.h
index 290d91a8..e6d48682 100644
--- a/history.h
+++ b/history.h
@@ -61,7 +61,7 @@ private:
/** Paths that we require to be valid for this item to be autosuggested */
path_list_t required_paths;
-
+
public:
const wcstring &str() const
{
@@ -135,7 +135,7 @@ private:
/** The index of the first new item that we have not yet written. */
size_t first_unwritten_new_item_index;
-
+
/** Whether we should disable saving to the file for a time */
uint32_t disable_automatic_save_counter;
@@ -186,7 +186,7 @@ private:
/** Saves history */
void save_internal(bool vacuum);
-
+
/** Saves history, maybe */
void save_internal_unless_disabled();
@@ -219,10 +219,10 @@ public:
/** Saves history */
void save();
-
+
/** Performs a full (non-incremental) save */
void save_and_vacuum();
-
+
/** Enable / disable automatic saving. Main thread only! */
void disable_automatic_saving();
void enable_automatic_saving();
@@ -235,7 +235,7 @@ public:
/* Gets all the history into a string with ARRAY_SEP_STR. This is intended for the $history environment variable. This may be long! */
void get_string_representation(wcstring &str, const wcstring &separator);
-
+
/** Sets the valid file paths for the history item with the given identifier */
void set_valid_file_paths(const wcstring_list_t &valid_file_paths, history_identifier_t ident);
@@ -352,7 +352,7 @@ struct file_detection_context_t
/* Paths that were found to be valid */
path_list_t valid_paths;
-
+
/* Identifier of the history item to which we are associated */
const history_identifier_t history_item_identifier;
diff --git a/input.cpp b/input.cpp
index 661fcbee..41121ab3 100644
--- a/input.cpp
+++ b/input.cpp
@@ -72,20 +72,20 @@ struct input_mapping_t
{
wcstring seq; /**< Character sequence which generates this event */
wcstring_list_t commands; /**< commands that should be evaluated by this mapping */
-
+
/* We wish to preserve the user-specified order. This is just an incrementing value. */
unsigned int specification_order;
-
+
wcstring mode; /**< mode in which this command should be evaluated */
wcstring sets_mode; /** new mode that should be switched to after command evaluation */
-
+
input_mapping_t(const wcstring &s, const std::vector<wcstring> &c,
const wcstring &m = DEFAULT_BIND_MODE,
const wcstring &sm = DEFAULT_BIND_MODE) : seq(s), commands(c), mode(m), sets_mode(sm)
{
static unsigned int s_last_input_mapping_specification_order = 0;
specification_order = ++s_last_input_mapping_specification_order;
-
+
}
};
@@ -307,12 +307,12 @@ void input_set_bind_mode(const wcstring &bm)
}
-/**
+/**
Returns the arity of a given input function
*/
int input_function_arity(int function)
{
- switch(function)
+ switch (function)
{
case R_FORWARD_JUMP:
case R_BACKWARD_JUMP:
@@ -322,7 +322,7 @@ int input_function_arity(int function)
}
}
-/**
+/**
Sets the return status of the most recently executed input function
*/
void input_function_set_status(bool status)
@@ -380,7 +380,7 @@ void input_mapping_add(const wchar_t *sequence, const wchar_t **commands, size_t
return;
}
}
-
+
// add a new mapping, using the next order
const input_mapping_t new_mapping = input_mapping_t(sequence, commands_vector, mode, sets_mode);
input_mapping_insert_sorted(new_mapping);
@@ -541,9 +541,9 @@ wchar_t input_function_pop_arg()
void input_function_push_args(int code)
{
int arity = input_function_arity(code);
- for(int i = 0; i < arity; i++)
+ for (int i = 0; i < arity; i++)
{
- input_function_push_arg(input_common_readch(0));
+ input_function_push_arg(input_common_readch(0));
}
}
@@ -554,7 +554,7 @@ static void input_mapping_execute(const input_mapping_t &m)
{
/* By default input functions always succeed */
input_function_status = true;
-
+
size_t idx = m.commands.size();
while (idx--)
{
@@ -565,7 +565,7 @@ static void input_mapping_execute(const input_mapping_t &m)
input_function_push_args(code);
}
}
-
+
idx = m.commands.size();
while (idx--)
{
@@ -583,13 +583,13 @@ static void input_mapping_execute(const input_mapping_t &m)
*/
int last_status = proc_get_last_status();
parser_t::principal_parser().eval(command.c_str(), io_chain_t(), TOP);
-
+
proc_set_last_status(last_status);
-
+
input_unreadch(R_NULL);
}
}
-
+
input_set_bind_mode(m.sets_mode.c_str());
}
@@ -656,7 +656,7 @@ static void input_mapping_execute_matching_or_generic()
//debug(0, L"trying mapping (%ls,%ls,%ls)\n", escape(m.seq.c_str(), 1),
// m.mode.c_str(), m.sets_mode.c_str());
-
+
if (m.mode != bind_mode)
{
//debug(0, L"skipping mapping because mode %ls != %ls\n", m.mode.c_str(), input_get_bind_mode());
@@ -667,7 +667,7 @@ static void input_mapping_execute_matching_or_generic()
{
generic = &m;
}
- else if(input_mapping_is_match(m))
+ else if (input_mapping_is_match(m))
{
input_mapping_execute(m);
return;
@@ -706,39 +706,39 @@ wint_t input_readch()
if (c >= R_MIN && c <= R_MAX)
{
- switch (c)
- {
- case R_EOF: /* If it's closed, then just return */
- {
- return WEOF;
- }
- case R_SELF_INSERT:
- {
- return input_common_readch(0);
- }
- case R_AND:
- {
- if(input_function_status)
- {
- return input_readch();
- }
- else
- {
- while((c = input_common_readch(0)) && c >= R_MIN && c <= R_MAX);
- input_unreadch(c);
- return input_readch();
- }
- }
- default:
- {
- return c;
- }
- }
+ switch (c)
+ {
+ case R_EOF: /* If it's closed, then just return */
+ {
+ return WEOF;
+ }
+ case R_SELF_INSERT:
+ {
+ return input_common_readch(0);
+ }
+ case R_AND:
+ {
+ if (input_function_status)
+ {
+ return input_readch();
+ }
+ else
+ {
+ while ((c = input_common_readch(0)) && c >= R_MIN && c <= R_MAX);
+ input_unreadch(c);
+ return input_readch();
+ }
+ }
+ default:
+ {
+ return c;
+ }
+ }
}
else
{
- input_unreadch(c);
- input_mapping_execute_matching_or_generic();
+ input_unreadch(c);
+ input_mapping_execute_matching_or_generic();
}
}
}
diff --git a/input.h b/input.h
index ed2614ca..b0afe081 100644
--- a/input.h
+++ b/input.h
@@ -18,7 +18,7 @@ inputrc information for key bindings.
/**
Key codes for inputrc-style keyboard functions that are passed on
to the caller of input_read()
-
+
NOTE: IF YOU MODIFY THIS YOU MUST UPDATE THE name_arr AND code_arr VARIABLES TO MATCH!
*/
enum
@@ -156,7 +156,7 @@ void input_set_bind_mode(const wcstring &bind_mode);
wchar_t input_function_pop_arg();
-/**
+/**
Sets the return status of the most recently executed input function
*/
void input_function_set_status(bool status);
diff --git a/pager.cpp b/pager.cpp
index 5037db66..b0573240 100644
--- a/pager.cpp
+++ b/pager.cpp
@@ -28,7 +28,7 @@ static size_t divide_round_up(size_t numer, size_t denom)
{
if (numer == 0)
return 0;
-
+
assert(denom > 0);
return numer / denom + (numer % denom ? 1 : 0);
}
@@ -76,7 +76,7 @@ static int print_max(const wcstring &str, highlight_spec_t color, int max, bool
written += wcwidth(ellipsis_char);
break;
}
-
+
line->append(c, color);
written += wcwidth(c);
}
@@ -91,7 +91,7 @@ line_t pager_t::completion_print_item(const wcstring &prefix, const comp_t *c, s
{
int comp_width=0, desc_width=0;
int written=0;
-
+
line_t line_data;
if (c->pref_width <= width)
@@ -117,23 +117,23 @@ line_t pager_t::completion_print_item(const wcstring &prefix, const comp_t *c, s
desc_width = width-comp_width-4;
}
-
+
int bg_color = secondary ? highlight_spec_pager_secondary : highlight_spec_normal;
if (selected)
{
bg_color = highlight_spec_search_match;
}
-
+
for (size_t i=0; i<c->comp.size(); i++)
{
const wcstring &comp = c->comp.at(i);
if (i != 0)
written += print_max(PAGER_SPACER_STRING, highlight_spec_normal, comp_width - written, true /* has_more */, &line_data);
-
+
int packed_color = highlight_spec_pager_prefix | highlight_make_background(bg_color);
written += print_max(prefix, packed_color, comp_width - written, ! comp.empty(), &line_data);
-
+
packed_color = highlight_spec_pager_completion | highlight_make_background(bg_color);
written += print_max(comp, packed_color, comp_width - written, i + 1 < c->comp.size(), &line_data);
}
@@ -181,9 +181,9 @@ void pager_t::completion_print(size_t cols, int *width_per_column, size_t row_st
rendering->row_end = row_stop;
size_t rows = (lst.size()-1)/cols+1;
-
+
size_t effective_selected_idx = this->visual_selected_completion_index(rows, cols);
-
+
for (size_t row = row_start; row < row_stop; row++)
{
for (size_t col = 0; col < cols; col++)
@@ -199,13 +199,13 @@ void pager_t::completion_print(size_t cols, int *width_per_column, size_t row_st
/* Print this completion on its own "line" */
line_t line = completion_print_item(prefix, el, row, col, width_per_column[col] - (is_last ? 0 : PAGER_SPACER_STRING_WIDTH), row%2, is_selected, rendering);
-
+
/* If there's more to come, append two spaces */
if (col + 1 < cols)
{
line.append(PAGER_SPACER_STRING, 0);
}
-
+
/* Append this to the real line */
rendering->screen_data.create_line(row - row_start).append_line(line);
}
@@ -217,14 +217,14 @@ void pager_t::completion_print(size_t cols, int *width_per_column, size_t row_st
static void mangle_1_completion_description(wcstring *str)
{
size_t leading = 0, trailing = 0, len = str->size();
-
+
// Skip leading spaces
for (; leading < len; leading++)
{
if (! iswspace(str->at(leading)))
break;
}
-
+
// Compress runs of spaces to a single space
bool was_space = false;
for (; leading < len; leading++)
@@ -247,14 +247,14 @@ static void mangle_1_completion_description(wcstring *str)
}
was_space = is_space;
}
-
+
// leading is now at len, trailing is the new length of the string
// Delete trailing spaces
while (trailing > 0 && iswspace(str->at(trailing - 1)))
{
trailing--;
}
-
+
str->resize(trailing);
}
@@ -271,7 +271,7 @@ static void join_completions(comp_info_list_t *comps)
const wcstring &desc = new_comp.desc;
if (desc.empty())
continue;
-
+
// See if it's in the table
size_t prev_idx_plus_one = desc_table[desc];
if (prev_idx_plus_one == 0)
@@ -284,7 +284,7 @@ static void join_completions(comp_info_list_t *comps)
// There's a prior completion with this description. Append the new ones to it.
comp_t *prior_comp = &comps->at(prev_idx_plus_one - 1);
prior_comp->comp.insert(prior_comp->comp.end(), new_comp.comp.begin(), new_comp.comp.end());
-
+
// Erase the element at this index, and decrement the index to reflect that fact
comps->erase(comps->begin() + i);
i -= 1;
@@ -296,21 +296,21 @@ static void join_completions(comp_info_list_t *comps)
static comp_info_list_t process_completions_into_infos(const completion_list_t &lst, const wcstring &prefix)
{
const size_t lst_size = lst.size();
-
+
// Make the list of the correct size up-front
comp_info_list_t result(lst_size);
for (size_t i=0; i<lst_size; i++)
{
const completion_t &comp = lst.at(i);
comp_t *comp_info = &result.at(i);
-
+
// Append the single completion string. We may later merge these into multiple.
comp_info->comp.push_back(escape_string(comp.completion, ESCAPE_ALL | ESCAPE_NO_QUOTED));
-
+
// Append the mangled description
comp_info->desc = comp.description;
mangle_1_completion_description(&comp_info->desc);
-
+
// Set the representative completion
comp_info->representative = comp;
}
@@ -323,7 +323,7 @@ void pager_t::measure_completion_infos(comp_info_list_t *infos, const wcstring &
for (size_t i=0; i < infos->size(); i++)
{
comp_t *comp = &infos->at(i);
-
+
// Compute comp_width
const wcstring_list_t &comp_strings = comp->comp;
for (size_t j=0; j < comp_strings.size(); j++)
@@ -331,17 +331,17 @@ void pager_t::measure_completion_infos(comp_info_list_t *infos, const wcstring &
// If there's more than one, append the length of ', '
if (j >= 1)
comp->comp_width += 2;
-
+
comp->comp_width += prefix_len + my_wcswidth(comp_strings.at(j).c_str());
}
-
+
// Compute desc_width
comp->desc_width = my_wcswidth(comp->desc.c_str());
-
+
// Compute preferred width
comp->pref_width = comp->comp_width + comp->desc_width + (comp->desc_width?4:0);
}
-
+
recalc_min_widths(infos);
}
@@ -353,16 +353,16 @@ bool pager_t::completion_info_passes_filter(const comp_t &info) const
return true;
const wcstring &needle = this->search_field_line.text;
-
+
/* We do substring matching */
const fuzzy_match_type_t limit = fuzzy_match_substring;
-
+
/* Match against the description */
if (string_fuzzy_match_string(needle, info.desc, limit).type != fuzzy_match_none)
{
return true;
}
-
+
/* Match against the completion strings */
for (size_t i=0; i < info.comp.size(); i++)
{
@@ -371,7 +371,7 @@ bool pager_t::completion_info_passes_filter(const comp_t &info) const
return true;
}
}
-
+
/* No match */
return false;
}
@@ -394,14 +394,14 @@ void pager_t::set_completions(const completion_list_t &raw_completions)
{
// Get completion infos out of it
unfiltered_completion_infos = process_completions_into_infos(raw_completions, prefix.c_str());
-
+
// Maybe join them
if (prefix == L"-")
join_completions(&unfiltered_completion_infos);
-
+
// Compute their various widths
measure_completion_infos(&unfiltered_completion_infos, prefix);
-
+
// Refilter them
this->refilter_completions();
}
@@ -444,7 +444,7 @@ bool pager_t::completion_try_print(size_t cols, const wcstring &prefix, const co
/* Set to one if the list should be printed at this width */
bool print = false;
-
+
/* Compute the effective term width and term height, accounting for disclosure */
int term_width = this->available_term_width;
int term_height = this->available_term_height - 1 - (search_field_shown ? 1 : 0); // we always subtract 1 to make room for a comment row
@@ -454,7 +454,7 @@ bool pager_t::completion_try_print(size_t cols, const wcstring &prefix, const co
}
size_t row_count = divide_round_up(lst.size(), cols);
-
+
/* We have more to disclose if we are not fully disclosed and there's more rows than we have in our term height */
if (! this->fully_disclosed && row_count > term_height)
{
@@ -467,7 +467,7 @@ bool pager_t::completion_try_print(size_t cols, const wcstring &prefix, const co
int pref_tot_width=0;
int min_tot_width = 0;
-
+
/* Skip completions on tiny terminals */
if (term_width < PAGER_MIN_WIDTH)
return true;
@@ -492,9 +492,9 @@ bool pager_t::completion_try_print(size_t cols, const wcstring &prefix, const co
min += 2;
}
min_width[col] = maxi(min_width[col],
- min);
+ min);
pref_width[col] = maxi(pref_width[col],
- pref);
+ pref);
}
min_tot_width += min_width[col];
pref_tot_width += pref_width[col];
@@ -585,15 +585,15 @@ bool pager_t::completion_try_print(size_t cols, const wcstring &prefix, const co
stop_row = start_row + term_height;
assert(start_row >= 0 && start_row <= last_starting_row);
}
-
+
assert(stop_row >= start_row);
assert(stop_row <= row_count);
assert(stop_row - start_row <= term_height);
completion_print(cols, width, start_row, stop_row, prefix, lst, rendering);
-
+
/* Ellipsis helper string. Either empty or containing the ellipsis char */
const wchar_t ellipsis_string[] = {ellipsis_char == L'\x2026' ? L'\x2026' : L'\0', L'\0'};
-
+
/* Add the progress line. It's a "more to disclose" line if necessary, or a row listing if it's scrollable; otherwise ignore it */
wcstring progress_text;
if (rendering->remaining_to_disclose == 1)
@@ -615,13 +615,13 @@ bool pager_t::completion_try_print(size_t cols, const wcstring &prefix, const co
/* Everything is filtered */
progress_text = L"(no matches)";
}
-
+
if (! progress_text.empty())
{
line_t &line = rendering->screen_data.add_line();
print_max(progress_text.c_str(), highlight_spec_pager_progress | highlight_make_background(highlight_spec_pager_progress), term_width, true /* has_more */, &line);
}
-
+
if (search_field_shown)
{
/* Add the search field */
@@ -632,12 +632,12 @@ bool pager_t::completion_try_print(size_t cols, const wcstring &prefix, const co
search_field_text.append(PAGER_SEARCH_FIELD_WIDTH - search_field_text.size(), L' ');
}
line_t *search_field = &rendering->screen_data.insert_line_at_index(0);
-
+
/* We limit the width to term_width - 1 */
int search_field_written = print_max(SEARCH_FIELD_PROMPT, highlight_spec_normal, term_width - 1, false, search_field);
search_field_written += print_max(search_field_text, highlight_modifier_force_underline, term_width - search_field_written - 1, false, search_field);
}
-
+
}
return print;
}
@@ -645,7 +645,7 @@ bool pager_t::completion_try_print(size_t cols, const wcstring &prefix, const co
page_rendering_t pager_t::render() const
{
-
+
/**
Try to print the completions. Start by trying to print the
list in PAGER_MAX_COLS columns, if the completions won't
@@ -657,27 +657,27 @@ page_rendering_t pager_t::render() const
rendering.term_height = this->available_term_height;
rendering.search_field_shown = this->search_field_shown;
rendering.search_field_line = this->search_field_line;
-
+
for (int cols = PAGER_MAX_COLS; cols > 0; cols--)
{
/* Initially empty rendering */
rendering.screen_data.resize(0);
-
+
/* Determine how many rows we would need if we had 'cols' columns. Then determine how many columns we want from that. For example, say we had 19 completions. We can fit them into 6 columns, 4 rows, with the last row containing only 1 entry. Or we can fit them into 5 columns, 4 rows, the last row containing 4 entries. Since fewer columns with the same number of rows is better, skip cases where we know we can do better. */
size_t min_rows_required_for_cols = divide_round_up(completion_infos.size(), cols);
size_t min_cols_required_for_rows = divide_round_up(completion_infos.size(), min_rows_required_for_cols);
-
+
assert(min_cols_required_for_rows <= cols);
if (cols > 1 && min_cols_required_for_rows < cols)
{
/* Next iteration will be better, so skip this one */
continue;
}
-
+
rendering.cols = (size_t)cols;
rendering.rows = min_rows_required_for_cols;
rendering.selected_completion_idx = this->visual_selected_completion_index(rendering.rows, rendering.cols);
-
+
if (completion_try_print(cols, prefix, completion_infos, &rendering, suggested_row_start))
{
break;
@@ -689,12 +689,12 @@ page_rendering_t pager_t::render() const
void pager_t::update_rendering(page_rendering_t *rendering) const
{
if (rendering->term_width != this->available_term_width ||
- rendering->term_height != this->available_term_height ||
- rendering->selected_completion_idx != this->visual_selected_completion_index(rendering->rows, rendering->cols) ||
- rendering->search_field_shown != this->search_field_shown ||
- rendering->search_field_line.text != this->search_field_line.text ||
- rendering->search_field_line.position != this->search_field_line.position ||
- (rendering->remaining_to_disclose > 0 && this->fully_disclosed))
+ rendering->term_height != this->available_term_height ||
+ rendering->selected_completion_idx != this->visual_selected_completion_index(rendering->rows, rendering->cols) ||
+ rendering->search_field_shown != this->search_field_shown ||
+ rendering->search_field_line.text != this->search_field_line.text ||
+ rendering->search_field_line.position != this->search_field_line.position ||
+ (rendering->remaining_to_disclose > 0 && this->fully_disclosed))
{
*rendering = this->render();
}
@@ -716,13 +716,13 @@ bool pager_t::select_next_completion_in_direction(selection_direction_t directio
{
return false;
}
-
+
/* Handle the case of nothing selected yet */
if (selected_completion_idx == PAGER_SELECTION_NONE)
{
switch (direction)
{
- /* These directions do something sane */
+ /* These directions do something sane */
case direction_south:
case direction_next:
case direction_prev:
@@ -736,7 +736,7 @@ bool pager_t::select_next_completion_in_direction(selection_direction_t directio
}
return true;
- /* These do nothing */
+ /* These do nothing */
case direction_north:
case direction_east:
case direction_west:
@@ -745,7 +745,7 @@ bool pager_t::select_next_completion_in_direction(selection_direction_t directio
return false;
}
}
-
+
/* Ok, we had something selected already. Select something different. */
size_t new_selected_completion_idx = selected_completion_idx;
if (! selection_direction_is_cardinal(direction))
@@ -784,7 +784,7 @@ bool pager_t::select_next_completion_in_direction(selection_direction_t directio
/* Cardinal directions. We have a completion index; we wish to compute its row and column. */
size_t current_row = this->get_selected_row(rendering);
size_t current_col = this->get_selected_column(rendering);
-
+
switch (direction)
{
case direction_north:
@@ -802,7 +802,7 @@ bool pager_t::select_next_completion_in_direction(selection_direction_t directio
}
break;
}
-
+
case direction_south:
{
/* Go down, unless we are in the last row. Note that this means that we may set selected_completion_idx to an out-of-bounds value if the last row is incomplete; this is a feature (it allows "last column memory"). */
@@ -815,11 +815,11 @@ bool pager_t::select_next_completion_in_direction(selection_direction_t directio
current_row = 0;
if (current_col + 1 < rendering.cols)
current_col++;
-
+
}
break;
}
-
+
case direction_east:
{
/* Go east, wrapping to the next row. There is no "row memory," so if we run off the end, wrap. */
@@ -835,7 +835,7 @@ bool pager_t::select_next_completion_in_direction(selection_direction_t directio
}
break;
}
-
+
case direction_west:
{
/* Go west, wrapping to the previous row */
@@ -851,33 +851,33 @@ bool pager_t::select_next_completion_in_direction(selection_direction_t directio
}
break;
}
-
+
default:
assert(0 && "Unknown cardinal direction");
break;
}
-
+
/* Compute the new index based on the changed row */
new_selected_completion_idx = current_col * rendering.rows + current_row;
}
-
+
if (new_selected_completion_idx != selected_completion_idx)
{
selected_completion_idx = new_selected_completion_idx;
-
+
/* Update suggested_row_start to ensure the selection is visible. suggested_row_start * rendering.cols is the first suggested visible completion; add the visible completion count to that to get the last one */
size_t visible_row_count = rendering.row_end - rendering.row_start;
-
+
if (visible_row_count > 0 && selected_completion_idx != PAGER_SELECTION_NONE) //paranoia
{
size_t row_containing_selection = this->get_selected_row(rendering);
-
+
/* Ensure our suggested row start is not past the selected row */
if (suggested_row_start > row_containing_selection)
{
suggested_row_start = row_containing_selection;
}
-
+
/* Ensure our suggested row start is not too early before it */
if (suggested_row_start + visible_row_count <= row_containing_selection)
{
@@ -891,13 +891,13 @@ bool pager_t::select_next_completion_in_direction(selection_direction_t directio
{
/* Scroll */
suggested_row_start = row_containing_selection - visible_row_count + 1;
-
+
/* Ensure fully_disclosed is set. I think we can hit this case if the user resizes the window - we don't want to drop back to the disclosed style */
fully_disclosed = true;
}
}
}
-
+
return true;
}
else
@@ -913,7 +913,7 @@ size_t pager_t::visual_selected_completion_index(size_t rows, size_t cols) const
{
return PAGER_SELECTION_NONE;
}
-
+
size_t result = selected_completion_idx;
if (result != PAGER_SELECTION_NONE)
{
@@ -922,7 +922,7 @@ size_t pager_t::visual_selected_completion_index(size_t rows, size_t cols) const
{
result -= rows;
}
-
+
/* If we are still beyond the last selection, clamp it */
if (result >= completion_infos.size())
result = completion_infos.size() - 1;
@@ -958,7 +958,7 @@ size_t pager_t::get_selected_row(const page_rendering_t &rendering) const
{
if (rendering.rows == 0)
return PAGER_SELECTION_NONE;
-
+
return selected_completion_idx == PAGER_SELECTION_NONE ? PAGER_SELECTION_NONE : selected_completion_idx % rendering.rows;
}
@@ -966,7 +966,7 @@ size_t pager_t::get_selected_column(const page_rendering_t &rendering) const
{
if (rendering.rows == 0)
return PAGER_SELECTION_NONE;
-
+
return selected_completion_idx == PAGER_SELECTION_NONE ? PAGER_SELECTION_NONE : selected_completion_idx / rendering.rows;
}
diff --git a/pager.h b/pager.h
index a1c024a6..a503d8c7 100644
--- a/pager.h
+++ b/pager.h
@@ -11,7 +11,7 @@
/* Represents rendering from the pager */
class page_rendering_t
{
- public:
+public:
int term_width;
int term_height;
size_t rows;
@@ -20,12 +20,12 @@ class page_rendering_t
size_t row_end;
size_t selected_completion_idx;
screen_data_t screen_data;
-
+
size_t remaining_to_disclose;
-
+
bool search_field_shown;
editable_line_t search_field_line;
-
+
/* Returns a rendering with invalid data, useful to indicate "no rendering" */
page_rendering_t();
};
@@ -44,127 +44,127 @@ class pager_t
{
int available_term_width;
int available_term_height;
-
+
size_t selected_completion_idx;
size_t suggested_row_start;
-
+
/* Fully disclosed means that we show all completions */
bool fully_disclosed;
-
+
/* Whether we show the search field */
bool search_field_shown;
-
+
/* Returns the index of the completion that should draw selected, using the given number of columns */
size_t visual_selected_completion_index(size_t rows, size_t cols) const;
-
+
/** Data structure describing one or a group of related completions */
- public:
+public:
struct comp_t
{
/** The list of all completin strings this entry applies to */
wcstring_list_t comp;
-
+
/** The description */
wcstring desc;
-
+
/** The representative completion */
completion_t representative;
-
+
/** On-screen width of the completion string */
int comp_width;
-
+
/** On-screen width of the description information */
int desc_width;
-
+
/** Preferred total width */
int pref_width;
-
+
/** Minimum acceptable width */
int min_width;
-
+
comp_t() : comp(), desc(), representative(L""), comp_width(0), desc_width(0), pref_width(0), min_width(0)
{
}
};
-
- private:
+
+private:
typedef std::vector<comp_t> comp_info_list_t;
-
+
/* The filtered list of completion infos */
comp_info_list_t completion_infos;
-
+
/* The unfiltered list. Note there's a lot of duplication here. */
comp_info_list_t unfiltered_completion_infos;
-
+
wcstring prefix;
-
+
void note_selection_changed();
-
+
bool completion_try_print(size_t cols, const wcstring &prefix, const comp_info_list_t &lst, page_rendering_t *rendering, size_t suggested_start_row) const;
-
+
void recalc_min_widths(comp_info_list_t * lst) const;
void measure_completion_infos(std::vector<comp_t> *infos, const wcstring &prefix) const;
-
+
bool completion_info_passes_filter(const comp_t &info) const;
-
+
void completion_print(size_t cols, int *width_per_column, size_t row_start, size_t row_stop, const wcstring &prefix, const comp_info_list_t &lst, page_rendering_t *rendering) const;
line_t completion_print_item(const wcstring &prefix, const comp_t *c, size_t row, size_t column, int width, bool secondary, bool selected, page_rendering_t *rendering) const;
-
- public:
-
+
+public:
+
/* The text of the search field */
editable_line_t search_field_line;
-
+
/* Sets the set of completions */
void set_completions(const completion_list_t &comp);
-
+
/* Sets the prefix */
void set_prefix(const wcstring &pref);
-
+
/* Sets the terminal width and height */
void set_term_size(int w, int h);
-
+
/* Changes the selected completion in the given direction according to the layout of the given rendering. Returns true if the selection changed. */
bool select_next_completion_in_direction(selection_direction_t direction, const page_rendering_t &rendering);
-
+
/* Returns the currently selected completion for the given rendering */
const completion_t *selected_completion(const page_rendering_t &rendering) const;
-
+
/* Indicates the row and column for the given rendering. Returns -1 if no selection. */
size_t get_selected_row(const page_rendering_t &rendering) const;
size_t get_selected_column(const page_rendering_t &rendering) const;
-
+
/* Produces a rendering of the completions, at the given term size */
page_rendering_t render() const;
-
+
/* Updates the rendering if it's stale */
void update_rendering(page_rendering_t *rendering) const;
-
+
/* Indicates if there are no completions, and therefore nothing to render */
bool empty() const;
-
+
/* Clears all completions and the prefix */
void clear();
-
+
/* Updates the completions list per the filter */
void refilter_completions();
-
+
/* Sets whether the search field is shown */
void set_search_field_shown(bool flag);
/* Gets whether the search field shown */
bool is_search_field_shown() const;
-
+
/* Indicates if we are navigating our contents */
bool is_navigating_contents() const;
-
+
/* Become fully disclosed */
void set_fully_disclosed(bool flag);
-
+
/* Position of the cursor */
size_t cursor_position() const;
-
+
/* Constructor */
pager_t();
};
diff --git a/parse_constants.h b/parse_constants.h
index ebf6030b..ee0c5a2a 100644
--- a/parse_constants.h
+++ b/parse_constants.h
@@ -43,7 +43,7 @@ enum parse_token_type_t
symbol_argument_or_redirection,
symbol_argument_list,
-
+
// "freestanding" argument lists are parsed from the argument list supplied to 'complete -a'
// They are not generated by parse trees rooted in symbol_job_list
symbol_freestanding_argument_list,
@@ -54,7 +54,7 @@ enum parse_token_type_t
symbol_optional_background,
symbol_end_command,
-
+
// Terminal types
parse_token_type_string,
parse_token_type_pipe,
@@ -156,7 +156,7 @@ struct parse_error_t
/** Return a string describing the error, suitable for presentation to the user. If skip_caret is false, the offending line with a caret is printed as well */
wcstring describe(const wcstring &src) const;
-
+
/** Return a string describing the error, suitable for presentation to the user, with the given prefix. If skip_caret is false, the offending line with a caret is printed as well */
wcstring describe_with_prefix(const wcstring &src, const wcstring &prefix, bool is_interactive, bool skip_caret) const;
};
diff --git a/parse_execution.cpp b/parse_execution.cpp
index 1da9858f..78baed79 100644
--- a/parse_execution.cpp
+++ b/parse_execution.cpp
@@ -32,7 +32,7 @@ static wcstring profiling_cmd_name_for_redirectable_block(const parse_node_t &no
{
assert(specific_statement_type_is_redirectable_block(node));
assert(node.has_source());
-
+
/* Get the source for the block, and cut it at the next statement terminator. */
const size_t src_start = node.source_start;
size_t src_len = node.source_length;
@@ -44,7 +44,7 @@ static wcstring profiling_cmd_name_for_redirectable_block(const parse_node_t &no
assert(term->source_start >= src_start);
src_len = term->source_start - src_start;
}
-
+
wcstring result = wcstring(src, src_start, src_len);
result.append(L"...");
return result;
@@ -325,7 +325,7 @@ parse_execution_result_t parse_execution_context_t::run_if_statement(const parse
{
run_job_list(*job_list_to_execute, ib);
}
-
+
/* It's possible there's a last-minute cancellation, in which case we should not stomp the exit status (#1297) */
if (should_cancel_execution(ib))
{
@@ -517,7 +517,7 @@ parse_execution_result_t parse_execution_context_t::run_switch_statement(const p
parse_error_list_t errors;
int expand_ret = expand_string(switch_value, switch_values_expanded, EXPAND_NO_DESCRIPTIONS, &errors);
parse_error_offset_source_start(&errors, switch_value_node.source_start);
-
+
switch (expand_ret)
{
case EXPAND_ERROR:
@@ -547,15 +547,15 @@ parse_execution_result_t parse_execution_context_t::run_switch_statement(const p
_(L"switch: Expected exactly one argument, got %lu\n"),
switch_values_expanded.size());
}
-
+
if (result == parse_execution_success)
{
const wcstring &switch_value_expanded = switch_values_expanded.at(0).completion;
-
+
switch_block_t *sb = new switch_block_t();
parser->push_block(sb);
-
+
/* Expand case statements */
const parse_node_t *case_item_list = get_child(statement, 3, symbol_case_item_list);
@@ -690,7 +690,7 @@ parse_execution_result_t parse_execution_context_t::report_error(const parse_nod
va_start(va, fmt);
error->text = vformat_string(fmt, va);
va_end(va);
-
+
this->report_errors(error_list);
}
return parse_execution_errored;
@@ -704,11 +704,11 @@ parse_execution_result_t parse_execution_context_t::report_errors(const parse_er
{
fprintf(stderr, "Bug: Error reported but no error text found.");
}
-
+
/* Get a backtrace */
wcstring backtrace_and_desc;
parser->get_backtrace(src, error_list, &backtrace_and_desc);
-
+
/* Print it */
fprintf(stderr, "%ls", backtrace_and_desc.c_str());
}
@@ -1315,7 +1315,7 @@ parse_execution_result_t parse_execution_context_t::run_1_job(const parse_node_t
/* Increment the eval_level for the duration of this command */
scoped_push<int> saved_eval_level(&eval_level, eval_level + 1);
-
+
/* Save the node index */
scoped_push<node_offset_t> saved_node_offset(&executing_node_idx, this->get_offset(job_node));
@@ -1352,7 +1352,7 @@ parse_execution_result_t parse_execution_context_t::run_1_job(const parse_node_t
PARSER_DIE();
break;
}
-
+
if (profile_item != NULL)
{
/* Block-types profile a little weird. They have no 'parse' time, and their command is just the block type */
@@ -1363,7 +1363,7 @@ parse_execution_result_t parse_execution_context_t::run_1_job(const parse_node_t
profile_item->cmd = profiling_cmd_name_for_redirectable_block(specific_statement, this->tree, this->src);
profile_item->skipped = result != parse_execution_success;
}
-
+
return result;
}
@@ -1556,7 +1556,7 @@ int parse_execution_context_t::line_offset_of_node_at_offset(node_offset_t reque
{
return -1;
}
-
+
/* Count the number of newlines, leveraging our cache */
const size_t offset = tree.at(requested_index).source_start;
assert(offset <= src.size());
@@ -1566,7 +1566,7 @@ int parse_execution_context_t::line_offset_of_node_at_offset(node_offset_t reque
{
return 0;
}
-
+
/* We want to return (one plus) the number of newlines at offsets less than the given offset. cached_lineno_count is the number of newlines at indexes less than cached_lineno_offset. */
const wchar_t *str = src.c_str();
if (offset > cached_lineno_offset)
diff --git a/parse_execution.h b/parse_execution.h
index fb46f10a..af2d7397 100644
--- a/parse_execution.h
+++ b/parse_execution.h
@@ -39,10 +39,10 @@ private:
//parse_error_list_t errors;
int eval_level;
-
+
/* The currently executing node index, used to indicate the line number */
node_offset_t executing_node_idx;
-
+
/* Cached line number information */
size_t cached_lineno_offset;
int cached_lineno_count;
@@ -67,13 +67,13 @@ private:
/* Report an error. Always returns true. */
parse_execution_result_t report_error(const parse_node_t &node, const wchar_t *fmt, ...) const;
parse_execution_result_t report_errors(const parse_error_list_t &errors) const;
-
+
/* Wildcard error helper */
parse_execution_result_t report_unmatched_wildcard_error(const parse_node_t &unmatched_wildcard);
/* Command not found support */
void handle_command_not_found(const wcstring &cmd, const parse_node_t &statement_node, int err_code);
-
+
/* Utilities */
wcstring get_source(const parse_node_t &node) const;
const parse_node_t *get_child(const parse_node_t &parent, node_offset_t which, parse_token_type_t expected_type = token_type_invalid) const;
@@ -116,8 +116,11 @@ public:
parse_execution_context_t(const parse_node_tree_t &t, const wcstring &s, parser_t *p, int initial_eval_level);
/* Returns the current eval level */
- int current_eval_level() const { return eval_level; }
-
+ int current_eval_level() const
+ {
+ return eval_level;
+ }
+
/* Returns the current line number, indexed from 1. Not const since it touches cached_lineno_offset */
int get_current_line_number();
@@ -125,7 +128,10 @@ public:
int get_current_source_offset() const;
/* Returns the source string */
- const wcstring &get_source() const { return src; }
+ const wcstring &get_source() const
+ {
+ return src;
+ }
/* Start executing at the given node offset. Returns 0 if there was no error, 1 if there was an error */
parse_execution_result_t eval_node_at_offset(node_offset_t offset, const block_t *associated_block, const io_chain_t &io);
diff --git a/parse_productions.cpp b/parse_productions.cpp
index 221316b3..1dd0ab7f 100644
--- a/parse_productions.cpp
+++ b/parse_productions.cpp
@@ -173,7 +173,7 @@ RESOLVE(statement)
case parse_keyword_end:
return NO_PRODUCTION;
- // All other keywords fall through to decorated statement
+ // All other keywords fall through to decorated statement
default:
return 4;
}
diff --git a/parse_tree.cpp b/parse_tree.cpp
index 4effea20..36c94544 100644
--- a/parse_tree.cpp
+++ b/parse_tree.cpp
@@ -304,7 +304,7 @@ static wcstring token_type_user_presentable_description(parse_token_type_t type,
case parse_token_type_end:
return L"end of the statement";
-
+
default:
return format_string(L"a %ls", token_type_description(type).c_str());
}
@@ -564,11 +564,11 @@ class parse_ll_t
const size_t child_start_big = nodes.size();
assert(child_start_big < NODE_OFFSET_INVALID);
node_offset_t child_start = static_cast<node_offset_t>(child_start_big);
-
+
// To avoid constructing multiple nodes, we push_back a single one that we modify
parse_node_t representative_child(token_type_invalid);
representative_child.parent = parent_node_idx;
-
+
node_offset_t child_count = 0;
for (size_t i=0; i < MAX_SYMBOLS_PER_PRODUCTION; i++)
{
@@ -1502,7 +1502,8 @@ bool parse_node_tree_t::job_should_be_backgrounded(const parse_node_t &job) cons
assert(job.production_idx == 0);
bool result = false;
const parse_node_t *opt_background = get_child(job, 2, symbol_optional_background);
- if (opt_background != NULL) {
+ if (opt_background != NULL)
+ {
assert(opt_background->production_idx <= 1);
result = (opt_background->production_idx == 1);
}
diff --git a/parse_tree.h b/parse_tree.h
index 0e1a0b2f..7de162ed 100644
--- a/parse_tree.h
+++ b/parse_tree.h
@@ -84,13 +84,13 @@ public:
/* Children */
node_offset_t child_start;
-
+
/* Number of children */
uint8_t child_count;
/* Which production was used */
uint8_t production_idx;
-
+
/* Type of the node */
enum parse_token_type_t type;
@@ -184,7 +184,7 @@ public:
/* Given a job, return all of its statements. These are 'specific statements' (e.g. symbol_decorated_statement, not symbol_statement) */
parse_node_list_t specific_statements_for_job(const parse_node_t &job) const;
-
+
/* Given a job, return whether it should be backgrounded, because it has a & specifier */
bool job_should_be_backgrounded(const parse_node_t &job) const;
};
@@ -257,9 +257,9 @@ bool parse_tree_from_string(const wcstring &str, parse_tree_flags_t flags, parse
optional_background = <empty> | <TOK_BACKGROUND>
end_command = END
-
+
# A freestanding_argument_list is equivalent to a normal argument list, except it may contain TOK_END (newlines, and even semicolons, for historical reasons
-
+
freestanding_argument_list = <empty> |
argument freestanding_argument_list |
<TOK_END> freestanding_argument_list
diff --git a/parse_util.cpp b/parse_util.cpp
index 0d626161..ae7d7e5f 100644
--- a/parse_util.cpp
+++ b/parse_util.cpp
@@ -154,11 +154,11 @@ static int parse_util_locate_brackets_of_type(const wchar_t *in, wchar_t **begin
wchar_t prev=0;
int syntax_error=0;
int paran_count=0;
-
+
wchar_t *paran_begin=0, *paran_end=0;
-
+
CHECK(in, 0);
-
+
for (pos = const_cast<wchar_t *>(in); *pos; pos++)
{
if (prev != '\\')
@@ -183,20 +183,20 @@ static int parse_util_locate_brackets_of_type(const wchar_t *in, wchar_t **begin
{
paran_begin = pos;
}
-
+
paran_count++;
}
else if (*pos == close_type)
{
-
+
paran_count--;
-
+
if ((paran_count == 0) && (paran_end == 0))
{
paran_end = pos;
break;
}
-
+
if (paran_count < 0)
{
syntax_error = 1;
@@ -204,34 +204,34 @@ static int parse_util_locate_brackets_of_type(const wchar_t *in, wchar_t **begin
}
}
}
-
+
}
prev = *pos;
}
-
+
syntax_error |= (paran_count < 0);
syntax_error |= ((paran_count>0)&&(!allow_incomplete));
-
+
if (syntax_error)
{
return -1;
}
-
+
if (paran_begin == 0)
{
return 0;
}
-
+
if (begin)
{
*begin = paran_begin;
}
-
+
if (end)
{
*end = paran_count?(wchar_t *)in+wcslen(in):paran_end;
}
-
+
return 1;
}
@@ -1288,16 +1288,16 @@ parser_test_error_bits_t parse_util_detect_errors(const wcstring &buff_src, pars
{
// In a few places below, we want to know if we are in a pipeline
const bool is_in_pipeline = node_tree.statement_is_in_pipeline(node, true /* count first */);
-
+
// We need to know the decoration
const enum parse_statement_decoration_t decoration = node_tree.decoration_for_plain_statement(node);
-
+
// Check that we don't try to pipe through exec
if (is_in_pipeline && decoration == parse_statement_decoration_exec)
{
errored = append_syntax_error(&parse_errors, node, EXEC_ERR_MSG, L"exec");
}
-
+
wcstring command;
if (node_tree.command_for_plain_statement(node, buff_src, &command))
{
@@ -1384,7 +1384,7 @@ parser_test_error_bits_t parse_util_detect_errors(const wcstring &buff_src, pars
errored = append_syntax_error(&parse_errors, node, (command == L"break" ? INVALID_BREAK_ERR_MSG : INVALID_CONTINUE_ERR_MSG));
}
}
-
+
// Check that we don't do an invalid builtin (#1252)
if (! errored && decoration == parse_statement_decoration_builtin && ! builtin_exists(command))
{
diff --git a/parser.cpp b/parser.cpp
index e95cb878..ec0f2256 100644
--- a/parser.cpp
+++ b/parser.cpp
@@ -973,7 +973,7 @@ bool parser_t::detect_errors_in_argument_list(const wcstring &arg_list_src, wcst
/* Failed to parse. */
errored = true;
}
-
+
if (! errored)
{
/* Get the root argument list */
@@ -1016,9 +1016,9 @@ void parser_t::get_backtrace(const wcstring &src, const parse_error_list_t &erro
if (! errors.empty())
{
const parse_error_t &err = errors.at(0);
-
+
const bool is_interactive = get_is_interactive();
-
+
// Determine if we want to try to print a caret to point at the source error
// The err.source_start <= src.size() check is due to the nasty way that slices work,
// which is by rewriting the source (!)
@@ -1028,11 +1028,11 @@ void parser_t::get_backtrace(const wcstring &src, const parse_error_list_t &erro
{
// Determine which line we're on
which_line = 1 + std::count(src.begin(), src.begin() + err.source_start, L'\n');
-
+
// Don't include the caret if we're interactive, this is the first line of text, and our source is at its beginning, because then it's obvious
skip_caret = (is_interactive && which_line == 1 && err.source_start == 0);
}
-
+
wcstring prefix;
const wchar_t *filename = this->current_filename();
if (filename)
diff --git a/parser.h b/parser.h
index 6f104302..6d4af156 100644
--- a/parser.h
+++ b/parser.h
@@ -215,13 +215,13 @@ struct profile_item_t
{
/** Time spent executing the specified command, including parse time for nested blocks. */
int exec;
-
+
/** Time spent parsing the specified command, including execution time for command substitutions. */
int parse;
-
+
/** The block level of the specified command. nested blocks and command substitutions both increase the block level. */
size_t level;
-
+
/** If the execution of this command was skipped. */
bool skipped;
@@ -243,7 +243,7 @@ private:
/** 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;
@@ -353,7 +353,7 @@ public:
{
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);
@@ -380,7 +380,7 @@ public:
/** Returns the job with the given pid */
job_t *job_get_from_pid(int pid);
-
+
/* Returns a new profile item if profiling is active. The caller should fill it in. The parser_t will clean it up. */
profile_item_t *create_profile_item();
diff --git a/reader.cpp b/reader.cpp
index 106a8d27..471afed9 100644
--- a/reader.cpp
+++ b/reader.cpp
@@ -206,10 +206,10 @@ public:
/** Current pager */
pager_t pager;
-
+
/** Current page rendering */
page_rendering_t current_page_rendering;
-
+
/** Whether autosuggesting is allowed at all */
bool allow_autosuggestion;
@@ -255,7 +255,7 @@ public:
{
return this->pager.is_navigating_contents();
}
-
+
/* The line that is currently being edited. Typically the command line, but may be the search field */
editable_line_t *active_edit_line()
{
@@ -487,16 +487,16 @@ static void update_buff_pos(editable_line_t *el, size_t buff_pos)
el->position = buff_pos;
if (el == &data->command_line && data->sel_active)
{
- if(data->sel_begin_pos <= buff_pos)
- {
- data->sel_start_pos = data->sel_begin_pos;
- data->sel_stop_pos = buff_pos;
- }
- else
- {
- data->sel_start_pos = buff_pos;
- data->sel_stop_pos = data->sel_begin_pos;
- }
+ if (data->sel_begin_pos <= buff_pos)
+ {
+ data->sel_start_pos = data->sel_begin_pos;
+ data->sel_stop_pos = buff_pos;
+ }
+ else
+ {
+ data->sel_start_pos = buff_pos;
+ data->sel_stop_pos = data->sel_begin_pos;
+ }
}
}
@@ -602,7 +602,7 @@ static void reader_repaint()
if (data->sel_active)
{
highlight_spec_t selection_color = highlight_make_background(highlight_spec_selection);
- for(size_t i = data->sel_start_pos; i <= std::min(len - 1, data->sel_stop_pos); i++)
+ for (size_t i = data->sel_start_pos; i <= std::min(len - 1, data->sel_stop_pos); i++)
{
colors[i] = selection_color;
}
@@ -615,7 +615,7 @@ static void reader_repaint()
// We set the term size to 1 less than the true term height. This means we will always show the (bottom) line of the prompt.
data->pager.set_term_size(maxi(1, common_get_width()), maxi(1, common_get_height() - 1));
data->pager.update_rendering(&data->current_page_rendering);
-
+
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;
@@ -717,15 +717,15 @@ void reader_data_t::command_line_changed(const editable_line_t *el)
{
size_t len = this->command_line.size();
- /* When we grow colors, propagate the last color (if any), under the assumption that usually it will be correct. If it is, it avoids a repaint. */
- highlight_spec_t last_color = colors.empty() ? highlight_spec_t() : colors.back();
- colors.resize(len, last_color);
+ /* When we grow colors, propagate the last color (if any), under the assumption that usually it will be correct. If it is, it avoids a repaint. */
+ highlight_spec_t last_color = colors.empty() ? highlight_spec_t() : colors.back();
+ colors.resize(len, last_color);
- indents.resize(len);
+ indents.resize(len);
- /* Update the gen count */
- s_generation_count++;
-}
+ /* Update the gen count */
+ s_generation_count++;
+ }
else if (el == &this->pager.search_field_line)
{
this->pager.refilter_completions();
@@ -1125,7 +1125,7 @@ static bool command_ends_paging(wchar_t c, bool focused_on_search_field)
{
switch (c)
{
- /* These commands always end paging */
+ /* These commands always end paging */
case R_HISTORY_SEARCH_BACKWARD:
case R_HISTORY_SEARCH_FORWARD:
case R_BEGINNING_OF_HISTORY:
@@ -1135,8 +1135,8 @@ static bool command_ends_paging(wchar_t c, bool focused_on_search_field)
case R_ACCEPT_AUTOSUGGESTION:
case R_CANCEL:
return true;
-
- /* These commands never do */
+
+ /* These commands never do */
case R_COMPLETE:
case R_COMPLETE_AND_SEARCH:
case R_BACKWARD_CHAR:
@@ -1148,12 +1148,12 @@ static bool command_ends_paging(wchar_t c, bool focused_on_search_field)
case R_SUPPRESS_AUTOSUGGESTION:
default:
return false;
-
- /* R_EXECUTE does end paging, but only executes if it was not paging. So it's handled specially */
+
+ /* R_EXECUTE does end paging, but only executes if it was not paging. So it's handled specially */
case R_EXECUTE:
return false;
-
- /* These commands operate on the search field if that's where the focus is */
+
+ /* These commands operate on the search field if that's where the focus is */
case R_BEGINNING_OF_LINE:
case R_END_OF_LINE:
case R_FORWARD_WORD:
@@ -1227,14 +1227,14 @@ static bool insert_string(editable_line_t *el, const wcstring &str, bool should_
el->insert_string(str);
update_buff_pos(el, el->position);
data->command_line_changed(el);
-
+
if (el == &data->command_line)
{
data->suppress_autosuggestion = false;
-
+
if (should_expand_abbreviations)
data->expand_abbreviation_as_necessary(1);
-
+
/* Syntax highlight. Note we must have that buff_pos > 0 because we just added something nonzero to its length */
assert(el->position > 0);
reader_super_highlight_me_plenty(-1);
@@ -1862,7 +1862,7 @@ static bool handle_completions(const std::vector<completion_t> &comp, bool conti
completion_insert(common_prefix.c_str(), flags);
success = true;
}
-
+
if (continue_after_prefix_insertion || common_prefix.empty())
{
/* We didn't get a common prefix, or we want to print the list anyways. */
@@ -1889,7 +1889,7 @@ static bool handle_completions(const std::vector<completion_t> &comp, bool conti
prefix.append(el->text, prefix_start + len - PREFIX_MAX_LEN, PREFIX_MAX_LEN);
}
- wchar_t quote;
+ wchar_t quote;
parse_util_get_parameter_info(el->text, el->position, &quote, NULL, NULL);
/* Update the pager data */
@@ -1898,10 +1898,10 @@ static bool handle_completions(const std::vector<completion_t> &comp, bool conti
/* Invalidate our rendering */
data->current_page_rendering = page_rendering_t();
-
+
/* Modify the command line to reflect the new pager */
data->pager_selection_changed();
-
+
reader_repaint_needed();
success = false;
@@ -2370,7 +2370,7 @@ static void move_word(editable_line_t *el, bool move_right, bool erase, enum mov
/* Don't autosuggest after a kill */
if (el == &data->command_line)
{
- data->suppress_autosuggestion = true;
+ data->suppress_autosuggestion = true;
}
if (move_right)
@@ -2430,7 +2430,7 @@ void reader_set_buffer(const wcstring &b, size_t pos)
{
if (!data)
return;
-
+
clear_pager();
reader_set_buffer_maintaining_pager(b, pos);
}
@@ -2792,7 +2792,7 @@ static void reader_super_highlight_me_plenty(int match_highlight_pos_adjust, boo
const editable_line_t *el = &data->command_line;
long match_highlight_pos = (long)el->position + match_highlight_pos_adjust;
assert(match_highlight_pos >= 0);
-
+
reader_sanity_check();
highlight_function_t highlight_func = no_io ? highlight_shell_no_io : data->highlight_function;
@@ -2807,7 +2807,7 @@ static void reader_super_highlight_me_plenty(int match_highlight_pos_adjust, boo
else
{
// Highlighting including I/O proceeds in the background
- iothread_perform(threaded_highlight, highlight_complete, ctx);
+ iothread_perform(threaded_highlight, highlight_complete, ctx);
}
highlight_search();
@@ -2902,7 +2902,7 @@ static bool selection_is_at_top()
size_t row = pager->get_selected_row(data->current_page_rendering);
if (row != 0 && row != PAGER_SELECTION_NONE)
return false;
-
+
size_t col = pager->get_selected_column(data->current_page_rendering);
if (col != 0 && col != PAGER_SELECTION_NONE)
return false;
@@ -3143,7 +3143,7 @@ const wchar_t *reader_readline(void)
set_command_line_and_position(&data->command_line, data->cycle_command_line, data->cycle_cursor_pos);
}
-
+
/* Clear the pager if necessary */
bool focused_on_search_field = (data->active_edit_line() == &data->pager.search_field_line);
if (command_ends_paging(c, focused_on_search_field))
@@ -3210,7 +3210,7 @@ const wchar_t *reader_readline(void)
{
break;
}
-
+
case R_CANCEL:
{
// The only thing we can cancel right now is paging, which we handled up above
@@ -3502,7 +3502,7 @@ const wchar_t *reader_readline(void)
clear_pager();
break;
}
-
+
/* The user may have hit return with pager contents, but while not navigating them. Clear the pager in that event. */
clear_pager();
@@ -3529,7 +3529,7 @@ const wchar_t *reader_readline(void)
{
/* It's our reponsibility to rehighlight and repaint. But everything we do below triggers a repaint. */
command_test_result = data->test_func(el->text.c_str());
-
+
/* If the command is OK, then we're going to execute it. We still want to do syntax highlighting, but a synchronous variant that performs no I/O, so as not to block the user */
bool skip_io = (command_test_result == 0);
reader_super_highlight_me_plenty(0, skip_io);
@@ -3780,7 +3780,7 @@ const wchar_t *reader_readline(void)
/* Up arrow, go north */
direction = direction_north;
}
-
+
/* Now do the selection */
select_completion_in_direction(direction);
}
@@ -3795,39 +3795,39 @@ const wchar_t *reader_readline(void)
editable_line_t *el = data->active_edit_line();
int line_old = parse_util_get_line_from_offset(el->text, el->position);
int line_new;
-
+
if (c == R_UP_LINE)
line_new = line_old-1;
else
line_new = line_old+1;
-
+
int line_count = parse_util_lineno(el->text.c_str(), el->size())-1;
-
+
if (line_new >= 0 && line_new <= line_count)
{
size_t base_pos_new;
size_t base_pos_old;
-
+
int indent_old;
int indent_new;
size_t line_offset_old;
size_t total_offset_new;
-
+
base_pos_new = parse_util_get_offset_from_line(el->text, line_new);
-
+
base_pos_old = parse_util_get_offset_from_line(el->text, line_old);
-
+
assert(base_pos_new != (size_t)(-1) && base_pos_old != (size_t)(-1));
indent_old = data->indents.at(base_pos_old);
indent_new = data->indents.at(base_pos_new);
-
+
line_offset_old = el->position - parse_util_get_offset_from_line(el->text, line_old);
total_offset_new = parse_util_get_offset(el->text, line_new, line_offset_old - 4*(indent_new-indent_old));
update_buff_pos(el, total_offset_new);
reader_repaint_needed();
}
}
-
+
break;
}
@@ -3955,19 +3955,19 @@ const wchar_t *reader_readline(void)
case R_BEGIN_SELECTION:
{
- data->sel_active = true;
- data->sel_begin_pos = data->command_line.position;
- data->sel_start_pos = data->command_line.position;
- data->sel_stop_pos = data->command_line.position;
- break;
+ data->sel_active = true;
+ data->sel_begin_pos = data->command_line.position;
+ data->sel_start_pos = data->command_line.position;
+ data->sel_stop_pos = data->command_line.position;
+ break;
}
case R_END_SELECTION:
{
- data->sel_active = false;
- data->sel_start_pos = data->command_line.position;
- data->sel_stop_pos = data->command_line.position;
- break;
+ data->sel_active = false;
+ data->sel_start_pos = data->command_line.position;
+ data->sel_stop_pos = data->command_line.position;
+ break;
}
case R_KILL_SELECTION:
@@ -4034,20 +4034,20 @@ const wchar_t *reader_readline(void)
}
else
{
- /* Expand abbreviations after space */
+ /* Expand abbreviations after space */
should_expand_abbreviations = (c == L' ');
}
/* Regular character */
editable_line_t *el = data->active_edit_line();
insert_char(data->active_edit_line(), c, should_expand_abbreviations);
-
+
/* End paging upon inserting into the normal command line */
if (el == &data->command_line)
{
clear_pager();
}
-
+
}
else
@@ -4077,7 +4077,7 @@ const wchar_t *reader_readline(void)
}
last_char = c;
-
+
reader_repaint_if_needed();
}
@@ -4129,13 +4129,13 @@ void reader_selected_completion_changed(pager_t *pager)
/* Only interested in the top level pager */
if (data == NULL || pager != &data->pager)
return;
-
+
const completion_t *completion = pager->selected_completion(data->current_page_rendering);
-
+
/* Update the cursor and command line */
size_t cursor_pos = data->cycle_cursor_pos;
wcstring new_cmd_line;
-
+
if (completion == NULL)
{
new_cmd_line = data->cycle_command_line;
diff --git a/reader.h b/reader.h
index 77ee655b..0a92aa1d 100644
--- a/reader.h
+++ b/reader.h
@@ -25,45 +25,45 @@ class history_t;
/* Helper class for storing a command line */
class editable_line_t
{
- public:
-
+public:
+
/** The command line */
wcstring text;
-
+
/** The current position of the cursor in the command line */
size_t position;
-
+
const wcstring &get_text() const
{
return text;
}
-
+
/* Gets the length of the text */
size_t size() const
{
return text.size();
}
-
+
bool empty() const
{
return text.empty();
}
-
+
void clear()
{
text.clear();
position = 0;
}
-
+
wchar_t at(size_t idx)
{
return text.at(idx);
}
-
+
editable_line_t() : text(), position(0)
{
}
-
+
/* Inserts the string at the cursor position */
void insert_string(const wcstring &str);
};
diff --git a/screen.cpp b/screen.cpp
index 7f7515d1..1fb7ec2f 100644
--- a/screen.cpp
+++ b/screen.cpp
@@ -1323,16 +1323,16 @@ void s_write(screen_t *s,
}
s->desired.cursor = cursor_arr;
-
+
if (cursor_position_is_within_pager)
{
s->desired.cursor.x = (int)cursor_pos;
s->desired.cursor.y = (int)s->desired.line_count();
}
-
+
/* Append pager_data (none if empty) */
s->desired.append_lines(pager.screen_data);
-
+
s_update(s, layout.left_prompt.c_str(), layout.right_prompt.c_str());
s_save_status(s);
}
diff --git a/screen.h b/screen.h
index 91c78635..c9e4ac40 100644
--- a/screen.h
+++ b/screen.h
@@ -51,8 +51,8 @@ struct line_t
colors.push_back(color);
}
}
-
-
+
+
size_t size(void) const
{
@@ -129,12 +129,12 @@ public:
{
return line_datas.size();
}
-
+
void append_lines(const screen_data_t &d)
{
this->line_datas.insert(this->line_datas.end(), d.line_datas.begin(), d.line_datas.end());
}
-
+
bool empty() const
{
return line_datas.empty();