diff options
author | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
commit | e0c6872cf40896c7be36b11dcc744620f10adf1d (patch) | |
tree | 60335e10d2f4354b0674ec22d7b53f0f8abee672 /graphics/asymptote/envcompleter.cc |
Initial commit
Diffstat (limited to 'graphics/asymptote/envcompleter.cc')
-rw-r--r-- | graphics/asymptote/envcompleter.cc | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/graphics/asymptote/envcompleter.cc b/graphics/asymptote/envcompleter.cc new file mode 100644 index 0000000000..9477a77f3c --- /dev/null +++ b/graphics/asymptote/envcompleter.cc @@ -0,0 +1,58 @@ +/***** + * envcompleter.cc + * Andy Hammerlindl 2006/07/31 + * + * Implements a text completion function for readline based on symbols in the + * environment. + *****/ + +#include <fstream> + +#include "table.h" +#include "envcompleter.h" + +namespace trans { + +bool basicListLoaded=false; +envCompleter::symbol_list basicList; + +static void loadBasicList() { + assert(basicListLoaded==false); + +#define ADD(word) basicList.push_back(symbol::literalTrans(#word)) +#include "keywords.cc" +#undef ADD + + basicListLoaded=true; +} + +void envCompleter::basicCompletions(symbol_list &l, string start) { + if (!basicListLoaded) + loadBasicList(); + + for (symbol_list::iterator p = basicList.begin(); p != basicList.end(); ++p) + if (prefix(start, *p)) + l.push_back(*p); +} + +void envCompleter::makeList(const char *text) { + l.clear(); + basicCompletions(l, text); + e.completions(l, text); + index=l.begin(); +} + +char *envCompleter::operator () (const char *text, int state) { + if (state==0) + makeList(text); + + if (index==l.end()) + return 0; + else { + symbol name=*index; + ++index; + return StrdupMalloc((string)name); + } +} + +} // namespace trans |