ExternalFactor is done
parent
97eeec4739
commit
a8975900bd
|
@ -26,12 +26,12 @@
|
|||
|
||||
+ listener/plugin:
|
||||
|
||||
- listener: if too many things popped off the stack, complain
|
||||
- gracefully handle non-working cfactor
|
||||
- don't show listener on certain commands
|
||||
- NPE in ErrorHighlight
|
||||
- some way to not have previous definitions from a source file
|
||||
clutter the namespace
|
||||
- finish ExternalFactor VocabularyLookup
|
||||
- maple-like: press enter at old commands to evaluate there
|
||||
- completion in the listener
|
||||
- special completion for USE:/IN:
|
||||
|
|
|
@ -115,6 +115,29 @@ public class ExternalFactor extends DefaultVocabularyLookup
|
|||
return new FactorStream(client);
|
||||
} //}}}
|
||||
|
||||
//{{{ getVocabularies() method
|
||||
public Cons getVocabularies()
|
||||
{
|
||||
Cons vocabs = super.getVocabularies();
|
||||
|
||||
try
|
||||
{
|
||||
Cons moreVocabs = (Cons)parseObject(eval("vocabs.")).car;
|
||||
while(moreVocabs != null)
|
||||
{
|
||||
String vocab = (String)moreVocabs.car;
|
||||
if(!Cons.contains(vocabs,vocab))
|
||||
vocabs = new Cons(vocab,vocabs);
|
||||
moreVocabs = moreVocabs.next();
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Log.log(Log.ERROR,this,e);
|
||||
}
|
||||
return vocabs;
|
||||
} //}}}
|
||||
|
||||
//{{{ searchVocabulary() method
|
||||
/**
|
||||
* Search through the given vocabulary list for the given word.
|
||||
|
@ -148,6 +171,39 @@ public class ExternalFactor extends DefaultVocabularyLookup
|
|||
}
|
||||
} //}}}
|
||||
|
||||
//{{{ getCompletions() method
|
||||
public void getCompletions(String vocab, String word, List completions,
|
||||
boolean anywhere)
|
||||
{
|
||||
super.getCompletions(vocab,word,completions,anywhere);
|
||||
|
||||
try
|
||||
{
|
||||
/* We can't send words across the socket at this point in
|
||||
human history, because of USE: issues. so we send name/vocab
|
||||
pairs. */
|
||||
Cons moreCompletions = (Cons)parseObject(eval(
|
||||
FactorReader.unparseObject(word)
|
||||
+ " "
|
||||
+ FactorReader.unparseObject(vocab)
|
||||
+ " "
|
||||
+ (anywhere ? "vocab-apropos" : "vocab-completions")
|
||||
+ " [ dup word-name swap word-vocabulary 2list ] map .")).car;
|
||||
|
||||
while(moreCompletions != null)
|
||||
{
|
||||
Cons completion = (Cons)moreCompletions.car;
|
||||
completions.add(searchVocabulary(completion.next(),
|
||||
(String)completion.car));
|
||||
moreCompletions = moreCompletions.next();
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Log.log(Log.ERROR,this,e);
|
||||
}
|
||||
} //}}}
|
||||
|
||||
//{{{ close() method
|
||||
/**
|
||||
* Close communication session. Factor will then exit.
|
||||
|
|
|
@ -220,35 +220,6 @@ public class FactorPlugin extends EditPlugin
|
|||
}
|
||||
} //}}}
|
||||
|
||||
//{{{ getCompletions() method
|
||||
/**
|
||||
* @param anywhere If true, matches anywhere in the word name are
|
||||
* returned; otherwise, only matches from beginning.
|
||||
*/
|
||||
public static List getCompletions(Iterator use, String word, boolean anywhere)
|
||||
{
|
||||
try
|
||||
{
|
||||
List completions = new ArrayList();
|
||||
|
||||
while(use.hasNext())
|
||||
{
|
||||
String vocab = (String)use.next();
|
||||
getExternalInstance().getCompletions(
|
||||
vocab,word,completions,anywhere);
|
||||
}
|
||||
|
||||
Collections.sort(completions,
|
||||
new MiscUtilities.StringICaseCompare());
|
||||
|
||||
return completions;
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} //}}}
|
||||
|
||||
//{{{ getCompletions() method
|
||||
/**
|
||||
* @param anywhere If true, matches anywhere in the word name are
|
||||
|
@ -358,14 +329,19 @@ public class FactorPlugin extends EditPlugin
|
|||
private static FactorWord[] findAllWordsNamed(View view, String word)
|
||||
throws Exception
|
||||
{
|
||||
ExternalFactor external = getExternalInstance();
|
||||
|
||||
ArrayList words = new ArrayList();
|
||||
Iterator vocabs = getExternalInstance().getVocabularies();
|
||||
while(vocabs.hasNext())
|
||||
|
||||
Cons vocabs = external.getVocabularies();
|
||||
while(vocabs != null)
|
||||
{
|
||||
Map vocab = (Map)vocabs.next();
|
||||
FactorWord w = (FactorWord)vocab.get(word);
|
||||
String vocab = (String)vocabs.car;
|
||||
FactorWord w = (FactorWord)external.searchVocabulary(
|
||||
new Cons(vocab,null),word);
|
||||
if(w != null)
|
||||
words.add(w);
|
||||
vocabs = vocabs.next();
|
||||
}
|
||||
return (FactorWord[])words.toArray(new FactorWord[words.size()]);
|
||||
} //}}}
|
||||
|
|
|
@ -79,6 +79,11 @@ USE: unparser
|
|||
2drop
|
||||
] ifte ;
|
||||
|
||||
: vocab-completions ( substring vocab -- list )
|
||||
#! Used by jEdit plugin. Like vocab-apropos, but only
|
||||
#! matches at the start of a word name are considered.
|
||||
words [ word-name over str-head? ] subset nip ;
|
||||
|
||||
: apropos. ( substring -- )
|
||||
#! List all words that contain a string.
|
||||
vocabs [ dupd vocab-apropos. ] each drop ;
|
||||
|
|
Loading…
Reference in New Issue