]> gitweb.factorcode.org Git - factor.git/commitdiff
ExternalFactor is done
authorSlava Pestov <slava@factorcode.org>
Thu, 25 Nov 2004 02:45:30 +0000 (02:45 +0000)
committerSlava Pestov <slava@factorcode.org>
Thu, 25 Nov 2004 02:45:30 +0000 (02:45 +0000)
TODO.FACTOR.txt
factor/ExternalFactor.java
factor/jedit/FactorPlugin.java
library/tools/word-tools.factor

index 8004ff5419ff300f8bbb35f2a0acf46db2682a28..7d0fcc48737d17b797f2724835ae94bdf65347d3 100644 (file)
 \r
 + listener/plugin:\r
 \r
+- listener: if too many things popped off the stack, complain\r
 - gracefully handle non-working cfactor\r
 - don't show listener on certain commands\r
 - NPE in ErrorHighlight\r
 - some way to not have previous definitions from a source file\r
   clutter the namespace\r
-- finish ExternalFactor VocabularyLookup\r
 - maple-like: press enter at old commands to evaluate there\r
 - completion in the listener\r
 - special completion for USE:/IN:\r
index 683ae9304d0165e340bf56eedb37068e3f896b45..b053554164af2ab896807673501c95fdebfaf049 100644 (file)
@@ -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.
index 28a0d415ff6353192b2e01f0ddd6a5613ee275bd..a25565d03d76b988556b1625b2e40156f29f9758 100644 (file)
@@ -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()]);
        } //}}}
index b5658b48fbac6da98fa8b3582fdc6dbf87abffda..4525eb40fa72500a420561d8ea99cc9673f2501c 100644 (file)
@@ -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 ;