mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-27 20:25:12 +00:00
Formatting
This commit is contained in:
parent
e411bac592
commit
e918851902
3 changed files with 19 additions and 19 deletions
|
@ -962,11 +962,11 @@ static void test_1_completion(wcstring line, const wcstring &completion, complet
|
||||||
const size_t in_cursor_pos = line.find(L'^');
|
const size_t in_cursor_pos = line.find(L'^');
|
||||||
assert(in_cursor_pos != wcstring::npos);
|
assert(in_cursor_pos != wcstring::npos);
|
||||||
line.erase(in_cursor_pos, 1);
|
line.erase(in_cursor_pos, 1);
|
||||||
|
|
||||||
const size_t out_cursor_pos = expected.find(L'^');
|
const size_t out_cursor_pos = expected.find(L'^');
|
||||||
assert(out_cursor_pos != wcstring::npos);
|
assert(out_cursor_pos != wcstring::npos);
|
||||||
expected.erase(out_cursor_pos, 1);
|
expected.erase(out_cursor_pos, 1);
|
||||||
|
|
||||||
size_t cursor_pos = in_cursor_pos;
|
size_t cursor_pos = in_cursor_pos;
|
||||||
wcstring result = completion_apply_to_command_line(completion, flags, line, &cursor_pos, append_only);
|
wcstring result = completion_apply_to_command_line(completion, flags, line, &cursor_pos, append_only);
|
||||||
if (result != expected)
|
if (result != expected)
|
||||||
|
@ -979,7 +979,7 @@ static void test_1_completion(wcstring line, const wcstring &completion, complet
|
||||||
|
|
||||||
static void test_completions()
|
static void test_completions()
|
||||||
{
|
{
|
||||||
#define TEST_1_COMPLETION(a, b, c, d, e) test_1_completion(a, b, c, d, e, __LINE__)
|
#define TEST_1_COMPLETION(a, b, c, d, e) test_1_completion(a, b, c, d, e, __LINE__)
|
||||||
say(L"Testing completions");
|
say(L"Testing completions");
|
||||||
TEST_1_COMPLETION(L"foo^", L"bar", 0, false, L"foobar ^");
|
TEST_1_COMPLETION(L"foo^", L"bar", 0, false, L"foobar ^");
|
||||||
TEST_1_COMPLETION(L"foo^ baz", L"bar", 0, false, L"foobar ^ baz"); //we really do want to insert two spaces here - otherwise it's hidden by the cursor
|
TEST_1_COMPLETION(L"foo^ baz", L"bar", 0, false, L"foobar ^ baz"); //we really do want to insert two spaces here - otherwise it's hidden by the cursor
|
||||||
|
@ -987,7 +987,7 @@ static void test_completions()
|
||||||
TEST_1_COMPLETION(L"'foo'^", L"bar", 0, false, L"'foobar' ^");
|
TEST_1_COMPLETION(L"'foo'^", L"bar", 0, false, L"'foobar' ^");
|
||||||
TEST_1_COMPLETION(L"'foo\\'^", L"bar", 0, false, L"'foo\\'bar' ^");
|
TEST_1_COMPLETION(L"'foo\\'^", L"bar", 0, false, L"'foo\\'bar' ^");
|
||||||
TEST_1_COMPLETION(L"foo\\'^", L"bar", 0, false, L"foo\\'bar ^");
|
TEST_1_COMPLETION(L"foo\\'^", L"bar", 0, false, L"foo\\'bar ^");
|
||||||
|
|
||||||
// Test append only
|
// Test append only
|
||||||
TEST_1_COMPLETION(L"foo^", L"bar", 0, true, L"foobar ^");
|
TEST_1_COMPLETION(L"foo^", L"bar", 0, true, L"foobar ^");
|
||||||
TEST_1_COMPLETION(L"foo^ baz", L"bar", 0, true, L"foobar ^ baz");
|
TEST_1_COMPLETION(L"foo^ baz", L"bar", 0, true, L"foobar ^ baz");
|
||||||
|
@ -995,7 +995,7 @@ static void test_completions()
|
||||||
TEST_1_COMPLETION(L"'foo'^", L"bar", 0, true, L"'foo'bar ^");
|
TEST_1_COMPLETION(L"'foo'^", L"bar", 0, true, L"'foo'bar ^");
|
||||||
TEST_1_COMPLETION(L"'foo\\'^", L"bar", 0, true, L"'foo\\'bar' ^");
|
TEST_1_COMPLETION(L"'foo\\'^", L"bar", 0, true, L"'foo\\'bar' ^");
|
||||||
TEST_1_COMPLETION(L"foo\\'^", L"bar", 0, true, L"foo\\'bar ^");
|
TEST_1_COMPLETION(L"foo\\'^", L"bar", 0, true, L"foo\\'bar ^");
|
||||||
|
|
||||||
TEST_1_COMPLETION(L"foo^", L"bar", COMPLETE_NO_SPACE, false, L"foobar^");
|
TEST_1_COMPLETION(L"foo^", L"bar", COMPLETE_NO_SPACE, false, L"foobar^");
|
||||||
TEST_1_COMPLETION(L"'foo^", L"bar", COMPLETE_NO_SPACE, false, L"'foobar^");
|
TEST_1_COMPLETION(L"'foo^", L"bar", COMPLETE_NO_SPACE, false, L"'foobar^");
|
||||||
TEST_1_COMPLETION(L"'foo'^", L"bar", COMPLETE_NO_SPACE, false, L"'foobar'^");
|
TEST_1_COMPLETION(L"'foo'^", L"bar", COMPLETE_NO_SPACE, false, L"'foobar'^");
|
||||||
|
|
|
@ -1657,7 +1657,7 @@ void history_t::add_with_file_detection(const wcstring &str)
|
||||||
{
|
{
|
||||||
ASSERT_IS_MAIN_THREAD();
|
ASSERT_IS_MAIN_THREAD();
|
||||||
path_list_t potential_paths;
|
path_list_t potential_paths;
|
||||||
|
|
||||||
/* Hack hack hack - if the command is likely to trigger an exit, then don't do background file detection, because we won't be able to write it to our history file before we exit. */
|
/* Hack hack hack - if the command is likely to trigger an exit, then don't do background file detection, because we won't be able to write it to our history file before we exit. */
|
||||||
bool impending_exit = false;
|
bool impending_exit = false;
|
||||||
|
|
||||||
|
@ -1674,14 +1674,14 @@ void history_t::add_with_file_detection(const wcstring &str)
|
||||||
if (unescape_string(potential_path, false) && string_could_be_path(potential_path))
|
if (unescape_string(potential_path, false) && string_could_be_path(potential_path))
|
||||||
{
|
{
|
||||||
potential_paths.push_back(potential_path);
|
potential_paths.push_back(potential_path);
|
||||||
|
|
||||||
/* What a hack! */
|
/* What a hack! */
|
||||||
impending_exit = impending_exit || contains(potential_path, L"exec", L"exit", L"reboot");
|
impending_exit = impending_exit || contains(potential_path, L"exec", L"exit", L"reboot");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (potential_paths.empty() || impending_exit)
|
if (potential_paths.empty() || impending_exit)
|
||||||
{
|
{
|
||||||
this->add(str);
|
this->add(str);
|
||||||
|
|
22
reader.cpp
22
reader.cpp
|
@ -950,7 +950,7 @@ wcstring completion_apply_to_command_line(const wcstring &val_str, complete_flag
|
||||||
bool add_space = !(flags & COMPLETE_NO_SPACE);
|
bool add_space = !(flags & COMPLETE_NO_SPACE);
|
||||||
bool do_replace = !!(flags & COMPLETE_NO_CASE);
|
bool do_replace = !!(flags & COMPLETE_NO_CASE);
|
||||||
bool do_escape = !(flags & COMPLETE_DONT_ESCAPE);
|
bool do_escape = !(flags & COMPLETE_DONT_ESCAPE);
|
||||||
|
|
||||||
const size_t cursor_pos = *inout_cursor_pos;
|
const size_t cursor_pos = *inout_cursor_pos;
|
||||||
bool back_into_trailing_quote = false;
|
bool back_into_trailing_quote = false;
|
||||||
|
|
||||||
|
@ -998,7 +998,7 @@ wcstring completion_apply_to_command_line(const wcstring &val_str, complete_flag
|
||||||
if (do_escape)
|
if (do_escape)
|
||||||
{
|
{
|
||||||
parse_util_get_parameter_info(command_line, cursor_pos, "e, NULL, NULL);
|
parse_util_get_parameter_info(command_line, cursor_pos, "e, NULL, NULL);
|
||||||
|
|
||||||
/* If the token is reported as unquoted, but ends with a (unescaped) quote, and we can modify the command line, then delete the trailing quote so that we can insert within the quotes instead of after them. See https://github.com/fish-shell/fish-shell/issues/552 */
|
/* If the token is reported as unquoted, but ends with a (unescaped) quote, and we can modify the command line, then delete the trailing quote so that we can insert within the quotes instead of after them. See https://github.com/fish-shell/fish-shell/issues/552 */
|
||||||
if (quote == L'\0' && ! append_only && cursor_pos > 0)
|
if (quote == L'\0' && ! append_only && cursor_pos > 0)
|
||||||
{
|
{
|
||||||
|
@ -1010,14 +1010,14 @@ wcstring completion_apply_to_command_line(const wcstring &val_str, complete_flag
|
||||||
back_into_trailing_quote = true;
|
back_into_trailing_quote = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
replaced = parse_util_escape_string_with_quote(val_str, quote);
|
replaced = parse_util_escape_string_with_quote(val_str, quote);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
replaced = val;
|
replaced = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t insertion_point = cursor_pos;
|
size_t insertion_point = cursor_pos;
|
||||||
if (back_into_trailing_quote)
|
if (back_into_trailing_quote)
|
||||||
{
|
{
|
||||||
|
@ -1025,7 +1025,7 @@ wcstring completion_apply_to_command_line(const wcstring &val_str, complete_flag
|
||||||
assert(insertion_point > 0);
|
assert(insertion_point > 0);
|
||||||
insertion_point--;
|
insertion_point--;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Perform the insertion and compute the new location */
|
/* Perform the insertion and compute the new location */
|
||||||
wcstring result = command_line;
|
wcstring result = command_line;
|
||||||
result.insert(insertion_point, replaced);
|
result.insert(insertion_point, replaced);
|
||||||
|
@ -2740,7 +2740,7 @@ static bool is_backslashed(const wcstring &str, size_t pos)
|
||||||
/* note pos == str.size() is OK */
|
/* note pos == str.size() is OK */
|
||||||
if (pos > str.size())
|
if (pos > str.size())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
size_t count = 0, idx = pos;
|
size_t count = 0, idx = pos;
|
||||||
while (idx--)
|
while (idx--)
|
||||||
{
|
{
|
||||||
|
@ -2972,13 +2972,13 @@ const wchar_t *reader_readline()
|
||||||
|
|
||||||
/* Clear the completion list */
|
/* Clear the completion list */
|
||||||
comp.clear();
|
comp.clear();
|
||||||
|
|
||||||
/* Figure out the extent of the command substitution surrounding the cursor. This is because we only look at the current command substitution to form completions - stuff happening outside of it is not interesting. */
|
/* Figure out the extent of the command substitution surrounding the cursor. This is because we only look at the current command substitution to form completions - stuff happening outside of it is not interesting. */
|
||||||
parse_util_cmdsubst_extent(buff, data->buff_pos, &cmdsub_begin, &cmdsub_end);
|
parse_util_cmdsubst_extent(buff, data->buff_pos, &cmdsub_begin, &cmdsub_end);
|
||||||
|
|
||||||
/* Figure out the extent of the token within the command substitution. Note we pass cmdsub_begin here, not buff */
|
/* Figure out the extent of the token within the command substitution. Note we pass cmdsub_begin here, not buff */
|
||||||
parse_util_token_extent(cmdsub_begin, data->buff_pos - (cmdsub_begin-buff), &token_begin, &token_end, 0, 0);
|
parse_util_token_extent(cmdsub_begin, data->buff_pos - (cmdsub_begin-buff), &token_begin, &token_end, 0, 0);
|
||||||
|
|
||||||
/* Figure out how many steps to get from the current position to the end of the current token. */
|
/* Figure out how many steps to get from the current position to the end of the current token. */
|
||||||
size_t end_of_token_offset = token_end - buff;
|
size_t end_of_token_offset = token_end - buff;
|
||||||
|
|
||||||
|
@ -2988,13 +2988,13 @@ const wchar_t *reader_readline()
|
||||||
data->buff_pos = end_of_token_offset;
|
data->buff_pos = end_of_token_offset;
|
||||||
reader_repaint();
|
reader_repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Remove a trailing backslash. This may trigger an extra repaint, but this is rare. */
|
/* Remove a trailing backslash. This may trigger an extra repaint, but this is rare. */
|
||||||
if (is_backslashed(data->command_line, data->buff_pos))
|
if (is_backslashed(data->command_line, data->buff_pos))
|
||||||
{
|
{
|
||||||
remove_backward();
|
remove_backward();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Construct a copy of the string from the beginning of the command substitution up to the end of the token we're completing */
|
/* Construct a copy of the string from the beginning of the command substitution up to the end of the token we're completing */
|
||||||
const wcstring buffcpy = wcstring(cmdsub_begin, token_end);
|
const wcstring buffcpy = wcstring(cmdsub_begin, token_end);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue