mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 21:03:12 +00:00
fix some style problems that have crept in
This commit is contained in:
parent
2fa4bd8fd7
commit
10ae6d8b26
7 changed files with 50 additions and 42 deletions
|
@ -1265,15 +1265,15 @@ void complete(const wcstring &cmd_with_subcmds, std::vector<completion_t> *out_c
|
||||||
parse_flag_include_comments,
|
parse_flag_include_comments,
|
||||||
&tree, NULL);
|
&tree, NULL);
|
||||||
|
|
||||||
// Find the plain statement to operate on. The cursor may be past it (#1261), so backtrack until
|
// Find the plain statement to operate on. The cursor may be past it (#1261), so backtrack
|
||||||
// we know we're no longer in a space. But the space may actually be part of the argument (#2477)
|
// until we know we're no longer in a space. But the space may actually be part of the
|
||||||
// so
|
// argument (#2477).
|
||||||
size_t position_in_statement = pos;
|
size_t position_in_statement = pos;
|
||||||
while (position_in_statement > 0 && cmd.at(position_in_statement - 1) == L' ') {
|
while (position_in_statement > 0 && cmd.at(position_in_statement - 1) == L' ') {
|
||||||
position_in_statement--;
|
position_in_statement--;
|
||||||
}
|
}
|
||||||
const parse_node_t *plain_statement =
|
const parse_node_t *plain_statement = tree.find_node_matching_source_location(
|
||||||
tree.find_node_matching_source_location(symbol_plain_statement, position_in_statement, NULL);
|
symbol_plain_statement, position_in_statement, NULL);
|
||||||
|
|
||||||
if (plain_statement == NULL) {
|
if (plain_statement == NULL) {
|
||||||
// Not part of a plain statement. This could be e.g. a for loop header, case expression,
|
// Not part of a plain statement. This could be e.g. a for loop header, case expression,
|
||||||
|
@ -1372,7 +1372,8 @@ void complete(const wcstring &cmd_with_subcmds, std::vector<completion_t> *out_c
|
||||||
// previous argument is the matching one. But if the cursor was in or at the end
|
// previous argument is the matching one. But if the cursor was in or at the end
|
||||||
// of the argument, then the current argument is the matching one, and the
|
// of the argument, then the current argument is the matching one, and the
|
||||||
// previous argument is the one before it.
|
// previous argument is the one before it.
|
||||||
bool cursor_in_whitespace = ! plain_statement->location_in_or_at_end_of_source_range(pos);
|
bool cursor_in_whitespace =
|
||||||
|
!plain_statement->location_in_or_at_end_of_source_range(pos);
|
||||||
if (cursor_in_whitespace) {
|
if (cursor_in_whitespace) {
|
||||||
current_argument = L"";
|
current_argument = L"";
|
||||||
previous_argument = matching_arg;
|
previous_argument = matching_arg;
|
||||||
|
|
|
@ -8,9 +8,6 @@
|
||||||
// Type "exit" or "quit" to terminate the program.
|
// Type "exit" or "quit" to terminate the program.
|
||||||
#include "config.h" // IWYU pragma: keep
|
#include "config.h" // IWYU pragma: keep
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
@ -20,14 +17,17 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
#include <wctype.h>
|
#include <wctype.h>
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "env.h"
|
#include "env.h"
|
||||||
#include "fallback.h" // IWYU pragma: keep
|
#include "fallback.h" // IWYU pragma: keep
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include "input_common.h"
|
#include "input_common.h"
|
||||||
#include "proc.h"
|
|
||||||
#include "print_help.h"
|
#include "print_help.h"
|
||||||
|
#include "proc.h"
|
||||||
#include "reader.h"
|
#include "reader.h"
|
||||||
#include "signal.h"
|
#include "signal.h"
|
||||||
#include "wutil.h" // IWYU pragma: keep
|
#include "wutil.h" // IWYU pragma: keep
|
||||||
|
|
|
@ -1294,8 +1294,7 @@ static void test_expand() {
|
||||||
L"Wrong fuzzy matching 5");
|
L"Wrong fuzzy matching 5");
|
||||||
|
|
||||||
// multiple slashes with fuzzy matching - #3185
|
// multiple slashes with fuzzy matching - #3185
|
||||||
expand_test(L"l///n", EXPAND_FOR_COMPLETIONS | EXPAND_FUZZY_MATCH,
|
expand_test(L"l///n", EXPAND_FOR_COMPLETIONS | EXPAND_FUZZY_MATCH, L"lol///nub/", wnull,
|
||||||
L"lol///nub/", wnull,
|
|
||||||
L"Wrong fuzzy matching 6");
|
L"Wrong fuzzy matching 6");
|
||||||
|
|
||||||
if (chdir_set_pwd(saved_wd)) {
|
if (chdir_set_pwd(saved_wd)) {
|
||||||
|
@ -1840,12 +1839,10 @@ static void test_complete(void) {
|
||||||
|
|
||||||
// Completing after spaces - see #2447
|
// Completing after spaces - see #2447
|
||||||
completions.clear();
|
completions.clear();
|
||||||
complete(L"echo (ls /tmp/complete_test/has\\ ", &completions, COMPLETION_REQUEST_DEFAULT,
|
complete(L"echo (ls /tmp/complete_test/has\\ ", &completions, COMPLETION_REQUEST_DEFAULT, vars);
|
||||||
vars);
|
|
||||||
do_test(completions.size() == 1);
|
do_test(completions.size() == 1);
|
||||||
do_test(completions.at(0).completion == L"space");
|
do_test(completions.at(0).completion == L"space");
|
||||||
|
|
||||||
|
|
||||||
// Add a function and test completing it in various ways.
|
// Add a function and test completing it in various ways.
|
||||||
struct function_data_t func_data = {};
|
struct function_data_t func_data = {};
|
||||||
func_data.name = L"scuttlebutt";
|
func_data.name = L"scuttlebutt";
|
||||||
|
|
|
@ -1414,7 +1414,8 @@ static bool format_history_record(const history_item_t &item, const bool with_ti
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool history_t::search(history_search_type_t search_type, wcstring_list_t search_args, bool with_time, io_streams_t &streams) {
|
bool history_t::search(history_search_type_t search_type, wcstring_list_t search_args,
|
||||||
|
bool with_time, io_streams_t &streams) {
|
||||||
// scoped_lock locker(lock);
|
// scoped_lock locker(lock);
|
||||||
if (search_args.empty()) {
|
if (search_args.empty()) {
|
||||||
// Start at one because zero is the current command.
|
// Start at one because zero is the current command.
|
||||||
|
|
|
@ -224,8 +224,8 @@ class history_t {
|
||||||
void save();
|
void save();
|
||||||
|
|
||||||
// Searches history.
|
// Searches history.
|
||||||
bool search(history_search_type_t search_type, wcstring_list_t search_args,
|
bool search(history_search_type_t search_type, wcstring_list_t search_args, bool with_time,
|
||||||
bool with_time, io_streams_t &streams);
|
io_streams_t &streams);
|
||||||
|
|
||||||
// Enable / disable automatic saving. Main thread only!
|
// Enable / disable automatic saving. Main thread only!
|
||||||
void disable_automatic_saving();
|
void disable_automatic_saving();
|
||||||
|
|
|
@ -368,7 +368,8 @@ int input_init() {
|
||||||
|
|
||||||
env_set(L"TERM", DEFAULT_TERM, ENV_GLOBAL | ENV_EXPORT);
|
env_set(L"TERM", DEFAULT_TERM, ENV_GLOBAL | ENV_EXPORT);
|
||||||
if (setupterm(NULL, STDOUT_FILENO, &err_ret) == ERR) {
|
if (setupterm(NULL, STDOUT_FILENO, &err_ret) == ERR) {
|
||||||
debug(0, _(L"Could not set up terminal using the fallback terminal type '%ls' - exiting"),
|
debug(0,
|
||||||
|
_(L"Could not set up terminal using the fallback terminal type '%ls' - exiting"),
|
||||||
DEFAULT_TERM);
|
DEFAULT_TERM);
|
||||||
exit_without_destructors(1);
|
exit_without_destructors(1);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -486,9 +486,10 @@ class wildcard_expander_t {
|
||||||
|
|
||||||
/// Given a directory base_dir, which is opened as base_dir_fp, expand the last segment of the
|
/// Given a directory base_dir, which is opened as base_dir_fp, expand the last segment of the
|
||||||
/// wildcard. Treat ANY_STRING_RECURSIVE as ANY_STRING. wc is the wildcard segment to use for
|
/// wildcard. Treat ANY_STRING_RECURSIVE as ANY_STRING. wc is the wildcard segment to use for
|
||||||
/// matching, wc_remainder is the wildcard for subdirectories, prefix is the prefix for completions.
|
/// matching, wc_remainder is the wildcard for subdirectories, prefix is the prefix for
|
||||||
void expand_last_segment(const wcstring &base_dir, DIR *base_dir_fp,
|
/// completions.
|
||||||
const wcstring &wc, const wcstring &prefix);
|
void expand_last_segment(const wcstring &base_dir, DIR *base_dir_fp, const wcstring &wc,
|
||||||
|
const wcstring &prefix);
|
||||||
|
|
||||||
/// Indicate whether we should cancel wildcard expansion. This latches 'interrupt'.
|
/// Indicate whether we should cancel wildcard expansion. This latches 'interrupt'.
|
||||||
bool interrupted() {
|
bool interrupted() {
|
||||||
|
@ -696,9 +697,11 @@ void wildcard_expander_t::expand_intermediate_segment(const wcstring &base_dir,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void wildcard_expander_t::expand_literal_intermediate_segment_with_fuzz(
|
void wildcard_expander_t::expand_literal_intermediate_segment_with_fuzz(const wcstring &base_dir,
|
||||||
const wcstring &base_dir, DIR *base_dir_fp, const wcstring &wc_segment,
|
DIR *base_dir_fp,
|
||||||
const wchar_t *wc_remainder, const wcstring &prefix) {
|
const wcstring &wc_segment,
|
||||||
|
const wchar_t *wc_remainder,
|
||||||
|
const wcstring &prefix) {
|
||||||
// This only works with tab completions. Ordinary wildcard expansion should never go fuzzy.
|
// This only works with tab completions. Ordinary wildcard expansion should never go fuzzy.
|
||||||
wcstring name_str;
|
wcstring name_str;
|
||||||
|
|
||||||
|
@ -727,8 +730,10 @@ void wildcard_expander_t::expand_literal_intermediate_segment_with_fuzz(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine the effective prefix for our children
|
// Determine the effective prefix for our children
|
||||||
// Normally this would be the wildcard segment, but here we know our segment doesn't have wildcards
|
// Normally this would be the wildcard segment, but here we know our segment doesn't have
|
||||||
// ("literal") and we are doing fuzzy expansion, which means we replace the segment with files found
|
// wildcards
|
||||||
|
// ("literal") and we are doing fuzzy expansion, which means we replace the segment with
|
||||||
|
// files found
|
||||||
// through fuzzy matching
|
// through fuzzy matching
|
||||||
const wcstring child_prefix = prefix + name_str + L'/';
|
const wcstring child_prefix = prefix + name_str + L'/';
|
||||||
|
|
||||||
|
@ -785,8 +790,10 @@ void wildcard_expander_t::expand_last_segment(const wcstring &base_dir, DIR *bas
|
||||||
/// prefix: the string that should be prepended for completions that replace their token.
|
/// prefix: the string that should be prepended for completions that replace their token.
|
||||||
// This is usually the same thing as the original wildcard, but for fuzzy matching, we
|
// This is usually the same thing as the original wildcard, but for fuzzy matching, we
|
||||||
// expand intermediate segments. effective_prefix is always either empty, or ends with a slash
|
// expand intermediate segments. effective_prefix is always either empty, or ends with a slash
|
||||||
// Note: this is only used when doing completions (EXPAND_FOR_COMPLETIONS is true), not expansions
|
// Note: this is only used when doing completions (EXPAND_FOR_COMPLETIONS is true), not
|
||||||
void wildcard_expander_t::expand(const wcstring &base_dir, const wchar_t *wc, const wcstring &effective_prefix) {
|
// expansions
|
||||||
|
void wildcard_expander_t::expand(const wcstring &base_dir, const wchar_t *wc,
|
||||||
|
const wcstring &effective_prefix) {
|
||||||
assert(wc != NULL);
|
assert(wc != NULL);
|
||||||
|
|
||||||
if (interrupted()) {
|
if (interrupted()) {
|
||||||
|
@ -819,7 +826,8 @@ void wildcard_expander_t::expand(const wcstring &base_dir, const wchar_t *wc, co
|
||||||
|
|
||||||
// This just trumps everything.
|
// This just trumps everything.
|
||||||
size_t before = this->resolved_completions->size();
|
size_t before = this->resolved_completions->size();
|
||||||
this->expand(base_dir + wc_segment + L'/', wc_remainder, effective_prefix + wc_segment + L'/');
|
this->expand(base_dir + wc_segment + L'/', wc_remainder,
|
||||||
|
effective_prefix + wc_segment + L'/');
|
||||||
|
|
||||||
// Maybe try a fuzzy match (#94) if nothing was found with the literal match. Respect
|
// Maybe try a fuzzy match (#94) if nothing was found with the literal match. Respect
|
||||||
// EXPAND_NO_DIRECTORY_ABBREVIATIONS (issue #2413).
|
// EXPAND_NO_DIRECTORY_ABBREVIATIONS (issue #2413).
|
||||||
|
@ -829,9 +837,8 @@ void wildcard_expander_t::expand(const wcstring &base_dir, const wchar_t *wc, co
|
||||||
assert(this->flags & EXPAND_FOR_COMPLETIONS);
|
assert(this->flags & EXPAND_FOR_COMPLETIONS);
|
||||||
DIR *base_dir_fd = open_dir(base_dir);
|
DIR *base_dir_fd = open_dir(base_dir);
|
||||||
if (base_dir_fd != NULL) {
|
if (base_dir_fd != NULL) {
|
||||||
this->expand_literal_intermediate_segment_with_fuzz(base_dir, base_dir_fd,
|
this->expand_literal_intermediate_segment_with_fuzz(
|
||||||
wc_segment, wc_remainder,
|
base_dir, base_dir_fd, wc_segment, wc_remainder, effective_prefix);
|
||||||
effective_prefix);
|
|
||||||
closedir(base_dir_fd);
|
closedir(base_dir_fd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -846,8 +853,8 @@ void wildcard_expander_t::expand(const wcstring &base_dir, const wchar_t *wc, co
|
||||||
// Not the last segment, nonempty wildcard.
|
// Not the last segment, nonempty wildcard.
|
||||||
assert(next_slash != NULL);
|
assert(next_slash != NULL);
|
||||||
wcstring child_effective_prefix = effective_prefix + wc_segment;
|
wcstring child_effective_prefix = effective_prefix + wc_segment;
|
||||||
this->expand_intermediate_segment(base_dir, dir, wc_segment,
|
this->expand_intermediate_segment(base_dir, dir, wc_segment, wc_remainder,
|
||||||
wc_remainder, effective_prefix + wc_segment + L'/');
|
effective_prefix + wc_segment + L'/');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recursive wildcards require special handling.
|
// Recursive wildcards require special handling.
|
||||||
|
@ -862,7 +869,8 @@ void wildcard_expander_t::expand(const wcstring &base_dir, const wchar_t *wc, co
|
||||||
assert(any_tail[0] == ANY_STRING_RECURSIVE);
|
assert(any_tail[0] == ANY_STRING_RECURSIVE);
|
||||||
|
|
||||||
rewinddir(dir);
|
rewinddir(dir);
|
||||||
this->expand_intermediate_segment(base_dir, dir, head_any, any_tail, effective_prefix);
|
this->expand_intermediate_segment(base_dir, dir, head_any, any_tail,
|
||||||
|
effective_prefix);
|
||||||
}
|
}
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue