mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-26 02:51:16 -03:00
Rename abbreviation triggers
This renames abbreviation triggers from `--trigger-on entry` and `--trigger-on exec` to `--on-space` and `--on-enter`. These names are less precise, as abbreviations trigger on any character that terminates a word or any key binding that triggers exec, but they're also more human friendly and that's a better tradeoff.
This commit is contained in:
@@ -788,9 +788,9 @@ class reader_data_t : public std::enable_shared_from_this<reader_data_t> {
|
||||
/// Do what we need to do whenever our pager selection changes.
|
||||
void pager_selection_changed();
|
||||
|
||||
/// Expand abbreviations in the given phases at the current cursor position, minus
|
||||
/// Expand abbreviations in the given triggers at the current cursor position, minus
|
||||
/// cursor_backtrack.
|
||||
bool expand_abbreviation_at_cursor(size_t cursor_backtrack, abbrs_phases_t phases);
|
||||
bool expand_abbreviation_at_cursor(size_t cursor_backtrack, abbrs_triggers_t triggers);
|
||||
|
||||
/// \return true if the command line has changed and repainting is needed. If \p colors is not
|
||||
/// null, then also return true if the colors have changed.
|
||||
@@ -1445,11 +1445,11 @@ static std::vector<positioned_token_t> extract_tokens(const wcstring &str) {
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Expand abbreviations in the given phase at the given cursor position.
|
||||
/// Expand abbreviations in the given triggers at the given cursor position.
|
||||
/// cursor. \return the replacement. This does NOT inspect the current reader data.
|
||||
maybe_t<abbrs_replacement_t> reader_expand_abbreviation_at_cursor(const wcstring &cmdline,
|
||||
size_t cursor_pos,
|
||||
abbrs_phases_t phases,
|
||||
abbrs_triggers_t triggers,
|
||||
parser_t &parser) {
|
||||
// Find the token containing the cursor. Usually users edit from the end, so walk backwards.
|
||||
const auto tokens = extract_tokens(cmdline);
|
||||
@@ -1464,7 +1464,7 @@ maybe_t<abbrs_replacement_t> reader_expand_abbreviation_at_cursor(const wcstring
|
||||
iter->is_cmd ? abbrs_position_t::command : abbrs_position_t::anywhere;
|
||||
|
||||
wcstring token_str = cmdline.substr(range.start, range.length);
|
||||
auto replacers = abbrs_match(token_str, position, phases);
|
||||
auto replacers = abbrs_match(token_str, position, triggers);
|
||||
for (const auto &replacer : replacers) {
|
||||
if (auto replacement = expand_replacer(range, token_str, replacer, parser)) {
|
||||
return replacement;
|
||||
@@ -1476,7 +1476,8 @@ maybe_t<abbrs_replacement_t> reader_expand_abbreviation_at_cursor(const wcstring
|
||||
/// Expand abbreviations at the current cursor position, minus the given cursor backtrack. This may
|
||||
/// change the command line but does NOT repaint it. This is to allow the caller to coalesce
|
||||
/// repaints.
|
||||
bool reader_data_t::expand_abbreviation_at_cursor(size_t cursor_backtrack, abbrs_phases_t phases) {
|
||||
bool reader_data_t::expand_abbreviation_at_cursor(size_t cursor_backtrack,
|
||||
abbrs_triggers_t triggers) {
|
||||
bool result = false;
|
||||
editable_line_t *el = active_edit_line();
|
||||
|
||||
@@ -1484,8 +1485,8 @@ bool reader_data_t::expand_abbreviation_at_cursor(size_t cursor_backtrack, abbrs
|
||||
// Try expanding abbreviations.
|
||||
this->update_commandline_state();
|
||||
size_t cursor_pos = el->position() - std::min(el->position(), cursor_backtrack);
|
||||
if (auto replacement = reader_expand_abbreviation_at_cursor(el->text(), cursor_pos, phases,
|
||||
this->parser())) {
|
||||
if (auto replacement = reader_expand_abbreviation_at_cursor(el->text(), cursor_pos,
|
||||
triggers, this->parser())) {
|
||||
push_edit(el, edit_t{replacement->range, std::move(replacement->text)});
|
||||
update_buff_pos(el, replacement->cursor);
|
||||
result = true;
|
||||
@@ -4188,7 +4189,7 @@ void reader_data_t::handle_readline_command(readline_cmd_t c, readline_loop_stat
|
||||
}
|
||||
|
||||
case rl::expand_abbr: {
|
||||
if (expand_abbreviation_at_cursor(1, abbrs_phase_entry)) {
|
||||
if (expand_abbreviation_at_cursor(1, abbrs_trigger_on_space)) {
|
||||
inputter.function_set_status(true);
|
||||
} else {
|
||||
inputter.function_set_status(false);
|
||||
@@ -4281,7 +4282,7 @@ parser_test_error_bits_t reader_data_t::expand_for_execute() {
|
||||
|
||||
// Exec abbreviations at the cursor.
|
||||
// Note we want to expand abbreviations even if incomplete.
|
||||
if (expand_abbreviation_at_cursor(0, abbrs_phase_exec)) {
|
||||
if (expand_abbreviation_at_cursor(0, abbrs_trigger_on_enter)) {
|
||||
// Trigger syntax highlighting as we are likely about to execute this command.
|
||||
this->super_highlight_me_plenty();
|
||||
if (conf.syntax_check_ok) {
|
||||
|
||||
Reference in New Issue
Block a user