mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 04:43:10 +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,
|
||||
&tree, NULL);
|
||||
|
||||
// Find the plain statement to operate on. The cursor may be past it (#1261), so backtrack until
|
||||
// we know we're no longer in a space. But the space may actually be part of the argument (#2477)
|
||||
// so
|
||||
// Find the plain statement to operate on. The cursor may be past it (#1261), so backtrack
|
||||
// until we know we're no longer in a space. But the space may actually be part of the
|
||||
// argument (#2477).
|
||||
size_t position_in_statement = pos;
|
||||
while (position_in_statement > 0 && cmd.at(position_in_statement - 1) == L' ') {
|
||||
position_in_statement--;
|
||||
}
|
||||
const parse_node_t *plain_statement =
|
||||
tree.find_node_matching_source_location(symbol_plain_statement, position_in_statement, NULL);
|
||||
const parse_node_t *plain_statement = tree.find_node_matching_source_location(
|
||||
symbol_plain_statement, position_in_statement, NULL);
|
||||
|
||||
if (plain_statement == NULL) {
|
||||
// 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
|
||||
// of the argument, then the current argument is the matching one, and the
|
||||
// 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) {
|
||||
current_argument = L"";
|
||||
previous_argument = matching_arg;
|
||||
|
|
|
@ -8,9 +8,6 @@
|
|||
// Type "exit" or "quit" to terminate the program.
|
||||
#include "config.h" // IWYU pragma: keep
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <errno.h>
|
||||
#include <getopt.h>
|
||||
#include <signal.h>
|
||||
|
@ -20,17 +17,20 @@
|
|||
#include <unistd.h>
|
||||
#include <wchar.h>
|
||||
#include <wctype.h>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "common.h"
|
||||
#include "env.h"
|
||||
#include "fallback.h" // IWYU pragma: keep
|
||||
#include "input.h"
|
||||
#include "input_common.h"
|
||||
#include "proc.h"
|
||||
#include "print_help.h"
|
||||
#include "proc.h"
|
||||
#include "reader.h"
|
||||
#include "signal.h"
|
||||
#include "wutil.h" // IWYU pragma: keep
|
||||
#include "wutil.h" // IWYU pragma: keep
|
||||
|
||||
struct config_paths_t determine_config_directory_paths(const char *argv0);
|
||||
|
||||
|
@ -159,7 +159,7 @@ static void output_bind_command(std::vector<wchar_t> &bind_chars) {
|
|||
}
|
||||
|
||||
static void output_info_about_char(wchar_t wc) {
|
||||
fprintf(stderr, "hex: %4X char: %s\n", wc, char_to_symbol(wc, false));
|
||||
fprintf(stderr, "hex: %4X char: %s\n", wc, char_to_symbol(wc, false));
|
||||
}
|
||||
|
||||
static bool output_matching_key_name(wchar_t wc) {
|
||||
|
@ -266,7 +266,7 @@ static void install_our_signal_handlers() {
|
|||
|
||||
/// Setup our environment (e.g., tty modes), process key strokes, then reset the environment.
|
||||
static void setup_and_process_keys(bool continuous_mode) {
|
||||
is_interactive_session = 1; // by definition this program is interactive
|
||||
is_interactive_session = 1; // by definition this program is interactive
|
||||
set_main_thread();
|
||||
setup_fork_guards();
|
||||
env_init();
|
||||
|
|
|
@ -1294,8 +1294,7 @@ static void test_expand() {
|
|||
L"Wrong fuzzy matching 5");
|
||||
|
||||
// multiple slashes with fuzzy matching - #3185
|
||||
expand_test(L"l///n", EXPAND_FOR_COMPLETIONS | EXPAND_FUZZY_MATCH,
|
||||
L"lol///nub/", wnull,
|
||||
expand_test(L"l///n", EXPAND_FOR_COMPLETIONS | EXPAND_FUZZY_MATCH, L"lol///nub/", wnull,
|
||||
L"Wrong fuzzy matching 6");
|
||||
|
||||
if (chdir_set_pwd(saved_wd)) {
|
||||
|
@ -1840,12 +1839,10 @@ static void test_complete(void) {
|
|||
|
||||
// Completing after spaces - see #2447
|
||||
completions.clear();
|
||||
complete(L"echo (ls /tmp/complete_test/has\\ ", &completions, COMPLETION_REQUEST_DEFAULT,
|
||||
vars);
|
||||
complete(L"echo (ls /tmp/complete_test/has\\ ", &completions, COMPLETION_REQUEST_DEFAULT, vars);
|
||||
do_test(completions.size() == 1);
|
||||
do_test(completions.at(0).completion == L"space");
|
||||
|
||||
|
||||
// Add a function and test completing it in various ways.
|
||||
struct function_data_t func_data = {};
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
if (search_args.empty()) {
|
||||
// Start at one because zero is the current command.
|
||||
|
|
|
@ -224,8 +224,8 @@ class history_t {
|
|||
void save();
|
||||
|
||||
// Searches history.
|
||||
bool search(history_search_type_t search_type, wcstring_list_t search_args,
|
||||
bool with_time, io_streams_t &streams);
|
||||
bool search(history_search_type_t search_type, wcstring_list_t search_args, bool with_time,
|
||||
io_streams_t &streams);
|
||||
|
||||
// Enable / disable automatic saving. Main thread only!
|
||||
void disable_automatic_saving();
|
||||
|
|
|
@ -304,7 +304,7 @@ void update_fish_color_support(void) {
|
|||
// otherwise infer it from the TERM variable or use terminfo.
|
||||
env_var_t fish_term256 = env_get_string(L"fish_term256");
|
||||
env_var_t term = env_get_string(L"TERM");
|
||||
bool support_term256 = false; // default to no support
|
||||
bool support_term256 = false; // default to no support
|
||||
if (!fish_term256.missing_or_empty()) {
|
||||
support_term256 = from_string<bool>(fish_term256);
|
||||
debug(2, L"256 color support determined by 'fish_term256'");
|
||||
|
@ -357,7 +357,7 @@ int input_init() {
|
|||
|
||||
int err_ret;
|
||||
if (setupterm(NULL, STDOUT_FILENO, &err_ret) == ERR) {
|
||||
debug(0, _(L"Could not set up terminal"));
|
||||
debug(0, _(L"Could not set up terminal"));
|
||||
env_var_t term = env_get_string(L"TERM");
|
||||
if (term.missing_or_empty()) {
|
||||
debug(0, _(L"TERM environment variable not set"));
|
||||
|
@ -368,7 +368,8 @@ int input_init() {
|
|||
|
||||
env_set(L"TERM", DEFAULT_TERM, ENV_GLOBAL | ENV_EXPORT);
|
||||
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);
|
||||
exit_without_destructors(1);
|
||||
} 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
|
||||
/// 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.
|
||||
void expand_last_segment(const wcstring &base_dir, DIR *base_dir_fp,
|
||||
const wcstring &wc, const wcstring &prefix);
|
||||
/// matching, wc_remainder is the wildcard for subdirectories, prefix is the prefix for
|
||||
/// completions.
|
||||
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'.
|
||||
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(
|
||||
const wcstring &base_dir, DIR *base_dir_fp, const wcstring &wc_segment,
|
||||
const wchar_t *wc_remainder, const wcstring &prefix) {
|
||||
void wildcard_expander_t::expand_literal_intermediate_segment_with_fuzz(const wcstring &base_dir,
|
||||
DIR *base_dir_fp,
|
||||
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.
|
||||
wcstring name_str;
|
||||
|
||||
|
@ -727,8 +730,10 @@ void wildcard_expander_t::expand_literal_intermediate_segment_with_fuzz(
|
|||
}
|
||||
|
||||
// Determine the effective prefix for our children
|
||||
// Normally this would be the wildcard segment, but here we know our segment doesn't have wildcards
|
||||
// ("literal") and we are doing fuzzy expansion, which means we replace the segment with files found
|
||||
// Normally this would be the wildcard segment, but here we know our segment doesn't have
|
||||
// wildcards
|
||||
// ("literal") and we are doing fuzzy expansion, which means we replace the segment with
|
||||
// files found
|
||||
// through fuzzy matching
|
||||
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.
|
||||
// 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
|
||||
// Note: this is only used when doing completions (EXPAND_FOR_COMPLETIONS is true), not expansions
|
||||
void wildcard_expander_t::expand(const wcstring &base_dir, const wchar_t *wc, const wcstring &effective_prefix) {
|
||||
// Note: this is only used when doing completions (EXPAND_FOR_COMPLETIONS is true), not
|
||||
// expansions
|
||||
void wildcard_expander_t::expand(const wcstring &base_dir, const wchar_t *wc,
|
||||
const wcstring &effective_prefix) {
|
||||
assert(wc != NULL);
|
||||
|
||||
if (interrupted()) {
|
||||
|
@ -801,7 +808,7 @@ void wildcard_expander_t::expand(const wcstring &base_dir, const wchar_t *wc, co
|
|||
const wcstring wc_segment = wcstring(wc, wc_segment_len);
|
||||
const bool segment_has_wildcards =
|
||||
wildcard_has(wc_segment, true /* internal, i.e. look for ANY_CHAR instead of ? */);
|
||||
const wchar_t * const wc_remainder = next_slash ? next_slash + 1 : NULL;
|
||||
const wchar_t *const wc_remainder = next_slash ? next_slash + 1 : NULL;
|
||||
|
||||
if (wc_segment.empty()) {
|
||||
// Handle empty segment.
|
||||
|
@ -819,7 +826,8 @@ void wildcard_expander_t::expand(const wcstring &base_dir, const wchar_t *wc, co
|
|||
|
||||
// This just trumps everything.
|
||||
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
|
||||
// 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);
|
||||
DIR *base_dir_fd = open_dir(base_dir);
|
||||
if (base_dir_fd != NULL) {
|
||||
this->expand_literal_intermediate_segment_with_fuzz(base_dir, base_dir_fd,
|
||||
wc_segment, wc_remainder,
|
||||
effective_prefix);
|
||||
this->expand_literal_intermediate_segment_with_fuzz(
|
||||
base_dir, base_dir_fd, wc_segment, wc_remainder, effective_prefix);
|
||||
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.
|
||||
assert(next_slash != NULL);
|
||||
wcstring child_effective_prefix = effective_prefix + wc_segment;
|
||||
this->expand_intermediate_segment(base_dir, dir, wc_segment,
|
||||
wc_remainder, effective_prefix + wc_segment + L'/');
|
||||
this->expand_intermediate_segment(base_dir, dir, wc_segment, wc_remainder,
|
||||
effective_prefix + wc_segment + L'/');
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue