Skip to content

Commit

Permalink
Add more changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisJefferson committed Nov 24, 2016
1 parent b62385c commit e2b416c
Showing 1 changed file with 100 additions and 37 deletions.
137 changes: 100 additions & 37 deletions lib/cmdledit.g
Original file line number Diff line number Diff line change
Expand Up @@ -751,24 +751,105 @@ GAPInfo.CommandLineEditFunctions.Functions.(INT_CHAR(' ')) :=
GAPInfo.CommandLineEditFunctions.Functions.SpaceDeletePrompt;
BindKeysToGAPHandler(" ");


BindGlobal("STANDARD_EXTENDERS", rec(
caseSensitive := function(cand, word)
local i, j, c;
i := Length(word);
while true do
if i = Length(cand[1]) then
break;
fi;
c := cand[1][i+1];
for j in [2..Length(cand)] do
if Length(cand[j]) > i and cand[j][i+1] = c then
j := j+1;
else
break;
fi;
od;
if j <= Length(cand) then
break;
else
i := i+1;
fi;
od;
if i > Length(word) then
return cand[1]{[1..i]};
else
return fail;
fi;
end,

caseInsensitive := function(cand, word)
local i, j, c, lowword, filtequal;
# Check if exactly 'word' exists, ignoring case.
lowword := LowercaseString(word);
filtequal := Filtered(cand, a -> LowercaseString(a) = lowword);
# If there are several equal words, just pick the first one...
if Length(filtequal) > 0 then
return filtequal[1];
fi;
i := Length(word);
while true do
if i = Length(cand[1]) then
break;
fi;
c := cand[1][i+1];
for j in [2..Length(cand)] do
if Length(cand[j]) > i and cand[j][i+1] = c then
j := j+1;
else
break;
fi;
od;
if j <= Length(cand) then
break;
else
i := i+1;
fi;
od;
if i >= Length(word) then
return cand[1]{[1..i]};
else
return fail;
fi;
end
));

# C-i: Completion as GAP level function
GAPInfo.CommandLineEditFunctions.Functions.Completion := function(l)
local cf, pos, word, wordplace, idbnd, i, cmps, r, searchlist, cand, c, j,
completeFilter;

completeFilter := function(filterlist, partial)
local completer, lowpartial;
completer := UserPreference("Autocompleter");
if completer = "case-insensitive" then
lowpartial := LowercaseString(partial);
return Filtered(filterlist,
a -> PositionSublist(LowercaseString(a), lowpartial) = 1);
elif IsFunction(completer) then
return completer(partial, filterlist);
elif completer <> "default" then
ErrorNoReturn("Invalid setting of UserPreference Autocompleter");
completeFilter, completeExtender, extension;

completeFilter := function(filterlist, partial)
local pref, lowpartial;
pref := UserPreference("Autocompleter");
if pref = "case-insensitive" then
lowpartial := LowercaseString(partial);
return Filtered(filterlist,
a -> PositionSublist(LowercaseString(a), lowpartial) = 1);
elif pref = "default" then
return Filtered(filterlist, a-> PositionSublist(a, partial) = 1);
elif IsRecord(pref) and IsFunction(pref.completer) then
return pref.completer(filterlist, partial);
else
ErrorNoReturn("Invalid setting of UserPreference 'Autocompleter'");
fi;
return Filtered(filterlist, a-> PositionSublist(a, partial) = 1);
end;

completeExtender := function(filterlist, partial)
local pref;
pref := UserPreference("Autocompleter");
if pref = "case-insensitive" then
return STANDARD_EXTENDERS.caseInsensitive(filterlist, partial);
elif pref = "default" then
return STANDARD_EXTENDERS.caseSensitive(filterlist, partial);
elif IsRecord(pref) and IsFunction(pref.extender) then
return pref.extender(filterlist, partial);
else
ErrorNoReturn("Invalid setting of UserPreference 'Autocompleter'");
fi;
end;

# check if Ctrl-i was hit repeatedly in a row
Expand Down Expand Up @@ -849,7 +930,7 @@ GAPInfo.CommandLineEditFunctions.Functions.Completion := function(l)
# in component name search we try again with all names if this is empty
if IsBound(cf.tabcompnam) and Length(cand) = 0 and cf.tabcount < 3 then
searchlist := ALL_RNAMES();
cand := completeFilter(searchlist, word);
cand := completeFilter(searchlist, word);
fi;

if (not IsBound(cf.tabcompnam) and cf.tabcount = 2) or
Expand All @@ -867,29 +948,11 @@ GAPInfo.CommandLineEditFunctions.Functions.Completion := function(l)
elif Length(cand) = 1 then
return [ wordplace[1], wordplace[2]+1, cand[1]{[1..Length(cand[1])]}];
fi;
i := Length(word);
while true do
if i = Length(cand[1]) then
break;
fi;
c := cand[1][i+1];
for j in [2..Length(cand)] do
if Length(cand[j]) > i and cand[j][i+1] = c then
j := j+1;
else
break;
fi;
od;
if j <= Length(cand) then
break;
else
i := i+1;
fi;
od;
if i > Length(word) then
return [ wordplace[1], wordplace[2]+1, cand[1]{[1..i]}];
else
extension := completeExtender(cand, word);
if extension = fail then
return [];
else
return [ wordplace[1], wordplace[2] + 1, extension ];
fi;
end;
GAPInfo.CommandLineEditFunctions.Functions.(INT_CHAR('I') mod 32) :=
Expand Down

0 comments on commit e2b416c

Please sign in to comment.