Re-implement abbreviations as a built-in

Prior to this change, abbreviations were stored as fish variables, often
universal. However we intend to add additional features to abbreviations
which would be very awkward to shoe-horn into variables.

Re-implement abbreviations using a builtin, managing them internally.

Existing abbreviations stored in universal variables are still imported,
for compatibility. However new abbreviations will need to be added to a
function. A follow-up commit will add it.

Now that abbr is a built-in, remove the abbr function; but leave the
abbr.fish file so that stale files from past installs do not override
the abbr builtin.
This commit is contained in:
ridiculousfish
2022-04-01 12:05:27 -07:00
parent 635cc3ee8d
commit 1402bae7f4
20 changed files with 608 additions and 339 deletions

View File

@@ -286,12 +286,12 @@ wcstring_list_t split_string_tok(const wcstring &val, const wcstring &seps, size
return out;
}
wcstring join_strings(const wcstring_list_t &vals, wchar_t sep) {
static wcstring join_strings_impl(const wcstring_list_t &vals, const wchar_t *sep, size_t seplen) {
if (vals.empty()) return wcstring{};
// Reserve the size we will need.
// count-1 separators, plus the length of all strings.
size_t size = vals.size() - 1;
size_t size = (vals.size() - 1) * seplen;
for (const wcstring &s : vals) {
size += s.size();
}
@@ -302,7 +302,7 @@ wcstring join_strings(const wcstring_list_t &vals, wchar_t sep) {
bool first = true;
for (const wcstring &s : vals) {
if (!first) {
result.push_back(sep);
result.append(sep, seplen);
}
result.append(s);
first = false;
@@ -310,6 +310,14 @@ wcstring join_strings(const wcstring_list_t &vals, wchar_t sep) {
return result;
}
wcstring join_strings(const wcstring_list_t &vals, wchar_t c) {
return join_strings_impl(vals, &c, 1);
}
wcstring join_strings(const wcstring_list_t &vals, const wchar_t *sep) {
return join_strings_impl(vals, sep, wcslen(sep));
}
void wcs2string_bad_char(wchar_t wc) {
FLOGF(char_encoding, L"Wide character U+%4X has no narrow representation", wc);
}