lfe_edlin_expand.erl - Command Line Expansion
Purpose: Provide tab completion and expansion for the LFE shell.
Location: src/lfe_edlin_expand.erl
Size: 232 LOC, 7.8KB
Module Classification: Shell support, command completion
Public API
expand(Before) -> {yes, Expansion, Matches} | no
Expand command-line input. Located at lfe_edlin_expand.erl:42-45.
Parameters:
Before- String before cursor- Returns:
{yes, Expansion, Matches}- Possible expansionsno- No completions available
Completion Types
Module Name Completion:
lfe> (lists:m<TAB>
→ lists:map lists:max lists:member ...
Function Name Completion:
lfe> (list<TAB>
→ lists list-comprehension ...
Variable Name Completion:
lfe> my-var<TAB>
→ my-variable-name
Local Bindings: Completes from current environment.
Implementation
Tokenization (expand/1 at lines 47-89):
- Parse
Beforestring into tokens - Identify last token (completion target)
- Determine context (module, function, variable)
- Find matches
- Return common prefix + alternatives
Module/Function Matching (match_module_functions/2 at lines 134-178):
match_module_functions(Prefix, Env) ->
% Get all loaded modules
Modules = code:all_loaded(),
% Get module exports
Exports = [Mod:module_info(exports) || {Mod, _} <- Modules],
% Filter by prefix
filter_matches(Prefix, flatten(Exports)).
Local Binding Matching (match_local_bindings/2 at lines 182-214):
Searches current environment for matching variable names.
Dependencies
LFE modules:
lfe_env- Access to bindingslfe_scan- Tokenization
Erlang stdlib:
code,lists,string
Used By
lfe_shell- Viaio:setopts([{expand_fun, Fun}])
Special Considerations
Performance: Completion must be fast (< 100ms) for responsive UX.
Context Sensitivity: Understands LFE syntax to provide relevant completions.
Module Loading: Only completes for loaded modules (doesn't search filesystem).